akhauriyash/Code-Regression huggingface dataset:
let lcs x y =
  let m = String.length x in
  let n = String.length y in
  let dp = Array.make_matrix (m+1) (n+1) 0 in
  let rec duduwa i j =
    if j > n then doit (i + 1)
    else begin
      dp.(i).(j) <- if x.[i-1] = y.[j-1] then dp.(i-1).(j-1) + 1 else if dp.(i-1).(j) > dp.(i).(j-1) then dp.(i-1).(j) else dp.(i).(j-1);
      duduwa i (j + 1)
    end
  and doit i =
    if i > m then dp.(m).(n)
    else duduwa i 1
  in
  doit 1

let () =
  let q = read_int () in
  let rec doit i =
    if i < q then begin
      let x = read_line () in
      let y = read_line () in
      Printf.printf "%d\n" (lcs x y);
      doit (i + 1)
    end
  in
  doit 0

Measured memory_bytes: 18612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

typedef struct _button{
	int xl,yu,xr,yl;
	string name;
}button;


map<string, vector<button> > page;
vector<string> rireki;


main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		
		page.clear();
		rireki.clear();
		
		int W,H;
		cin>>W>>H;
		
		for(int i=0;i<n;i++){
			string name;
			int b;
			cin>>name>>b;
			if(i==0)rireki.push_back(name);
			for(int j=0;j<b;j++){
				int xl,xr,yu,yl;
				string tname;
				cin>>xl>>yu>>xr>>yl>>tname;
				button tbutton={xl,yu,xr,yl,tname};
				
				page[name].push_back(tbutton);
			}
		}
		
		int m;
		cin>>m;
		int p=0;
		
		for(int i=0;i<m;i++){
			string com;
			cin>>com;
			if(com=="click"){
				
				int x,y;
				cin>>x>>y;
				
				string target="";
				
				for(vector<button>::iterator vp=page[rireki[p]].begin();vp!=page[rireki[p]].end();++vp){
					if(vp->xr>=x && vp->xl<=x && vp->yu<=y && vp->yl>=y)target=vp->name;
				}
				
				if(target=="")continue;
				
				if(p==rireki.size()-1){
					rireki.push_back(target);
					++p;
					
					
				}else{
					++p;
					rireki[p]=target;
					while(p+1<rireki.size())rireki.pop_back();
				}
				
				
			}else if(com=="show"){
				cout<<rireki[p]<<endl;
			}else if(com=="back"){
				if(p)--p;
			}else if(com=="forward"){
				if(p<rireki.size()-1)++p;
			}
		}
		
	}
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int result = 6 - Integer.parseInt(br.readLine()) - Integer.parseInt(br.readLine());

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21076
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
long long  n,m;
long long  a[1000010];
long long  ans[1000010];
long long qwq;
map<long long ,long long  >cnt;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),ans[i]=ans[i-1]+a[i];
	cnt[0]=1;
	for(int i=1;i<=n;i++) {
		long long t=ans[i]%m;
		qwq+=cnt[t];
		++cnt[t];
	}
	printf("%lld",qwq);
	return 0;
}

Measured memory_bytes: 9088
a=[]

for i in range(5):
    a.append(int(input()))

k=int(input())
for i in range(5):
    for j in range(5):
        if(i==j):
            continue
        else:
            if(abs(a[i]-a[j])>k):
                print(':(')
                exit()

print('Yay!')


