akhauriyash/Code-Regression huggingface dataset:
K=int(input())
num=7

#10と互いに素ではない数は必ずあまりが出る
if K%2==0 or K%5==0:
  print(-1)
  exit()

i=1
while 1:
  num=num%K
  if num==0:
    print(i)
    break
  num = 10*num + 7
  i+=1


Measured memory_bytes: 9048
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include<regex>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	string s; cin >> s;

	int x = 0, y = s.size()-1, ans = 0;
	//xを無視した文字列が回文だったら、xを挿入して回文にできる。

	//左と右から順番にみていって、xが出たほうだけ何もせずに進める。
	//xとxでないものの数だけxを挿入してあげないといけないので、ansをインクリメント
	//xでないものとxでないものがあったら、同じでないといけない。
	//同じなら両側とも進めて、違うなら-1を代入して終了。

	while (x < y) {
		if (s[x] == 'x') {
			if (s[y] == 'x') { x++; y--; }
			else { ans++; x++; }
		}
		else if(s[y]=='x')
		{
			ans++; y--;
		}
		else if (s[x] == s[y]) { x++; y--; }
		else { ans = -1; break; }

	}
	
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
char s[2][3];
int i,j;
int flag = 1;
  for(i=0;i<2;i++){
    for(j=0;j<3;j++){
        scanf("%c",&s[i][j]);
        if(j==2) getchar();
  }
  }
  // printf("%s%s",s[0],s[1]);
for(i=0;i<3;i++){
    if(s[0][i]!=s[1][2-i]) flag = 0;
}
if(flag) printf("YES");
else printf("NO");
return 0;}


Measured memory_bytes: 128
A, B, C, K = map(int, input().split())

if A <= K:
    ans = 1 * A
    K = K - A
else:
    ans = K
    print(ans)
    exit(0)

if 0 < K:
    ans = ans + 0 * B
    K = K - B

if 0 < K:
    ans = ans + (-1) * K

print(ans)

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

int main() {
    int N;
    string S;
    cin >> N;

    string arare = "Three";

    for(int i=0;i<N;i++) {
        cin >> S;
        if(S == "Y") {
            arare = "Four";
            break;
        }
    }

    cout << arare << endl;
}


Measured memory_bytes: 256
// AOJ 1070 FIMO sequence
// 2018.3.22 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
while (c < '0') c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define FH   0        // First half
#define SH   1        // Second half
#define ALL  2
#define MAX 200005

int que[2][MAX]; int qt[2], qe[2];
int min[2][MAX]; int at[2], ae[2];
int max[2][MAX]; int zt[2], ze[2];
#define size(id)  (qe[id]-qt[id])
#define minSZ(id) (ae[id]-at[id])
#define maxSZ(id) (ze[id]-zt[id])

int del(int id);
void add(int id, int a)
{
	if (id == ALL) {
		add(SH, a);
		if (size(FH) < size(SH)) add(FH, del(SH));
		return;
	}
	que[id][qe[id]++] = a;
	if (size(id) == 1) {
		min[id][ae[id]++] = a, max[id][ze[id]++] = a;
	} else if (id == FH) {
		if (min[id][ae[id]-1] > a) min[id][ae[id]++] = a;
		if (max[id][ze[id]-1] < a) max[id][ze[id]++] = a;
	} else {
		while (minSZ(id) > 0 && min[id][ae[id]-1] > a) ae[id]--;
		while (maxSZ(id) > 0 && max[id][ze[id]-1] < a) ze[id]--;
		min[id][ae[id]++] = a, max[id][ze[id]++] = a;
	}
}

int del(int id)
{
	int a;
	if (id == ALL) {
		a = del(FH);
		if (size(FH) < size(SH)) add(FH, del(SH));
	} else if (id == FH) {
		a = que[id][--qe[id]];
		if (min[id][ae[id]-1] == a) ae[id]--;
		if (max[id][ze[id]-1] == a) ze[id]--;
	} else {
		a = que[id][qt[id]++];
		if (min[id][at[id]] == a) at[id]++;
		if (max[id][zt[id]] == a) zt[id]++;
	}
	return a;
}

int gmin(int id, int th)
{
	if (id == FH) return min[id][ae[id]-th];
	else          return min[id][at[id]+th-1];
}

