akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int Maxn=1e6+5;
const int inf=0x3f3f3f3f;
class union_find
{
	protected:
		int par[Maxn],rank[Maxn];
	public:
		void init(int n){for (int i=0;i<n;rem(i++));}
		void rem(int i){par[i]=i;rank[i]=0;}
		int find(int x){return x==par[x]?x:par[x]=find(par[x]);}
		void unite(int x,int y)
		{
			x=find(x);
			y=find(y);
			if (x==y) return;
			if (rank[x]<rank[y]) par[x]=y;
			else
			{
				par[y]=x;
				if (rank[x]==rank[y]) rank[x]++;
			}
		}
		bool same(int x,int y) {return find(x)==find(y);}
};
union_find uf;
vector <int> vec[Maxn];
vector <pair <int,int> > query[Maxn];
int id[Maxn],n,m;
bool use[Maxn];
int dist[Maxn];
int main()
{
	cin>>n>>m;
	for (int i=0;i<m;++i)
	{
		int p,q,c;
		cin>>p>>q>>c;p--;q--;
		query[c].push_back({p,q});
	}
	int sz=n;
	for (int i=0;i<Maxn;++i)
	{
		if (query[i].empty()) continue;
		for (auto &p:query[i])
		{
			uf.rem(p.first);
			uf.rem(p.second);
			id[p.first]=id[p.second]=~0;
			use[p.first]=use[p.second]=false;
		}
		for (auto &p:query[i]) uf.unite(p.first,p.second);
		for (auto &p:query[i])
		{
			if (!use[p.first])
			{
				use[p.first]=true;
				int r=uf.find(p.first);
				if (!~id[r]) id[r]=sz++;
				vec[p.first].push_back(id[r]);
				vec[id[r]].push_back(p.first);
			}
			if (!use[p.second])
			{
				use[p.second]=true;
				int r=uf.find(p.second);
				if (!~id[r]) id[r]=sz++;
				vec[p.second].push_back(id[r]);
				vec[id[r]].push_back(p.second);
			}
		}
	}
	queue <int> q;
	q.push(0);
	memset(dist,63,sizeof(dist));
	for (dist[0]=0;!q.empty();)
	{
		int v=q.front();q.pop();
		for (auto &x:vec[v])
		{
			if (dist[x]==inf)
			{
				dist[x]=dist[v]+1;
				q.push(x);
			}
		}
	}
	if (dist[n-1]==inf) cout<<"-1\n";
	else cout<<dist[n-1]/2<<endl;
	return 0;
}

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

 #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int Maxn  =  10000;
const ld  pi   =  acos(-1);
const int mod =  1000000007;
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x;return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
int roundUp(int numToRound, int multiple)
{
 if(multiple == 0)
 {
  return numToRound;
 }

 int roundDown = ( (int) (numToRound) / multiple) * multiple;
 int roundUp = roundDown + multiple; 
 int roundCalc = roundUp;
 return (roundCalc);
}


 

int calc(int a, int b, int c) {
	return abs(a - b) + abs(a - c) + abs(b - c);
}


//Binary exponentiation
int binpow(int a,int b) {
    int res = 1;
while (b > 0) {
        if (b & 1)res = res * a;
        a = a * a;
        b >>= 1;
}
return res;
}
// gcd
int gcd(int a, int b){
    while(b){
        a=a%b;
        swap(a,b);
    }
    return a;
}
//lcm
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}
  
 
  

int prefix[100001]; 
  
void buildPrefix(int L,int R) 
{ 
    
    vector<bool> prime(100001,true); 
   
  
    for (int p = 2; p * p <= 100001; p++) { 
  
        
        if (prime[p] == true) { 
  
           
            for (int i = p * 2; i <= 100001; i += p) 
                prime[i] = false; 
        } 
    } 
  
    
    prefix[0] = prefix[1] = 0; 
    for (int p = L; p <= L-R; p++) { 
        prefix[p] = prefix[p - 1]; 
        if (prime[p]) 
            prefix[p] += p; 
    } 
} 
  
  int hexadecimalToDecimal(vector<char> hexVal) 
{    
    int len = (hexVal.size()); 
      int base = 1; 
      
    int dec_val = 0; 
      
    
    for (int i=len-1; i>=0; i--) 
    {    if (hexVal[i]>='0' && hexVal[i]<='9') 
        { 
            dec_val += (hexVal[i] - 48)*base; 
               base = base * 16;} 
  
        
        else if (hexVal[i]>='A' && hexVal[i]<='F') 
        { 
            dec_val += (hexVal[i] - 55)*base; 
          
            
            base = base*16; 
        } 
    } 
      
    return dec_val; 
} 


  
 
int32_t main(){IOS

int a,b,c;
cin>>a>>b>>c;
int x=a;
a=b;
b=x;

int y=c;
c=a;
a=y;
cout<<a<<" "<<b<<" "<<c<<endl;






 
}



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