Measured memory_bytes: 3060
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int[] a, b, c, rev;
	int n, m, ans;

	void run(){
		// 10Â©ç5ÂIÔñP(10,5)=30240
		// 2^5=32p^[½]³¹éD½]³¹ÄàÏíçÈ¢àÌÍpX
		// 5Â©çÈép^[ÉÎ·éCp^[ðcè5ÂÅìêé©»è

		n=10;
		m=n/2;
		a=new int[n];
		rev=new int[1<<m];
		for(int i=0; i<1<<m; i++){
			int x=i;
			x=(x&0x55555555)<<1|(x>>1)&0x55555555;
			x=(x&0x33333333)<<2|(x>>2)&0x33333333;
			x=(x&0x0f0f0f0f)<<4|(x>>4)&0x0f0f0f0f;
			x=(x<<24)|((x&0xff00)<<8)|((x>>8)&0xff00)|(x>>24);
			rev[i]=(int)(x>>(32-m))&((1<<m)-1);
		}

		for(;;){
			for(int i=0; i<n; i++){
				String s=sc.next();
				if(s.equals("END")){
					return;
				}
				a[i]=Integer.parseInt(s, 2);
			}
			solve();
		}
	}

	void solve(){
		ans=0;
		int comb=(1<<m)-1;
		b=new int[m];
		c=new int[m];
		boolean[] used=new boolean[m];
		for(; comb<1<<n;){
			int div=1;
			for(int i=0, j=0, k=0; k<10; k++){
				if((comb>>k&1)==1){
					b[i++]=a[k];
					if(rev[a[k]]==a[k]){
						div*=2;
					}
				}else{
					c[j++]=a[k];
				}
			}

			Arrays.sort(b);
			int sum=0;
			for(;;){
				for(int sup=0; sup<1<<m; sup++){
					for(int i=0; i<m; i++){
						if((sup>>i&1)==1){
							b[i]=rev[b[i]];
						}
					}
					// bÌÀÑðcÅ\zÅ«é©
					Arrays.fill(used, false);
					sum++;
					// boolean f=true;
					for(int i=0; i<m; i++){
						int bits=0;
						for(int j=0; j<m; j++){
							bits=(bits<<1)|(b[j]>>i&1);
						}
						// debug(i, bits, Integer.toBinaryString(bits));

						int k=-1;
						for(int j=0; j<m; j++){
							if(!used[j]
									&&((c[j]^bits)==(1<<m)-1||(rev[c[j]]^bits)==(1<<m)-1)){
								k=j;
							}
						}

						if(k>=0){
							used[k]=true;
						}else{
							// f=false;
							sum--;
							break;
						}
					}

					for(int i=0; i<m; i++){
						if((sup>>i&1)==1){
							b[i]=rev[b[i]];
						}
					}
				}
				if(!nextPermutation(b)){
					break;
				}
			}

			if(sum!=0){
				// debug("sum", sum, "r", div);
			}
			ans+=sum/div;

			int x=comb&-comb, y=comb+x;
			comb=((comb&~y)/x>>1)|y;
		}
		// 8ÅêÎ¢¢ñ¶áËH
		ans/=8;
		// debug(ans);
		println(""+ans);
	}

	void swap(int[] is, int i, int j){
		int t=is[i];
		is[i]=is[j];
		is[j]=t;
	}

	void rev(int[] is, int i, int j){
		for(j--; i<j; i++, j--){
			int t=is[i];
			is[i]=is[j];
			is[j]=t;
		}
	}

	boolean nextPermutation(int[] is){
		int n=is.length;
		for(int i=n-1; i>0; i--){
			if(is[i-1]<is[i]){
				int j=n;
				while(is[i-1]>=is[--j]);
				swap(is, i-1, j);
				rev(is, i, n);
				return true;
			}
		}
		rev(is, 0, n);
		return false;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, m, d = MAP()
if d == 0:
	print((m-1)/n)
else:
	print(2*(n-d)/n/n*(m-1))


Measured memory_bytes: 5460
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)

int main() {
    int N,M;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    cin >> M;
    vector<int> B(M);
    rep(i, M) cin >> B[i];
    sort(A.begin(), A.end());
    int c = 0;
    rep(i, M) {
        auto it = lower_bound(A.begin(), A.end(), B[i]);
        if (it != A.end() && *it == B[i]) c++;
    }
    cout << c << endl;
    return 0;
}




Measured memory_bytes: 3396
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3604
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()
A.sort()


def solve():
    big = A[-1]
    small = A[0]
    res = []
    for i in range(1, N - 1):
        if A[i] > 0:
            res.append((small, A[i]))
            small -= A[i]
        else:
            res.append((big, A[i]))
            big -= A[i]
    res.append((big, small))
    print(big - small)
    for x, y in res:
        print(x, y)


solve()


Measured memory_bytes: 23260
from sys import stdin

a = int(stdin.readline().rstrip())


num = list(range(1,10))

for i in num[::-1]:
    if a/int(i) > 10:
        print('No')
        break
    else:
        if a%int(i)==0 and a//int(i) < 10:
            print('Yes')
            break
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int opt;

void dfs(vector<int> v,int k)
{
    bool flag = true;
    rep(i,v.size()){
        if(v[i] != k){
            flag = false;
        }
    }
    if(flag){
        opt = max(opt,(int)v.size());
        return;
    }
    vector<int> u;
    rep(i,v.size()-1){
        if(v[i] == k || v[i+1] == k){
            u.push_back(k);
        }else{
            u.push_back(v[i]);
        }
    }
    dfs(u,k);
}

int main()
{
    opt = -1;
    string s;
    cin >> s;
    vector<int> vec(s.length());
    int flag[27];
    rep(i,27){
        flag[i] = 0;
    }
    rep(i,s.length()){
        vec[i] = (int)(s[i] - 'a');
        flag[(int)(s[i] - 'a')] = 1;
    }
    rep(i,27){
        if(flag[i] == 1){
            dfs(vec,i);
        }
    }
    cout << s.length() - opt << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int H, W;
	string S;
	cin >> H >> W;
	char column;
	int row;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> S;
			if(S == "snuke"){
				column = 'A' + j;
				row = i + 1;
			}
		}
	}
	cout << column << row << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii; 
#define fst first
#define snd second 
#define pb(a) push_back(a) 
#define mp(a, b) make_pair(a, b) 
#define debug(...) fprintf(stderr, __VA_ARGS__) 

