akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main(){
    int N;
    cin >> N;
    
    int cnt[10][10];
    rep(i,10) rep(j,10) cnt[i][j]=0;
    
    for(int n=1; n<=N; n++){
        int last = n % 10;
        int first = 0;
        int n_ = n;
        while(n_ > 0){
            first = n_;
            n_ /= 10;
        }
        cnt[first][last] ++;
    }
    
    int ans = 0;
    for(int i=1; i<=9; i++) for(int j=1; j<=9; j++){
        ans += cnt[i][j] * cnt[j][i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a,c,d;
    scanf("%d", &a);
    
    if(a==1)
    {
        printf("Hello World");
    }
    if(a==2){
    scanf("%d %d",&c,&d);
    printf("%d",c+d);
    }
    
    
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

void select(int A[],int n){
  int i,j,mini,k,count=0;
  for(i=0;i<=n-1;i++){
    mini = i;
    for(j=i;j<=n-1;j++){      
      if(A[j]<A[mini]){
	mini =j;
      }
    }
    if(i!=mini){
    k = A[i];
    A[i]=A[mini];
    A[mini] = k;
    count++;
    }
  }
  for(i=0;i<n;i++){
    if(i>=1)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);
}

int main(){
  int i,j,n,A[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  select(A,n);
  return 0;
}

Measured memory_bytes: 604
def accsum(n):
  return (n*(n+1))//2
N = int(input())
l = 0
r = 10**7
while N > 0:
  m = (l+r)//2
  if accsum(m-1) < N <= accsum(m):
    print(m)
    l = 0
    r = 10**7
    N -= m
  elif N <= accsum(m-1):
    r = m
  else:
    l = m

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] arr = new int[N];
		for(int i = 0; i < arr.length; i++) arr[i] = sc.nextInt();
		
		System.out.println(countOceanView(arr));
	}
	
	private static int countOceanView(int[] arr) {
		
		int ans = 1;
		for(int i = 1; i < arr.length; i++){
			if(arr[i] >= arr[i - 1]) ans++;
			arr[i] = Math.max(arr[i], arr[i - 1]);
		}
		
		return ans;
	}
}

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

const int N=2e5+100;
typedef long long ll;

struct stu
{
    int a,b;
    bool operator <(const stu &x) const
    {
        return b<x.b;
    }
}s[N];
int main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   int n;cin>>n;
   for(int i=1;i<=n;i++){
      cin>>s[i].a>>s[i].b;
   }
   sort(s+1,s+1+n);
   ll sum=0;
   for(int i=1;i<=n;i++){
       sum+=s[i].a;
    if(sum>s[i].b) {
        puts("No");
        return 0;
    }
   }
   puts("Yes");
    return 0;
}




Measured memory_bytes: 1792
p = 2019
s  = list(map(int, list(input())))[::-1]
sm = 0
cnt = [0] * p
cnt[0] = 1
n = len(s)
for i in range(n):
    d = s[i] * pow(10, i, p)
    sm = (sm + d) % p
    cnt[sm] += 1
ans = 0
for i in range(p):
    ans += cnt[i] * (cnt[i]-1) // 2
print(ans)

Measured memory_bytes: 12176
/*  ex4_1
    B30095    */
#include <stdio.h>
#include <math.h>
 
int main(void){
    int TreesNum, distance;
    scanf("%d %d", &TreesNum, &distance);
 
    int visibleTreesNum = 2 * distance + 1;  // number of visible trees
    int inspectorNum = ceil((double)TreesNum / visibleTreesNum);  // number of inspectors needed
    
    printf("%d", inspectorNum);
 
    return 0;
}

Measured memory_bytes: 128
from itertools import product as pro
n = int(input())
m = len(str(n))
ans = 0
for i in range(3,m+1):
    for l in pro([3,5,7],repeat=i):
        lst = list(l)
        x = ""
        for j in lst:
            x += str(j)
        if 3 in lst and 5 in lst and 7 in lst:
            if int(x) <= n:
                ans += 1
print(ans)

Measured memory_bytes: 9196
#include <iostream>

using namespace std;

int a[100010];