int gmax(int id, int th)
{
	if (id == FH) return max[id][ze[id]-th];
	else          return max[id][zt[id]+th-1];
}

int main()
{
	int q, op, a;

    while (q = in()) {
		qt[FH] = qt[SH] = qe[FH] = qe[SH] = 0;
		at[FH] = at[SH] = ae[FH] = ae[SH] = 0;
		zt[FH] = zt[SH] = ze[FH] = ze[SH] = 0;

		while (q--) {
			op = in();
			if      (op == 0) { add(ALL, in()); continue; }
			else if (op == 1) a = del(ALL);
			else if (op == 2) a = gmin(FH, 1);
			else if (op == 3) a = gmin(SH, 1);
			else if (op == 4) a = gmin(FH, in());
			else if (op == 5) a = gmin(SH, in());
			else if (op == 6) a = gmax(FH, 1);
			else if (op == 7) a = gmax(SH, 1);
			else if (op == 8) a = gmax(FH, in());
			else              a = gmax(SH, in());
			printf("%d\n", a);
		}
		puts("end");
	}
	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll modncr(ll n,ll r){
  if(r*2>n)return modncr(n,n-r);
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,N,K,a,ans=0;
  cin>>N>>K;
  vec v(N,0);
  rep(i,N){
    cin>>a;
    v[a-1]++;
  }
  vsort(v);
  rep(i,N-K){
    ans+=v[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1920
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

char s[maxn];

int main()
{
	scanf("%s",s+1); int len=strlen(s+1);
	rep(i,1,len)
	{
		if(s[i]=='?') printf("D");
		else printf("%c",s[i]);
	}
	return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define int long long

struct UnionFind{
    vector<int> par;
    vector<int> siz;

    UnionFind(int n): par(n), siz(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    int size(int x){
        return siz[root(x)];
        
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx != ry){
            par[ry] = rx;
            siz[rx] += siz[ry];
        }
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }
};

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    UnionFind uf(n);
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        uf.unite(a[i], b[i]);
    }

    int ans = 0;

    set<int> st;
    for(int i=0; i<n; i++){
        st.insert(uf.root(i));
    }

    cout << st.size()-1 << endl;



    return 0;
}

Measured memory_bytes: 8436
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static int solve (char[] c) {
		if (c.length == 1) return c[0] - '0';
		String ret = "";
		for (int i = 0; i < c.length - 1; i++)
			ret += ((c[i] - '0') + (c[i + 1] - '0')) % 10;
		return solve(ret.toCharArray());
	}

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

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {
			System.out.println(solve(line.toCharArray()));
			line = null;
		}

	}

}

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

int main(){
  string S;
  cin >> S;
  
  if(S=="SSS") cout << 0 << endl;
  else if(S=="SRR" || S=="RRS") cout << 2 << endl;
  else if(S=="RRR") cout << 3 << endl;
  else cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        ll a,b,c,d;cin>>a>>b>>c>>d;
        c--;
        
        ll n=a+b;
        
        if(a==b){
            for(ll i=c;i<d;i++){
                if(i&1) cout<<'B';
                else cout<<'A';
            }
            cout<<endl;
            continue;
        }
        
        ll k=(a+b)/(min(a,b)+1);
        if(a<b){
            if((a+1)*k==b){
                for(ll i=c;i<d;i++){
                    if(i%(k+1)==k) cout<<'A';
                    else cout<<'B';
                }
                cout<<endl;
                continue;
            }
        }
        if(a>b){
            if((b+1)*k==a){
                for(ll i=c;i<d;i++){
                    if(i%(k+1)==k) cout<<'B';
                    else cout<<'A';
                }
                cout<<endl;
                continue;
            }
        }
        
        ll left=0,right=a+b;
        while(right-left>1){
            ll mid=(left+right)/2;
            
            ll rea=a,reb=b;
            rea-=mid*k;
            reb-=mid;
            
            bool ok=true;
            
            if(rea<0||reb<0) ok=false;
            
            if(rea<reb){
                if((rea+1)*k-1<reb) ok=false;
            }
            
            if(ok) left=mid;
            else right=mid;
        }
        
        a-=left*k;
        b-=left;
        
        assert(a>=0);
        assert(b>=0);
        
        ll left2=0,right2=min(k,a+1);
        
        while(right2-left2>1){
            ll mid=(left2+right2)/2;
            
            ll rea=a-mid,reb=b;
            
            bool ok=true;
            
            if(rea<0) ok=false;
            else if(rea==0){
                if(reb>k) ok=false;
            }else{
                if(a>=b){
                    if((reb+1)*k-mid>=rea) ok=true;
                    else ok=false;
                }else{
                    if((rea+1)*k>=reb) ok=true;
                    else ok=false;
                }
            }
            
            if(ok) left2=mid;
            else right2=mid;
        }
        
        a-=left2;
        
        //cout<<left<<" "<<left2<<endl;
        
        for(ll i=c;i<d;i++){
            if(i<left*(k+1)){
                if(i%(k+1)==k) cout<<'B';
                else cout<<'A';
            }else if(i<left*(k+1)+left2){
                cout<<'A';
            }else{
                if((n-i)%(k+1)==0) cout<<'A';
                else cout<<'B';
            }
        }
        cout<<endl;
        
    }
}