template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; inline void read(int& x) { x = 0; char ch = getchar(); for(;!isdigit(ch); ch = getchar()); for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; } const int N = 500000; string procStatus() { ifstream t("/proc/self/status"); return string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()); } int n; int a[N + 5], w[N + 5]; bool chk() { static int vis[N + 5]; for(int i = 1; i <= n; ++i) if(!vis[i]) { vis[i] = i; for(int j = a[i]; j; j = a[j]) { if(vis[j] == i) return true; if(vis[j]) break; vis[j] = i; } } return false; } int fa[N + 5]; int find(int x) { return (x == fa[x]) ? x : fa[x] = find(fa[x]); } struct node { int sz0, sz1, id; node() { } node(int s0, int s1, int _id): sz0(s0), sz1(s1), id(_id) { } inline bool operator < (const node& b) const { return (ll)sz1 * b.sz0 > (ll)b.sz1 * sz0; } }; 

int main() { 
	read(n); 
	for(int i=2;i <=n;++i) 
		read(a[i]);
	for(int i=1;i<=n;++i)
		read(w[i]);
	static node q[N + 5]; 
	static node cur[N + 5]; 
	int cnt = 0;
	for(int i=1;i<=n;++i)
		fa[i] =i;
	for(int i=1;i<= n; ++i)
	{
		cur[i]=node((w[i]==0), (w[i] == 1), i); if(i > 1) q[++ cnt] = cur[i]; } make_heap(q + 1, q + cnt + 1); ll ans = 0; while(cnt) { node temp = q[1]; pop_heap(q + 1, q + cnt-- + 1); if(temp.sz0 != cur[temp.id].sz0 || temp.sz1 != cur[temp.id].sz1) continue; int u = temp.id, f = find(a[u]); fa[u] = f; ans += (ll)cur[f].sz1 * temp.sz0; cur[f] = node(temp.sz0 + cur[f].sz0, temp.sz1 + cur[f].sz1, f); if(f) { q[++ cnt] = cur[f]; push_heap(q + 1, q + cnt + 1); } } printf("%lld\n", ans); return 0; } 


Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N,M;
    cin >> N >> M;
    vector<pair<long,int>> items(N);

    for(auto i = 0; i < N; i++){
        cin >> items[i].first >> items[i].second;
    }

    sort(items.begin(), items.end());

    int buy = 0;
    unsigned long long ans = 0;
    
    for(int i =0; i < N; i++){
        if(buy + items[i].second >= M){
            ans += (M - buy) * items[i].first;
            cout << ans;
            return 0;
        }
        else{
            ans += items[i].first * items[i].second;
            buy += items[i].second;
        } 

    }

    
}

Measured memory_bytes: 1792
# ABC136C

n = int(input())
h = list(map(int, input().split()))
h = h[::-1]
ans = "Yes"
for i in range(len(h)-1):
    if h[i] < h[i+1]:
        if h[i]+1 == h[i+1]:
            h[i+1] -= 1
        else:
            ans = "No"
            break
print(ans)


Measured memory_bytes: 14396
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int n;


int main()
{
    scanf("%d",&n);
    set<int> s;
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        s.insert(x);
    }
    printf("%d",s.size()%2==0 ? s.size()-1:s.size());
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
using namespace std;



int main(int argc, const char * argv[]) {
    // insert code here...
    int s;
    int second, minute,hour;
    
    
    
    cin >> s;
    
    second = s%60;
    minute = (s/60)%60;
    hour = (s/60)/60;
    
    cout << hour << ":" << minute << ":" << second << endl;
    
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s, ans;
  int cnt=0, cnt2=0;
  cin >> s;

  for (int i=1; i<s.size(); i++) {
    if (i>=2 && i<s.size()-1) {
      if (s[i]=='C') cnt++;
    }
    if (s[i]>='A' && s[i]<='Z') {
      cnt2++;
    }
  }
  if (cnt!=1 or cnt2!=1 or s[0]!='A') {
    cout << "WA" << endl;
    return 0;
  }

  cout << "AC" << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())

A=list(map(int,input().split()))

if N==1:
    print(0)
    exit()
elif N==2:
    B=[A[0]-1,A[1]-2]
    b=sum(B)//2
