prompt
string
response
string
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
def reversi(N: int, C: list)->int: MOD = 10**9 + 7 dp = [0] * (N+1) dp[0] = 1 lefts = {} for i, c in enumerate(C): if c in lefts and lefts[c] != i: dp[i+1] = (dp[i] + dp[lefts[c]]) % MOD else: dp[i+1] = dp[i] lefts[c] = i+1 return dp[N] if __name...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.*; public class Main { int N; int[] C; Map<Integer, List<Integer>> indexes; static final long MOD = 1000000007; long result; long[] memo; long add(long a, long b) { return (a + b) % MOD; } Main() { Scanner in = new Scanner(System.in); N = Integer.parseInt(in.nextLine()); C = new int...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] c = new int[n]; HashMap<Integer,ArrayList<Integer>> map = new HashMap<>(); int[] place = new int[n]...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
N = int(input()) MOD = 10**9 + 7 C = [int(input()) for i in range(N)] dp = [0] * (N+1) dp[0] = 1 last_idx = {} for i, c in enumerate(C, 1): dp[i] = dp[i-1] if c in last_idx: idx = last_idx[c] if idx != i - 1: dp[i] += dp[idx] dp[i] %= MOD last_idx[c] = i print(dp[-1]%MOD)
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <iostream> using namespace std; typedef long long ll; int N,C[200010]; int col_id[200010] = {}; int col_sum[200010] = {}; ll dp[200010] = {},inf = 1e9+7; int main(){ cin >> N; int c; for(int i=1;i<=N;i++){ cin >> C[i]; } dp[0] = 1; for(int i=1;i<=N;i++){ (dp[i] += dp[i-...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int last,x,n,c[200019]; ll ans; int main() { cin >> n; ans=1; last=-1; for(int i=0; i<n; i++){c[i]=0;} for(int i=0; i<n; i++){ cin >> x; if(x==last){continue;} last=x; ans = (ans+c[x])%1000000007; c[x]=ans; } cou...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
# include "iostream" # include "cstdio" using namespace std; const int maxm=2e5+10; const int Mod=1e9+7; int N,C[maxm]; long long DP[maxm],Add[maxm]; int main(){ register int i; scanf("%d",&N); for(i=1;i<=N;i++) scanf("%d",C+i); Add[C[1]]=1; for(i=1;i<=N;i++){ DP[i]=Add[C[i]]; if(C[i]==C[i+1]) continue; ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; //const int MOD=998244353; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector<int> v(n); for(int&i:v) cin>>i; vector<long long> dp(2e5+1); dp[v[0]]=1; for(int i=1; i<n...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.*; public class Main { private static final long MOD_CONST = 1000000007; private static long mul(long a, long b) { return (a * b) % MOD_CONST; } private static long add(long a, long b) { return (a + b) % MOD_CONST; } private static ArrayList<Integer> runLengthCompressio...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i) #define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i) int main(){ int N; cin >> N; const LL mod = 1e9+7; LL ans = 1; vector<LL> x(2e5+1,0); int b = 0; repp(i,0,N){ int c...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <stdio.h> #include <iostream> #include <vector> using namespace std; const int N=200010,mod=(int)1e9+7; int a[N],f[N],s[N]; vector<int> pos[N]; int main(){ int n,i,x,m=0,j; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&x); if(x!=a[m]) a[++m]=x; } s[a[1]]=1; for(i=1;i<=m;i++){ f[i]=s[a[i]]; s[a[i...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include<cstdio> using namespace std; const int mod = 1e9 + 7; int f[200005], lp[200005], sp[200005], a[200005], n, in; int main() { scanf("%d", &n), f[0] = 1; for(register int i = 1; i <= n; ++i) scanf("%d", &a[i]); for(register int i = 1; i <= n; ++i) { f[i] = f[i - 1]; if(a[i + 1] == a[i]) continue; (f[i...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.*; import java.util.*; import java.util.Map.Entry; public class Main { final boolean isDebug = false; String fileName = "input.txt"; FastScanner sc; //PrintWriter out; final int MOD = (int)1e9+7; final int INF = Integer.MAX_VALUE / 2; /* solve */ void solve() throws Exception{ int N = sc....
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
N = int(input()) C = [-1] for _ in range(N): c = int(input()) if c == C[-1]: continue else: C.append(c) MOD = 10**9+7 dp = 1 prev = [0]*(max(C)+1) for c in C[1:]: dp = (dp+prev[c]) % MOD prev[c] = dp print(dp)
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#!/usr/bin/python3 # -*- coding:utf-8 -*- def main(): MAX = 10**9 + 7 n = int(input()) lc = [int(input()) for _ in range(n)] dp = [0] * (n) last_is = [-1]*(2*10**5+1) dp[0] = 1 last_is[lc[0]] = 0 for i,c in enumerate(lc[1:], 1): last_i = last_is[c] dp[i] = dp[i-1] if last_i != -1 and ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
from collections import defaultdict MOD = int(1e9) + 7 def main(): N = int(input()) C = [int(input()) for _ in range(N)] dp = [1] * (N+1) last = defaultdict(lambda: -1) for i in range(N): c = C[i] if last[c] != -1 and last[c] != i-1: dp[i+1] = (dp[i] + dp[last[c]+1]) %...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <iostream> using namespace std; #define MOD 1000000007 #define MAXN 200010 typedef long long ll; int n; ll dp[MAXN]; ll sum[MAXN]; int c[MAXN]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> c[i]; dp[0] = 1; sum[c[0]] = 1; for (int i = 1; i < n; i++) { if (c[i] != c[i-1]...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.*; public class Main{ public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int[] last=new int[200000]; Arrays.fill(last,Integer.MAX_VALUE); long[]dp=new long[n+1]; dp[0]=1; for(int i=1;i<=n;++i) { int v=s.nextInt()-1; if(last[v]<i-1) { ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; #define M 200005 typedef long long ll; int A[M],B[M]; ll dp[M],tot[M]; const ll P=1e9+7; int main() { int n,m=0; scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",A+i); for(int i=1;i<=n;++i) if(A[i]!=A[i-1]) B[++m]=A[i]; dp[0]=1; for(int i=1;i<=m;++i) { dp[i]=(dp...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
from collections import defaultdict N = int(input()) stones = [] last = None n_stone = 0 for i in range(N): stone = int(input()) if stone != last: stones.append(stone) last = stone count = defaultdict(int) seq = 1 for i, c in enumerate(stones): prev = count[c] count[c] = prev + seq...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include<bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; typedef long long LL; const int maxn=2e5+5; const LL mo=1e9+7; int n,a[maxn]; LL f[maxn],s[maxn]; int main() { scanf("%d",&n); fo(i,1,n) scanf("%d",&a[i]); f[0]=1; fo(i,1,n) { f[i]=f...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.*; import java.io.*; class Mod{ static final int MOD = 1000_000_007; static final long[] fact = makeFactorialArray(1000000); static final long[] factInv = makeInversedArray(fact); public static long add(long a, long b){ long tmp = (a+b)%MOD; return tmp>=0 ? tmp : tmp+MO...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> #define MOD 1000000007 using namespace std; int main() { int n, x; int pre = 0, cur = 1; map<int, int> last; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); if (x == pre) { continue; } if (last.count(x) != 0) { cur = 1LL * (cur + last[x]) % MOD; } last[...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
MOD = 10**9 + 7 N = int(input()) C = [] for i in range(N): c = int(input())-1 if not C or C[-1] != c: C.append(c) N = len(C) prev = [None]*(max(C)+1) dp = [0]*(N+1) dp[0] = 1 for i,c in enumerate(C): if prev[c] is None: dp[i+1] = dp[i] else: dp[i+1] = dp[i] + dp[prev[c]+1] ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import sys n=int(input()) c=[int(i) for i in sys.stdin] x=[0]*(200001) c.append(0) x[c[0]]+= 1 num=1 p=10**9 +7 for i in range(1,n): if c[i]-c[i-1]: x[c[i]]+= num x[c[i]]= x[c[i]]%p if c[i]-c[i+1]: num=x[c[i]]%p else: num=0 print(num)
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include<cstdio> #define mod 1000000007 #define maxn 200005 int n,val[maxn],dp[maxn],la[maxn],pos[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&val[i]); la[i]=pos[val[i]],pos[val[i]]=i; } dp[0]=1; for(int i=1;i<=n;i++) { dp[i]=dp[i-1]; if(val[i]!=val[i-1]&&la[i]) dp[i]=(dp[i]+dp...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n = int(input()) mod = 10**9+7 count = [0]*(2*10**5+1) l = [0]+[int(input()) for i in range(n)] dp = [0]*(n+1) dp[0] = 1 for i in range(1,n+1): if l[i] == l[i-1]: dp[i] = dp[i-1] continue dp[i] = (dp[i-1]+count[l[i]])%mod count[l[i]] = dp[i] print(dp[-1])
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main { private static final long MOD = 1_000_000_007; public static void main(final String[] args) {...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 2e5+10; const int MOD = 1e9+7; int a[MAX_N],b[MAX_N]; ll dp[MAX_N],sum[MAX_N]; int n; void solve() { n = unique(a+1,a+n+1)-(a+1); dp[0] = 1LL; for(int i=1; i<=n; i++){ dp[i] = dp[i-1]; (dp[i]+=sum[a[i]])%=MOD; (sum[a[i]...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import sys from collections import defaultdict from itertools import groupby read = sys.stdin.read N, *C = map(int, read().split()) C = [i for i, _ in groupby(C)] mod = 10 ** 9 + 7 cnt = defaultdict(int) dp = 1 for idx, i in enumerate(C): prev = dp dp = (cnt[i] + dp) % mod cnt[i] = (cnt[i] + prev) % mod ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; const int maxn=2e5+1; const int md=1e9+7; void inc(int &x,int y){ x=x+y>=md?x+y-md:x+y; } int n,c[maxn],f[maxn]; vector<int>son[maxn]; int pos[maxn],tot; int cnt[maxn]; int main(){ scanf("%d",&n); for (int i=1,x;i<=n;++i){ scanf("%d",&x); if (x!=c[tot]) c[++tot]=x...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <cstdio> // B - Reversi #define MOD 1000000007 using namespace std; int C[200005]; int cnt[200005]; int main() { int N,i,ans; scanf("%d",&N); ans = 1; for (i = 1;i <= N;i++) { scanf("%d",&C[i]); if (C[i] != C[i - 1]) { ans += cnt[C[i]]; ans %= M...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import sys input = sys.stdin.readline N = int(input()) C = [int(input()) for _ in range(N)] mod = 10 ** 9 + 7 newC = [] while C: c = C.pop() if not newC or newC[-1] != c: newC.append(c) N = len(newC) seen = [0] * (2*10 ** 5 + 10) dp = [0] * (N + 1) dp[0] = 1 seen[newC[0]] = 1 for i, c in enumerate(n...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> #define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i]; typedef long long int ll; using namespace std; ll mod=1e9+7 ; ll dp[200010]; int chnum[200010]; int main(){ int n;cin>>n; dp[0]=1; for(int i=0;i<n;){ i++; int C; cin>>C; dp[i]=dp[i-1]+(chnum[C]!=0&&chnum[C]<i-1?dp[chnum[C]]:0...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n=int(input());d=[0]*200001;a=1;b=0 for i in range(n): c=int(input()) if b!=c: a+=d[c] d[c]=a b=c print(a%(10**9+7))
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <cstdio> #include <algorithm> using namespace std; #define N 200000 + 5 #define Mod 1000000007 int n, Dp[N], Last[N]; int main() { scanf("%d", &n); Dp[0] = 1; for (int i = 1, x; i <= n; i ++) { scanf("%d", &x); Dp[i] = Dp[i - 1]; if (Last[x] && Last[x] != i - 1) Dp[i] = (Dp[i] + Dp[Last[x]]) % M...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.HashMap; import java.util.Map; public class Main { private static void solve() { int n = ni(); int[] c = na(n); long[] dp = new long[n]; Map<Integer, Integer> map = new HashMap<>(); int mod = (int)1e9+7; dp[0] = 1; map.put(c[0], 0); for (int i = 1; i < n; i ++) { ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { static PrintWriter out; static InputReader ir; static boolean debug = true; static void solve() { in...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.HashMap; import java.util.Scanner; class Problem { private int N; private int[] C; private final int MOD = (int) 1e9 + 7; Problem() { Scanner sc = new Scanner(System.in); N = sc.nextInt(); C = new int[N]; for (int i = 0; i < N; i++) { C[i] =...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
from collections import deque mod = 10**9 + 7 N = int(input()) C = [int(input()) for i in range(N)] dq = deque() dq.append(C[0]) for c in C: if c != dq[-1]: dq.append(c) C = list(dq) N = len(C) dp = [0]*(N+1) dp[0] = 1 acc = [0]*(2*pow(10,5)+1) for i in range(1,N+1): dp[i] = dp[i-1] dp[i] += acc[C[i...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
N = int(input()) DP = [0] * (N+1) DP[0] = 1 su = [0] * (2*(10**5)+1) prev = None MOD = 10**9+7 for i in range(N): C = int(input()) if prev == C: DP[i+1] = DP[i] else: su[C] += DP[i] su[C] %= MOD DP[i+1] = su[C] DP[i+1] %= MOD prev = C print(DP[N])
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import sys readline = sys.stdin.readline N = int(readline()) MOD = 10**9 + 7 last = [-1]*(3*10**5) dp = [0]*(N+1) dp[0] = 1 for i in range(1, N+1): c = int(readline()) if last[c] != -1 and last[c]+1 < i: dp[i] = (dp[last[c]] + dp[i-1]) % MOD else: dp[i] = dp[i-1] last[c] = i print(dp[N]...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include<bits/stdc++.h> #define M 200005 #define ll long long using namespace std; const int mod=1e9+7; int n,col[M],num[M]; ll dp[M],sum[M]; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&col[i]); int len=0; for(int i=1;i<=n;++i) if (col[i]!=col[i-1]) num[++len]=col[i]; for(int i=1;i<=len;++i){ ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n = int(input()) mod = 10**9 + 7 dict = dict() list = [] res = 1 for i in range(n): x = input() list.append(x) if x in dict and list[i - 1] != x: res += dict[x] dict[x] = res elif x not in dict: dict[x] = res print(res % mod)
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import sys MOD = 10**9 + 7 N = int(input()) Cs = [int(sys.stdin.readline())-1 for _ in range(N)] numCs = [0] * (2 * 10**5) anss = [0] * N numCs[Cs[0]] = 1 anss[0] = 1 for i, C in enumerate(Cs[1:], 1): if C == Cs[i-1]: anss[i] = anss[i-1] else: numCs[C] += anss[i-1] anss[i] = numCs[C] ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include<iostream> using namespace std; int main(){ int N; cin>>N; int C[N+1],S[200001]; long int dp[N+1]; dp[1]=1; for(int i=1; i<200001; ++i) S[i]=0; for(int i=1; i<=N; ++i){ cin>>C[i]; } S[C[1]]=1; for(int i=1; i<N; ++i){ if(C[i]==C[i+1]) dp[i+1]=dp[i]; else if(S[C[i+1]]==0) dp[i+1]=...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main(void) { LL p = 1000000007; int n; cin >> n; vector<int> cs(n); for(int &c: cs) cin >> c; cs.erase(std::unique(cs.begin(), cs.end()), cs.end()); vector<LL> pre(212345); LL tmp = 1; for(int c: cs) { tmp = tmp + pre[c]; ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5+10; const ll mod = 1e9+7; int c[N],pos[N]; ll dp[N]; int main(void) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&c[i]); if(i==1) { dp[i]=1; pos[c[i]]=i; continue; } if(c[i]==c[i-1]) { dp[i]=d...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; #define LL long long int N; int A[200010], pre[200010], suc[200010], H[200010], f[200010]; LL pp = (1e9) + 7; int main(){ cin >> N; for (int i = 1; i <= N; i++){ cin >> A[i]; pre[i] = H[A[i]]; suc[H[A[i]]] = i; H[A[i]] = i; } f[N] = 1; for (int i = N - 1; i >...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
MOD = 10 ** 9 + 7 n = int(input()) c = [int(input()) for _ in range(n)] l = [c[0]] for i in range(1, n): if c[i] != c[i - 1]: l.append(c[i]) n = len(l) p = [-1] * (max(c) + 1) q = [-1] * n for i, x in enumerate(l[::-1]): q[n - i - 1] = p[x] p[x] = n - i - 1 dp = [0] * (n + 1) dp[0] = 1 for i in rang...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> #define PI 3.14159265358979323846264338327950288419 using namespace std; const int mod = 1000000007; int n, c[200005]; int dp[200005], sum_dp_col[200005]; int main(){ scanf("%d", &n); dp[0] = 1; for(int i = 1; i <= n; i++){ scanf("%d", &c[i]); dp[i] = dp[i - 1]; if(i == 1 || (c[i]...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.util.*; import java.io.*; import static java.lang.System.in; public class Main { static int n,m; static long mod = 1000000000+7; // static ArrayList<Integer>[] graph,tree; public static void main(String[] args)throws IOException { //BufferedReader reader = new BufferedReader(new Inp...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { new Main().go(); } PrintWriter out; Reader in; BufferedReader br; Main() throws IOException { ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <iostream> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define vec vector #define ll long long #define MOD 1000000007 int main(void) { int n; cin >> n; vec<int> c(n + 1); c[0] = 200005; rep(i, n) cin >> c[i + 1]; vec<ll> s(200010, 0); s[c[0]] = 1;...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n = int(input()) c = [-1] + [int(input()) for i in range(n)] count = [0]*(200005) dp = [0]*(n+1) dp[0] = 1 mod = 10**9+7 #dp[i]: i番目までの場合の数 for i in range(n): dp[i+1] = dp[i] if c[i+1] != c[i]: dp[i+1] += count[c[i+1]] dp[i+1] %= mod count[c[i+1]] += dp[i] count[c[i+1]] %= mod ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.*; import java.util.*; import java.util.function.Function; public class Main { static int N; static int[] C; public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); N = sc.nextInt(); C = sc.nextIntArray(N); System.out.println(s...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include<bits/stdc++.h> #define M 200005 #define ll long long using namespace std; const int P=1e9+7; int n,s[M],B[M],m=0; ll pr[M],dp[M]; int main(){ cin>>n; for(int i=1;i<=n;i++) scanf("%d",&s[i]); for(int i=1;i<=n;i++) if(s[i]!=s[i-1])B[++m]=s[i]; n=m; dp[0]=1; for(int i=1;i<=n;i++){ dp[i]=(dp[i-1]+pr[B[...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; imp...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.HashMap; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelpe...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
N = int(input()) C = [int(input()) for _ in range(N)] mod = 10 ** 9 + 7 D = [] prev = -1 for ci in C: if prev != ci: D.append(ci) prev = ci M = len(D) dic = dict() dp = [1] * M for i in range(M): if D[i] in dic: temp = dp[dic[D[i]]] dp[i] = (dp[i - 1] + temp) % mod else: ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <bits/stdc++.h> using namespace std; int main() { const int mod = 1000000007; int n, patterns = 1, prev = 0; cin >> n; vector<int> p(200001); for (int i = 0; i < n; i++) { int c, w; cin >> c; if (c == prev) continue; w = (patterns + p.at(c)) % mod; patterns = w; p.at(c) = w; ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n=int(input()) arr=[int(input()) for _ in range(n)] mod=10**9+7 dp=[0]*n dp[0]=1 record={arr[0]:0} for i,v in enumerate(arr): if i==0: continue dp[i]=dp[i-1] if v in record and record[v]<i-1: dp[i]+=dp[record[v]] dp[i]=dp[i]%mod record[v]=i print(dp[-1])
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n = int(input()) iro = [-1 for i in range(2*(10**5)+1)] dp = [1 for i in range(n+1)] mod = 10**9 + 7 for i in range(1,n+1): dp[i] = dp[i-1] now = int(input()) if iro[now] != -1 and iro[now] != i-1: dp[i] += dp[iro[now]] iro[now] = i dp[i] %= mod print(dp[n])
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n = int(input()) z = [] pre = 0 for _ in range(n): i = int(input()) if i != pre: z.append(i) pre = i n = len(z) dp = [1] * (n+1) dpp = [0] * 2 * 10 ** 5 for i in range(n): dp[i+1] = dp[i] + dpp[z[i]-1] dpp[z[i]-1] += dp[i] dp[i+1] %= 10 ** 9 + 7 print(dp[n])
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
import java.io.*; import java.util.*; public class Main implements Runnable { FastReader scn; PrintWriter out; String INPUT = ""; void solve() { int n = scn.nextInt(), mod = 1000_000_000 + 7; int[] arr = work(n); n = arr.length; HashMap<Integer, Integer> map = new HashMap<>(); map.put(arr[1], 1); ...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
#include <cstdio> #include <cstring> const int N = 2e5 + 10; const int MOD = 1e9 + 7; int lst[N], f[N]; int main() { int n; memset(lst, 0, sizeof lst); scanf("%d", &n); f[0] = 0; for (int i = 1; i<= n; ++i) { int a; scanf("%d", &a); f[i] = f[i - 1]; if (lst[a] != 0 && lst[a] != i - 1) f[i] =(f[i] + f...
Problem: There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possibl...
n = int(input()) C = [] MOD = 10 ** 9 + 7 pre = -1 for i in range(n): a = int(input()) if a != pre: C.append(a) pre = a N = len(C) dp = [0] * (N + 1) col = {} pre = -1 dp[0] = 1 for i in range(1, N + 1): if C[i - 1] not in col: dp[i] = dp[i - 1] col[C[i - 1]] = dp[i] else: ...
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
s = input() print(s.translate(str.maketrans({"1": "9", "9": "1"})))
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); str = str.replace("1","*").replace("9","1").replace("*","9"); System.out.println(str); } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include <iostream> using namespace std; int main() { string n; cin>>n; cout<<10-(n[0]-'0')<<10-(n[1]-'0')<<10-(n[2]-'0')<<endl; return 0; }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
print(''.join(map(lambda x:str(int(x)^8),input())))
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
for i in input(): print('9' if i=='1' else '1',end="")
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include <iostream> using namespace std; int main(){ int N; cin >> N; cout << 1110 - N; }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); String t = ""; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '1') { t += "9"; } if (c == '9') { t += "1"; } } ...
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include <iostream> using namespace std; int main() { int n; cin >> n; cout << 1110 - n << '\n'; return 0; }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include <bits/stdc++.h> using namespace std; int main() { int R; cin >> R; cout << 1110-R << endl; }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N =sc.nextInt(); System.out.println(1110-N); } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
n=input() rn=n.translate(str.maketrans({"1":"9","9":"1"})) print(rn)
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
print(input().replace('9','2').replace('1','9').replace('2','1'))
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String nn = String.valueOf(n); int[] nnn = new int[3]; for (int i = 0; i <= 2; i++) { if (nn.charAt(i) == '1') { nnn[i] = 9; } else { nnn[i] = 1; } } ...
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
S = input() for i in S: print(10 - int(i),end='') print()
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include<iostream> using namespace std; int main() { int n; while(cin>>n) { cout<<1110-n<<endl; } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[3]; a[0] = n / 100; a[1] = (n - n / 100 * 100) / 10; a[2] = n % 10; for (int i = 0; i < a.length; i++) { if (a[i] == 1) { a[i] = 9...
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include<iostream> int main(){ int A; std::cin >> A; std::cout << 1110-A << std::endl; return 0; }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.*; public class Main{ public static void main(String[] args)throws Exception{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println(1110 - n); } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s=scan.nextLine(); String t=""; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='1')t+='9'; else t+="1"; } System.out.println(t); } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
n = input() for i in n: print("1" if i=="9" else "9",end="")
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); System.out.println(1110 - n); } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include <stdio.h> int main(){ int n; scanf("%d",&n); printf("%d",1110-n); return 0; }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
#include <iostream> using namespace std; int main() { int a,b; cin>>a; b=1110-a; cout<<b; return 0; }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
s = input() print(*['9' if i == '1' else '1' for i in s], sep='')
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
print(input().replace("1","8").replace("9","1").replace("8","9"))
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int n100 = n / 100; int n10 = (n / 10) % 10; int n1 = n % 10; System.out.print(10 - n100); System.out.print(1...
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); s = s.replaceAll("1", "2"); s = s.replaceAll("9", "3"); s = s.replaceAll("2", "9"); s = s.replaceAll("3", "1"); System.out.println(s); } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println(1110-n); } }
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
# -*- coding: utf-8 -*- n = int(input()); print( 1110 - n )
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
print(input().replace("1","*").replace("9","1").replace("*","9"))
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
d={"9":"1","1":"9"} print("".join([d[x]for x in input()]))
Problem: Cat Snuke is learning to write characters. Today, he practiced writing digits `1` and `9`, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit `1` with `9` and each digit `9` with `1` in n. Constraints * 111 \leq n \l...
print("".join(list(map(lambda x: "9" if x=="1" else "1", input()))))