akhauriyash/Code-Regression huggingface dataset:
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int D[101][2] = {0};
int main()
{
	int N = 0;
	scanf("%d", &N);
	int i = 0;
	memset(&D,0,sizeof(D));

	for (i = 0; i < N; i++) {
		scanf("%d %d", &D[i][0], &D[i][1]);
	}

	int same = 0, count = 0, ans = 0;
	for (i = 0; i < N; i++) {
		if (D[i][0] == D[i][1]) {
			same = 1;
		} else {
			same = 0;
			count = 0;
		}
		if (same == 1) {
			count++;
		}
		if (count == 3) {
			ans = 1;
		}
	}

	yesno(ans);
	return 0;
}


Measured memory_bytes: 1656
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;


int main(){
    int n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    int ans=0;
    for(int i=1;i<=n;i++){
        if(a[i]!=i) continue;
        if(a[i]==i && i==n){
            ans++;
            break;
        }
        if(a[i+1]==i+1){
            i++;
            ans++;
        }else{
            ans++;
        }
    } 
    cout<<ans<<endl;
     
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

int f(string s){
    int ret = 0;
    REP(i, s.size()){
        ret *= 10;
        ret += (int)(s[i] - '0');
    }
    return ret;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    string c = a + b;
    int num = f(c);
    for (int i = 0; i*i <= num; i++) {
        if(i*i == num){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
    int m,n;
    while(cin >> n >> m)
    {
        int c,t;
        int ans;
        int mins = 100010;
        bool p =false;
        for(int i = 0; i < n ;i ++)
        {
            cin >> c >> t;
            if(c < mins && t <= m)
            {
                mins = c;
                ans = c;
            }
            if(t <= m)p =true;
        }
        if(p == false)cout << "TLE"<< endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)

int main()
{
  int N;
  cin >> N;
  int a[N];
  int ans = 0;
  rep(i, N)
  {
    cin >> a[i];
    ans += a[i] - 1;
  };

  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

void rightTriangle(int, int, int);
int main()
{
    int number;
    std::cin >> number;
    for (int i = 0; i < number; ++i) {
        int a, b, c;
        std::cin >> a >> b >> c;
        rightTriangle(a, b, c);
    }
    return 0;
}
void rightTriangle(int a, int b, int c)
{
    if (a * a + b * b == c * c
        || b * b + c * c == a * a
        || c * c + a * a == b * b) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, M; cin >> N >> M;
    Graph G(N);
    for(int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < N; i++) cout << G[i].size() << endl;
    return 0;
}

Measured memory_bytes: 3568
import numpy as np
import math

a = []
for i in range(5):
	a.append(int(raw_input()))
b = np.array(a)
c = b % 10
c[c==0]=10
min_id = np.argmin(c)

for i in range(5):
	if i != min_id:
		b[i] = 10 * math.ceil(b[i] / 10.0)
print np.sum(b)

Measured memory_bytes: 16008
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    string S, T;
    cin >> S >> T;
    int ans = 0;
    if (S[0] == T[0]) ans++;
    if (S[1] == T[1]) ans++;
    if (S[2] == T[2]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
n = int(input())

# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor

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

dic = {}
for a in range(1,n+1):
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            dic[num] += count
           
over = [0]*5
            
for num,count in dic.items():
    if count + 1 >= 75:
        over[0] += 1
    elif count + 1 >= 25:
        over[1] += 1
    elif count + 1 >= 15:
        over[2] += 1
    elif count + 1 >= 5:
        over[3] += 1
    elif count + 1 >= 3:
        over[4] += 1
        
for i in range(1,5):
    over[i] = over[i] + over[i-1]

ans = over[0]
ans += over[1] * (over[4]-1)
ans += over[2] * (over[3]-1)
ans += (over[4] - over[3]) * (over[3]*(over[3]-1)//2)
ans += over[3] * ((over[3]-1)*(over[3]-2)//2)

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define lop(i,n,a) for(int i=0;i<n;i+=a)
#define rep(i,n,a) for(int i=a;i<n;i++)
#define inarr(arr,n) lop(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define pii pair<int,int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
using namespace std;
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  ll a,b,k;cin>>a>>b>>k;
  ll aa=a;
  a=a-min(a,k);
  k-=min(aa,k);
  b=b-min(b,k);
  cout<<a<<" "<<b<<endl;
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 


Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define MOD 1000000007;//1e9+7

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

int main() {
    long long A, B;
    cin >> A >> B;
    cout << (A / gcd(A, B))*B;
}

Measured memory_bytes: 256
n = int(input())
XL = []
for i in range(n):
  x, l = map(int, input().split())
  XL.append([x, l])
  
XL.sort(key=lambda x: x[0]+x[1])

seen = -10**10
ans = 0
for i in range(n):
  rob = XL[i]
  if seen <= rob[0]-rob[1]:
    seen = rob[0]+rob[1]
    ans += 1

print(ans)

Measured memory_bytes: 24552
#include <stdio.h>

int function(int n){
	if(n%2==0){
		return (n/2);
	}else{
		return (3*n)+1;
	}
}
int a[1000001];
int b[1000001]={};
int main(void){
	int s,i;
	scanf("%d",&s);
	for(i=1;i<=1000000;i++){
		if(i==1){
			a[1]=s;
			b[a[i]]++;
			continue;
		}
		a[i]=function(a[i-1]);
		b[a[i]]++;
		if( b[a[i]]==2){
			printf("%d",i);
			return 0;
		}
	}
	return 0;
}

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

int main(void) {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a.at(i);
    }
    auto bound = lower_bound(a.begin(), a.end(), x);
    if (bound == a.begin()) {
        cout << 0 << endl;
        return 0;
    }
    cout << min(bound  - a.begin(), a.end() - bound) << endl;
    return 0;
}

Measured memory_bytes: 3624
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}




signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> x(n), y(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        x[i].resize(a[i]);
        y[i].resize(a[i]);
        for(int j = 0; j < a[i]; ++j){
            cin >> x[i][j] >> y[i][j];
            --x[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); ++i){
        vector<int> res(n, -1);
        bool fl = true;
        for(int j = 0; j < n; ++j){
            if(i & (1 << j)){
            for(int k = 0; k < a[j]; ++k){
                if(y[j][k] == 0){
                    if(res[x[j][k]] == 1)
                        fl = false;
                    res[x[j][k]] = 0;
                }else{
                    // real
                    if(res[x[j][k]] == 0)
                        fl = false;
                    res[x[j][k]] = 1;
                }
            }
            }
        }
        for(int j = 0; j < n; ++j){
            if(i & (1 << j) && res[j] == 0)
                fl = false;
            if(!(i & (1 << j)) && res[j] == 1)
                fl = false;
        }
        if(fl){
            ans = max(ans, __builtin_popcount(i));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(System.out);
    int N = (int)1e5+1, mod = (int)1e9+7,n,m; 


    void solve(){
        int a = in.ni(), b = in.ni();
        out.println(Math.max(a+b,Math.max(2*a-1,2*b-1)));
    }

    void run(){
        solve();
        // out.flush();
        out.close();
    }
    public static void main(String[] args) {
        boolean memory = false;
        Thread t=new Thread(null, null, "T", 1<<28) {
            public void run() {
                new Main().run();
            }
        };
        if(memory) t.start();
        else new Main().run();
    }
    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        String nextLine(){
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }  
            return str;
        }
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}
    }
    class Edges{
        int u,v,w;
        public Edges(int u,int v,int w){
            this.u = u;
            this.v = v;
            this.w = w;
        }
    }
    void pn(Object o){out.println(o);out.flush();}
    long inv(long a, long b){return 1<a ? b - inv(b%a,a)*b/a : 1;}//a^(-1)%b
    long fe(long a,long b){
        long ans = 1L;
        while(b>0){
            if((b&1)>0)ans=ans*a%mod;
            a = a%mod*a%mod;
            b>>=1;
        }
        // pn("ans = "+ans);
        return ans;
    }
    long gcd(long a,long b){
        if(a==0)return b;
        return gcd(b%a,a);
    }
    class pair{
        int x,y;
        public pair(int f,int s){
            this.x = f;
            this.y = s;
        }
    }
    class triple{
        int i,l,r;
        public triple(int i,int l,int r){
            this.i = i;
            this.l = l;
            this.r = r;
        }
    }
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while(0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, X, D;

// k個の数字を選んだ時に、合計値として有り得る値の範囲
// 0 <= k <= N
PLL range(ll k) {
  PLL res(k*X, k*X);

  if (k == N) {
    res.first += ((N-1)*N/2) * D;
    res.second += ((N-1)*N/2) * D;
  } else {
    res.first += ((k-1)*k / 2) * D;
    res.second += ((2*N-k-1) * k / 2) * D;
  }
  //for (ll i=0; i<=k-1; i++)
  //  res.first += i * D;
  //for (ll i=N-k; i<=N-1; i++)
  //  res.second += i * D;

  return res;
}

map<ll, vector<PLL>> mp;

signed main() {
  cin >> N >> X >> D;

  if (D == 0) {
    if (X == 0) {
      cout << 1 << endl; // S=0のみ
      return 0;
    } else {
      cout << N+1 << endl; // S=0,X,2X,..,NX
      return 0;
    }
  }

  if (D < 0) {
    X *= -1;
    D *= -1;
  }

  // D > 0
  rep(k, N+1) {
    ll m = (k*X) % D; // 余り
    m = (m+3*D) % D;
    auto r = range(k);
    //printf("k=%d min=%d max=%d m=%d mod_mid=%d mod_max=%d\n",
    //    k, r.first, r.second, m,
    //    (r.first - m)/D, (r.second - m)/D);
    mp[m].emplace_back((r.first - m)/D, (r.second - m)/D);
  }

  //swap(mp[0][0],mp[0][1]);
  //for (auto p: mp[0]) {
  //  printf("mod_min=%d mod_max=%d\n",
  //      p.first, p.second);
  //}

  ll ans = 0;
  for (auto e : mp) {
    ll m = e.first;
    auto ranges = mp[m];
    sort(begin(ranges), end(ranges));
    rep(i, ranges.size()) {
      // printf("mod_min=%d mod_max=%d\n", ranges[i].first, ranges[i].second);
    }

    vector<PLL> merged_ranges;
    merged_ranges.push_back(ranges[0]);
    for (ll i=1; i<ranges.size(); i++) {
      auto r = ranges[i];
      auto last_r = merged_ranges[ merged_ranges.size()-1 ];
      if (r.first <= last_r.second+1) {
        chmax(merged_ranges[ merged_ranges.size()-1 ].second, r.second);
      } else {
        merged_ranges.push_back(r);
      }
    }

    for (auto mr: merged_ranges) {
      // printf("mr_min=%d mr_max=%d\n", mr.first, mr.second);
      ans += mr.second - mr.first + 1;
    }
  }

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


Measured memory_bytes: 22144
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include<bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li  int64_t
#define ld  double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl      cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpl;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return 1<<n;}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-1,0,1,0},dy[]={0,-1,0,1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

li n,arr[105];

void solve(){
    cin>>n;
    li i,ans=1,maxcnt=0;
    rep(i,1,n+1){
        li x=i,cnt=0;
        while(x%2==0){
            x/=2;
            cnt++;
        }
        if(cnt>maxcnt){
            maxcnt=cnt;
            ans=i;
        }
    }
    cout<<ans;
}

int main(){
    opt
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    li t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<cmath>
using namespace std;
int main(){
	double a,b,c,d, x,y,z,X,Y,Z,d2, k=M_PI/180;
	while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d),a!=-1&&b!=-1&&c!=-1&&d!=-1){
		z=sin(a*k),Z=sin(c*k);
		x=cos(a*k)*cos(b*k),y=cos(a*k)*sin(b*k);
		X=cos(c*k)*cos(d*k),Y=cos(c*k)*sin(d*k);
		d2=(x-X)*(x-X)+(y-Y)*(y-Y)+(z-Z)*(z-Z);
		printf("%.0f\n",acos((2-d2)/2)*6378.1);
	}
	return 0;
}

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

int main() {
	int n, n1, n2, n3, n4;
	cin >> n;
	n1 = n / 1000;
	n2 = (n / 100) % 10;
	n3 = (n / 10) % 10;
	n4 = n % 10;

	int count;

	if (n1 == 2) {
		count++;
	}
	if (n2 == 2) {
		count++;
	}
	if (n3 == 2) {
		count++;
	}
	if (n4 == 2) {
		count++;
	}

	cout << count << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;


ull N, A, B, C;
vector <string> proc;

vector <char> path;


string follow_path_one(vector <char> &path) {
	string ans;

	ans = "No";
	int i;
	for (i = 0; i < N; i++) {
		if (proc.at(i) == "AB") {
			if (A == 0 && B == 0) {
				break;
			}
			else if (A == 1) {
				A--, B++;
				path.push_back('B');
			} else {
				A++, B--;
				path.push_back('A');
			}
		}
		else if (proc.at(i) == "BC") {
			if (B == 0 && C == 0) {
				break;
			}
			else if (B == 1) {
				B--, C++;
				path.push_back('C');
			}
			else {
				B++, C--;
				path.push_back('B');
			}
		} else { // "AC"
			if (A == 0 && C == 0) {
				break;
			}
			else if (A == 1) {
					A--, C++;
					path.push_back('C');
			}
			else {
				A++, C--;
				path.push_back('A');
			}

		}

	}
	if (i == N) ans = "Yes";

	return ans;
}


void check_and_setPath(int i, ull& a, ull& b, ull c, string cond_bc, char for_b, string cond_ac, char for_a, vector <char> &path) {

	if (a == 1 && b == 1 && c == 0 && i < N - 1) {
		if (proc.at(i + 1) == cond_bc) {
			a--, b++;
			path.push_back(for_b);

			return;
		}
		else if (proc.at(i + 1) == cond_ac) {
			a++, b--;
			path.push_back(for_a);
			return;
		}
	}

	if (a >= b) {
		a--, b++;
		path.push_back(for_b);
		return;
	}
	else {
		a++, b--;
		path.push_back(for_a);
		return;
	}

}


string follow_path(vector <char> &path) {
	string ans;

	ans = "No";
	int i;

	for (i = 0; i < N; i++) {
		if (proc.at(i) == "AB") {
			if (A == 0 && B == 0) {
				break;
			}
			check_and_setPath(i, A, B, C, "BC", 'B', "AC", 'A', path);
		}
		else if (proc.at(i) == "BC") {
			if (B == 0 && C == 0) {
				break;
			}
			check_and_setPath(i, B, C, A, "AC", 'C', "AB", 'B', path);
		}
		else { // "AC"
			if (C == 0 && A == 0) {
				break;
			}
			check_and_setPath(i, C, A, B, "AB", 'A', "BC", 'C', path);
		}

	}
	if (i == N) {
		ans = "Yes";
	}

	return ans;
}

int main() {
	ll i;
	string S;

	cin >> N >> A >> B >> C;

	for (int i = 0; i < N; i++) {
		cin >> S;
		proc.push_back(S);
	}

	vector <char> path;


	string ans;;
	if (A + B + C == 0) {
		ans = "No";
	} else if (A + B + C == 1) {
		ans = follow_path_one(path);
	}
	else {
		ans = follow_path(path);
	}

	cout << ans << endl;
	if (ans == "Yes") {
		for (auto i : path)
			cout << i << endl;
	}
}

Measured memory_bytes: 5932
#define N (1<<6)
#include <bits/stdc++.h>

using namespace std;

int g[N][N],p[N];
int n,M,a,b,c,t;

struct matrix
{
	int n,a[N][N];
	matrix(int tn,int x):n(tn)
	{
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				a[i][j]=i==j?x:0;
	}

	matrix(int tn,int g[][N]):n(tn)
	{
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				a[i][j]=g[i][j];
	}

	matrix operator*(matrix& b)
	{
		matrix c(n,0);
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++)
					c.a[i][j]+=a[i][k]*b.a[k][j],c.a[i][j]%=M;
		return c;
	}

	matrix operator^(int k)
	{
		matrix res(n,1),cur(*this);
		for(;k;k>>=1,cur=cur*cur)
			if(k&1) res=res*cur;
		return res;
	}
};

int main()
{
	for(;cin>>n>>M>>a>>b>>c>>t;)
	{
		memset(g,0,sizeof(g));
		for(int i=0;i<n;i++)
			scanf("%d",p+i);
		for(int i=0;i<n;i++)
		{
			g[i][i]=b;
			if(i>0) g[i-1][i]=a;
			if(i<n-1) g[i+1][i]=c;
		}

		matrix m(n,g); m=m^t;

		for(int i=0;i<n;i++)
		{
			int res=0;
			for(int j=0;j<n;j++) 
				res+=p[j]*m.a[j][i],res%=M;
			if(i<n-1)
				printf("%d ",res);
			else
				printf("%d\n",res);
		}
	}
}

Measured memory_bytes: 1332
W,H,N = map(int,input().split())
minx,maxx = 0,W
miny,maxy = 0,H

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        minx = max(minx,x)
    elif a == 2:
        maxx = min(maxx,x)
    elif a == 3:
        miny = max(miny,y)
    elif a == 4:
        maxy = min(maxy,y)

if minx >= maxx or miny >= maxy:
    print(0)
else:
    print((maxy-miny)*(maxx-minx))

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

typedef long long LL;

const int N=1000;

int n,m,a,b;

void into(){
  scanf("%d%d%d%d",&n,&m,&a,&b);
}

int ans[N+9][N+9];

void Get_ans(){
  for (int i=1;i<=b;++i)
	for (int j=1;j<=m;++j) ans[i][j]=1;
  for (int i=1;i<=n;++i)
	for (int j=1;j<=a;++j) ans[i][j]^=1;
}

void work(){
  Get_ans();
}

void outo(){
  for (int i=1;i<=n;++i){
	for (int j=1;j<=m;++j)
      putchar(ans[i][j]+'0');
    puts("");
  }
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 7576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) 

int main()
{
	ios;
	ll a,b,c;
	cin>>a>>b>>c;
	if(b*c>=a)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(void){
    string s;
    int i,j;
    cin >> s;
    for(i=0;i<8;i++){
        string siki;
        siki +=s[0];
        int tmp=(s[0]-'0');
        for(j=0;j<3;j++){
            if(i&(1<<j)){
                siki = siki + '+'+s[j+1];
                tmp = tmp +(s[j+1]-'0');
            }
            else{
                siki = siki + '-'+s[j+1];
                tmp = tmp-(s[j+1]-'0');
            }
        }
        if(tmp==7){
            cout << siki << "=7";
            return 0;
        }
    }
}

Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<iosfwd>
#include<sstream>
#include <algorithm>
#define N 100
using namespace std;
int main(){
    int n,y;

    cin >> n >> y;
    //x+y+z=n
    //10000x+5000y+1000z=y
    int a=-1;
    int b=-1;
    int c=-1;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
                if(i+j<=n && 10000*i + 5000*j +1000*(n-i-j)== y) {a=i; b=j; c=n-i-j; break;}
            
        }
    }
    cout << a << " " << b << " " << c << endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;

class Program
{
    static readonly double INF = 1e20;

    static void Main(string[] args)
    {
        while (true)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = input[0], M = input[1], P = input[2], A = input[3] - 1, B = input[4] - 1;
            if (N == 0) break;
            int[] nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            double[][] dist = E.Range(0, M).Select(i => E.Repeat(INF, M).ToArray()).ToArray();

            for (int i = 0; i < P; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                dist[input[0] - 1][input[1] - 1] = input[2];
                dist[input[1] - 1][input[0] - 1] = input[2];
            }
            double[][] dp = E.Range(0, 1 << N).Select(i => E.Repeat(INF, M).ToArray()).ToArray();
            dp[0][A] = 0;
            for (int mask = 0; mask < (1 << N); mask++)
                foreach (int use in E.Range(0, N).Where(use => (mask >> use & 1) == 0))
                    foreach (int i in E.Range(0, M).Where(i => dp[mask][i] < INF))
                        foreach (int j in E.Range(0, M).Where(j => i != j && dist[i][j] < INF))
                        {
                            double cost = dp[mask][i] + dist[i][j] / nums[use];
                            int nextMask = mask | 1 << use;
                            dp[nextMask][j] = Math.Min(dp[nextMask][j], cost);
                        }

            double ans = E.Range(0, 1 << N).Min(mask => dp[mask][B]);
            Console.WriteLine((ans >= INF) ? "Impossible" : ans.ToString("f3"));
        }
    }
}

Measured memory_bytes: 6452
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	}

}


Measured memory_bytes: 49656
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
string s;
int ans;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>s;
	for(int i=0;i<3;i++){
		if(s[i]=='1')
		ans++;
	}
	cout<<ans;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, k, s;
	scanf("%d%d%d", &n, &k, &s);
	for (int i = 1; i <= k; i ++)
		printf("%d ", s);
	for (int i = k + 1; i <= n; i ++)
		printf("%d ", s == (int)1e9 ? (int)1e9 - 1 : s + 1);
	puts("");
	return 0;
}

Measured memory_bytes: 1280
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	ll=[]
	for i in range(n):
		b , c = input().split()
		c=int(c)
		ll.append((b,-c,i+1))
	ll.sort()
	for _, _, i in ll:
		print(i)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  string s;
  cin >> s;
  if (s == "ABC")
    cout << "ARC" << endl;
  else
  {
    cout << "ABC" << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
class Node:
    def __init__(self):
        self.parent_id = -1
        self.depth = 0
        self.children = []

def calc_depth(node_id, arg_depth):
    nodes[node_id].depth = arg_depth
    for child in nodes[node_id].children:
        calc_depth(child, arg_depth+1)

V = int(input())
global nodes
nodes = []
#予めV個のノードを準備
for loop in range(V):
    node = Node()
    nodes.append(node)

#親子関係を取得
for loop in range(V):
    table = list(map(int,input().split()))
    node_id = table[0]
    num = table[1]
    for i in range(num):
        child_id = table[2+i]
        nodes[node_id].children.append(child_id)
        nodes[child_id].parent_id = node_id

#根を探して深さを計算
for i in range(V):
    if nodes[i].parent_id == -1:
        calc_depth(i,0)
        break

for i in range(V):
    print("node %d: parent = %d, depth = %d, "%(i, nodes[i].parent_id, nodes[i].depth),end="")

    if nodes[i].parent_id == -1:
        print("root,",end = "")
    else:
        if len(nodes[i].children) == 0:
            print("leaf,",end="")
        else:
            print("internal node,",end="")

    print(" [",end="")
    print(', '.join(map(str,nodes[i].children)),end="")
    print("]")



Measured memory_bytes: 40700
import math
import itertools
import statistics
#import collections

#n =  list(map(int, input().split()))
s = int(input())
ABC =[111, 222, 333, 444, 555, 666, 777, 888, 999]
for i in range(len(ABC)):
    if s <= ABC[i]:
        print(ABC[i])
        exit()
    

Measured memory_bytes: 5652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
int main()
{
    int H,W;cin>>H>>W;
    mat A(100,vec(100)),B(100,vec(100));
    for(int i=1;i<=H;i++)
	{
        for(int j=1;j<=W;j++)
		{
            cin>>A[i][j];
        }
    }
    for(int i=1;i<=H;i++)
	{
        for(int j=1;j<=W;j++)
		{
            cin>>B[i][j];
        }
    }
    vector<vector<vector<bool>>> dp(90,vector<vector<bool>>(90,vector<bool>(13000,false)));
    dp[1][1][abs(A[1][1]-B[1][1])]=true;
    for(int h=1;h<=H;h++)
	{
        for(int w=1;w<=W;w++)
        {
            for(int k=0;k<13000;k++)
			{
                if(dp[h-1][w][k])
				{
                    dp[h][w][abs(k+A[h][w]-B[h][w])]=true;
                    dp[h][w][abs(k-A[h][w]+B[h][w])]=true;
                }
                if(dp[h][w-1][k])
				{
                    dp[h][w][abs(k+A[h][w]-B[h][w])]=true;
                    dp[h][w][abs(k-A[h][w]+B[h][w])]=true;                    
                }
            }
        }
    }
    for(int k=0;k<13000;k++)
	{
        if(dp[H][W][k])
		{
            cout<<k<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 13952
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		List<Double> list=new ArrayList<Double>();
		//Integer[] array = new Integer[m];
		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();
		for(int i=0;n>i;i++) {
			int h = sc.nextInt();
			list.add(t-h*0.006);
		}
		//System.out.println(list);
		double answer = 10000;
		int count=0;
		for(int i=0;list.size()>i;i++) {
			double b = Math.abs(a-list.get(i));
			if(b<answer) {
				count=i+1;
				answer=b;
			}
		}
		System.out.println(count);
	}
}

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

#define INF 1000000000

using namespace std;

int main() {
    int n, l = INF, r = 0, a;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        l = min(l, a);
        r = max(r, a);
    }
    cout << r - l << endl;
    return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1000001
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){

    fast;

    ll i,n,k;
    cin >> n >> k;
    ll a[n];
    for(i=0;i<n;i++){
        cin >> a[i];
    }

    ll dp[n];

    for(i=0;i<n;i++){
        dp[i]=-1;
    }

    dp[0] = 0;

    for(i=1;i<=n;i++){
        for(ll j=1;j<=k;j++){
            if(i-j>=0){
                if(dp[i]==-1){
                    dp[i]=dp[i-j]+abs(a[i]-a[i-j]);
                }
                else{
                    dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
                }
            }
        }
    }

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

}

//    cout << fixed << setprecision(12);




Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

template <typename T>
T gcd(T a, T b){
    if(a < b) swap(a, b);
    while(b != 0){
        T tmp = b;
        b = a%b;
        a = tmp;
    }
    return a;
}

template <typename T>
T lcm(T a, T b){
    return (a*b)/gcd<T>(a, b);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll A, B;
    cin >> A >> B;
    cout << lcm<ll>(A, B) << endl;
}

Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int a,b,c;cin>>a>>b>>c;
  if(a==b)cout<<c;
  else if(a==c)cout<<b;
  else cout<<a;
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
import itertools,bisect
cubes = [n**3 for n in xrange(1,1111)]
num = []
for n,m in itertools.combinations_with_replacement(cubes,2):
    num.append(n+m)
num.sort()
while True:
    z_cube = input()**3
    if z_cube == 0:
        break
    print z_cube-num[bisect.bisect(num,z_cube)-1]

Measured memory_bytes: 25740
#include <stdio.h>
#include <string.h>

int main() {
	char str;
	scanf("%s",&str);
	if (strcmp("SUN",&str) == 0) {
		printf("7");
	}
	else if (strcmp("MON", &str) == 0) {
		printf("6");
	}
	else if (strcmp("TUE", &str) == 0) {
		printf("5");
	}
	else if (strcmp("WED", &str) == 0) {
		printf("4");
	}
	else if (strcmp("THU", &str) == 0) {
		printf("3");
	}
	else if (strcmp("FRI", &str) == 0) {
		printf("2");
	}
	else if (strcmp("SAT", &str) == 0) {
		printf("1");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    string s; cin >> s;
    if(s.size() == 2) cout << s << endl;
    else{
        reverse(ALL(s));
        cout << s << endl;
    }
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
import numpy as np
from collections import deque
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
done = [0 for _ in range(M)]
X = sorted(np.diff(np.array(X)))[::-1]
q = deque(X)
for i in range(N):
    if i > 0:
        try:
            q.popleft()
        except:
            print("0")
            exit()
print(sum(q))

Measured memory_bytes: 23072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<PP,vector<PP>,greater<PP>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
//const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
ll ans=0,sum=0,k=0,u=0,t=1,mod,b;
ll fac(ll a,ll p){
    a%=mod;
    if(p==0)return 1;
    if(p&1)return (a*fac(a,p-1))%mod;
    return (fac(a,p/2)*fac(a,p/2))%mod;
}
ll f(ll n){
    if(n==0)return 0;
    if(n&1)return (f(n-1)*(t%mod)+1)%mod;
    else return (f(n/2)+f(n/2)*fac((t%mod),n/2))%mod;
}
ll g(ll n){
    if(n==0)return 0;
    if(n&1)return (g(n-1)*(t%mod)+b%mod*(n-1))%mod;
    return (g(n/2)+(g(n/2)*fac((t%mod),n/2))%mod+(b%mod*(n/2)%mod*f(n/2))%mod)%mod;
}

int main(){
    ll l,a,n;cin>>l>>a>>b>>mod;
    while(sum<l){
        if(sum<0)break;
        t=t*10%mod;
        k=(k+1)*10-1;
        u++;
        if(k<a&&k>=0)continue;
        n=(k-a)/b+1;
        if(sum+n>l||n<0||sum+n<0)n=l-sum;
        sum+=n;
        ans=((ans*fac(fac(10,n),u))%mod+((a%mod)*f(n))%mod+g(n)%mod)%mod;
        a=k+b-(k-a)%b;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;

priority_queue<int> bo;
priority_queue<int, vector<int>, greater<int> > so;
int cheak[100];

int num(char s){
  int r;
  if(s=='1')r=1;
  else if(s=='2')r=2;
  else if(s=='3')r=3;
  else if(s=='4')r=4;
  else if(s=='5')r=5;
  else if(s=='6')r=6;
  else if(s=='7')r=7;
  else if(s=='8')r=8;
  else if(s=='9')r=9;
  else if(s=='0')r=0;
  return r;
}

main(){
  char s[6];
  int n;
  int match;
  int ma,mb;
  int t,c;
  while(cin >> s >> n,s=="0"|| n){
    match=0;
    cheak[0]=0;
    
    for(int i=0;i<strlen(s);i++){
      cheak[0]*=10;
      cheak[0]+=num(s[i]);
    }

    t=cheak[0];
    for(int i=1;i<=20 && match==0;i++){
      for(int j=0;j<n;j++){
	c=t%10;
	bo.push(c);
	so.push(c);
	t=t/10;
      }
      for(int j=0;j<n;j++){
	t=t*10;
	t+=bo.top()-so.top();
	bo.pop();so.pop();
      }
      for(int j=0;j<i;j++){
	if(cheak[j]==t){
	  ma=i;
	  mb=j;
	  match=1;
	}
      }
      cheak[i]=t;
    }
    cout << mb << " " << cheak[mb] << " " << ma-mb << endl;
  }
}

Measured memory_bytes: 1220
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main()
{
	ios_base::sync_with_stdio(false);
	ll n, x,ret=M;
	cin >> n >> x;
	vll a(n),b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) b[i] = a[i];

	rep(i, n) {
		ll tmp = x * i;
		rep(j, n) {
			b[j] = min(b[j], a[(j - i + n) % n]);
			tmp += b[j];
		}
		ret = min(ret, tmp);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
 
def main():
    N = int(input())
    a = list(map(int,input().split()))
    num = 1
 
    for i in a:
        if(i==num):
            num += 1
 
    if(num!=1):
        print(len(a) - num + 1)
    else:
        print('-1')
 
main()

Measured memory_bytes: 24744
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define sc second
#define mod 1000000007
using namespace std;
ll n, v[400001], a, b, c, d, nr;
map<string, int>mp;
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>s;
        mp[s]++;
        if(mp[s]==1)
            nr++;
    }
    cout<<nr;
    return 0;
}


Measured memory_bytes: 19216
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
int N,K;
cin >>N>>K;

string s;
cin >> s;

int left[300010];
left[1]=1;
char c=s[0];
int l=1;
 for(int i=1;i<s.size();i++){
    if(s[i]==c){
        continue;
    }
    else{
        c=s[i];
        left[++l]=i+1;       
    }
}
for(int i=l+1;i<=300000;i++){
    left[i]=N+1;
}
 int x;
 int ans=0;
for(int k=1;k<=l;k++){
    if(s[left[k]-1]=='0'){
        x=left[k+2*K]-left[k];
        ans=max(x,ans);
    }
    else{
        x=left[k+2*K+1]-left[k];
        ans=max(x,ans);

    }
}
cout << ans <<endl;

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;

const int MAX = 1e6 + 10;

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

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

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

int main() {
    long long X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0) {
        cout << 0 << '\n';
        return 0;
    }

    long long rank = (X+Y)/3;
    long long num = X - rank;
    COMinit();
    long long ans = COM(rank, num);
    cout << ans << '\n';
}



Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;using vll = vector<ll>;
int main(){
  ll n, ans=0;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  a.push_back(0);
  
  ll cnt=1;
  for (ll i = 0; i < n + 1; i++) {
    if (a[i] == a[i+1]) {
      cnt++;
    }
    else {
      if (cnt % 2 == 1) ans++;
      cnt = 1;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1792