else:
    B=[]
    for i in range(N):
        B.append(A[i]-(1+i))
    #print(B)
    B.sort()
    #print(B)
    b=B[N//2]

ans=0
for i in range(N):
    ans+=abs(A[i]-(b+1+i))
print(ans)

Measured memory_bytes: 99668
#include <stdio.h>
int main(void){
  char a[3];
  int count=0,countt=0;
  for(int k=0;k<3;k++){
    scanf("%s",&a[k]);
  if(a[k]=='R'){
    count++;
  }else{
    if(countt<count)
    countt=count;
    count=0;
  }
  }
  if(countt<count)
    countt=count;
  printf("%d",countt);
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始

int main(){
    int x;
    cin>>x;
    int n = x/100;//回数
    int r = x%100;//余り
    int ansflg = 1;
    // 最低限必要な回数
    int count = r/5;
    if(r%5>0) count+=1;
    if(count>n) ansflg = 0;
    cout<<ansflg<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 500000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	string s,t;
	cin>>s>>t;
	int ans=0;
	REP(i,3){
		if(s[i]==t[i])ans++;
	}
	OUT(ans);
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut cnt: i32 = 0;
    let mut another_count = 0;
    let n = read();
    for _ in 0..n {
        cnt += 1;
        let now: i32 = read();
        if now != cnt {
            if another_count == 0 {
                another_count = now;
                continue;
            }
            if another_count != cnt {
                println!("NO");
                return;
            }
            continue;
        }
    }
    println!("YES");
}


Measured memory_bytes: 4352
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9
struct Puzzle{
  int f[N2];
  int space;
  string path;
  bool operator < (const Puzzle &p) const{
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i]) continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};
static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};
bool isTarget(Puzzle p){
  for(int i=0;i<N2;i++)
    if(p.f[i] != (i+1)) return false;
  return true;
}
string bfs(Puzzle s){
  queue<Puzzle>Q;
  map<Puzzle,bool>V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;
  while(!Q.empty() ){
    u=Q.front();Q.pop();
    if(isTarget(u))return u.path;
    int sx=u.space/N;
    int sy=u.space%N;
    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N) continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
	v.space=tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path += dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}