int main() {
  string s;
  cin >> s;
  string ans = "Good";
  for(int i=0; i<3; i++){
    if(s.at(i) == s.at(i+1)){
      ans = "Bad";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,m;
  int i,j;
  int c = 0;
  int max = 0;
  string s[100],a[100];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> s[i];
  }
  cin >> m;
  for(i=0;i<m;i++){
    cin >> a[i];
  }
  for(i=0;i<n;i++){
    for(j=i;j<n;j++){
      if(s[i]==s[j]){
        c++;
      }
    }
    for(j=0;j<m;j++){
      if(s[i]==a[j]){
        c--;
      }
    }
    if(max<c){
      max = c;
    }
    c = 0;
  }
  if(max>0){
    cout << max;
  }
  else{
    cout << 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;


int main(){
	string a,b;
	std::cin >> a>>b;
	if(a.size()==b.size()){
		rep(i,a.size()){
			std::cout << a[i]; 
			std::cout << b[i]; 
		}
	}else{
		rep(i,b.size()){
			std::cout << a[i]; 
			std::cout << b[i]; 
		}
		std::cout << a[a.size()-1] << std::endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M,sum=0;
    cin >> N >> M;
 
    int l,i=0,A[N];
    while(cin>>l){
        A[i] = l;
        sum += A[i];
        i++;
    }

    int cnt = 0;

    for (int i=0 ; i<N ; i++) {
        if (!(A[i] < (sum + (4 * M) - 1) / (4 * M))) {
            cnt++;
        }
    }

    if (cnt >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
  
    
  	return 0;
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int a,b;
int ans;
int main() {
    cin >> a;
    ans = (a-2)*180;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
char str[100100];
int main()
{
	char a[5];
	while(scanf("%s",str+1)!=EOF)
	{
		int sum=0;
		int len=strlen(str+1);
		a[1]=str[len];	
		for(int i=len-1; i>=1; i--)
		{
			if(str[i]!=a[1])
			{
				a[1]=str[i];
				sum++;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[])
{
  int a, b, i, j;
  int aa[100][100] = {0};
  int bb[100];

  scanf("%d %d",&a, &b);

  for (i = 0; i < a; i++) {
    for (j = 0; j < b; j++) {
      scanf("%d", &aa[i][j]);
    }
  }

  for (i = 0; i < b; i++)
    scanf("%d", &bb[i]);

  for (i = 0; i < a; i++) {
    int t = 0;
    for (j = 0; j < b; j++)
      t += (aa[i][j] * bb[j]);

    printf("%d\n", t);
  }

    return 0;
}

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

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

int main() {
    string S, T;
    cin >> S;
    cin >> T;
    int count = 0;
    rep(i, S.size()) {
        if (S[i] != T[i]) {
            ++count;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3916
/*
                                            lllllll                                                                                     tttt          
                                            l:::::l                                                                                  ttt:::t          
                                            l:::::l                                                                                  t:::::t          
                                            l:::::l                                                                                  t:::::t          
    ssssssssss           ooooooooooo         l::::l         ooooooooooo            cccccccccccccccc       aaaaaaaaaaaaa        ttttttt:::::ttttttt    
  ss::::::::::s        oo:::::::::::oo       l::::l       oo:::::::::::oo        cc:::::::::::::::c       a::::::::::::a       t:::::::::::::::::t    
ss:::::::::::::s      o:::::::::::::::o      l::::l      o:::::::::::::::o      c:::::::::::::::::c       aaaaaaaaa:::::a      t:::::::::::::::::t    
s::::::ssss:::::s     o:::::ooooo:::::o      l::::l      o:::::ooooo:::::o     c:::::::cccccc:::::c                a::::a      tttttt:::::::tttttt    
 s:::::s  ssssss      o::::o     o::::o      l::::l      o::::o     o::::o     c::::::c     ccccccc         aaaaaaa:::::a            t:::::t          
   s::::::s           o::::o     o::::o      l::::l      o::::o     o::::o     c:::::c                    aa::::::::::::a            t:::::t          
      s::::::s        o::::o     o::::o      l::::l      o::::o     o::::o     c:::::c                   a::::aaaa::::::a            t:::::t          
ssssss   s:::::s      o::::o     o::::o      l::::l      o::::o     o::::o     c::::::c     ccccccc     a::::a    a:::::a            t:::::t    tttttt
s:::::ssss::::::s     o:::::ooooo:::::o     l::::::l     o:::::ooooo:::::o     c:::::::cccccc:::::c     a::::a    a:::::a            t::::::tttt:::::t
s::::::::::::::s      o:::::::::::::::o     l::::::l     o:::::::::::::::o      c:::::::::::::::::c     a:::::aaaa::::::a            tt::::::::::::::t
 s:::::::::::ss        oo:::::::::::oo      l::::::l      oo:::::::::::oo        cc:::::::::::::::c      a::::::::::aa:::a             tt:::::::::::tt
  sssssssssss            ooooooooooo        llllllll        ooooooooooo            cccccccccccccccc       aaaaaaaaaa  aaaa               ttttttttttt  
*/
#include <iostream>
using namespace std;
#define YukinonMyWife   ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j)        memset(i,j,sizeof (i))
#define size(v)         (long long)(v).size()
typedef int64_t   ll;
typedef uint64_t ull;
const double EPS  =       1e-8;
const  int   INF  =     0x3F3F3F3F;
const   ll   LINF = 4611686018427387903;
const  int   MOD  =       1e9+7;



void solve() {
  
}


signed main() {
	YukinonMyWife
	int a, b;
  cin >> a >> b;
  cout << a * b << endl;
	
	return 0;
}


Measured memory_bytes: 3656
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m;
int a[101010], b[101010];
bool aa[101010], bb[101010];
vector<int> G[101010];
int main() {
	cin >> n >> m;
	REP(i, m) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
		G[a[i]].emplace_back(b[i]);
	}
	int num = INF;
	int ans = 0;
	REP(i, n) {
		if (i == num) {
			ans++;
			num = INF;
		}
		REP(j, G[i].size()) {
			num = min(num, G[i][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = 998244353;
const int N = (int)2e5 + 5;

void solve(){
	int n;
	cin>>n;
	cout<<n*n;
}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll n,k;
    cin>>n>>k;
    int a[n];
    vector<vector<int>> v(202020);
    rep(i,n){
        cin>>a[i];
        v[a[i]].push_back(i);
    }
    ll t = 1;
    int idx = 0;
    while(1){
        int cur = lower_bound(v[a[idx]].begin(),v[a[idx]].end(),idx)-v[a[idx]].begin();
        int nxt = cur+1;
        if(nxt==v[a[idx]].size()){
            nxt=0;
            ++t;
        }
        idx = (v[a[idx]][nxt]+1)%n;
        if(idx==0)break;
    }
    k%=t;
    if(k==0)return 0;
    idx = 0;
    k-=1;
    while(k){
        int cur = lower_bound(v[a[idx]].begin(),v[a[idx]].end(),idx)-v[a[idx]].begin();
        int nxt = cur+1;
        if(nxt==v[a[idx]].size()){
            nxt=0;
            --k;
        }
        idx = (v[a[idx]][nxt]+1)%n;
    }
    vector<int> ans;
    vector<int> cnt(202020);
    rep(_,1){
        REP(i,idx,n){
            if(!cnt[a[i]]){
                ++cnt[a[i]];
                ans.push_back(a[i]);
            }
            else {
                while(cnt[a[i]]){
                    int x = ans.back();
                    ans.pop_back();
                    --cnt[x];
                }
            }
        }
        for(auto e : ans)cout<<e<<" ";
        cout<<endl;
    }
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  lli k;
  while (cin >> n >> k) {
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
      int a, b;
      cin >> a >> b;
      v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    lli sum = 0;
    each (i, v) {
      sum += i.second;
      if (k <= sum) {
        cout << i.first << endl;
        break;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 1400
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);;
		while(true) {
			int[] array = {scan.nextInt(), scan.nextInt()};
			Arrays.sort(array);
			if(array[0] == 0 && array[1] == 0) {
				break;
			}
			System.out.println(array[0] + " " + array[1]);
		}
		scan.close();
	}
}


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

int main() {
    double r; cin >> r;
    double ans = 2.0*r*3.141592;
    cout << fixed << setprecision(10);
    cout << ans << endl;
}


Measured memory_bytes: 3804
Option Strict On

Module Module1
    Sub Main()
        'let'
        Dim tmp() As Long =
            Array.ConvertAll(Of String, Long) _
            (Console.ReadLine().Split(), AddressOf Long.Parse)
        Dim a As Long = tmp(0)
        Dim b As Long = tmp(1)
        Dim c As Long = tmp(2)
        Dim d As Long = tmp(3)

        Dim arr() As Long = New Long() {a, b, c}

        'var'
        Dim flg As Boolean

        If Math.Abs(a - c) > d Then
            flg = calc(arr, d)
        End If

        Console.WriteLine(New String() {"Yes", "No"}(Convert.ToInt32(flg)))

    End Sub

    Function calc(ByVal arr() As Long, ByVal d As Long) As Boolean
        'var'
        Dim result As Boolean
        For i As Int32 = 0 To UBound(arr) - 1
            If Math.Abs(arr(i) - arr(i + 1)) > d Then
                result = True
            End If
        Next
        Return result
    End Function

End Module


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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());

  ll ans = 0;
  int res = n-1;
  rep(i,n){
    if(i == 0){
      ans += a[0];
      res--;
      continue;
    }
    else if(res >= 2) {
      ans += a[i]*2;
      res -= 2;
      continue;
    }
    else if(res == 1) {
      ans += a[i];
      res -= 1;
      continue;
    }
    if(res==0) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4768
/*input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 51;
int a[N];
int n;

void solve(){
	cin >> n;
	REP(i,n)cin >> a[i];
	int ops = 0;
	while(1){
		bool ok = 1;
		int cur = 0;
		REP(i,n){
			if(a[i] >= n){
				// a[i]-k*(n+1) < n
				// a[i]-n < k*(n+1)
				int howmany = (a[i]-n)/(n+1);
				if(a[i]-howmany*(n+1) >= n)howmany++;
				ok = 0;
				ops += howmany;
				cur += howmany;
				a[i] -= howmany*(n+1);
			}
		}
		REP(i,n){
			a[i] += cur;
		}
		if(ok)break;
	}
	cout << ops;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;


int main() {
    int x; cin >> x;

    // i=1~1000のべき乗数の元
    // j=べき乗の指数
    // 1~1000についてすべてのべき乗数を試す
    int ans = 1;
    for(int i = 2; i <= 1000; i++){
        for(int j = 2; j <= 1000; j++){
            int p = pow(i, j);
            if(ans < p && p <= x) ans = p;
        }
    }
    cout << ans << endl;

    // 冗長な解答
    // // xをデクリメントして検証する
    // for(int i = x; i > 0; i--){
    //     // iがべき乗数かを2から判定する
    //     for(int j = 2; j * j <= i; j++){
    //         int n = j;
    //         while(n < i) n *= j;
    //         // nがiと同じであればべき乗数
    //         if(n == i){
    //             cout << i << endl;
    //             return 0;
    //         }
    //     }
    // }
    // cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 4152
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        PrintWriter O = new PrintWriter(out);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[h][w];
        int[] point = new int[90001];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = sc.nextInt();
                point[a[i][j]] = i * w + j;
            }
        }
        long[] ds = new long[h * w + 1];
        for (int i = 1; i <= h * w; i++) {
            if (i > d) ds[i] = ds[i - d] + abs(point[i] / w - point[i - d] / w) + abs(point[i] % w - point[i - d] % w);
        }
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            O.println(ds[r] - ds[l]);
        }
        O.flush();
    }

    static class sc {
        static Scanner s = new Scanner(in);

        static String next() {
            return s.next();
        }

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

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

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

Measured memory_bytes: 65716
#include <stdio.h>
 
int main() {
  long n, a;
  long x[200001] = {0};
 
  scanf("%ld", &n);
  for (int i = 1; i < n; i++) {
    scanf("%ld", &a);
    x[a] = x[a] + 1;
  }
 
  for (int i = 1; i <= n; i++) {
    printf("%ld\n", x[i]);
  }
 
  return 0;
}

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

//関数


    
    
    
//main関数
int main() {
    
    
    //入力
    long N,C,K;
    cin>>N>>C>>K;
    vector<long> T(N);
    for(int i=0;i<N;i++){
        cin>>T.at(i);
    }
    
    
    
    //計算
    sort(T.begin(),T.end());
    
    /*for(int i=0;i<N;i++){
        cout<<T.at(i)<<endl;
    }*/
    
    long ans=0;
    while(T.size()>0){
        ans++;
        for(int i=C-1;i>=0;i--){
            if(i<T.size() && T.at(i)<=T.at(0)+K){
                T.erase(T.begin(),T.begin()+i+1);
                break;
            }
        }
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int a[3];
    cin >> a[0] >> a[1];
    a[2] = a[0] + a[1];
    rep(i, 3)
    {
        if (a[i] % 3 == 0)
        {
            cout << "Possible" << endl;
            return 0;
        }
    }
    cout << "Impossible" << endl;
    return 0;
}

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

int main(){
  int i,j,a,d,n;
  int num[1000000];
  for(i = 1; i < 1000000; i++){
    num[i]=0;
  }
  num[1]=1;
    for(i = 2; i < 1000000; i++){
      if(num[i]==0){
	for(j = 2*i; j <1000000; j+=i){
	  num[j]=1;
	}
      }
    }

  while(1){
    int count=0;
    int memo;
    cin >> a >> d >> n;
    if(a==0 && d==0 && n==0)break;
         
    for(i = a; i <1000000; i+=d){
      if(num[i]==0){
	count++;
      }
      if(count==n){
	memo=i;
	break;
      }
    }
    cout << memo << endl;
  }
  
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
vector<T> GetListOfDivisor(T N){
    vector<T> res;
    vector<T> res2;
    for(long long i=1; i*i<=N; i++){
        if(N%i!=0) continue;
        res.push_back(i);
        res2.push_back(N/i);
    }
    reverse(res2.begin(), res2.end());
    if(res.back() == res2.front()) res.pop_back();
    res.insert(res.end(), res2.begin(), res2.end());
    return res;
}

bool isValid(ll N, ll K){
    if(K==1) return false;
    while(N % K == 0) N /= K;
    return (N % K) == 1;
}

int main()
{
    ll N;
    cin >> N;

    set<ll> s;
    auto ret = GetListOfDivisor(N);
    for(auto v : ret){
        if(isValid(N, v)) s.insert(v);
    }
    ret = GetListOfDivisor(N-1);
    for(auto v : ret){
        auto ret2 = GetListOfDivisor(v);
        for(auto v2 : ret2) s.insert(v2);
    }
    cout << (s.size() - 1) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef pair<string, int> Psi;
typedef pair<ll, ll> Pll;
#define int long long
signed main(){
	int N;
	cin >> N;
	int x,y;
	cin >> x >> y;
	rep(i,N-1){
		int t,a;
		cin >> t >> a;
		if(t < x && a < y){
			int tmp = x/t;
			int tmp2 = y/a;
			if(tmp > tmp2){
				if(x%t==0){
					t*=tmp;
					a*=tmp;
				}
				else{
					t*=(tmp+1);
					a*=(tmp+1);
				}
			}
			else{
				if(y%a==0){
					t*=tmp2;
					a*=tmp2;
				}
				else{
					t*=(tmp2+1);
					a*=(tmp2+1);
				}
			}
			x = t;
			y = a;
		}
		else if(t < x && a >= y){
			int tmp = x/t;
			if(x%t==0){
				t*=tmp;
				a*=tmp;
			}
			else{
				t*=(tmp+1);
				a*=(tmp+1);
			}
			x = t;
			y = a;
		}
		else if(a < y && t >= x){
			int tmp = y/a;
			if(y%a==0){
				t*=tmp;
				a*=tmp;
			}
			else{
				t*=(tmp+1);
				a*=(tmp+1);
			}
			x = t;
			y = a;
		}
		else{
			x = t;
			y = a;
		}
		
	}
	cout << x+y << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
const int N=2e5+5;
int n,l,a[N];
int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<n;i++){
		if(a[i]+a[i+1]>=l){
			printf("Possible\n");
			for(int j=1;j<i;j++){
				printf("%d\n",j);
			}
			for(int j=n-1;j>i;j--){
				printf("%d\n",j);
			}
			printf("%d\n",i);
			return 0;
		}
	}
	printf("Impossible\n");
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

using ll = long long;

int main() {
	string str;
	cin >> str;
	// std::cout << "debug str" << str << std::endl; // debug
	ll ans = 0;
	int m = 2019;
	int sum = 0; // only store value after mod
	int digit_like = 1;
	vector<int> remainder_counter(m);
	remainder_counter[0]++;
	//for (auto itr = str.rbegin(); itr != str.rend(); itr++) {
	for (int i = str.length() - 1; i >= 0; i--) {
		int n = str[i] - '0';
		n *= digit_like;
		// std::cout << "debug n " << n << " digit_like " << digit_like << std::endl; // debug
		sum = (sum + n) % m;
		// std::cout << "debug sum " << sum << std::endl; // debug
		ans += remainder_counter[sum]; // do before remainder_counter increment
		remainder_counter[sum]++;
		// for nest
		digit_like = (digit_like * 10) % m;
	}
	// std::cout << "debug ans " << ans << std::endl; // debug
	cout << ans;


	// std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; 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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  map<ll,ll> mp;
  ll sum=0;
  REP(i, N){
    cin >> A[i];
    mp[A[i]]++;
    sum+=A[i];
  }
  
  ll Q;
  cin >> Q;
  vector<ll> ans(Q);
  REP(i,Q){
    ll B,C;
    cin >> B >> C;
    ll x = mp[B];
    mp.erase(B);
    sum-=B*x;
    mp[C]+=x;
    sum+=C*x;
    ans.at(i)=sum;
  }

  REP(i,Q){
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 8720
#include <stdio.h>

int main(void)
{
	int n, i, j, yakusu_num=0, tmp;

	scanf("%d",&n);
	
	for(i=105; i<=n; i+=2){
		tmp=0;
		for(j=1; j<=i; j+=2){
			if((i%j)==0){
				tmp++;
			}
		}
		if(tmp == 8){
			yakusu_num++;
		}
	}
	
	printf("%d\n",yakusu_num);
	
	return 0;
}


Measured memory_bytes: 128
N, M, X = map(int, input().split())
C = []
A = []
result = -1

for i in range(N):
    tmp = list(map(int, input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])

for n in range(1 << N):
    Cn = 0
    skill = [0] * M
    for i in range(N):
        if (n >> i) & 1 == 1:
            Cn += C[i]
            for j in range(M):
                skill[j] += A[i][j]

    if all(x >= X for x in skill):
        if result == -1:
            result = Cn
        else:
            result = min(result, Cn)

print(result)


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    
    int i;
    for(i = 0; i < n; i++){
        cin >> a.at(i);
    }
    
    sort(a.begin(), a.end());
    
    long sum = 0;
    for(i = 0; i < n; i++){
        sum += a.at(i);
    }
    
    cout << a.at(0) << " ";
    cout << a.at(n - 1) << " ";
    cout << sum << endl;
}


Measured memory_bytes: 3156
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}




int main() {
	ll  N, A, B,q1=0,q2=0,q3=0;
	
	cin >>N>> A >> B;
	rep(i, N) {
		int p;
		cin >> p;
		if (p > B) {
			q3++;
		}
		else if (p > A) {
			q2++;
		}
		else {
			q1++;
		}
	};

	cout << Min(q1,q2,q3) << endl;
	
}



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

int main(){
  ll x,k,d;
  cin >> x >> k >> d;
  if(x<0) x*=(-1);
  ll ans;
  ll a = x/d;
  ll b = k-a;
  ll c = x-a*d;
  if(a>k) ans = abs(x-d*k);
  else{
    if(b%2==0) ans = c;
    else ans = abs(c-d);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

vector<int> adj[maxN];
int f[maxN], prs[maxN], root[maxN], pc, k, n;
ll sign[maxN];

void erat(int k) {
	root[1] = 1;
	for(int i = 2; i <= k; i++) {
		if(!f[i]) prs[pc++] = i, f[i] = i, root[i] = i;;
		for(int j = 0; j < pc && ll(i) * prs[j] <= k && prs[j] <= f[i]; j++) {
			f[prs[j] * i] = prs[j];
			int ne = i * prs[j];
			if(prs[j] == f[i])
				root[ne] = root[i];
			else
				root[ne] = root[i] * prs[j];
		}
	}
}

ll buc[maxN];
vector<ll> multi(const vector<ll>& one, const vector<ll>& two) {
	if(one.empty()) return two;
	if(two.empty()) return one;
	vector<ll> ret(k + 1);
	for(int u = 1; u <= k; u++) {
		int sz = k / u;
		for(int i = 1; i <= sz; i++) buc[i] = 0;
		for(int i = 1; i <= sz; i++)
			for(auto el: adj[root[i]])
				buc[el] = (buc[el] + one[i * u]) % MOD;
		ll suma = 0;
		for(int i = 1; i <= sz; i++) LOG << buc[i] << ' '; LOG << '\n';
		for(int i = 1; i <= sz; i++) {
			ll copr = 0;
			for(auto el: adj[root[i]])
				copr = (copr + buc[el] * sign[el]) % MOD;
			suma = (suma + copr * two[i * u]) % MOD;
		}
		ret[u] = suma;
	}
	return ret;
}

vector<ll> fastPow(vector<ll> a, ll b) {
	vector<ll> ret;
	while(b) {
		if(b & 1) ret = multi(ret, a);
		b >>= 1;
		a = multi(a, a);
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> k;
	erat(k);
	sign[1] = 1;
	adj[1].push_back(1);
	for(int i = 2; i <= k; i++) {
		if(root[i] != i) continue;
		sign[i] = (MOD - 1) * sign[i / f[i]] % MOD;
		adj[i] = adj[i / f[i]];
		for(auto el: adj[i / f[i]]) adj[i].push_back(el * f[i]);
	}

/*	for(int i = 1; i <= k; i++) {
		LOG << "nm " << i << ' ' << root[i] << '\n';
		for(auto el: adj[i]) LOG << el << ' '; LOG << '\n';
	}*/

	vector<ll> base(k + 1);
	fill(base.begin(), base.end(), 1);
auto expp = fastPow(base, n);
	//auto expp = multi(base, base);
	for(int i = 1; i <= k; i++) LOG << expp[i] << ' '; LOG << '\n';
	ll ans = 0;
	for(ll i = 1; i <= k; i++)
		ans = (ans + i * expp[i]) % MOD;
	cout << ans << '\n';
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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


int main(){
	int A,B,C,D;
	cin>>A>>B>>C>>D;

	printf("%d\n",max(0,min(B,D)-max(A,C)));
	return 0;
}



Measured memory_bytes: 256
from collections import Counter
n,k,l=map(int,input().split())
city1=[i for i in range(n)]
city2=[i for i in range(n)]
def root(c,x):
  if x==c[x]:
    return x
  else:
    c[x]=root(c,c[x])
    return c[x]
def union(c,x,y):
  rx=root(c,x)
  ry=root(c,y)
  if rx>ry:
    c[rx]=ry
  else:
    c[ry]=rx
for i in range(k):
  a,b=map(int,input().split())
  union(city1,a-1,b-1)
for i in range(l):
  a,b=map(int,input().split())
  union(city2,a-1,b-1)
r=[]
for i in range(n):
  r.append((root(city1,i),root(city2,i)))
c=Counter(r)
for i in range(n):
  ans=c[r[i]]
  if i==n-1:
    print(ans)
  else:
    print(ans,end=' ')

Measured memory_bytes: 55932
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;

int main(){
	cin >> N;

	ll even=0, odd=0;
	for(int k=0; k<=40; k++){
		if(k%2) odd += 1ll<<k;
		else even += 1ll<<k;
	}

	string ans;
	for(int k=40; k>0; k--){
		//if(k%2) cout << -(((1ll<<(k-1))-1)&odd) << " " << N << " " << -(((1ll<<(k+1))-1)&odd) << endl;
		//else cout << (((1ll<<(k-1))-1)&even) << " " << N << " " << (((1ll<<(k+1))-1)&even) << endl;
		if(k%2 && (((1ll<<(k-1))-1)&odd) < -N && -N <= (((1ll<<(k+1))-1)&odd)){
			ans += '1';
			N += 1ll<<k;
		} else if(!(k%2) && (((1ll<<(k-1))-1)&even) < N && N <= (((1ll<<(k+1))-1)&even)){
			ans += '1';
			N -= 1ll<<k;
		} else{
			ans += '0';
		}
	}

	if(N==1) ans += '1';
	else ans += '0';

	auto nonzero = 0;
	while(nonzero<ans.size() && ans[nonzero]=='0') nonzero++;

	if(nonzero==ans.size()) cout << 0 << endl;
	else cout << ans.substr(nonzero) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define vvl vector<vector<ll>>
#define vl  vector<ll>
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
//lcm:最小公倍数、gcd:最大公約数
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back 
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

//ll n;
//string s;
signed main(){
	acc_io;
	//ll n;
	string sa,sb,sc;
	cin>>sa>>sb>>sc;
	queue<char>a,b,c;
	rep(i,0,sa.size()) a.push(sa[i]);
	rep(i,0,sb.size()) b.push(sb[i]);
	rep(i,0,sc.size()) c.push(sc[i]);
	char next;
	next=a.front();
	a.pop();
	while(1){
		if(next=='a'){
			if(a.empty()){
				cout<<"A"<<endl;
				return 0;
			}
			next=a.front();
			a.pop();
		}
		else if(next=='b'){
			if(b.empty()){
				cout<<"B"<<endl;
				return 0;
			}
			next=b.front();
			b.pop();
		}
		else{
			if(c.empty()){
				cout<<"C"<<endl;
				return 0;
			}
			next=c.front();
			c.pop();
		}
	}
	return 0;
}


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

using namespace std;

struct Trie {
    struct Node {
        int ch[2];
        int d;
        Node(int _d) {
            ch[0]=ch[1]=0;
            d = _d;
        }
    };

    vector<Node> t;
    Trie() {
        t.reserve(200'005);
        t.emplace_back(0);
    }
    void add(const string& p) {
        int x = 0;
        for (int i=0; i<(int)p.size(); i++) {
            int k = p[i]-'0';
            if (!t[x].ch[k]) {
                t[x].ch[k] = t.size();
                t.emplace_back(i+1);
            }
            x = t[x].ch[k];
        }
    }
};

void solve() {
    int n; cin >> n;
    long long L; cin >> L;
    Trie t;
    for (int _ = 0; _ < n; _++) {
        string s; cin >> s;
        t.add(s);
    }
    long long sg = 0;
    for (auto& p: t.t) {
        long long k = L - p.d;
        k &= -k;
        if (!p.ch[0]) sg^=k;
        if (!p.ch[1]) sg^=k;
    }
    cout << (sg?"Alice":"Bob");
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };
char ban[25][25];// tmp[25][25];
int sx, sy, gx, gy;
int ans = 20;
int W, H;
void dfs(char C[25][25], int depth, int ty, int tx, int before)
{
  //printf("ty=%d tx=%d\n",ty,tx );
  if(depth == 10)return;
  for(int r =0; r < 4; r++)
    {
      //if(before == r)continue;
      char tmp[25][25];
     	for(int i = 0; i < H; i++)
     	{
     		for(int j = 0; j < W; j++)
     		{
     			tmp[i][j]=C[i][j];
     		}
     	}
      int y = ty, x = tx;
      if(y+dd[r]<0||y+dd[r]>=H||x+dd[r+1]<0||x+dd[r+1]>=W)continue;
      if(tmp[y+dd[r]][x+dd[r+1]]=='1')continue;
      int flag = 0;
      while(true)
	{
	  y += dd[r];
	  x += dd[r + 1];
	  if(y< 0||y>=H||x<0||x>=W)break;
	  if(y == gy && x == gx)
	    {
	    	//printf("%d %d karagoal\n", ty, tx);
	      ans = min(ans, depth+1);
	    }
	  if(tmp[y][x]=='1')
	    {
	      flag = 1;
	      tmp[y][x] = '0';
	      y -= dd[r];
	      x -= dd[r+1];
	      break;
	    }
	}
      if(flag)
	{
		//printf("%d %d kara %d %d  %d\n",ty, tx, y, x, r);
	  dfs(tmp, depth+1, y, x,(r+2)%4);
	}
      
    }
 
}


int main()
{
  while(true)
    {
      scanf("%d%d", &W, &H);
      //printf("now%d %d\n",W, H);
      if(W == 0 && H == 0)break;
      for(int i = 0; i < H; i++)
	{
	  for(int j = 0; j < W; j++)
	    {
	      cin >> ban[i][j];
	      // scanf("%c", &ban[i][j]);
	      if(ban[i][j]=='2')
		{
		  sy=i;
		  sx=j;
		}
	      if(ban[i][j]=='3')
		{
		  gy=i;
		  gx=j;
		}
		//cout << ban[i][j];
	    }
	    //cout << endl;
	}
      // printf("jj\n");
      ans = 20;
      dfs(ban, 0, sy, sx, -1);
      if(ans == 20)printf("-1\n");
      else printf("%d\n",ans);
			  
    }
  return 0;
}

Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  long long x = t1 * (a1 - b1);
  long long y = t2 * (a2 - b2);
  if (x + y == 0) {
    cout << "infinity\n";
    return 0;
  }
  if ((__int128) x * (x + y) >= 0) {
    cout << 0 << '\n';
    return 0;
  }
  __int128 p = abs(x);
  __int128 q = abs(x + y);
  cout << (long long) (p / q * 2) + 1 - (p % q == 0) << '\n';
  return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
s = input()
flg = 0
for i in range(a +b +1):
    try:
        if (0 <= int(s[i]) <= 9):
            if i == a:
                flg = 0
                break
    except:
        if i == a:
            flg = 1
        else:
            flg = 0
            break
print("Yes" if flg == 1 else "No")

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
int main() {
    string n;
    cin>>n;
    for(int i=0;i<3;i++){
        if(n[i]=='1')n[i]='9';
        else if(n[i]=='9')n[i]='1';
    }
    cout<<n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=2e5+5;
const int MOD=1e9+7;

int main(){
	int N;
	cin>>N;
	vi C;
	int b=0;
	rep(i,N){
		int a;
		cin>>a;
		if(a!=b){
			C.push_back(a);
			b=a;
		}
	}
	int M=sz(C);
	int pr[MAX];
	map<int,int> mp;
	rep(i,M){
		auto itr=mp.find(C[i]);
		if(itr == mp.end()){
			pr[i]=-1;
			mp[C[i]]=i;
		}
		else{
			pr[i]=itr->second;
			itr->second = i;
		}
	}
	int dp[MAX];
	dp[0]=1;
	rep1(i,M-1){
		if(pr[i]==-1)dp[i]=dp[i-1];
		else dp[i]=(dp[i-1]+dp[pr[i]])%MOD;
	}
	cout<<dp[M-1]<<endl;
}

Measured memory_bytes: 12020
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <deque>


using namespace std;

typedef long long ll;
typedef vector<vector<int> > Graph;


int main() {
    
    string S;
    cin>>S;
    deque<char> dq1,dq2;
    
    int count=0;
    

    
    int Q;
    cin>>Q;
    int F;
    char C;
    
    for(int i=0;i!=Q;++i){
        int T;
        cin>>T;
        switch(T){
            case 1:
                ++count;
                break;
            case 2:
                cin>>F;
                cin>>C;
                if(count%2==0){
                    
                    switch(F){
                        case 1:
                            dq1.push_front(C);
                            break;
                        case 2:
                            dq2.push_back(C);
                            break;
                            
                    }
                
                }else{
                    switch(F){
                        case 1:
                            dq2.push_back(C);
                            break;
                        case 2:
                            dq1.push_front(C);
                            break;
                    }
                }
        }
        
    }
    
    if(count%2==0){
        for(deque<char>::iterator itr=dq1.begin();itr!=dq1.end();++itr){
            cout<<*itr;
        }
        cout<<S;
        for(deque<char>::iterator itr=dq2.begin();itr!=dq2.end();++itr){
            cout<<*itr;
        }
        cout<<endl;
    }else{
        reverse(dq1.begin(),dq1.end());
        reverse(dq2.begin(),dq2.end());
        reverse(S.begin(),S.end());
        for(deque<char>::iterator itr=dq2.begin();itr!=dq2.end();++itr){
                   cout<<*itr;
        }
        cout<<S;
         for(deque<char>::iterator itr=dq1.begin();itr!=dq1.end();++itr){
                  cout<<*itr;
              }
             cout<<endl;
        
        
    }
    

}
    

Measured memory_bytes: 3916