int main()
{
    int N; cin >> N;
    for (int i=0;i<N;++i) cin>>a[i], a[i]--;
    
    int ans=0;
    
    for(int i=0;i<N;++i) {
        if (a[i] == i) {
            int tmp=a[i];
            a[i]=a[i+1];
            a[i+1]=tmp;
            ans++;
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#define mod 1000000007
using namespace std;
long long x,y,tx,ans,fac[1000001],invfac[1000001];
void exgcd(long long a,long long b)
{
	if (b==0)
	{
		x=1;
		y=0;
		return;
	}
	exgcd(b,a%b); 
	tx=x;
	x=y;
	y=tx-a/b*y;
	return;
}
long long C(long long a,long long b)
{
	if (a>b)
		return 0;
	return fac[b]*invfac[a]%mod*invfac[b-a]%mod;
}
int main()
{
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	h--;
	w--;
	a--;
	b--;
	fac[0]=1;
	for (int i=1;i<=1000000;++i)
		fac[i]=fac[i-1]*i%mod;
	exgcd(fac[1000000],mod);
	invfac[1000000]=x;
	for (int i=999999;i>=0;--i)
		invfac[i]=invfac[i+1]*(i+1)%mod;
	for (int i=a+1;i<=h;++i)
		ans=(ans+((C(i,w-b-1+i)-(i!=a+1)*C(i-1,w-b-2+i))%mod+mod)%mod*C(h-i,h-i+b+1)%mod)%mod;
	cout<<(ans+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll w[101],val[101],dp[101][100001],N,W;
ll trump(ll n,ll m){
	if(n==N+1)return 0;
	if(dp[n][m]!=-1)return dp[n][m];
	ll a=0,b=0;
	if(m>=w[n])
	a=val[n]+trump(n+1,m-w[n]);
	b=trump(n+1,m);
	return dp[n][m]=max(a,b);
}
int main(){
	ios::sync_with_stdio(false);
	cin>>N>>W;
    memset(dp,-1,sizeof(dp));
	for(int i=1;i<=N;i++){
		cin>>w[i]>>val[i];
	}
	cout<<trump(1,W)<<endl;
	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll k;cin>>k;
  buf=(k+49)/50+49;
  cout<<50<<endl;
  if(k%50!=0){
  for(i=0;i<k%50;i++){
    cout<<buf<<" ";
  }
  for(;i<50;i++){
    cout<<buf-(k%50)-1<<" ";
  }
  }
  else{
    for(i=0;i<50;i++){
      cout<<buf<<" ";
    }
  }
  cout<<endl;


  return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

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

if K == 0:
    print (1)
    exit()

dp = [[0] * (K + 1) for _ in range(N + 1)]
for j in range(K + 1):
    dp[N][j] = 1
# dp[N][0] = 1
# print (dp[N])
for i in range(N - 1, -1, -1):
    for j in range(K + 1):
        if j <= A[i]:
            dp[i][j] = dp[i + 1][j]
        else:
            dp[i][j] = dp[i + 1][j] - dp[i + 1][j - A[i] - 1]
    # print (i)
    # print (dp[i])
    for j in range(K):
        dp[i][j + 1] += dp[i][j]
        dp[i][j + 1] %= MOD
    # print (dp[i])
    
print ((dp[0][K] - dp[0][K - 1]) % MOD)

Measured memory_bytes: 119276
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int sum =0;
  for (int i=0; i < N; i++){
    int l,r;
    cin >> l >> r;
    sum += r-l+1;
  }
  cout << sum << endl;
}
     

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

struct card{
  string mark;
  int num;
  string tramp;
  int ord;
};

void SelectionSort(int M,vector<card> A){
  bool flag = true;

  for(int i=0;i<M;++i){
    int minj = i;
    for(int j=i;j<M;++j){
      if(A.at(j).num < A.at(minj).num){
        minj = j;
      }
    }
      swap(A.at(i),A.at(minj));
    }
    for(int i=0;i<M-1;++i){
      cout << A.at(i).tramp << " ";
      if(i < M-1){
        if(A.at(i).num == A.at(i+1).num && A.at(i).ord > A.at(i+1).ord) flag = false;
      }
    }
    cout << A.at(M-1).tramp << endl;
    if(flag){
      cout << "Stable" << endl;
    }else{
      cout << "Not stable" << endl;
    }
}

void BubbleSort(int M,vector<card> A){
  bool flag = true;
  for(int i=0;i<M;++i){
    for(int j=M-1;j>i;--j){
      if(A.at(j).num < A.at(j-1).num) swap(A.at(j),A.at(j-1));
    }
  }
  for(int i=0;i<M-1;++i){
    cout << A.at(i).tramp << " ";
    if(i < M-1){
      if(A.at(i).num == A.at(i+1).num && A.at(i).ord > A.at(i+1).ord) flag = false;
    }
  }
  cout << A.at(M-1).tramp << endl;
  if(flag){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }
}

int main(){
  int N;

  cin >> N;
  vector<card> vec(N);

  for(int i=0;i<N;++i){
    string S;
    string c;
    cin >> S;
    vec.at(i).tramp = S;
    vec.at(i).mark = S.at(0);
    c = S.at(1);
    vec.at(i).num = stoi(c);
    vec.at(i).ord = i;
  }
  BubbleSort(N,vec);
  SelectionSort(N,vec);

}



Measured memory_bytes: 3204
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    if (n < 600)
        cout << 8 << endl;
    else if (n < 800)
        cout << 7 << endl;
    else if (n < 1000)
        cout << 6 << endl;
    else if (n < 1200)
        cout << 5 << endl;
    else if (n < 1400)
        cout << 4 << endl;
    else if (n < 1600)
        cout << 3 << endl;
    else if (n < 1800)
        cout << 2 << endl;
    else
        cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define int64_t int 

using namespace std;

int main(){
	
	int n;
	cin>>n;
	
	int a[n][3];
	int dp[n][3];
	
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<3;i++){
		dp[0][i] = a[0][i];
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			dp[i][j] = a[i][j] + max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
		}
	}
	int ans = INT_MIN;
	
	for(int i=0;i<3;i++){
		ans = max(ans,dp[n-1][i]);
	}
	
	cout<<ans;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
typedef long long ll;
const int N=200005;
const int mod=1e9+7;
int n;
ll s[N];
using namespace std;

/*struct node
{
	int t,next;
}adj[N<<1];
void add(int s,int t)
{
	adj[++now]=(node){t,head[s]};
	head[s]=now;
}*/
int calc(int a,int b)
{
	int ans=1,tmp=a;
	while (b)
	{
		if (b&1) ans=(ll)ans*tmp%mod;
		tmp=(ll)tmp*tmp%mod,b>>=1;
	}
	return ans;
}
inline int read()
{
	char c;int x;
	while (c=getchar(),c<'0' || c>'9');x=c^'0';
	while (c=getchar(),c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x;
}
void write(int x)
{
	if (x==0) return;
	write(x/10);
	putchar((x%10)+'0');
}
int main()
{
	#ifdef Kay
		freopen ("code.in","r",stdin);
		freopen ("code.out","w",stdout);
	#endif
	cin>>n;
	int i;
	for (i=1;i<=n;i++)
	scanf ("%lld",&s[i]),s[i]+=s[i-1];
	ll ans=1ll<<60;
	for (i=1;i<n;i++)
	{
		ll x=s[i],y=s[n]-s[i];
		x=max(x-y,y-x);
		ans=min(ans,x);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstdio>
using namespace std;
int main(void){
	int M,D,count=0,a=0,b=0;
	cin>>M>>D;
	a=D/10;
	b=D-a*10;
	for(int i=1;i<=M;i++)
	{
		for(int j=2;j<=(D/10);j++){
			if((i%j==0&&i/j<=9&&2<=i/j)&&(j!=(D/10)||i/j<=(b)))
				count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdint.h>
#include <math.h>
using namespace std;

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

Measured memory_bytes: 512
INFTY = 1 << 32

def floyd(n, d):
    for k in range(n):
        for i in range(n):
            if d[i][k] == INFTY:
                continue
            for j in range(n):
                if d[k][j] == INFTY:
                    continue
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


if __name__ == '__main__':
    n, e = [int(v) for v in input().split()]
    d = [[INFTY] * n for i in range(n)]
    for i in range(n):
        d[i][i] = 0
    for i in range(e):
        u, v, c = [int(v) for v in input().split()]
        d[u][v] = c

    floyd(n, d)

    negative = False
    for i in range(n):
        if d[i][i] < 0:
            negative = True
            break

    if negative:
        print('NEGATIVE CYCLE')
    else:
        for i in range(n):
            line = []
            for j in range(n):
                if d[i][j] == INFTY:
                    line.append('INF')
                else:
                    line.append(str(d[i][j]))
            print(' '.join(line))


Measured memory_bytes: 6004
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<31;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
}; 

int main() {
    int s; cin >> s;
    combination cm(4005);
    mint ans = 0;
    for (int n = 1; n <= s/3; n++) {
        ans += cm(s-3*n+n-1,n-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	string s;
	// int f=true;
	while(cin>>s,s[0]!='0'){
		int a=0,b=0;
		reep(i,1,s.size()){
			if(s[i]=='A'){
				a++;
			}
			else{
				b++;
			}
		}
		if(a>b) a++;
		else b++;
		cout<<a<<" "<<b<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> c(26),t(26);
  for(int i=0;i<26;i++){
    t[i]=51;
  }
  for(int i=0;i<n;i++){
    cin >> s[i];
    for(int j=0;j<s[i].size();j++){
      c[s[i][j]-'a']++;
    }
    for(int j=0;j<26;j++){
      t[j]=min(t[j],c[j]);
      c[j]=0;
    }
  }
  for(int i=0;i<26;i++){
    if(t[i]!=51){
      for(int j=0;j<t[i];j++){
        cout << char('a'+i);
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int a=1,b=1;
int c;
for(int i=0;i<9;i++){
b=1;
for(int j=0;j<9;j++){
c=a*b;
cout<<a<<"x"<<b<<"="<<c<<endl;
b++;
}
a++;
}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib>
using namespace std;
int main(void){
  string A, B;
  cin >> A;
  cin >> B;
  if(A.at(0) == B.at(2) && A.at(1) == B.at(1) && A.at(2) == B.at(0)){
    cout << "YES";
  } else {
    cout << "NO";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = b;
		if(a <= 5) {
			ans = 0;
		}else if(a < 13) {
			ans /= 2;
		}
		System.out.println(ans);
		sc.close();
	}
}


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

def main():
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))

    k = 0
    c = [[None for j in range(w)] for i in range(h)]
    p = 0
    for i in range(h):
        jlist = range(w) if i % 2 == 0 else reversed(range(w))
        for j in jlist:
            c[i][j] = p + 1
            a[p] -= 1
            if a[p] == 0:
                p += 1
            k += 1
        print(" ".join(str(x) for x in c[i]))

if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
	long a, b, c, k, sum = 0;
	cin >> a >> b >> c >> k;
	while(a > 0 && k > 0) {
		sum += 1;
		a--;
		k--;
	}
	while(b > 0 && k > 0) {
		sum += 0;
		b--;
		k--;
	}	
	while(c > 0 && k > 0) {
		sum -= 1;
		c--;
		k--;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3672
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

X = int(input())

while True:
    if is_prime(X) == True:
        print(X)
        exit()
    else:
        X += 1


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0

typedef struct tag_card {
    char suit_;
    int num_;
} card_t;

void DisplayArray(card_t C[], int N)
{
    int i;
    for (i = 0; i < N; i++) {
        if (i) printf(" ");
        printf("%c%d", C[i].suit_, C[i].num_);
    }
    printf("\n");
}

void BubbleSort(card_t C[], int N)
{
    int i, j;
    card_t tmp;

    for (i = 0; i < N - 1; i++) {
        for (j = N - 1; j >= i; j--) {
            if (C[j].num_ < C[j - 1].num_) {
                tmp = C[j];
                C[j] = C[j - 1];
                C[j - 1] = tmp;
            }
        }
    }
}

void SelectionSort(card_t C[], int N)
{
    int i, j, minj;
    card_t tmp;

    for (i = 0; i < N; i++) {
        minj = i;
        for (j = i; j < N; j++) {
            if (C[j].num_ < C[minj].num_) {
                minj = j;
            }
        }
        tmp = C[i];
        C[i] = C[minj];
        C[minj] = tmp;
    }
}

int IsStable(card_t cBubble[], card_t cSelection[], int N)
{
    int i;

    for (i = 0; i < N; i++) {
        if (cBubble[i].suit_ != cSelection[i].suit_) return FALSE;
    }

    return TRUE;
}

int main(void)
{
    int N, i;
    scanf("%d%*c", &N);
    card_t* C1 = (card_t*)malloc(sizeof(card_t) * N);
    card_t* C2 = (card_t*)malloc(sizeof(card_t) * N);

    for (i = 0; i < N; i++) {
        scanf("%c%d%*c", &C1[i].suit_, &C1[i].num_);
        C2[i] = C1[i];
    }

    BubbleSort(C1, N);
    SelectionSort(C2, N);

    DisplayArray(C1, N);
    printf("Stable\n");
    DisplayArray(C2, N);
    if (IsStable(C1, C2, N)) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }

    return 0;
}

Measured memory_bytes: 612
if __name__ == '__main__':
    try:
        count = []
        result = 0
        T = int(input())
        for _ in range(T):
            x, y = map(int, input().split())
            count.append([x, y])

        for i in range(T-2):
            if count[i][0] == count[i][1] and count[i+1][0] == count[i+1][1] and count[i+2][0] == count[i+2][1]:
                print("Yes")
                exit(0)

        print("No")
    except Exception:
        pass

Measured memory_bytes: 8932
#!/usr/bin/env python3
from functools import lru_cache
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

"""
URL: https://atcoder.jp/contests/dp/tasks/dp_j
J - Sushi / 
実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 
100 点

問題文
N 枚の皿があります。 皿には 1,2,…,N と番号が振られています。 
最初、各 i (1≤i≤N) について、皿 i には ai (1≤ai≤3) 個の
    寿司が置かれています。
すべての寿司が無くなるまで、太郎君は次の操作を繰り返し行います。
1,2,…,N の目が等確率で出るサイコロを振り、出目を i とする。 
皿 i に寿司がある場合、皿 i の寿司を 1 個食べる。 
皿 i に寿司が無い場合、何も行わない。
すべての寿司が無くなるまでの操作回数の期待値を求めてください。

解説 :
「皿1に寿司が2個、皿2に寿司が1個」という状態と 
    「皿1に寿司が1個、皿2に寿司が2個」という状態だと、
        操作回数の期待値は同じ。
よく考えると、「どの皿に何個あるか」という
    ところまでわかる必要はなくて、
        「1個の皿がいくつ(c1)、2個の皿がいくつ(c2)、
            3個の皿がいくつ(c3)」だけで期待値は決まることがわかる。
すると結局

dp[c3][c2][c1] = 1 + 
    dp[c3][c2][c1 - 1] * (1の皿が選ばれる確率) + 
        dp[c3][c2 - 1][c1 + 1] * (2の皿が選ばれる確率) + 
            dp[c3 - 1][c2 + 1][c1] * (1の皿が選ばれる確率) + 
                dp[c3][c2][c1] * (0の皿が選ばれる確率) 

この確率漸化式になる
あとはdp[c3][c2][c1]を左辺に移行してごにょごにょして
dp[c3][c2][c1] = (n + 
    dp[c3][c2][c1 - 1] * c1 + 
        dp[c3][c2 - 1][c1 + 1] * c2 + 
            dp[c3 - 1][c2 + 1][c1] * c3) / (c1 + c2 + c3)
という遷移式を完成
メモ化再帰でもできるという噂があるがPythonはカスなので 
    いろいろと工夫する必要があります。
知見的には 
    ====================================
    | 期待値 = Σ ワンステップ前の期待値 * |
    |    そのステップになるための確率)    |
    ====================================
です。
"""
#solve
def solve():
    n = II()
    c = LI()
    c1, c2, c3 = [c.count(i) for i in range(1, 4)]
    d = [[[0] * (n + 2) for _ in range(n + 2)] for _ in range(n + 2)]
    for i in range(c3 + 1):
        di = d[i]
        dim1 = d[i - 1]
        for j in range(c3 + c2 + 1 - i):
            dim1jp1 = dim1[j + 1]
            dijm1 = di[j - 1]
            dij = di[j]
            for k in range(c3 + c2 + c1 - i - j + 1):
                l = i + j + k
                if l == 0: continue
                res = n
                if i: res += i * dim1jp1[k]
                if j: res += j * dijm1[k + 1]
                if k: res += k * dij[k-1]
                dij[k] = res / l
    print(d[c3][c2][c1])
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 505996
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin >> n;
	cout << n << ":";
	vector<int> ret;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			n /= i;
			ret.push_back(i);
		}
	}
	if(n >= 2) ret.push_back(n);
	for(int i : ret) cout << ' ' << i;
	cout << endl;
	return 0;
}

Measured memory_bytes: 3084
#define _CRT_SECURE_NO_WARNINGS 1

#include <set>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int maxn = 1e3 + 7;

int main() {
	int n;
	LL d;
	cin >> n >> d;
	LL ans = 0;
	rep(i,1,n) {
		LL x,y;
		cin >> x >> y;
		if(x * x + y * y <= d * d) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
n,m = map(int, input().split())
h = [0]
h.extend([int(i) for i in input().split()])
bld = [0]*(n+1)

for i in range(m):
  a,b = map(int, input().split())
  if h[a]>h[b]:
    bld[b] += 1
  elif h[a]<h[b]:
    bld[a] += 1
  else:
    bld[a] += 1
    bld[b] += 1

print(bld.count(0)-1)

Measured memory_bytes: 20000
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int k,n;
    string s;
    cin >> n >> s >> k;
    
    for (int i=0;i<n;i++){
    if (s[i] != s[k-1]) s[i] = '*';
    }
    
    cout <<  s << endl;
}


Measured memory_bytes: 256
while (n = gets.to_i) != 0
	gem = {}
	n.times { gem[gets.split.map &:to_i] = 0}
	m = gets.to_i
	x = y = 10
	m.times {
		dir, dist = gets.split
		dist = dist.to_i
		dx = dy = 0
		case dir
			when ?N; dy = 1
			when ?S; dy = -1
			when ?W; dx = -1
			when ?E; dx = 1
		end
		dist.times {
			x += dx
			y += dy
			gem.delete [x, y]
		}
	}
	puts gem.empty? ? 'Yes' : 'No'
end

Measured memory_bytes: 6116
#include <bits/stdc++.h>
using namespace std;
int h,w;
vector<vector<char> >a;
int check(int i,int j)
{
  vector<vector<int> >dis(h);
  for(int e=0;e<h;e++)dis[e].resize(w);
  queue<pair<int,int> >qu;
  qu.push({i,j});
  while(!qu.empty())
  {
    //cout<<qu.size()<<endl;
    pair<int,int>q=qu.front();
    qu.pop();
    if(q.first!=0)
    {
      if(!dis[q.first-1][q.second] && !((q.first-1)==i && q.second==j) && a[q.first-1][q.second]!='#')
      {
        dis[q.first-1][q.second]+=1+dis[q.first][q.second];
        qu.push({q.first-1,q.second});
        //cout<<qu.front().first<<" "<<qu.front().second<<endl;
      }
    }
    if(q.second!=0)
    {
      if(!dis[q.first][q.second-1] && !(q.first==i && (q.second-1)==j) && a[q.first][q.second-1]!='#')
      {
        dis[q.first][q.second-1]+=1+dis[q.first][q.second];
        qu.push({q.first,q.second-1});
      }
    }
    if(q.second!=w-1)
    {
      if(!dis[q.first][q.second+1] && !(q.first==i && (q.second+1)==j) && a[q.first][q.second+1]!='#')
      {
        dis[q.first][q.second+1]+=1+dis[q.first][q.second];
        qu.push({q.first,q.second+1});
        
      }
    }
    if(q.first!=h-1)
    {
      if(!dis[q.first+1][q.second] && !((q.first+1)==i && q.second==j) && a[q.first+1][q.second]!='#')
      {
        dis[q.first+1][q.second]+=1+dis[q.first][q.second];
        qu.push({q.first+1,q.second});
      }
    }
  }
    int max=0;
    for(int o=0;o<h;o++)
    {
      for(int m=0;m<w;m++)
      {
        if(dis[o][m]>max)max=dis[o][m];
      }
    }
    return max;
}
int main()
{
	
  	cin>>h>>w;
  	a.resize(h);
  	for(int i=0;i<h;i++)
    {
      a[i].resize(w);
      for(int j=0;j<w;j++)cin>>a[i][j];
    }
  int ans=0;
  	for(int i=0;i<h;i++)
    {
      for(int j=0;j<w;j++)
      {
        if(a[i][j]=='.')if(check(i,j)>ans)ans=check(i,j);
      }
    }
  //cout<<check(1,1);
  cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 3588
char*p,s[99999],t[99999];c,l,i;main(n){for(;scanf("%d",&n)*n;puts(s))for(scanf("%s",s);n--;strcpy(s,t))for(c=*s,p=t,l=i=0;c;c=s[i])sprintf(p,"%d%c",++l,c),s[++i]-c?l=0,p=t+strlen(t):0;}

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

const long long limit = 1e18;

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

  long long ans = 1;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (limit / ans < a || ans * a > limit) {
      flag = true;
    } else {
      ans *= a;
    }
  }

  if (flag) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys

coin = [1, 5, 10, 50, 100, 500]

def charge(remain):
	if remain == 0:
		return [0] * 6
	ch = [0] * 6
	index = 5
	while remain > 0:
		while remain >= coin[index]:
			ch[index] += 1
			remain -= coin[index]
		index -= 1
	return ch

def compute(p, n):
	candidates = []
	for r in range(500):
		pay = [0] * 6
		q = p + r
		for i in range(5, -1, -1):
			m = q / coin[i]
			pay[i] = min(m, n[i])
			q -= pay[i] * coin[i]
		if q == 0:
			candidates.append(sum(pay) + sum(charge(r)))
	return min(candidates)
	
if __name__ == '__main__':
	for input in sys.stdin:
		input = map(int, input.split())
		p, n = input[0], input[1:]
		if p == 0:
			break
		print compute(p, n)
		

Measured memory_bytes: 4284
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> p(n),q(n);
    rep(i,0,n-1) cin>>p[i];
    rep(i,0,n-1) cin>>q[i];
    vector<int> a(n);
    rep(i,0,n-1) a[i] = i+1;
    int p_val,q_val;
    int cnt = 0;
    do{
        bool p_flag = true;
        bool q_flag = true;
        rep(i,0,n-1){
            if(a[i]!=p[i]) p_flag = false;
            if(a[i]!=q[i]) q_flag = false;
        }
        if(p_flag) p_val = cnt;
        if(q_flag) q_val = cnt;
        cnt++;
    } while(next_permutation(a.begin(),a.end()));
    cout<<abs(p_val-q_val)<<endl;
    return 0;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    string S, T;
    cin >> S >> T;

    int count = 0;
    for(int i = 0 ; i < 3; i++ ){
       if( S[i] == T[i] ){
        count++;
       }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

const int MAX_PR = 300010;
// looking for all prime numbers
bool not_prime[MAX_PR];

map<LL, LL> prsquare;

vector<LL> a;

map<LL, pair<LL, int> > have;

int main() {	
	vector<LL> primes;
	primes.clear();
	SET(not_prime, 0);
	ffor (i, 2, MAX_PR)
		if (!not_prime[i]){
	    primes.pb(i);
			for (int j = 2 * i; j < MAX_PR; j += i)
				not_prime[j] = true;
	  }
	FOR (i, primes.sz)
		prsquare.insert(make_pair(1LL * primes[i] * primes[i], primes[i]));
	
	int n;
	cin >> n;
	FOR (i, n) {
		LL b;
		cin >> b;
		LL comp = 1LL;
		LL newb = 1LL;
		int idx = 0;
		while (primes[idx] <= 3333 && 1LL * primes[idx] * primes[idx] <= b) {
			int cnt = 0;
			while (b % primes[idx] == 0) {
				cnt++;
				b /= primes[idx];
			}
			cnt %= 3;
			FOR (j, cnt)
				newb *= primes[idx];
			FOR (j, (3 - cnt) % 3) {
				if (comp < 100000000000LL)
					comp *= primes[idx];
			}
			idx++;
		}
		newb *= b;
		if (prsquare.find(b) != prsquare.end()) {
			if (comp < 1000000000LL)
				comp *= prsquare[b];
			else
				comp = 100000000000LL;
		}
		else if (b < MAX_PR && !not_prime[b]) {
			FOR (j, 2)
				if (comp < 100000000000LL)
					comp *= b;
		}
		else
			comp = 100000000000LL;
		if (have.find(newb) != have.end()) {
			if (newb != 1) {
				pair<LL, int> pp = have[newb];
				have[newb] = make_pair(pp.first, pp.second + 1);
			}
		}
		else {
			have.insert(make_pair(newb, make_pair(comp, 1)));
			a.pb(newb);
		}
	}
	int cnt = 0;
	FOR (i, a.sz) {
		pair<LL, int> pp = have[a[i]];
		if (!pp.second)
			continue;
		if (have.find(pp.first) != have.end()) {
			pair<LL, int> pp1 = have[pp.first];
			cnt += max(pp.second, pp1.second);
			have[pp.first] = make_pair(pp1.first, 0);
		}
		else
			cnt += pp.second;
	}
	cout << cnt << endl;
	return 0;
}

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

int main(void){
    int N,count[10001]={0};
    cin>>N;
    for(int x=1;x<100;x++){
        for(int y=1;x*x+y*y+x*y+x+y+1<=N;y++){
            for(int z=1;x*x+y*y+z*z+x*y+y*z+z*x<=N;z++){
                count[x*x+y*y+z*z+x*y+y*z+z*x]++;
            }
        }
    }
    for(int i=1;i<=N;i++){
        cout << count[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <cmath>
#include <cstdio>

using namespace std;

int N, sum, o[1000010];
char a[1000010];

int main() {
    scanf("%d%s", &N, a + 1);
    for (int i = 1; i < N; ++i) a[i] = abs(a[i + 1] - a[i]);
    --N;
    if (N == 1) {
        printf("%d\n", (int)a[1]);
        return 0;
    }
    o[1] = 0;
    for (int i = 2; i <= N; ++i) {
        int mul = N - i + 1, div = i - 1;
        o[i] = o[i - 1];
        while (!(mul & 1)) {
            mul >>= 1;
            ++o[i];
        }
        while (!(div & 1)) {
            div >>= 1;
            --o[i];
        }
    }
    for (int i = 1; i <= N; ++i) o[i] = !o[i];
    for (int i = 1; i <= N; ++i) {
        sum += o[i] * a[i];
    }
    if (sum & 1) {
        puts("1");
        return 0;
    }
    sum = 0;
    for (int i = 1; i <= N; ++i) {
        if (a[i] == 1) {
            sum = 1;
            break;
        }
    }
    if (sum) {
        puts("0");
        return 0;
    }
    for (int i = 1; i <= N; ++i) sum += o[i] * (a[i] == 2);
    puts(sum & 1 ? "2" : "0");
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  string s;
  cin >> n >> s;
  
  if(n % 2 == 1){
    cout << "No" << "\n";
    return 0;
  }
  
  for(int i = 0; i < n / 2; i++){
    if(s.at(i) != s.at(i + (s.size() / 2))){
      cout << "No" << "\n";
      return 0;
    }
  }
  
  cout << "Yes" << "\n";
  return 0;
}

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

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main(void){
    int N, A[100004],B[100004],val, eventot=0, oddtot=0, total=0, even=0, odd=0;
    cin >>N;
    rep(i, N){
        cin >> A[i];
        if(i % 2 == 0 && i!= 0 && i!= (N-1)){
            eventot += (A[i] - A[i-1]);
            B[i+1] = eventot;
            even += eventot;
            //cout << eventot << " " << even << " :even "  << B[i+1]<< endl;
        }
        if(i%2 == 1){
            oddtot += (A[i] - A[i-1]);
            B[i+1] = oddtot;
            odd += oddtot;
            //cout << oddtot << " " << odd << " :odd " << B[i+1] << endl;
        }
        total += A[i];
        //cout << eventot << " " << even << " " << oddtot << " " <<odd << " " <<total << endl;
        /*rep(j, N){
            cout << B[j] << " ";
        }*/
        //cout << endl;
    }
    total /= 2;
    B[0] = total - ((N-1)/2)*A[0] - even - odd;
    B[1] = A[0] - B[0];
    rep(i, N){
        if(i % 2 == 0 && i!= 0){
            B[i] += B[0];
        }
        if(i%2 == 1 && i!= 1){
            B[i] += B[1];
        }
        cout << 2*B[i];
        if(i != N-1)  cout << " ";
        else cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int gcd(int a,int b){
	while(a){b%=a;swap(a,b);}return b;
}
int p[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	int ret=p[0];
	for(int i=0;i<a;i++)ret=gcd(ret,p[i]);printf("%d\n",ret);
}

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

int main(){
    int N, X, T, ans;
    cin >> N >> X >> T;

    int tmp = N / X;
    if(N%X==0){
    ans = T*tmp;
    }else{
    ans = T*(tmp+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
var
	N,i,a:Longint;
	x:int64;
	p:Array[1..20000]of Longint;
begin
	read(N);
	for i:=1 to N do begin
		writeln((N+1)*i);
		read(a);
		p[a]:=i;
	end;
	for i:=1 to N do begin
		x:=N+1;
		writeln(x*(N-i)+p[i]);
	end;
end.


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n,k;
    cin>>n>>k;
    vector<int> array(1e5+1,0);
    for(int i=0;i<n;i++) {
        int a,b;
        cin>>a>>b;
        array[a]+=b;
    }

    int count=0;
    for(int i=0;i<1e5+1;i++) {
        if(array[i]==0) continue;
        count+=array[i];
        if(count>=k) {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int n, k;
    int dislike[10];
    for (int i = 0; i < 10; ++i) {
        dislike[i] = 0;
    }
    cin >> n >> k;
    for (int i = 0; i < k; ++i) {
        int temp;
        cin >> temp;
        dislike[temp] = 1;
    }
    for (int i = n; i < 100000; ++i) {
        bool found = true;
        string cur = to_string(i);
        for (int j = 0; j < cur.size(); ++j) {
            if (dislike[cur[j] - '0'] == 1) {
                found = false;
                break;
            }
            
        }
        if (found == true) {
            cout << i;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll H, W;
    cin >> H >> W;

    ll a1 = ll(H % 3 > 0) * W;

    ll a2 = ll(W % 3 > 0) * H;

    ll ans = min(a1, a2);

    ll a3 = INF;
    vector<ll> v(3);
    FOR(h, 1, H) {
        v[0] = h * W;
        v[1] = (H - h) * (W / 2);
        v[2] = (H - h) * (W / 2 + int(W & 1));
        sort(ALL(v));
        a3 = min(a3, v[2] - v[0]);
    }


    FOR(w, 1, W) {
        v[0] = w * H;
        v[1] = (W - w) * (H / 2);
        v[2] = (W - w) * (H / 2 + int(H & 1));
        sort(ALL(v));
        a3 = min(a3, v[2] - v[0]);
    }

    print(min(ans, a3));
    
}


Measured memory_bytes: 3656