int main(){
  Puzzle in;
  for(int i=0;i<N2;i++){
    cin >> in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=bfs(in);
  cout << ans.size() << endl;
  return 0;
}
	 		  



Measured memory_bytes: 30532
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
  ll a,b;
  cin>>a>>b;
  cout<<((a==2||b==2)?"No":"Yes")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = 3.14159265359;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int a[N];

void solve(){
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for (int i = k+1; i <= n; i++){
        if (a[i-k] < a[i]){
            cout << "Yes" << ndl;
        }
        else{
            cout << "No" << ndl;
        }
    }
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 4440
n=int(input())

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def affine(a,b,word):
    retval=""
    for w in word:
        retval+=chr(ord('a')+((ord(w)-ord('a'))*a+b)%26)
    return retval

for i in range(n):
    encrypted=input().split(" ")
    for a in range(1,27):
        for b in range(1,27):
            if GCD(a,26)!=1:
                continue
            plain=[affine(a,b,s) for s in encrypted]
            if ("this" in plain) or ("that" in plain):
                print(" ".join(plain))
                break



Measured memory_bytes: 5600
//IDA*(Iterative Deepening A*)
//MD=manhattan direction
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

const int N=4;
const int N2=16;
const int LIMIT=45;

const int dx[4]={-1,0,1,0};
const int dy[4]={0,-1,0,1};
const char dir[4]={'u','l','d','r'};

int MDT[N2][N2];

class puzzle
{
public:
	int f[N2];
	int space;
	int MD;
};

puzzle state;
int limit;
int path[LIMIT];

int getallMD(puzzle p)
{
	int sum=0;
	for(int i=0;i<N2;i++)
	{
		if(p.f[i]==N2)continue;
		sum+=MDT[i][p.f[i]-1];
	}
	return sum;
}

bool istarget()
{
	for(int i=0;i<N2;i++)if(state.f[i]!=i+1)return false;
	return true;
}

bool dfs(int depth,int prev)
{
	if(state.MD==0)return true;
	if(depth+state.MD>limit)return false;
	
	int sx=state.space/N;
	int sy=state.space%N;
	puzzle tmp;
	
	for(int r=0;r<4;r++)
	{
		int tx=sx+dx[r];
		int ty=sy+dy[r];
		if(tx<0||tx>=N||ty<0||ty>=N)continue;
		if(abs(prev-r)==2)continue;
		tmp=state;
		state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
		state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
		swap(state.f[sx*N+sy],state.f[tx*N+ty]);
		state.space=tx*N+ty;
		if(dfs(depth+1,r)){path[depth]=r;return true;}
		state=tmp;
	}
	
	return false;
}

string IDA(puzzle in)
{
	in.MD=getallMD(in);
	
	for(limit=in.MD;limit<=LIMIT;limit++)
	{
		state=in;
		if(dfs(0,-3))
		{
			string ans="";
			for(int i=0;i<limit;i++)ans+=dir[path[i]];
			return ans;
		}
	}
	return "unsolvable";
}

int main()
{
	for(int i=0;i<N2;i++)
	{
		for(int j=0;j<N2;j++)
		{
			MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
		}
	}
	
	puzzle in;
	
	for(int i=0;i<N2;i++)
	{
		cin>>in.f[i];
		if(in.f[i]==0)
		{
			in.f[i]=N2;
			in.space=i;
		}
	}
	
	string ans=IDA(in);
	
	if(ans!="unsolvable")cout<<ans.length()<<endl;
	else cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3152
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)

using namespace std;


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    int i,j,p=1,q=1;
    long n,m,tmp;
    int a[10000];
    string s[200000];
    string str;
    string strstr[205];
    string strs;
    char c;
    int strr[200005];
    ll k;
    ll sum=0;
    ll sumof=0;
    ll kei=0;
    int f=0;

    cin >> str >>k;
    strs=str+str;
    //strs.resize(sizeof(strs));
    //str.resize(sizeof(str));
        if(str.length()==1){
        kei=k/2;
        cout<<kei<<endl;
        return 0;
    }
    for(i=1;str[i]!='\0';i++){
        if(str[i-1]!=str[i]) f=1;
    }
    if(f==0){
        if(str.length()%2==1){
            cout<<str.length()*k/2<<endl;
            return 0;
        }
    }
    for(i=0;str[i]!='\0';i++){
        if(i==0){
            c=str[i];
        }else{
            if(c==strs[i]&&c==strs[i+1]){
                sumof++;
                i++;
            }else if(c==str[i]){
            //    cout<<i<<endl;
                sumof++;
            } 
            c=str[i];
        }
    }
    if(k==1){
        cout<<sumof<<endl;
        return 0;
    }
    for(i=0;strs[i]!='\0';i++){
        if(i==0){
            c=strs[i];
        }else{
            if(c==strs[i]&&strs[i]==strs[i+1]){
                sum++;
                i++;
            }else if(c==strs[i]){
              //  cout<<i<<endl;
                sum++;
            } 
            c=strs[i];
        }
    }

    kei=(k-1)*(sum-sumof)+sumof;
    //cout<<sumof<<endl;
    //cout<<str<<endl;
    cout<<kei<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
  ll n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  vector<int> num(1000000,0);
  num[0] = 2;
  ll ans = 0;

  REP(i,n) {
    ll p = a[i];
    if (num[p] != 0){
      num[p] = 2;
      continue;
    }
    for (ll j = p; j <= pow(10,6); j += p){
      ++num[j];
    }
  }

  REP(i,n){
    if (num[a[i]] == 1) ++ans;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7964
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<bool> dp(10001, 0);
    dp[0] = 1;
    for(int i=0;i<n;i++){
        int x = a[i];
        for(int j=10000;j>=0;j--){
            if(j-x>=0 && dp[j-x])
                dp[j] = true;
        }
    }
    int maxx = 0;
    for(int i=10000;i>=0;i--){
        if(i%10 && dp[i]){
            maxx = i;
            break;
        }
    }
    cout << maxx << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


ll c, d;
ll f(ll n) {
    ll g = __gcd(c, d);
    g = c / g * d;
    ll nt = n / c + n / d - n / g;
    return n - nt;
}


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

//    int n, l;
//    cin >> n >> l;
//    int a[n];
//    for (int i = 1; i <= n; i++) {
//        a[i] = i - 1 + l;
//    }
//
//
//    int ans = accumulate(a + 1, a + n + 1, 0);
//    sort(a + 1, a + n + 1, f);
//    cout << ans - a[1];


    ll a, b;
    cin >> a >> b >> c >> d;
//    cout << f(b);
    cout << f(b) - f(a - 1);







}

Measured memory_bytes: 256
def f(a,b,c)
h,*t=a
a==[]||h>b[-1]&&f(t,b+[h],c)||h>c[-1]&&f(t,b,c+[h])
end
gets.to_i.times{puts f(gets.split.map(&:to_i),[0],[0])?:YES: :NO}

Measured memory_bytes: 6104
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

/** 累積和 */
template<typename T>
vector<T> calc_csum(vector<T> &val) {
	vector<T> sum(val.size() + 1);
	partial_sum(val.begin(), val.end(), sum.begin() + 1);
	return sum;
}

template<typename T>
T sum_csum(vector<T> &sum, int begin, int end) {
	return sum[end] - sum[begin];
}

template<typename T>
vector< vector<T> > calc_csum2(vector< vector<T> > &val) {
	int H = val.size();
	int W = val[0].size();
	vector< vector<T> > sum(H + 1, vector<T>(W + 1));

	for (int y = 0; y < H; y++) {
		partial_sum(val[y].begin(), val[y].end(), sum[y + 1].begin() + 1);
	}

	for (int y = 0; y < H; y++) {
		for (int x = 0; x <= W; x++) {
			sum[y + 1][x] += sum[y][x];
		}
	}

	return sum;
}

template<typename T>
T sum_csum2(vector< vector<T> > &sum, int y1, int y2, int x1, int x2) {
	return sum[y2][x2] - sum[y2][x1] - sum[y1][x2] + sum[y1][x1];
}

/** /累積和 */


typedef tuple<int, int, int, int> Kukei;

int H, W, S;
int total_power;
VVI tile;
VVI c_tile;
vector< vector< vector< vector<PII> > > > memo;

bool can_group(int x1, int x2, int y1, int y2) {
	return total_power - S <= sum_csum2<int>(c_tile, y1, y2, x1, x2);
}

PII dfs(int x1, int x2, int y1, int y2) {
	PII tmp = memo[y1][x1][y2][x2];
	if (tmp.first != -1) {
		return tmp;
	}
	
	PII res(-1, -1);

	if (!can_group(x1, x2, y1, y2)) {
		return memo[y1][x1][y2][x2] = res;
	}

	for (int v = x1 + 1; v < x2; v++) {
		if (!can_group(x1, v, y1, y2) || !can_group(v, x2, y1, y2)) {
			continue;
		}

		PII a = dfs(x1, v, y1, y2);
		PII b = dfs(v, x2, y1, y2);

		res = max(res, make_pair(a.first + b.first, min(a.second, b.second)));
	}

	for (int h = y1 + 1; h < y2; h++) {
		if (!can_group(x1, x2, y1, h) || !can_group(x1, x2, h, y2)) {
			continue;
		}

		PII a = dfs(x1, x2, y1, h);
		PII b = dfs(x1, x2, h, y2);

		res = max(res, make_pair(a.first + b.first, min(a.second, b.second)));
	}

	if (res.first == -1) {
		res = make_pair(1, sum_csum2<int>(c_tile, y1, y2, x1, x2));
	}

	return memo[y1][x1][y2][x2] = res;
}

int main(void) {
	while(cin >> H >> W >> S, H) {
		tile = VVI(H, VI(W, 0));
		total_power = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> tile[i][j];
				total_power += tile[i][j];
			}
		}

		memo = vector< vector< vector< vector<PII> > > >(H + 1,
				vector< vector< vector<PII> > >(W + 1,
				vector< vector<PII> >(H + 1,
				vector<PII>(W + 1,
				make_pair(-1, -1)))));

		c_tile = calc_csum2<int>(tile);

		PII ans = dfs(0, W, 0, H);

		cout << ans.first << " " << (S - total_power + ans.second) << endl;
	}

	return 0;
}

