akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 998244353;

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    vector<int> blue(n);
    vector<int> red(n);
    for(int i=0; i<n; ++i){
        blue[i] = s[i] - '0';
        red[i] = 2 - blue[i];
    }

    vector<int> dp(1, 1);
    for(int i=0; i<2*n; ++i){
        vector<int> nextDp = dp;
        nextDp.resize(i+2, 0);
        for(int j=0; j<=i; ++j){
            nextDp[j+1] += dp[j];
            nextDp[j+1] %= MOD;
        }
        for(int j=0; j<=i+1; ++j){
            if(!(j <= blue.front() && i - j + 1 <= red.front()))
                nextDp[j] = 0;
        }
        dp = move(nextDp);

        for(int j=1; j<n; ++j){
            if(blue[j] > 0){
                -- blue[j];
                ++ blue[j-1];
            }
            if(red[j] > 0){
                -- red[j];
                ++ red[j-1];
            }
        }
    }

    int ans = 0;
    for(int i=0; i<=2*n; ++i){
        ans += dp[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>

using namespace std;

int main() {
	long int K;
	char s[120000];
	
	cin >> s;
	cin >> K;

	int len = strlen(s);

	for(int i = 0;i < len;i++)
	{
		if(s[i] == 'a')
			continue;

		int cost = (int)('z' - s[i]) + 1;

		if(cost <= K)
		{
			s[i] = 'a';
			K -= cost;
		}
	}

	s[len - 1] = (int)(s[len - 1] - 'a' + K) % 26 + (int)'a'; 

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
b = 0
c = 0
while c == 0:
    for i in range(n):
        if a[i]%2 == 0:
            a[i] = a[i]/2
            b += 1
        else:
            c += 1

print(int(b/n))

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

int main(){
	int n;
	cin >> n;
	vector<int> v(n),c(n);
	for(int i=0; i<n; i++) cin >> v[i];
	for(int i=0; i<n; i++) cin >> c[i];
	int ans = 0;
	for(int i=0; i<n; i++){
		if(v[i]-c[i] > 0){
			ans += v[i]-c[i];
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    string str;
    int q;
    cin >> str >> q;

    for (int i = 0; i < q; i++) {
        string inst;
        unsigned int a,b;
        cin >> inst >> a >> b;

        if (inst == "print") {
            cout << str.substr(a,b-a+1) << endl;
        } else if (inst == "reverse") {
            string target = str.substr(a,b-a+1);
            reverse(target.begin(), target.end());
            str = str.substr(0,a) + target + str.substr(b+1);
        } else if (inst == "replace") {
            string rep;
            cin >> rep;
            str = str.substr(0,a) + rep + str.substr(b+1);
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define l long long
using namespace std;l q,x,y,f[99]={0,1},m=1e9+7;main(){cin>>q;rep(i,97)f[i+2]=f[i]+f[i+1];rep(i,q){cin>>x>>y;if(x>y)swap(x,y);if(y<=2){cout<<1<<" "<<(y==1?1:x==1?2:4)<<" ";continue;}rep(j,99){if(x<f[j]||y<f[j+1]){l a=x==1?2:1;rep(k,j-2){l n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];if(n<=x&&m<=y)a+=(y-m)/n+1;}if(f[j]<=x){a++;rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);}cout<<j-2<<" "<<a%m<<" ";j=99;}}}}


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

int main()
{
    string a,b;
    cin>>a>>b;
    if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def main():
	n=int(input())
	
	if n%2==1:
		print(0)
		exit(0)
	else:
		ans=0
		for i in range(1,36):
			ans+=n//(2*(5**i))
		print(ans)




	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;

int n; 

int main() {
	scanf("%d", &n);
	if(n >= 30) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 3764
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n;
int arr[100005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	
	int ans=0;
	rep(x,0,n){
		cin>>arr[x];
		
		if (x%2==0 && arr[x]%2==1) ans++;
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int get() { int r; cin >> r; return r; }
signed main() {
	int x, y;
	while (cin >> x >> y) {
		if (x < 0)x = -x;
		if (y < 0)y = -y;
		int p = x + y;
		if (p == 1) cout << "1\n";
		else if (p % 2 == 1) cout << p + (x == 0 || y == 0) << endl;
		else cout << p - x % 2 << endl;
	}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define ll unsighned long int

int main(){
    int h,n;
    cin >> h >> n;
    int a = 0;

    for(int i = 0; i < n; ++i){
        int b;
        cin >> b;
        a += b;
    }

    if(a >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
 
}

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

int main() {
    int   N;
    cin >> N;
    vector<int> D(N);
    int total = 0;
    int total2 = 0;

    for (int i = 0; i < N; i++) {
      cin >> D.at(i);
      int NUM = D.at(i);
      total = total + NUM;
      total2 = total2 + NUM*NUM;

    }

    cout << (total*total - total2)/2<< endl;
}


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


int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long ans = 0;

    rep(i, 0, n){
        long long x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        long long y = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        //if(a[x] == b[i]) x--;
        ans += x * y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
import sys
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            print(i,j,n-i-j)
            sys.exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int counter = 0;
		while (scanner.hasNext()) {

			if (counter == 0) {
				counter = scanner.nextInt();
				if (counter == 0) {
					break;
				}
			}

			String answer = "";
			int calc = counter;
			int rem = 0;

			while (calc >= 8) {
				rem = calc%8;
				answer = String.valueOf(rem) + answer;

				calc = calc/8;
			}
			// 最後の数値
			answer =  String.valueOf(calc) + answer;

			// 単純に置換
			answer = answer.replace("7", "9");
			answer = answer.replace("6", "8");
			answer = answer.replace("5", "7");
			answer = answer.replace("4", "5");

			System.out.println(answer);

			counter = 0;
		}

		scanner.close();
	}



}


Measured memory_bytes: 69716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int A, B; cin >> A >> B;
    for (int i = 0; i < 10000; i++)
    {
        if( (int)(i*0.08)==A && (int)(i*0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use 5.010;
my @args;
for (<>) {
    chomp $_;
    push @args, $_;
}

my ($N, $M, $X, $Y) = split " ", shift @args;
my @x = split " ", shift @args;
my @y = split " ", shift @args;
my $xmax = (sort {$b <=> $a} @x)[0];
my $ymin = (sort {$a <=> $b} @y)[0];

if ($xmax < $ymin and $xmax < $Y and $X < $ymin) {
    say 'No War';
} else {
    say 'War';
}

__END__



Measured memory_bytes: 1920
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int dp[101][21] = { 0 };
	int  n, s[101], i, j;
	cin>>n;
	for (i = 1; i <= n; i++)
		cin>>s[i];
	dp[1][s[1]] = 1;
	for (i = 1; i <= n - 1; i++)
	{
		for (j = 0; j <21; j++)
		{
			if (dp[i][j] >= 1)
			{
				if (j + s[i + 1] <= 20)
					dp[i + 1][j + s[i + 1]] = dp[i][j]+ dp[i + 1][j + s[i + 1]];
				if (j - s[i + 1] >= 0)
					dp[i + 1][j - s[i + 1]] = dp[i][j]+dp[i + 1][j - s[i + 1]];
			}
		}
	}
	cout<<dp[n - 1][s[n]]<<endl ;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(a) (a.begin(),a.end())
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  string s;
  cin >> s;
  deque<char>st;
  st.push_back(s[0]);
  REP(i,1,s.size()){
    char now = s[i];
    char mae = 'T';
    if(st.size() != 0)mae = st.back();
    if(mae == 'S'){
      if(now == 'T')st.pop_back();
      else st.push_back('S');
    }
    else{
      st.push_back(now);
    }
  }
  string ans;
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 3704
def main():
    n = int(input())
    s = list(input())
    r = [0] * n
    g = [0] * n
    b = [0] * n
    # print(s)
    for i, rgb in enumerate(s):
        if rgb == 'R':
            r[i] += 1
        elif rgb == 'G':
            g[i] += 1
        else:
            b[i] += 1

        if i != 0:
            r[i] += r[i-1]
            g[i] += g[i-1]
            b[i] += b[i-1]
    # print(r)
    ans = 0
    mid = [0] * n
    # print('A')
    for i, rgb in enumerate(s):
        # print(i)

        # print('A')
        for j in range(1,i+1):
            # print(i,j,rgb)
            if i+j >= n or i-j < 0:
                break
            # print(s[i-j],rgb,s[i+j])
            if rgb != s[i-j] and s[i-j] != s[i+j] and rgb != s[i+j]:
                mid[i] += 1



    # print(mid)
    for i, ss in enumerate(s):
        if i == 0:
            continue
        if ss == 'R':
            tmp = g[i-1] * (b[-1] - b[i])
            tmp += b[i-1] * (g[-1] - g[i])
            tmp -= mid[i]
        elif ss == 'G':
            tmp = r[i-1] * (b[-1] - b[i])
            tmp += b[i-1] * (r[-1] - r[i])
            tmp -= mid[i]
        else:
            tmp = g[i-1] * (r[-1] - r[i])
            tmp += r[i-1] * (g[-1] - g[i])
            tmp -= mid[i]
        ans += tmp
    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 9464
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;

#define mem(x,y) memset(x,y,sizeof(x))

const int N=600,M=105000;

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    if (a<b) swap(a,b);
    if ((a-b) % 2==1) printf("Borys\n");
    else printf("Alice\n");

    return 0;
}


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

public class Main{
	static StringBuilder sb = new StringBuilder();
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			int[] A = new int[n];
			for(int i = 0; i<n ; i++)
			{
				A[i] = Integer.parseInt(br.readLine());
			}
			shellSort(A,n);
			
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	public static void shellSort(int[] arr , int l)
	{
		
		int m = 1 ,cnt =0;
		int G[] = new int[15];
		G[0] = 1;
		while((G[m] = G[m-1] * 3 +1) <= l){
			m++;
		}
		sb.append(m).append('\n');
		m--;
		for(; m >= 0 ; m--){
			sb.append(G[m]);
			if(m!=0)
				sb.append(' ');
			cnt += insertionSort(arr,l,G[m]);
		}
		sb.append('\n').append(cnt).append('\n');
		
		for(m = 0 ; m < l ; m++){
			sb.append(arr[m]).append('\n');
		}
			System.out.print(sb);
	}
	public static int insertionSort(int[] a,int n , int g)
	{
		int cnt = 0;
		int v;
		for(int i = g ; i < n ; i++)
		{
			v = a[i];
			int j = i-g;
			while(j >= 0 && a[j] > v)
			{
				a[j+g] = a[j];
				a[j] = v;
				j -= g;
				cnt++;
			}
		}
		return cnt;
	}
}

Measured memory_bytes: 131508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define MOD 1e9+7

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 (a>b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = a*x+b*y; //AとBだけ
    chmin(ans, 2*c*max(x, y)); //Cだけ
    if (x > y) {
        chmin(ans, 2*c*y+a*(x-y));
    } else {
        chmin(ans, 2*c*x+b*(y-x));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<char> s(n);
  rep(i, n) cin >> s[i];
  unordered_map<char, int> mp;
  rep(i, n) mp[s[i]];
  if(mp.size() == 4) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    s = list(input())
    first = int(''.join(s[:2]))
    end = int(''.join(s[2:4]))

    if 1 <= first and first <= 12:
        if 1 <= end and end <= 12:
            print('AMBIGUOUS')
            return
        else:
            print('MMYY')
            return
    else:
        if 1 <= end and end <= 12:
            print('YYMM')
            return
        else:
            print('NA')
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n=int(input())
h=list(map(int,input().split()))
ans=0
while h!=[0]*n:
  now=0
  for i in range(n):
    if now==1:
      if h[i]==0:
        ans+=1
        now=0
      else:
        h[i]-=1
    else:
      if h[i]!=0:
        h[i]-=1
        now=1
  if now==1:ans+=1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
  int n,i;
  int judge=0;
  int j=1;
  int ans = 0;
  scanf("%d",&n);
  int s[200001];
  
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
    if(s[i] == 1){
      judge += 1;
    }
  }
  
  if(judge == 0){
    printf("-1");
    return 0;
  }
    
  for(i=0;i<n;i++){
   switch(s[i] == j){
    case 0: ans += 1;break;
    case 1: j += 1;break;
   }
  }
    
  printf("%d",ans);
  return 0;
}
 

Measured memory_bytes: 896
#include<cstdio>
#include<cctype>
const int N=100007,P=1000000007;
int a[N],deg[N],vis[N],pre[N],cnt[N],f[N];
int read(){int x=0,c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
int add(int a,int b){return a+=b-P,a+(a>>31&P);}
int mul(int a,int b){return 1ll*a*b%P;}
int main()
{
    int n=read(),ans=1;
    for(int i=1;i<=n;++i) ++deg[a[i]=read()];
    for(int i=1,p;(p=i)<=n;++i)
    {
	if(deg[i]>2) return puts("0"),0;
	if(deg[i]<2||vis[i]) continue;
	do
	{
	    if(vis[p]) return puts("0"),0;
	    vis[p]=1,pre[a[p]]=p,p=a[p];
	}while(p^i);
    }
    for(int i=1,p,l1,l2;i<=n;++i)
	if(!deg[i])
	{
	    for(p=i,l1=0,l2=0;!vis[p];p=a[p]) vis[p]=1,++l1;
	    do ++l2,p=pre[p]; while(deg[p]^2);
	    if(l1<l2) ans=add(ans,ans); else if(l1>l2) return puts("0"),0;
	}
    for(int i=1;i<=n;++i)
	if(!vis[i])
	{
	    int p=i,l=0;
	    do ++l,p=a[p],vis[p]=1; while(p^i);
	    ++cnt[l];
	}
    for(int i=1;i<=n;ans=mul(ans,f[cnt[i++]]))
    {
	f[0]=1,f[1]=1+(i^1&&i&1);
	for(int j=2;j<=cnt[i];++j) f[j]=add(mul(i,mul(j-1,f[j-2])),mul(f[1],f[j-1]));
    }
    printf("%d",ans);
}


Measured memory_bytes: 1920
#include <stdio.h>

int main(){
   int n,a[3][3],i,j,k,b,c[3][3];
 
   for (i=0;i<3;i++)
      for (j=0;j<3;j++) {
          scanf("%d",&a[i][j]);
          c[i][j]=0;
      }
   scanf("%d",&n);
   for (i=0;i<n;i++) {
      scanf("%d",&b);
      for (j=0;j<3;j++)
         for (k=0;k<3;k++) 
            if (a[j][k]==b) c[j][k]=1;
   }
   if (c[0][0]+c[1][1]+c[2][2]==3 || c[2][0]+c[1][1]+c[0][2]==3) {
      puts("Yes");
      return 0;
   }
   for (i=0;i<3;i++)
      if (c[i][0]+c[i][1]+c[i][2]==3 || c[2][i]+c[1][i]+c[0][i]==3) {
         puts("Yes");
         return 0;
      }
   puts("No");
   return 0;
}


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

int main()
{
    int N;
    int a[110]; // 最大 100 個ですが余裕をもたせます
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> a[i];

    sort(a, a + N, greater<int>()); // a[0:N] を大きい順にソート
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; ++i)
    {
        if (i % 2 == 0)
        { // Alice のターン
            Alice += a[i];
        }
        else
        { // Bob のターン
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N){
    ll ans = 0;
    return ans;
}

int main(){
    ll N,K,S; cin >> N >> K >> S;
    ll X = 1e9;
    if(S == X) X--;
    rep(i,N){
        if(i < K) cout << S << " ";
        else cout << X << " ";
    }
}

Measured memory_bytes: 1280
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;

const int N = 100010 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
	char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
	cout << x << endl ;
	exit(0) ;
}

void PRINT(string x) {
	cout << x << endl ;
	exit(0) ;
}

void douout(double x){
	 printf("%lf\n", x + 0.0000000001) ;
}

int n, sum, ansid ;
int a[N] ;

signed main(){
	scanf("%d", &n) ;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]) ;
		sum += a[i] ;
	}
	double ave = 1.0 * sum / n, ans = dinf ;
	for (int i = 1; i <= n; i++) {
		if (ans > abs(1.0 * a[i] - ave)) ans = abs(1.0 * a[i] - ave), ansid = i;
	}
	printf("%d\n", ansid - 1) ;
}

/*
写代码时请注意：
	1.是否要开Long Long？数组边界处理好了么？
	2.实数精度有没有处理？
	3.特殊情况处理好了么？
	4.做一些总比不做好。
思考提醒：
	1.最大值和最小值问题可不可以用二分答案？
	2.有没有贪心策略？否则能不能dp？
*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String ans = "";

		if ( N <= 999 ) {
			ans = "ABC";
		} else {
			ans = "ABD";
		}
		System.out.println( ans );
	}
}

Measured memory_bytes: 21972
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))


x = [1 for _ in range(N)]
for i in range(1, N):
    if i == 0:
        x[i] = 1
    elif T[i - 1] < T[i]:
        x[i] = 1
    else:
        x[i] = T[i]

y = [1 for _ in range(N)]
for i in range(N - 2, -1, -1):
    if i == N - 1:
        y[i] == 1
    if A[i] > A[i + 1]:
        y[i] = 1
    else:
        y[i] = A[i]

ans = 1

for i in range(N):
    ans = ans * min(x[i], y[i]) % int(1e9 + 7)


for x,y,t,a in zip(x,y,T,A):
    if x == 1 and t > a:
        ans = 0
    if y == 1 and t < a:
        ans = 0


print(ans)

Measured memory_bytes: 19136
import math
A, B = map(int, input().split())
gcd = math.gcd(A, B)
ans = [1]
while gcd % 2 == 0:
  ans.append(2)
  gcd = gcd // 2
f = 3
while f * f <= gcd:
  if gcd % f == 0:
    ans.append(f)
    gcd = gcd // f
  else:
    f += 2
if gcd != 1:
  ans.append(gcd)
print(len(set(ans)))

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  set<int> colors;
  int frees = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    int col = a / 400;
    if (8 <= col)
      ++frees;
    else
      colors.insert(col);
    //cout << col << "\n";
  }
  cout << max(1lu, colors.size()) << " "
       << colors.size() + frees << "\n";
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int itemCount = int.Parse(Reader.ReadLine());
        int[] items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int[] ordered = items.OrderBy(a => a).ToArray();
        int center1 = ordered[ordered.Length / 2 - 1];
        int center2 = ordered[ordered.Length / 2];

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < itemCount; i++) {
            if(center1 == center2) {
                ans.AppendLine(center1.ToString());
                continue;
            } 
            if(items[i]<= center1) {
                ans.AppendLine(center2.ToString());
            } else {
                ans.AppendLine(center1.ToString());
            }
        }
        Console.Write(ans.ToString());
         
    }



    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


6
5 5 4 4 3 3



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 50680
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//-----------------------------------//

int digitsum(ll x) {
	int res = 0;
	while (x > 0) {
		res += x % 10;
		x /= 10;
	}
	return res;
}

double calc(ll n) {
	int ds = digitsum(n);
	return (double)n / ds;
}

ll func(ll n) {
	pair<double, ll> res(calc(n), n);

	ll div = 1, x = n;
	
	while (div < 10000000000000000ll) {
		if (x % 10 == 9) {
			x /= 10;
			div *= 10;
		}
		ll m = (x + 1) * div - 1;
		x++;
		if (n > m) continue;
		pair<double, ll> cur(calc(m), m);
		chmin(res, cur);
	}

	return res.se;
}

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

	vector<ll> ans;
	ans.push_back(1);
	while (ans.back() < 1000000000000000ll) {
		ans.push_back(func(ans.back() + 1));
	}

	REP(i, K) printf("%lld\n", ans[i]);

	return 0;
}


Measured memory_bytes: 256
import math
 
MOD = 1000000000 + 7
 
def egcd(a, b):
    if a ==  0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b%a, a)
        return (g, x - (b//a) * y, y)
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception("No inverse exists")
    else:
        return x % m
 
def combination(n, r):
    return math.factorial(n)%MOD * modinv(math.factorial(r), MOD) * modinv(math.factorial(n-r), MOD) % MOD
    # return math.factorial(n) // math.factorial(r) // math.factorial(n-r)
 
N, K = [int(x) for x in input().split()]
 
for i in range(1, K+1):
    if N-K+1 < i:
        ans = 0
    else:
        ans = (combination(N-K+1, i) * math.factorial((K-i)+(i-1)))%MOD * (modinv(math.factorial(K-i), MOD)%MOD) * (modinv(math.factorial(i-1), MOD)%MOD)
 
    print(ans%MOD)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int n,m;
  cin>>n>>m;
  int left=1;
  int right=n;
  rep(i,m){
    int l,r;
    cin>>l>>r;
    if(l>=left){
      left=l;
    }
    if(r<=right){
      right=r;
    }
  }
  if(right-left+1>0){
    cout<<right-left+1<<endl;
  }else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import bisect

n = int(input())
a = list(map(int, input().split()))

a.sort()

if n == 2:
    print(a[1], a[0])
    exit()
# value = comb(a[1], a[0], exact=True)
# ans = [a[1], a[0]]
# index = 0
# for i in range(2, n):
#     value_tmp = comb(a[i], a[index], exact=True)
#     x = a[i]
#     y = a[index]
#     diff = abs((x-2*y)//2)
#     while 1:
#         y_new = a[index+1]
#         diff_new = abs((x-2*y_new)//2)
#         if diff_new > diff:
#             break
#         else:
#             index += 1
#     if value_tmp > value:
#         ans = [a[i], a[index]]
#         # value = value_tmp
# print(*ans)

x = a[-1]
index = bisect.bisect_left(a[:n-1], x/2)

ans = []
ans.append([abs(x/2-a[index-1]), a[index-1]])
ans.append([abs(x/2-a[index]), a[index]])
# ans.append([abs(x/2-a[index+1]), a[index+1]])

ans.sort()

print(x, ans[0][1])


Measured memory_bytes: 19820
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323
//void quick(int *,long long,long long);

int main(){
     
	char i='A';
	char x,y;
	while(scanf("%c,%c",&x,&y)!=EOF){
		if(i==x)
			i=y;
		else if(i==y)
			i=x;
	}
	printf("%c\n",i);
	return 0;
}

Measured memory_bytes: 544
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}

ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}





// substr(start, len)

int main(){
  long double a, b, c;

  cin >> a >> b >> c;

  if(c - a - b - 2*sqrt(a*b) > 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

// CHECK if it's possible to overflow!!
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	int u, v;
	cin >> N;
	cin >> u >> v;
	u--;
	v--;

	vector<vector<int>> tree(N);
	queue<int> next;
	vector<int> depth_u(N, INF32);
	vector<int> depth_v(N, INF32);

	for (int i = 0; i < N - 1; i++)
	{
		int from, to;
		cin >> from >> to;
		tree[from - 1].push_back(to - 1);
		tree[to - 1].push_back(from - 1);
	}

	depth_u[u] = 0;
	next.push(u);

	for (; !next.empty();)
	{
		int current = next.front();
		next.pop();
		for (auto to : tree[current])
		{
			if (depth_u[current] + 1 < depth_u[to])
			{
				depth_u[to] = depth_u[current] + 1;
				next.push(to);
			}
		}
	}

	depth_v[v] = 0;
	next.push(v);

	for (; !next.empty();)
	{
		int current = next.front();
		next.pop();
		for (auto to : tree[current])
		{
			if (depth_v[current] + 1 < depth_v[to])
			{
				depth_v[to] = depth_v[current] + 1;
				next.push(to);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (depth_u[i] < depth_v[i])
		{
			ans = max(depth_v[i] - 1, ans);
		}
	}
	cout << ans << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 6656
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;
ll mpow(ll a, ll b){ll r=1;a%=mod;while(b){r=r*((b%2)?a:1)%mod,a=a*a%mod,b>>=1;}return r;}



int main() {
	int n; cin>>n;
	int p[2][2010];
	vector<vector<vector<int>>> nxt(2);
	rep(i,0,2){
		nxt[i].resize(n+1);
		rep(j,0,n+1)nxt[i][j].resize(n+1);
	}
	rep(i,0,2*n){
		char c; int x;
		cin>>c>>x;
		p[c=='W'][x-1]=i;
	}
	rep(i,0,2)rep(j,0,n){
		rep(k,j+1,n) if(p[i][k]<p[i][j]) nxt[i][j][n]++;
		rrep(k,n-1,-1) nxt[i][j][k]=nxt[i][j][k+1]+(p[i==0][k]<p[i][j]);
	}
	vector<vector<int>> dp(n+1);
	rep(i,0,n+1) dp[i].resize(n+1,inf);
	dp[0][0]=0;
	rep(i,0,n+1)rep(j,0,n+1){
		if(i<n)dp[i+1][j]=min(dp[i+1][j],dp[i][j]+nxt[0][i][j]);
		if(j<n)dp[i][j+1]=min(dp[i][j+1],dp[i][j]+nxt[1][j][i]);
	}
	printf("%d\n",dp[n][n]);
	return 0;
}

Measured memory_bytes: 47360
import java.util.Scanner;
public class Main { 
	public static void main(String[] args) {
		// ?¨??????\??????????????????????????????????????? 
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt(); 
		int n = sc.nextInt();
		int[] values = new int[w]; 
		for (int i = 0; i < values.length; i++) { 
			values[i] = i + 1; 
			} 
		for (int i = 0; i < n; i++) { 
			String str = sc.next(); 
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1; 
			int b = Integer.parseInt(ab[1]) - 1; 
			int num;
			num=values[a];
			values[a]=values[b];
			values[b]=num;
	
			} 
		// values?????????????????? } }
		for(int i=0;i<values.length;i++)
		{
			System.out.println(values[i]);
		}
	}
}

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

int main(){
    int n;
    cin >> n;
    int result = n / 1.08;
    if(result * 1.08 == n){
        cout << result << endl;
    }else if(int((result+1) * 1.08) == n){
        cout << result+1 << endl;
    }else if(int((result-1) * 1.08) == n){
        cout << result-1 << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

int main()
{
    faster_io;
    double w,h,x,y;

    cin>>w>>h>>x>>y;
    int f=0;
    if(w/2==x && h/2==y) f=1;

    double ans = (w*h)/2;
    cout<<fixed<<setprecision(6)<<ans<<" "<<f<<endl;

    return 0;
}






Measured memory_bytes: 256
#include<cstdio>
long long a,b,k;
int main()
{
    scanf("%lld%lld%lld",&k,&a,&b);
    if(k<=a)return puts("1"),0;
    else if(a<=b)return puts("-1"),0;  
    else printf("%lld\n",((k-a)/(a-b)+bool((k-a)%(a-b)))<<1|1);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
#include<math.h>

int main(void){
    int N;
    scanf("%d", &N);
    int x;
    for(x=N; x>0; x--) {
        int root = (int)sqrt(x);
       if(root * root == x) {
           printf("%d\n",x);
           return 0;
       }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
    
    
  int main(){
   lint h,w,k;
   cin>>h>>w>>k;
   char x[h][w];
   lint a[h][w];
   lint t=1;
   rep(i,h){
       rep(j,w){
           cin>>x[i][j];
           if(x[i][j]=='#'){
               a[i][j]=t;
               ++t;
           }else a[i][j]=0;
       }
   }
   lint tmp,tmp1;
   rep(i,h){
       rep(j,w){
       if(j==0){tmp=a[i][j];
             continue;
       }
       tmp1=a[i][j];
       if(tmp1==0)a[i][j]=tmp;
       else tmp=tmp1;

       }
   }
    rep(i,h){
       repm(j,w){
       if(j==(w-1)){tmp=a[i][j];
             continue;
       }
       tmp1=a[i][j];
       if(tmp1==0)a[i][j]=tmp;
       else tmp=tmp1;

       }
   }
     rep(j,w){
       rep(i,h){
       if(i==0){tmp=a[i][j];
             continue;
       }
       tmp1=a[i][j];
       if(tmp1==0)a[i][j]=tmp;
       else tmp=tmp1;

       }
   }
    rep(j,w){
       repm(i,h){
       if(i==(h-1)){tmp=a[i][j];
             continue;
       }
       tmp1=a[i][j];
       if(tmp1==0)a[i][j]=tmp;
       else tmp=tmp1;

       }
   }
   rep(i,h){
       rep(j,w){
           cout<<a[i][j]<<" ";
       }
       cout<<endl;
   }
  }
     
  

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define SORT(x) sort(x.begin(),x.end())
using ll = long long;

int main() {
	ll n, k; cin >> n >> k;
	vector<ll> a(n); rep(i, 0, n) cin >> a[i];
	
	if ((n - 1) % (k - 1) >= 1) cout << (n - 1) / (k - 1) + 1 << endl;
	else cout << (n - 1) / (k - 1) << endl;

	return 0;
}

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

int main(){
    unsigned long N;
    cin >> N;
    vector<long> a(N);
    for(auto& i : a)cin >> i;
    long C;
    cin >> C;
    long u{C};
    for(const auto i : a)u = __gcd(u, abs(i));
    
    vector<long> sieve(31622, 1);
    for(long i = 2; i < 31622; ++i)
        if(sieve[i]){
            if(u % i == 0 && cout << i << endl)
                while(u % i == 0)u /= i;
            else if(C % i == 0 && i <= N){
                vector<long> v(i);
                for(unsigned long j = 0, k = 0; j < N; ++j, k = k == i - 2 ? 0 : ++k)v[k] += a[j];
                if(none_of(v.begin(), v.end(), [&i](auto x){return x % i;}))cout << i << endl;
            }
            for(auto j = i * i; j < 31622; j += i)sieve[j] = 0;
        }
    if(u ^ 1)cout << u << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i + 1];
  vector<int> b(n + 1);
  for(int i = n; i >= 1; --i) {
    int sum = 0;
    for(int j = i + i; j <= n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum ^ a[i];
  }
  vector<int> ans;
  for(int i = 1; i <= n; i++) {
    if(b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  int m = ans.size();
  rep(i, m) {
    printf("%d%c", ans[i], i + 1 == m ? '\n' : ' ');
  }

  return 0;
}

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0,nn=(intl)(n);i<nn;++i)
#define Rep1(i,n) for(intl i=1,nn=(intl)(n)+1;i<nn;++i)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);}
#define Input2(a,b) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);cin>>(b).at(ii);}
#define mp make_pair
#define mt make_tuple
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
using si = set<intl>;
using vsi = vec<si>;
using mii = map<intl,intl>;
using vmii = vec<mii>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;



int main(){
  string S,T;
  cin >>S>>T;
  intl ans =0;
  Rep(i,S.size()){
    ans += (S.at(i) != T.at(i) )?1:0;
  }
  cout <<ans;
}
    
    
    

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define X first
#define Y second

const int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
const char dirchar[] = {'W', 'N', 'E', 'S'};

bool field[21][21];

int main() {
    int N, M;
    while (cin >> N, N) {
        fill_n((bool *)field, 21*21, false);
        REP(i, N) {
            int x, y;
            cin >> x >> y;
            field[y][x] = true;
        }
        int x = 10, y = 10;
        if (field[y][x]) {
            field[y][x] = false;
            N--;
        }
        cin >> M;
        REP(i, M) {
            char d;
            int step;
            cin >> d >> step;
            int dir = find(dirchar, dirchar+4, d)-dirchar;
            REP(i, step) {
                x += dx[dir];
                y += dy[dir];
                if (field[y][x]) {
                    field[y][x] = false;
                    N--;
                }
            }
        }
        cout << (N == 0 ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 3048
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

int N;
vector<int> a;

int count(int i, LONG n) {
	int cnt = 0;
	if (i == N) {
		return n % 2 == 0 ? 1 : 0;
	}
	for (int j = a[i] - 1; j <= a[i] + 1; j++) {
		cnt += count(i + 1, j * n);
	}
	return cnt;
}

int main(void) {
	cin >> N;
	a.resize(N);
	REP(i, N) cin >> a[i];
	cout << count(0, 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int n = s.size();
  string ans = {};
  vi C(26);

  if(n < 26){
    rep(i, n) C[s[i] - 'a']++;
    rep(i, 26){
      if(C[i] == 0){
        ans = s + char('a' + i);
        std::cout << ans << '\n';
        return 0;
      }
    }
  }

  // n=26のとき
  int index;
  for (int i = n-2; i >= 0; i--) {
    C[s[i+1] - 'a']++;
    if(s[i] < s[i+1]){
      index = i;
      break;
    }
    if(i == 0){
      std::cout << -1 << '\n';
      return 0;
    }
  }
  rep(i, index) ans += s[i];
  rep(i, 26){
    if(C[i] == 1 && i > (s[index] - 'a')){
      ans += char('a' + i);
      std::cout << ans << '\n';
      return 0;
    }
  }
}


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

using namespace std;

int main()
{

	int N;
	int K;
	string S;
	cin >> N;
	cin >> K;
	cin >> S;

	int idx = 0;
	for (int k = 0; k < K; ++k){
		//cerr << S << endl; 
		int s=-1;
		for (int i = idx; i < N - 1; ++i) {
			if (S[i] != S[i + 1]) {
				s = i+1;
				break;
			}
		}
		if (s == -1) {
			break;
		}
		int e = N-1;
		for (int i = s; i < N - 1; ++i) {
			if (S[i] != S[i + 1]) {
				e = i;
				break;
			}
		}	
		int w = e - s + 1;
		for (int i = 0; i < (int)((w+1)/2); ++i) {
			auto cs = S[s + i];
			auto ce = S[e - i];
				

			if (cs == 'R') {
				S[e - i] = 'L';
			}
			else {
				S[e - i] = 'R';
			}
			if (ce == 'R') {
				S[s + i] = 'L';
			}
			else {
				S[s + i] = 'R';
			}
			
		}
		idx = e;
	}
	//cerr << S << endl;
	int v = 0;
	for (int i = 0; i < N - 1; ++i) {
		if (S[i] == S[i + 1]) {
			v++;
		}
	}
	cout << v;
	return 0;
}


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

using namespace std;

const int max_n = 17, inf = 1000111222, mod = 1000000007;

int n, a, b, c[1 << max_n], d[1 << max_n];

string ToString(int a, int k) {
	string s;
	for (int i = 0; i < k; ++i) {
		s += '0' + (a % 2);
		a /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}

int get_bits(int a) {
	int ans = 0;
	while (a) {
		ans += a % 2;
		a /= 2;
	}
	return ans;
}

void get_c(int from, int to, int st, int n) {
	// cout << "from: " << ToString(from, n) << ", to: " << ToString(to, n) << ", st: " << st << ", n: " << n << endl;
	assert(get_bits(from ^ to) % 2);
	if (n == 1) {
		c[st] = from;
		c[st + 1] = to;
		return;
	}
	int b1 = from & (1 << (n - 1));
	int b2 = to & (1 << (n - 1));

	if (b1 != b2) {
		int mid = from ^ b1 ^ 1;
		get_c(from ^ b1, mid, st, n - 1);
		get_c(mid, to ^ b2, st + (1 << (n - 1)), n - 1);
		int l = st, r = st + (1 << (n - 1));
		if (b2) {
			l += (1 << (n - 1));
			r += (1 << (n - 1));
		}
		for (int i = l; i < r; ++i) {
			c[i] ^= 1 << (n - 1);
		}
	} else {
		get_c(from ^ b1, to ^ b2, st, n - 1);
		for (int i = (1 << n) - 4; i >= 0; i -= 4) {
			int x = st + i / 2;
			c[st + i + 3] = c[x + 1] ^ b1;
			c[st + i + 2] = c[x + 1] ^ b1 ^ (1 << (n - 1));
			c[st + i + 1] = c[x] ^ b1 ^ (1 << (n - 1));
			c[st + i] = c[x] ^ b1;
		}
	}


	// if (n == 1) {
	// 	assert(val < 2);
	// 	c[0] = val;
	// 	return;
	// }
	// cout << ToString(val & (~(1 << (n - 1))), n) << "  " << val << endl;
	// get_c(val & ~(1 << (n - 1)), n - 1);
	// if (val & (1 << (n - 1))) {
	// 	for (int i = 0; i < (1 << (n - 1)); ++i) {
	// 		cout << ToString(c[i], n - 1) << endl;
	// 	} cout << endl << endl;
	// 	for (int i = 0; i < (1 << (n - 1)); ++i) {
	// 		c[i + (1 << (n - 1))] = c[i];
	// 		c[i] = d[i];
	// 	}
	// 	for (int i = 0; i < (1 << n); ++i) {
	// 		cout << ToString(c[i], n) << endl;
	// 	} cout << endl << endl;
	// } else {
	// 	for (int i = (1 << n) - 1; i >= 0; --i) {
	// 		c[i] = c[i / 2] + (i % 2) * (1 << (n - 1));
	// 	}
	// }
}

int main() {
	cin >> n >> a >> b;
	if (get_bits(a ^ b) % 2 == 0) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	get_c(a, b, 0, n);
	for (int i = 0; i < (1 << n); ++i) {
		printf("%d ", c[i]);
	}
	return 0;
}

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

using namespace std;

string str;
long res;

int main()
{
	cin >> str;

	long i = 0;
	long n = str.length();

	while (i < n)
	{
		long j = i + 1;
		while (str[i] == str[j] && j < n)
			++j;

		if (j >= n)
			break;

		++res;
		i = j;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 512