Measured memory_bytes: 3640
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)
while 1:
    h,w=map(int,stdin.readline().rstrip().split())
    if (h,w)==(0,0):
        break
    a=[stdin.readline().rstrip() for _ in range(h)]
    s=input()
    nx,ny=0,0
    o=0
    cnt=0
    for i in s:
        nh=0
        for j in range(h):
            if i in a[j]:
                o=a[j].index(i)
                cnt+=(abs(nx-o)+abs(ny-nh)+1)
                break
            else:
                nh+=1
        nx,ny=o,nh
    print(cnt)


Measured memory_bytes: 6552
import numpy as np
N, M = map(int, input().split())
mat = np.zeros((N, N))
for i in range(M):
    a, b = map(int, input().split())
    mat[a-1][b-1] += 1
    mat[b-1][a-1] += 1

ans = np.sum(mat, axis=1)
for i in range(N):
    print(int(ans[i]))


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

int s[200001];
int a[200001];
int main()
{

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        a[i] = s[i];
    }
    sort(s + 1, s + n + 1, greater<int>());

    for (int i = 1; i <= n; ++i)
    {
        if (a[i] < s[n / 2])
            cout << s[n / 2] << endl;
        else
            cout << s[n / 2 + 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, m;
vector <string> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    a.resize(n);
    for(auto &i : a) cin >> i;
    for(auto &i : a){
        bool b = 0;
        for(int j = 0 ; j < m ; j++){
            if(i[j] == '.') continue;
            if(b) finish("Impossible");
            while(j < m && i[j] == '#') j++;
        }
    }
    int x = 0, y = 0;
    while(x != n - 1 || y != m - 1){
        a[x][y] = '.';
        if(y + 1 < m && a[x][y + 1] == '#') y++;
        else if(x + 1 < n && a[x + 1][y] == '#') x++;
        else break;
    }
    a[x][y] = '.';
    for(auto &i : a){
        for(auto &j : i){
            if(j != '.') finish("Impossible");
        }
    }
    cout << "Possible" << endl;
}


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

using namespace std;

using int64 = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cout << fixed << setprecision(12);

  int n;
  double a;
  double d;
  cin >> n >> a >> d;

  double ans = 0;
  while (n > 0) {
    ans += (a + (2 * n - 1) / 2.0 * d);
    double na = (2 * a * n + 2 * a + 5 * d) / (2 * n);
    double nd = (2 * d * n + 4 * d) / (2 * n);
    a = na;
    d = nd;
    n--;
    // cout << "ans: " << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int n;
string s;
long long gogo[20000];
long long MAX_MOD = 0;
int solve(int len) {
	long long dying = 1;
	int itr = 0;
	long long now = 0;
	for (int q = 0; q < s.length(); ++q) {
		now *= 26LL;
		now += s[q] - 'a';
		now %= MAX_MOD;
		if (q >= len) {
			now += (MAX_MOD - ((dying * (s[q - len] - 'a') % MAX_MOD))) % MAX_MOD;
			now %= MAX_MOD;
		}
		else {
			dying *= 26LL;
			dying %= MAX_MOD;
		}
		if (q >= len - 1) {
			gogo[itr] = now;
			itr++;
		}
	}
	set<long long> nya;
	for (int i = itr - len - 1; i >= 0; --i) {
		nya.insert(gogo[i + len]);
		if (nya.find(gogo[i]) != nya.end()) return true;
	}
	return false;
}
int main() {
#define int long long
	cin >> n >> s;
	MAX_MOD = 1e9 + 9;
	int bot = 0;
	int top = s.length();
	while (top - bot > 1) {
		int mid = (top + bot) / 2;
		if (solve(mid) == true) {
			bot = mid;
		}
		else top = mid;
	}
	long long final_ans = bot;
	for (long long q = 0; q <= 100; ++q) {
		MAX_MOD = 1e9 + 10 + q;
		int bot = 0;
		int top = s.length();
		while (top - bot > 1) {
			int mid = (top + bot) / 2;
			if (solve(mid) == true) {
				bot = mid;
			}
			else top = mid;
		}
		final_ans = min(final_ans, bot);
	}
	cout << final_ans << endl;
}


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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int counter = 0;
		vector< vector<int> > hyou(n, vector<int>(5));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> hyou[i][j];
			}
		}
		bool hantei = true;
		while (hantei) {
			hantei = false;
			for (int i = n-1; i >= 0; i--) {
				for (int j = 0; j < 3; j++) {
					if(hyou[i][j] != 0 && hyou[i][j] == hyou[i][j+1] && hyou[i][j] == hyou[i][j+2]) {
						hantei = true;
						if (j < 2 && hyou[i][j] == hyou[i][j+3]) {
							if (j < 1 && hyou[i][j] == hyou[i][j+4]) {
								counter += (hyou[i][j] * 5);
								hyou[i][0] = hyou[i][1] = hyou[i][2] = hyou[i][3] = hyou[i][4] = 0;
								break;
							}
							counter += (hyou[i][j] * 4);
							hyou[i][j] = hyou[i][j+1] = hyou[i][j+2] = hyou[i][j+3] = 0;
							break;
						}
						counter += (hyou[i][j] * 3);
						hyou[i][j] = hyou[i][j+1] = hyou[i][j+2] = 0;
						break;
					}
				}
			}
			for (int i = 0; i < 5; i++) {
				for (int j = n-1; j >= 0; j--) {
					if (hyou[j][i] == 0) {
						for (int k = j-1; k >= 0; k--) {
							if (hyou[k][i] != 0) {
								hyou[j][i] = hyou[k][i];
								hyou[k][i] = 0;
								break;
							}
						}
					}
				}
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
  //init();
    run();
    return 0;
}


void run(){
  int a,b;
  scanf("%02lld%02lld",&a,&b);
  bool ym=false,my=false;
  if(1<=b&&b<=12)ym=true;
  if(1<=a&&a<=12)my=true;
  if(ym&&my)puts("AMBIGUOUS");
  else if(ym)puts("YYMM");
  else if(my)puts("MMYY");
  else puts("NA");
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string N;
  cin>>N;
  if(N=="AAA"||N=="BBB")
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <list>
using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int main() 
{
	int a, b;

	cin >> a >> b;

	int c = a;
	int numTaps = 1;

	if (b == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	while (c < b)
	{
		c -= 1;
		c += a;
		++numTaps;
	}

	cout << numTaps << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	string a,b,c;
	cin>>a>>b>>c;
    int d=a.size(),e=b.size(),f=c.size();
  
    if(a[d-1]==b[0]&&b[e-1]==c[0])cout<<"YES";
    else cout<<"NO";
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RREP(i,n) RFOR(i,0,n)

const int _N = 3e5 + 100;

int n;

int d[_N];
int main(){
	cin >> n;
	REP(i, n){
		cin >> d[i];
		d[i] /= 10;
	}

	int i=0, cango=0;
	for(;i <= min(cango, n-1);i++){
		cango = max(cango, i+d[i]);
	}
	if(cango<n){
		cout << "no" << endl;
		return 0;
	}

	i=0;cango=0;
	for(;i <= min(cango, n-1);i++){
		cango = max(cango, i+d[n-1-i]);
	}
	if(cango<n){
		cout << "no" << endl;
		return 0;
	}

	cout << "yes" << endl;
}

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

int main(){
  int h,w;
  while(true){
    cin>>h>>w;
    if(h==0&&w==0)break;
    rep(i,h){
      rep(j,w){
        cout<<((i+j)%2==0 ? '#' : '.');
      }
      cout<<endl;
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3084
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
	int n,s=100000,a,b;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		s*=1.05;
		if(s%1000>=1)
		{
			a=1000-s%1000;
			s+=a;
		}
	}
	cout<<s<<endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int ans = 0;
    int tmp = 0;
    vector<int> h(n);
    for(int i=0;i<n;++i){
      cin>>h[i];
    }
    for(int i=0;i<n;++i){
      if(h[i]>=tmp) ans +=1;
      tmp = max(tmp,h[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((ll)(1e15))
#define pi (2*acos(0))
#define mp make_pair
#define M ((int)(998244353))
#define xx first
#define yy second
#define NN ((int)(305))
#define N ((int)(1e5 + 5))
#define pq priority_queue
///#define Q queue
#define eps 0
#define log 20
#define pb push_back
#define MOD 998244353


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long lu;


typedef tree < pair < int,int >,  null_type,  less < pair < int,int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;



int main()
{
    double t, x;
    scanf("%lf %lf",&t,&x);
    printf("%0.15lf\n",t/x);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector> 
#include <string>
#include <string.h>
#define LL long long
using namespace std;


int main()
{
    LL int n;
    cin>>n;
    LL int add=0;
    LL int num[100000];
    for (LL int i=0;i<n;i++)
    {
        cin>>num[i];
    }
    for (LL int i=0;i<n-1;i++)
    {
        if (i+1==num[i])
        {
            add++;
            num[i]=num[i+1];
            num[i+1]=i+1;
        }
    }
    if (num[n-1]==n)
    add++;
    cout<<add<<endl;
    return 0;
}
    
        


Measured memory_bytes: 1024
class square():
    
    def __init__(self, x,y):
        self.x = x
        self.y = y
        
    def draw(self):
        
        for i in range(0,self.x):
            for i in range(0,self.y):
                print('#',end="")
            print('') 
        print('')
        
while True:
    H,W = map(int,input().split())
    
    if H == 0 and W == 0:
        break
        
    s = square(H,W)
    s.draw()

Measured memory_bytes: 7016
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        long[] b = new long[n]; for(int i=0; i<n; i++) b[i] = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(bf.readLine());
        long[] a = new long[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        boolean continueloop = true;
        long ans = 0;
        boolean[] diff = new boolean[n];
        for(int i=0; i<n; i++) diff[i] = (a[i]!=b[i]);
        while(continueloop) {
          continueloop = false;
          for(int i=1; i<=n; i++) {
            if(diff[i%n] && (a[i%n] >= 0L + a[i-1] + a[(i+1)%n])) {
              if((0L + a[i%n] - b[i%n]) % (0L + a[i-1] + a[(i+1)%n]) == 0) {
                ans += (int)((a[i%n] - b[i%n])/(0L + a[i-1] + a[(i+1)%n]));
                a[i%n] = b[i%n];
                diff[i%n] = false;
                continueloop = true;
                continue;
              }
              ans += (1L*a[i%n]/(0L +a[i-1] + a[(i+1)%n]));
              a[i%n] %= 0L + a[i-1] + a[(i+1)%n];
              diff[i%n] = (a[i%n]!=b[i%n]);
              if(a[i%n] < b[i%n]) {
                out.println("-1");
                out.close();
                System.exit(0);
              }
              continueloop = true;

              //continueloop = true;
            }
          }
        }
        for(int i=0; i<n; i++) {
          if(a[i] != b[i]) {
            out.println("-1");
            out.close();
            System.exit(0);
          }
        }
        out.println(ans);
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int A, B, C;
    cin >> A >> B >> C;
    vector<int> S = {A, B, C};
    sort(all(S));
    cout << S.back() * 10 + S[1] + S[0] << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int n,m,h,K;
int score[1005];
int ti[1005];
vector<pair<int,bool> >s[1005][1005];
int main(){
    while(1){
    for(int i=0;i<1005;i++){
        for(int j=0;j<1005;j++){
            s[i][j].resize(0);
        }
    }
    vector<P>tate2[1005];
    scanf("%d %d %d %d",&n,&m,&h,&K);
    if(!n) break;
    for(int i=1;i<=n;i++){
        scanf("%d",&score[i]);
    }
    for(int i=1;i<=m;i++){
        int r,p; 
        scanf("%d %d",&r,&p);
        tate2[r].pb(mp(p,r+1));
        tate2[r+1].pb(mp(p,r));
    }
    for(int i=1;i<=n;i++){
        sort(tate2[i].begin(),tate2[i].end());
    }
    for(int i=1;i<=n;i++){
        int now=i;
        for(int k=1;k<=h;k++){
            for(int op=0;op<tate2[now].size();op++){
                if(tate2[now][op]==mp(k,now-1)){
                    s[now-1][k].pb(mp(i,false));
                    now--;
                    break;
                }else if(tate2[now][op]==mp(k,now+1)){
                    s[now][k].pb(mp(i,true));
                    now++;
                    break;
                }
            }
        }
        ti[i]=score[now];
    }
    int maxi=0;
    for(int i=0;i<1005;i++){
        for(int j=0;j<1005;j++){
            int z;
            z=(int)s[i][j].size();
            if(!z) continue;
            int ax=0,bx=0;
            for(int k=0;k<z;k++){
               if(s[i][j][k].second){
                  ax=ti[s[i][j][k].first];
               }else{
                  bx=ti[s[i][j][k].first];
               }
               if(ax && bx) break;
            }
            int dif=0;
            int rp;
            for(int ww=0;ww<s[i][j].size();ww++){
                if(s[i][j][ww].first<=K && s[i][j][ww].second){
                    dif+=(ax-bx);
                }else if(s[i][j][ww].first<=K){
                    dif+=(bx-ax);
                }
            }
            maxi=max(maxi,dif);
        }
    }
    int ans=0;
    for(int i=1;i<=K;i++){
        ans+=ti[i];
    }
    ans-=maxi;
    printf("%d\n",ans);
    }
}

Measured memory_bytes: 30348
#include<bits/stdc++.h>
using namespace std;
 
const int N = 1e5 + 10;
int cnt[N];
 
int main() {
  	int n, m, a, b;
  	cin >> n >> m;
  	for (int i = 0; i < m; i++) {
		cin >> a >> b;
      	cnt[a]++;
      	cnt[b]++;
    }
  	for (int i = 1; i <= n; i++)
      	if (cnt[i] % 2)
			return cout << "NO\n", 0;
   	return cout << "YES\n", 0;
}


Measured memory_bytes: 768
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int N, T;
    cin >> N >> T;
    int mini = 1001;
    for(int i = 0; i < N; i++){
        int c, t;
        cin >> c >> t;
        if(t <= T && c < mini){
            mini = c;
        }
    }
    if(mini == 1001){
        cout << "TLE" << endl;
    }else{
        cout << mini << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
music_list = []
for _ in range(N):
    title,time = input().split()
    music_list.append([title,int(time)])

last_music = input()

ans = 0
sleep_flg = False
for music in music_list:
    if(sleep_flg):
        ans += music[1]

    if(music[0] == last_music):
        sleep_flg = True

print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include<string.h>
#include<cstdio>
#include <stack>
#include <vector>
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];//存每个点的祖先
int dis[maxn];//这个点到祖先的距离
int findset(int x)
{
    if(x==pre[x])   return x;
    int r=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];//当前点x到根节点的距离=现在的距离+父节点到根节点的距离
    return pre[x]=r;//把每个子节点合并到他的祖先
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;
int main()
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");
   else     printf("No\n");
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ if(a>b) a=b;}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n  >>k;
	VI v(n);
	rep(i, n) cin >>v[i];
	ll ans = 0;
	rep(l, k+1) rep(r, k-l+1){
		if(r+l >n) continue;
		VL slc;
		rep(i, l) slc.push_back(v[i]);
		rep(i, r) slc.push_back(v[n-1-i]);
		ll sm = accumulate(all(slc), 0LL);
		sort(all(slc));
		rep(i, min(k-l-r, sz(slc))) {
			if(slc[i] >0) break;
			sm -= slc[i];
		}
		ans = max(ans , sm);
	}
	
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
using namespace std;

int main(){
	int a[4]={0};
	char dami,c[3];
	
	
    while(EOF!=scanf("%d,%s",&dami,c)){
        if(c[0]=='A'&&c[1]!='B')a[0]++;
        if(c[1]=='B')a[2]++;
        if(c[0]=='B')a[1]++;
        if(c[0]=='O')a[3]++;
    }
	int x=0;
	cout<<a[x++]<<endl;
	cout<<a[x++]<<endl;
	cout<<a[x++]<<endl;
	cout<<a[x++]<<endl;

	return 0;
}

Measured memory_bytes: 1208
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    

    class Program
    {


        static string Solve(string S, string T)
        {
            int sn = S.Length;
            int tn = T.Length;
            int[,] dp = new int[sn + 1, tn + 1];

            for (int i = 0; i <= sn; i++) dp[i, 0] = 0;
            for (int j = 0; j <= tn; j++) dp[0, j] = 0;

            for(int i = 1; i <= sn; i++)
            {
                for(int j = 1; j <= tn; j++)
                {
                    if (S[i - 1] == T[j - 1]) dp[i, j] = dp[i - 1, j - 1] + 1;
                    else dp[i, j] = Math.Max(dp[i - 1, j], dp[i, j - 1]);
                }
            }

            
            string ans = "";
            int u = sn;
            int v = tn;

            while (u > 0 && v > 0)
            {
                if (S[u - 1] == T[v - 1])
                {
                    ans = S[u - 1] + ans;
                    u--;
                    v--;
                }
                else if(dp[u - 1, v] == dp[u, v - 1])
                {
                    u--;                   
                }
                else if (dp[u, v] == dp[u - 1, v])
                {
                    u--;
                }
                else if (dp[u, v] == dp[u, v - 1])
                {
                    v--;
                }
                

            }


            return ans;
        }


        
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            Console.WriteLine(Solve(S, T));
            
        }
    }
}

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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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 gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
	string O=in<string>();
	string E=in<string>();
  	if(O.size()>E.size()){
   		REP(i,O.size()-1){
    		cout<<O[i]<<E[i];
    	}
      	cout<<O[O.size()-1]<<endl;
    }else{
    	REP(i,O.size()){
    		cout<<O[i]<<E[i];
    	}
    }
  	return 0;
}


Measured memory_bytes: 256
def main():
    a, b, c = map(int, input().split())

    dataset = set()
    for i in range(2, 100000):
        now_amari = (a * i) % b
        dataset.add(now_amari)

    if c in dataset:
        print('YES')
    else:
        print('NO')



if __name__ == '__main__':
    main()


Measured memory_bytes: 38728
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
ll N, M, K,H,W, ans, mi1,mi2,sum;
string s;
int main() {
	cin >> N;
	vector<LL> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (i == 0)ans = a[0];
		else ans = ans^a[i];
	}

	if (N % 3 == 0) {
		if (ans == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}
	if (N % 3 == 1) {
		for (int i = 0; i < N; i++) {
			ans = ans^a[i];
		}
		for (int i = 0; i < N; i++) {
			ans = ans^a[i];
		}
		if (ans == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}

	if (N % 3 == 2) {
		for (int i = 0; i < N; i++) {
			ans = ans^a[i];
		}
		for (int i = 0; i < N; i++) {
			ans = ans^a[i];
		}

		if (ans == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}

	return 0;
}



Measured memory_bytes: 1024
#include<map>
#include<queue>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

void bfs(vector<int> a,map<vector<int>,int> &memo){
	int n=a.size();
	memo[a]=0;
	queue< pair< int,vector<int> > > Q; Q.push(make_pair(0,a));
	while(!Q.empty()){
		int t=Q.front().first;
		vector<int> a=Q.front().second; Q.pop();

		if(t==4) break;

		rep(l,n) for(int r=l+1;r<n;r++) {
			reverse(a.begin()+l,a.begin()+r+1);
			if(memo.count(a)==0){
				memo[a]=t+1;
				Q.push(make_pair(t+1,a));
			}
			reverse(a.begin()+l,a.begin()+r+1);
		}
	}
}

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	map<vector<int>,int> memo1,memo2;
	bfs(a,memo1);
	sort(a.begin(),a.end());
	bfs(a,memo2);

	int ans=9;
	map<vector<int>,int>::iterator it;
	for(it=memo1.begin();it!=memo1.end();++it) if(memo2.count(it->first)>0) ans=min(ans,it->second+memo2[it->first]);
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 83092
#include<iostream>
using namespace std;
string s,s1,s2;
int t,n,m,x,tmp,cnt=0,p,pp;
int a[500001];
//int x[500001],y[500001];
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++)
        cin>>a[i];
    tmp=a[n-1];
    int i=0,j=0;
    for (j=0; j<n; j++){
    	if (a[j]<=tmp){
    		x=a[j]; a[j]=a[i]; a[i]=x; i++;
    		if (j==n-1)
    		   p=i-1;
		}
	}
	if (p==0)
	   cout<<"["<<a[0]<<"] ";
	   //printf("[%d]",a[0]);
	else
	   cout<<a[0];
	   //printf("%d",a[0]);
	for (int i=1; i<n; i++)
	    if (i==p)
	       cout<<" ["<<a[i]<<"]";
	       //printf(" [%d]",a[i]);
	    else
	       cout<<' '<<a[i];
	       //printf(" %d",a[i]);
	cout<<'\n';
	return 0;
} 


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

#define reint register int
#define coint const int

using namespace std;

coint SIZE = 200000 + 5;

int li[SIZE], tmp[SIZE];

inline int getint(void) {
    reint x = 0, ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar());
    for (; ch >= '0' && ch <= '9';
        x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar());
    return x;
}

int main(void) {
    coint n = getint();
    for (reint i = 1; i <= n; ++i) tmp[i] = li[i] = getint();
    sort(tmp + 1, tmp + n + 1);
    for (reint i = 1; i <= n; ++i)
        if (li[i] == tmp[n]) printf("%d\n", tmp[n - 1]);
        else printf("%d\n", tmp[n]);

    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 4e2+5;

ll dp[L][L];
ll pref[L][L];

void solve()
{
    ll n = nxt();
    basic_string <ll> a(n, 0);
    generate(all(a), nxt);

    for(ll i=0; i<n; i++)
    {
        pref[i][i] = a[i];

        for(ll j=i+1; j<n; j++)
        {
            pref[i][j] = pref[i][j-1] + a[j];
        }
    }

    for(ll i=n-1; i>=0; i--)
    {
        for(ll j=i; j<n; j++)
        {
            if(i == j)
            {
                continue;
            }

            else
            {
                dp[i][j] = 1e18;

                for(ll k=i; k<j; k++)
                {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + pref[i][j]);
                }
            }
        }
    }

    cout << dp[0][n-1] << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

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

const int INF = 0x3f3f3f3f;
int t1, t2, t3, n, e[105][105];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) e[i][j] = INF;
		e[i][i] = 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> t1 >> t2;
		for (int j = 0; j < t2; j++) {
			cin >> t3;
			e[t1][t3] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				e[j][k] = min(e[j][k], e[j][i] + e[i][k]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << ((e[1][i] == INF) ? -1 : e[1][i]) << endl;
	}
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(ll i=1;i<=(n);++i)
#define ifr(i,n) for(ll i=(n)-1;i>=0;--i)
#define iFr(i,n) for(ll i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  ll arr[n*n];
  ll enpty[n*n];
  fr(i,n*n){
    enpty[i] = 0;
  }
  fr(i,n*n){
    arr[i] = min({i/n,i%n,n-i/n-1,n-i%n-1});
  }
  ll ans,k,b;
  ans=0;
  queue<ll> que;
  fr(i,n*n){
    cin>>b;
    --b;
    ans += arr[b];
    enpty[b] = 1;
    que.push(b);
    while (!que.empty()) {
    k = que.front();
    que.pop();
    if(k/n>0){
      if(arr[k-n] > arr[k]-enpty[k]+1 and arr[k-n]>0){
      arr[k-n]=arr[k]-enpty[k]+1;
      que.push (k-n);
    }}
    if(k%n>0){
      if (arr[k-1] > arr[k]-enpty[k]+1 and arr[k-1]>0){
      arr[k-1]=arr[k]-enpty[k]+1;
      que.push (k-1);
    }}
    if(k/n<n-1){
      if(arr[k+n] > arr[k]-enpty[k]+1 and arr[k+n]>0){
      arr[k+n]=arr[k]-enpty[k]+1;
      que.push (k+n);
    }}
    if(k%n<n-1){
      if(arr[k+1]> arr[k]-enpty[k]+1 and arr[k+1]>0){
      arr[k+1]=arr[k]-enpty[k]+1;
      que.push (k+1);
    }}
  }
  }
  cout<<ans;
}

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

using namespace std;

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int A, B;
	cin >> A >> B;

	if (((A % 3) == 0) || ((B % 3) == 0) || (((A + B) % 3) == 0)) {
		cout << "Possible" << endl;
	} else {
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 256