Measured memory_bytes: 19592
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

	int h, cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> h;
		if (h >= k) cnt++;
	}

  	cout << cnt << endl;	
  
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	string s;
	cin >> s;
	if(s.size() == 2 && s[0] == s[1]){
		cout << "1 2" << endl;
		return 0;
	}
	if(s.size() >= 3 && s[0] == s[1]){
		cout << "1 3" << endl;
		return 0;
	}
	for(int i = 2; i < s.size(); i++){
		if(s[i-1] == s[i]){
			cout << i-1 << ' ' << i+1 << endl;
			return 0;
		}
	}
	for(int i = 1; i < s.size()-1; i++){
		if(s[i-1] == s[i+1]){
			cout << i << ' ' << i+2 << endl;
			return 0;
		}
	}
	cout << "-1 -1" << endl;
	return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve():
    # implement process
    pass

def main():
    # input
    n, *a = open(0).read().split()
    
    # process
    s_list = list(a)
    s_set = set()
    for s in s_list:
      s_set.add(s)
    
    ans = str( len( s_set) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
5
grape
grape
grape
grape
grape
"""
_EXPECTED = """\
1
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 39308
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cfloat>
#include <cstring>
#include <cctype>
#include <queue>
using namespace std;


int h, w;
char field[52][52];
int tbl[52][52];
vector<int> ps;
vector<char> cs;
int dp[522][522];

bool reachable(){
	bool visit[52][52] = {};
	queue<int> q;
	q.push(1 << 8 | 1);
	while( !q.empty() ){
		int y = q.front() >> 8;
		int x = q.front() & 255;
		q.pop();
		if(y == h && x == w) return true;

		if( field[y + 1][x] != '#' ){
			if( !visit[y+1][x] ){
				visit[y+1][x] = true;
				q.push(y + 1 << 8 | x);
			}
		}
		if( field[y][x + 1] != '#' ){
			if( !visit[y][x+1] ){
				visit[y][x+1] = true;
				q.push(y << 8 | x + 1);
			}
		}
	}
	return false;
}

void add_edge(int p, vector<int> &e){
	bool visit[52][52] = {};
	queue<int> q;
	q.push(p);

	while( !q.empty() ){
		p = q.front();
		q.pop();

		int y = p >> 8;
		int x = p & 255;
		
		for(int i = 0; i < 2; ++i){
			int ny = y + i;
			int nx = x + (1 - i);

			if( !visit[ny][nx] ){
				visit[ny][nx] = true;
				if( tbl[ny][nx] != -1 ){
					if( tbl[ny][nx] == -2 ){
						q.push(ny << 8 | nx);
					}
					else{
						e.push_back(tbl[ny][nx]);
					}
				}
			}
		}
	}
}


int main(){
	vector<int>::iterator it1, it2;

	while( scanf("%d%d", &h, &w), h != 0 ){
		memset(field, '#', sizeof field);
		memset(tbl, -1, sizeof tbl);

		for(int i = 1; i <= h; ++i){
			scanf(" %s", field[i] + 1);
			field[i][w+1] = '#';
		}

		if( !reachable() ){
			puts("-1");
			continue;
		}

		if( field[1][1] == '.' ){
			field[1][1] = '~';
		}
		if( field[h][w] == '.' ){
			field[h][w] = '~';
		}

		ps.clear();
		cs.clear();
		for(int i = 1; i <= h; ++i){
			for(int j = 1; j <= w; ++j){
				if( field[i][j] == '.' ){
					tbl[i][j] = -2;
				}
				else if( field[i][j] != '#' ){
					tbl[i][j] = ps.size();
					ps.push_back(i << 8 | j);
					cs.push_back( field[i][j] );
				}
			}
		}

		for(int i = 0; i < ps.size(); ++i){
			for(int j = 0; j < ps.size(); ++j){
				dp[i][j] = i == j ? 0 : -10000;
			}
		}

		vector<vector<int> > G(ps.size());
		vector<vector<int> > rG(ps.size());
		for(int i = 0; i < ps.size(); ++i){
			add_edge(ps[i], G[i]);

			for(it1 = G[i].begin(); it1 != G[i].end(); ++it1){
				rG[*it1].push_back(i);
				dp[i][*it1] = (cs[i] == cs[*it1] + 32);
			}
		}

		for(int d = 2; d < ps.size(); ++d)
		for(int i = 0; i + d < ps.size(); ++i){
			int j = i + d;

			int t = dp[i][j];

			if( cs[i] == cs[j] + 32 ){
				for(it1 = G[i].begin(); it1 != G[i].end(); ++it1)
				for(it2 = rG[j].begin(); it2 != rG[j].end(); ++it2){
					t = max(t, dp[*it1][*it2] + 1);
				}
			}

			for(int k = i; k < j; ++k){
				t = max(t, dp[i][k] + dp[k][j]);
			}
			dp[i][j] = t;
		}

		printf("%d\n", dp[0][ps.size() - 1] );

	}
}

Measured memory_bytes: 2676
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()

bool chk[10050];
int main() {
	int N, K, i, j;
	scanf("%d %d", &N, &K);
	for (i = 0; i < K; i++) {
		scanf("%d", &j);
		chk[j] = true;
	}
	for (int i = N;; i++) {
		int t = i;
		while (t) {
			if (chk[t % 10]) break;
			t /= 10;
		}
		if (!t) return !printf("%d\n", i);
	}
}

Measured memory_bytes: 256
# ...###のようにする
N = int(input())
S = input()

white_change_counts = [-1] * (N + 1)
black_change_counts = [-1] * (N + 1)
max_count = -1
white_change_counts[0] = 0
black_change_counts[0] = S.count('.')
min_count = white_change_counts[0] + black_change_counts[0]

for index in range(1, N + 1):
    if S[index - 1] == ".":
        white_change_counts[index] = white_change_counts[index - 1]
        black_change_counts[index] = black_change_counts[index - 1] - 1
    else:
        white_change_counts[index] = white_change_counts[index - 1] + 1
        black_change_counts[index] = black_change_counts[index - 1]

    count = white_change_counts[index] + black_change_counts[index]
    if min_count > count:
        min_count = count

print(min_count)


Measured memory_bytes: 12808
/*
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
*/
#include <bits/stdc++.h>

#define rep(i,n)  for(int i=0; i<(n); i++)
using ll = long long;
using namespace std;

int main()
{
  int a,b;
  string s,t,u;
  cin >> s >> t >> a >> b >> u;
  if(s == u){
      a--;
  }
  if(t == u){
    b--;
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 384
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let s:String = read();
    let len = s.chars().count();
    if s.chars().skip(2).take(len-3).filter(|&x| x=='C').count() == 1 {
        if s.chars().nth(0).unwrap()== 'A'{
            if s.chars().filter(|&x| x.is_lowercase()).count() == (len-2){
                println!("AC");
                return;
            }
        }
    }
    println!("WA");
}

Measured memory_bytes: 4352
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function mkdivisorpair(n::Int)
  divisors=[]
  for i=1:div(n^0.5,1)
    if n%i==0
      push!(divisors,(Int(i),Int(n/i)))
    end
  end
  sort!(divisors)
  return divisors
end
function main()
  d=mkdivisorpair(pI(readline()))
  ans=100000
  for i in d
    ans=min(ans,max(ndigits(i[1]),ndigits(i[2])))
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 168332
#include<cstdio>
#include<cmath>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005,P=200003;
struct Complex
{
	double x,y;
	inline Complex(const double& X=0,const double& Y=0) { x=X; y=Y; }
	friend inline Complex operator + (const Complex& A,const Complex& B)
	{
		return Complex(A.x+B.x,A.y+B.y);
	}
	friend inline Complex operator - (const Complex& A,const Complex& B)
	{
		return Complex(A.x-B.x,A.y-B.y);
	}
	friend inline Complex operator * (const Complex& A,const Complex& B)
	{
		return Complex(A.x*B.x-A.y*B.y,A.x*B.y+A.y*B.x);
	}
	inline void operator /= (const double& p)
	{
		x/=p; y/=p;
	}
}b[P<<2]; int n,a[N],g,lg[N],rg[P],cnt,cur; long long ans;
inline int quick_pow(int x,int p,int mul=1)
{
	for (;p;p>>=1,x=1LL*x*x%P) if (p&1) mul=1LL*mul*x%P; return mul;
}
inline int getroot(CI x=P)
{
	RI i,j; for (i=2;i<=x-2;++i) if ((x-1)%i==0) rg[++cnt]=i;
	for (i=2;;++i)
	{
		bool flag=1; for (j=1;j<=cnt;++j)
		if (quick_pow(i,rg[j])==1) { flag=0; break; }
		if (flag) return i;
	}
}
namespace Poly
{
	const double pi=acos(-1);
	int lim,p,rev[P<<2];
	inline void init(CI n)
	{
		for (lim=1,p=0;lim<=n;lim<<=1,++p);
		for (RI i=0;i<lim;++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<p-1);
	}
	inline void FFT(Complex *f,CI opt)
	{
		RI i,j,k; for (i=0;i<lim;++i) if (i<rev[i]) swap(f[i],f[rev[i]]);
		for (i=1;i<lim;i<<=1)
		{
			Complex D(cos(pi/i),sin(pi/i)*opt);
			for (j=0;j<lim;j+=(i<<1))
			{
				Complex W(1,0); for (k=0;k<i;++k,W=W*D)
				{
					Complex x=f[j+k],y=f[i+j+k]*W;
					f[j+k]=x+y; f[i+j+k]=x-y;
				}
			}
		}
		if (!~opt) for (i=0;i<lim;++i) f[i]/=lim;
	}
};
int main()
{
	RI i; for (g=getroot(P),cur=1,i=0;i<P-1;++i,(cur*=g)%=P) lg[cur]=i;
	for (scanf("%d",&n),i=1;i<=n;++i) scanf("%d",&a[i]),a[i]&&(b[lg[a[i]]].x+=1.0);
	for (Poly::init(P<<1),Poly::FFT(b,1),i=0;i<Poly::lim;++i) b[i]=b[i]*b[i];
	for (Poly::FFT(b,-1),i=1;i<P;++i) ans+=1LL*i*(long long)(b[lg[i]].x+b[lg[i]+P-1].x+0.5);
	for (i=1;i<=n;++i) ans-=1LL*a[i]*a[i]%P; return printf("%lld",ans>>1LL),0;
}

Measured memory_bytes: 20168
#!/bin/python

import os
import sys


def solution(D, N):
    res = str(N) if N<100 else str(N+1)
    for i in range(D):
        res += "00"
    return res
    
if __name__ == '__main__':
    bnm = raw_input().split()
    D = int(bnm[0])
    N = int(bnm[1])
    result = solution(D,N)

    print str(result)

Measured memory_bytes: 2568
//Name : Rupa Dey
  //Date : 13 September 2020
//joi sri gour hori gobindo...
//gobindo ja hobe vlor jonnoi hobe..
#include<bits/stdc++.h>
#define ll long long
#define d double
#define ld long double
#define vi vector<int>
#define vul vector<ull>
#define vl vector<ll>
#define pb push_back
#define si set<int>
#define sl set<ll>
#define yes cout<<"YES\n"<<endl
#define no cout<<"NO\n"<<endl
#define ys cout<<"Yes\n"<<endl
#define n0 cout<<"No\n"<<endl
#define test cin>>t; while(t--)
#define for(i,a,n) for(i=a;i<n;i++)
#define mp make_pair
#define ft first
#define sc second
#define gp ' ';
#define MAX 9999999
#define MOD 1000000007
#define nd endl
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x,y,tot=0,i,j,k;
    cin>>x;
    if(x==0) cout<<"1"<<nd;
    else
        cout<<"0"<<nd;


}
//hare krishna...
//hey gobindo kripa koro......
//only gobindo exists..^..


Measured memory_bytes: 3652
//package com.company;
import java.io.*;
import java.util.*;
//public class Aatc {
    public class Main {
    public static void main(String[] args) {

        out = new PrintWriter(new BufferedOutputStream(System.out));
        MyScanner sc = new MyScanner();//start
        int a=sc.nextInt();
        int sum=1000-(a%1000);
        out.println(sum=(sum==1000)?0:sum);
        out.close();
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------

}


Measured memory_bytes: 33040