akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int matches[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

class State{
private:
    int digits;
    vector<int> counts;
    
public:
    State(){
        digits = 0;
        counts = vector<int>(9);
    }
    
    bool operator < ( const State& right ) const {
        if(this->digits == right.digits){
            for(int i=8; i>=0; i--){
                int a = this->counts[i];
                int b = right.counts[i];
                if(a != b)
                    return a < b;
            }
            return true; //IDC
        }
        return this->digits < right.digits;
    }
    
    State add(int x){
        State res = *this;
        res.digits++;
        res.counts[x]++;
        return res;
    }
    bool valid(){
        return digits;
    }
    void show(){
        string s;
        for(int i=8; i>=0; i--)
            s += string(counts[i], '1'+i);
        cout << s << endl;
    }
};

int main(){
    int N, M; cin >> N >> M;
    vector<int> A(M);
    for(auto &d: A){
        cin >> d; d--;
    }
    vector<State> dp(N+10);
    for(int i=0; i<N; i++){
        if(i != 0 && !dp[i].valid())
            continue;
        for(auto d: A)
            dp[i+matches[d]] = max(dp[i+matches[d]], dp[i].add(d));
    }
    dp[N].show();
    return 0;
}


Measured memory_bytes: 1024
def run(s, k):
    cnt = 0
    for si in s:
        si = int(si)
        if si == 1:
            cnt += 1
        else:
            return si
        if k == cnt:
            return 1


def read_line():
    s = input()
    k = int(input())
    return (s, k)


def main():
    s, k = read_line()
    print(run(s, k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N, Y = list(map(int, input().split()))

judge = 0

for x in range(N + 1):
	for y in range(N + 1 - x):
		if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
			if judge == 0:
				print(x, y, N - x - y)
				judge = 1
				break


if judge == 0:
	print(-1, -1, -1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;


unsigned int uns(int N){
  if(N<0)return N*-1;
  return N;
}

int main(){
  int a[100002]={};
  int nm=0;
  int N;
  cin>>N;
  LOOP1(i,N){
    cin>>a[i];
    nm+=uns(a[i]-a[i-1]);
  }
  nm+=uns(a[N]);
  int dm=nm;
  LOOP1(i,N){
    nm=dm;
    //iを通らない。
    //不通過処理
    nm-=uns(a[i]-a[i-1])+uns(a[i+1]-a[i]);
    nm+=uns(a[i+1]-a[i-1]);
    cout << nm;
    cout << endl;
  }
}


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

void InsertionSort( int *x, int n )             //main関数で配列のアドレスを受け取る
{
    int v, j;                                   //vを抜き出し、適切な位置へとソート

    for( int i = 1; i <= n - 1; i++ )           //1からn-1まで順にvとして抜き出しソート
    {
        v = x[i];                               //最初のvはx[1],...,最後のvはx[n-1]. 
        j = i - 1;                              //x[i]を対象とするなら、x[i-1]と比べる。

        while( j >= 0 && x[j] > v )             //前の要素の方が大きい場合、入れ替え続ける
        {
            x[j+1] = x[j];
            j--;
            x[j+1] = v;
        }

        for( int t = 0; t < n - 1; t++ )            //途中結果の出力
            cout << x[t] << " ";
        cout << x[n-1] << endl;

    }

}

int main()
{
    int num;                            //num個の要素
    
    cin >> num;

    int x[num];                         //num個の配列を確保
    
    for( int i = 0; i < num; i++ )      //入力
        cin >> x[i];

    for( int i = 0; i < num - 1; i++ )  //入力直後の並びを出力
        cout << x[i] << " ";
    cout << x[num-1] << endl;    

    InsertionSort( x , num );
    
    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	int N,K,A,B[102];
	int dp[102][7]={},ans=0;
	memset(B,-1,sizeof(B));
	cin>>N>>K;
	for(int i=0;i<K;i++){
		cin>>A;
		cin>>B[A];
	}

	dp[0][0]=1;
	for(int i=0;;i++){
		for(int j=0;j<=6;j++){
			dp[i][j]%=10000;
			//printf("%d ",dp[i][j]);
			if(B[i]!=-1 && (j!=B[i] && j!=B[i]+3)){
				dp[i][j]=0;
				continue;
			}
			for(int k=1;k<=3;k++){
				if(j-3==k) continue;
				else if(j==k) dp[i+1][j+3] += dp[i][j]%10000;
				else dp[i+1][k] += dp[i][j]%10000;
			}
		}//puts("");
		if(i==N) break;
	}
	for(int i=0;i<=6;i++){
		//printf("%d ",dp[N][i]);
		ans += dp[N][i]%10000;
	}//puts("");
	printf("%d\n",ans%10000);
	return 0;
}

Measured memory_bytes: 1148
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

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

    int N, M;
    cin >> N >> M;
    vector<vi> A(N, vi(M));
    rep(i, N)rep(j, M)cin >> A[i][j], --A[i][j];

    vi cur(N), ng(M);
    
    int ans = INT_MAX;
    rep(i, M) {
        vi cnt(M);
        rep(j, N) {
            while (ng[A[j][cur[j]]])cur[j]++;
            cnt[A[j][cur[j]]]++;
        }
        pii ma(-1, -1);
        rep(j, M)smax(ma, mp(cnt[j], j));
        smin(ans, ma.first);
        ng[ma.second] = 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Name:- OMHARI 
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std; 

#define F               first
#define S               second
#define ull             unsigned long long
#define ll              long long
#define ul              unsigned long
#define db              double
#define ST              string
#define pb              push_back
#define mp              make_pair
#define el              "\n"
#define vll             vector <ll>
#define vl              vector <long int>
#define vi              vector <int>
#define all(v)          (v.begin(), v.end()) 
#define rall(v)         (v.rbegin(), v.rend()) 
#define is_sort(v)      is_sorted all(v)
#define max_of(v)       *max_element all(v)
#define min_of(v)       *min_element all(v)
#define itos(s)         to_string(s)
#define cntone(x)       __builtin_popcountll(x)
#define cntzro(x)       __builtin_clz(x)
#define For(i, a, b)    for(int i=a; i<b; i++)
#define Forr(i, a, b)    for(int i=a; i>=b; i--)
const ll mod = 1e9+7;

void solve()
{
    int d,t,s;
    cin>>d>>t>>s;
    if(d<=s*t)
    cout<<"Yes";
    else
    cout<<"No";
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    /***************-Code starts from here-***************/
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0; 
} 

Measured memory_bytes: 3604
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=10010;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n,m;
struct LY { int x,y,nx; bool op; }a[N]; int k=0;
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
#define mp make_pair
vector <pii> G[N];
set <int> s[N];
int deg[N];
int st[N],z=0;
void del (int i) { s[a[i].x].erase (i),s[a[i].y].erase (i); }
void add (int i) { s[a[i].x].insert (i),s[a[i].y].insert (i); }
void solve ()
{
	queue <int> q;
	for (int i=1; i<=n; i++)
		if (deg[i]==1) q.push (i);
	while (q.size ())
	{
		int u=q.front (); q.pop ();
		z=0;
		bool fg=0;
		for (set <int> :: iterator it=s[u].begin (); it!=s[u].end (); it++)
		{
			int i=*it;
			if (a[i].x==a[i].y) { a[i].op=1,fg^=1; if (fg) swap (a[i].x,a[i].y); continue; }
			st[++z]=i;
		}
		while (z>=2)
		{
			int i=st[z],j=st[z-1]; del (i),del (j);
			if (a[i].x==u) swap (a[i].x,a[i].y);
			if (a[j].x==u) swap (a[j].x,a[j].y);
			if (a[i].x==a[j].x&&a[i].y==a[j].y) { swap (a[j].x,a[j].y),a[i].op=a[j].op=1; z-=2; continue; }
			a[++k].x=a[i].x,a[k].y=a[j].x,add (k);
			a[i].nx=a[j].nx=k;
			z-=2;
		}
		if (z)
		{
			for (pii x:G[u]) if (deg[x.fi]-1>=1)
			{
				int v=x.fi,i=st[z--]; del (i);
				a[++k]=a[i]; a[i].nx=k;
				((a[i].x==u)?a[k].x:a[k].y)=v;
				add (k);
			}
		}
		for (pii x:G[u])
			if (--deg[x.fi]==1) q.push (x.fi);
	}
}
int ans[N]; bool fg=0;
void dfs (int u,int fa,int aim)
{
	if (u==aim)
	{
		while (z) ++ans[st[z--]];
		fg=1;
	}
	if (fg) return ;
	for (pii x:G[u]) if (x.fi!=fa)
		st[++z]=x.se,dfs (x.fi,u,aim),--z;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n),sc(m);
	for (int i=1; i< n; i++)
	{
		int x,y; sc(x),sc(y);
		G[x].pb (mp(y,i)),G[y].pb (mp(x,i));
		++deg[x],++deg[y];
	}
	for (int i=1; i<=m; i++)
	{
		int x,y; sc(x),sc(y); a[++k].x=x,a[k].y=y;
		add (i),fg=0,z=0,dfs (x,0,y);
	}
	solve ();
	for (int i=k; i>=1; i--) if (!a[i].op)
	{
		int j=a[i].nx;
		if ((a[i].x==a[j].x)+(a[i].y==a[j].y)==0) swap (a[i].x,a[i].y);
	}
	for (int i=1; i< n; i++)
		ans[0]+=min (ans[i],2);
	pr(ans[0]);
	for (int i=1; i<=m; i++)
		printf ("%d %d\n",a[i].x,a[i].y);

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    int D[11];
    cin >> N >> K;
    map<int,int> mp;
    rep(i,0,K){
        cin >> D[i];
        mp[D[i]] = 1;
    }
    rep(i,N,100000){
        string str = to_string(i);
        bool flg = true;
        rep(j,0,str.size()){
            if(mp[str[j] - '0'] == 1){
                flg = false;
            }
        }
        if(flg){
            print(i);
            return 0;
        }
    }
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M, C;
  cin >> N >> M >> C;
  vector<int> bs(M);
  F0R(i, M) {
    cin >> bs[i];
  }
  int rs = 0;
  F0R(i, N) {
    int r = C;
    F0R(j, M) {
      int a;
      cin >> a;
      r += a * bs[j];
    }
    if (r > 0) rs++;
  }
  cout << rs;
}
#endif


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	 

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int W = sc.nextInt();

		int dp[] = new int[W+1];
		for(int i = 0; i < dp.length; i++){
			dp[i] = -1;
		}
		dp[0] = 0;

		int value,weight;

		for(int loop = 0; loop < N; loop++){

			value = sc.nextInt();
			weight = sc.nextInt();

			for(int i = W; i-weight >= 0; i--){
				if(dp[i-weight] == -1)continue;
				dp[i] = Math.max(dp[i],dp[i-weight]+value);
			}
		}

		int ans = 0;
		for(int i = 1; i <= W; i++){
			ans = Math.max(ans, dp[i]);
		}

		System.out.println(ans);
	}
}



Measured memory_bytes: 27196
#include<stdio.h>

int main(){
    long long A, B, C;
    long long ans;

    scanf("%lld %lld %lld", &A, &B, &C);

    if(B>=C){
        ans = B+C;
    }else if((A+B)>=C-1){
        ans = B+C;
    }else{
        ans = (A+B+1)+B;
    }

    printf("%lld", ans);

    return 0;
}

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

int main() {
    int N, M;
    vector<string> S, T;
    cin >> N;
    for (int i = 0; i < N; i++){
        string s;
        cin >> s;
        S.push_back(s);
    }

    cin >> M;
    for (int i = 0; i < M; i++){
        string t;
        cin >> t;
        T.push_back(t);
    }

    sort(S.begin(), S.end());
    sort(T.begin(), T.end());

    int i = 0;
    int j = 0;
    int ans = 0;

    while (i < N) {
        int tmp = 1;
        if (i+1 < N){
            while (S[i] == S[i + 1]){
                tmp++;
                i++;
                if (i+1 >= N){
                    break;
                }
            }
        }
        while (j < M) {
            if (T[j] == S[i]){
                tmp--;
            }
            j++;
        }
        ans = max(ans,tmp);
        i++;
        j = 0;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static final int MAX = 20;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] array = new int[N];
		
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}
		
		long[][] DP = new long[N][MAX + 1];
		
		DP[0][array[0]] = 1L;
		
		for(int i = 0; i < N - 1; i++){
			for(int number = 0; number <= MAX; number++){
				if(DP[i][number] > 0){
					if(number + array[i + 1] <= 20){
						DP[i + 1][number + array[i + 1]] += DP[i][number]; 
					}
					
					if(number - array[i + 1] >= 0){
						DP[i + 1][number - array[i + 1]] += DP[i][number]; 
					}
				}
			}
		}
		
		System.out.println(DP[N - 2][array[N - 1]]);
	}

}

Measured memory_bytes: 18100
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (N, M, P) = get!(usize, usize, i64);
    let ABC = get!(usize, usize, i64; M);

    let INF = 1000000000000;
    let mut dp = vec!(INF; N + 1);
    let mut used = vec!(false; N + 1);
    dp[1] = 0;
    used[1] = true;
    for k in 0..2*N {
        for i in 0..M {
            let (a, b, c) = ABC[i];
            let w = P - c;
            if used[a] && dp[b] > dp[a] + w {
                dp[b] = dp[a] + w;
                used[b] = true;
                if k >= N - 1 {
                    dp[b] = -INF;
                }
            }
        }
    }
    let mut ans = cmp::max(0, -dp[N]);
    if ans == INF {
        ans = -1;
    }
    println!("{}", ans);
}



Measured memory_bytes: 4352
// --------------
// Tejas Pandey  |
// 19 - 09 - 20  |
// Atcoder BC 179|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define maxn 1000007
#define vi vector<int>
typedef long long int ll;

ll facs[maxn];

void pre(){
	memset(facs,0,sizeof(facs));
	for(int i = 1;i < maxn;i++){
		for(int j = i;j < maxn;j += i)
			facs[j] += 1;
	}
}

int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  pre();
  ll ans = 0;
  for(int i = 1;i < n;i++){
	ans += facs[i];
  } 
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 11404
A, B, C, X, Y = map(int, input().split())
tmp = min(X, Y)
ans = 0
if A + B <= 2 * C:
    ans = (X * A) + (Y * B)
else:
    ans = 2 * C * tmp
    if X > Y:
        if A > 2 * C:
            ans += (X - tmp) * (2 * C)
        else:
            ans += (X - tmp) * A
    elif Y > X:
        if B > 2 * C:
            ans += (Y - tmp) * (2 * C)
        else:
            ans += (Y - tmp) * B
print(ans)

Measured memory_bytes: 3064
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<long long>;

	class InputData {
	public:
		void getInput(void);
		void skipInput(void);
		Str getStr(void);
		Num getNum(void);
		BigNum getBigNum(void);
	private:
		Str str;
		Num num;
		BigNum bNum;
	};
	Str AtCoder::InputData::getStr(void) {
		return this->str;
	}
	Num AtCoder::InputData::getNum(void) {
		return this->num;
	}
	BigNum AtCoder::InputData::getBigNum(void) {
		return this->bNum;
	}
	void AtCoder::InputData::skipInput(void) {
		std::string buf = "";
		std::getline(std::cin, buf);
	}
	void AtCoder::InputData::getInput(void) {
		this->str.clear();
		this->num.clear();
		this->bNum.clear();

		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				this->str.push_back(row);
				this->num.push_back(std::atoi(row.c_str()));
				this->bNum.push_back(std::atoll(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		this->str.push_back(row);
		this->num.push_back(std::atoi(row.c_str()));
		this->bNum.push_back(std::atoll(row.c_str()));
	}

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(long long);
		void decrement(void);
		void decrement(long long);
		long long getResult(void);
	private:
		long long result;
	};
	void Ans::showResult(void) {
		printf("%lld\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(long long value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(long long value) {
		this->result -= value;
	}
	long long AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::InputData* data = new AtCoder::InputData();
	data->getInput();

	AtCoder::Str str = data->getStr();

	AtCoder::exp(&str[0], &str);
	
	{
		int buf = 0;
		const int size = str.size();
		for (int i = 0; i < size; i++) {
			buf += std::atoi(str[i].c_str());
		}
		if (0 == buf % 9) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
	delete(data);

	return 0;
}

Measured memory_bytes: 10188
#include <stdio.h>
#define MAX(x,y) ((x)>(y))?(x):(y)
#define MIN(x,y) ((x)<(y))?(x):(y)

int main(void) {
	int W,H,N,i,x,y,a;
	int wxs,wxe,wys,wye;
	
	scanf("%d %d %d",&W,&H,&N);
	wxs = 0;
	wxe = W;
	wys = 0;
	wye = H;
	
	for (i = 0;i < N;i++) {
		scanf("%d %d %d",&x,&y,&a);
		switch (a) {
			case 1:
				wxs = MAX(x,wxs);
			break;
			case 2:
				wxe = MIN(x,wxe);
			break;
			case 3:
				wys = MAX(y,wys);
			break;
			case 4:
				wye = MIN(y,wye);
			break;
			default:
			break;
		}
	}
	
	printf("%d\n",((wxe>wxs) ? wxe-wxs : 0)*((wye>wys) ? wye-wys : 0));
	
	return 0;
}


Measured memory_bytes: 128
N, X, M = map(int,input().split())

ans_list = [X]
if N == 1:
    print(X)
else:
    for i in range(1,N):
        ans = ans_list[-1]**2%M
        if ans in ans_list:
            break
        else:
            ans_list.append(ans)

    st_index = ans_list.index(ans)

    if st_index == N-1:
        print(sum(ans_list))
    else:
        total = sum(ans_list[:st_index])
        N -= st_index
        syo = N//(i-st_index)
        mod = N%(i-st_index)

        total += sum(ans_list[st_index:])*syo
        total += sum(ans_list[st_index:st_index+mod])
        print(total)

Measured memory_bytes: 68628
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		ArrayList<Integer> a = new ArrayList<Integer>();
		for(int i = 0; i < N; i ++) {
			a.add(stdIn.nextInt());
		}
		
		Collections.sort(a);
		
		int alice = 0;
		int bob = 0;
		for(int i = a.size() - 1; 0 <= i; i --) {
			alice += a.get(i);
			if(0 <= i - 1) {
				i --;
				bob += a.get(i);
			}
		}
		System.out.println(alice - bob);
	}

}

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

signed main(void){
    int n, x, y; cin >> n >> x >> y;x--;y--;
    vector<int>ans(n,0);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int without = abs(j-i);
            int with = min(abs(i-x)+abs(j-y)+1, abs(j-x)+abs(i-y)+1);

            int tmp = min(with, without);
            // cout << i << ' ' << j << ' ' << tmp << endl;
            ans[tmp]++;
        }
    }
    for(int i=1;i<n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define pii pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = a; i <= (ll)b; ++i)
#define per(i, a, b) for (ll i = a; i >= (ll)b; --i)
#define ll long long
#define lowbit(x) ((x) & (-x))
#define debug(...) fprintf(stderr, __VA_ARGS__)
inline int __gcd(int a,int b) {return b>0 ? __gcd(b,a%b):a;}

const int mod=1e9+7;
const int maxn=1e5+5;

int a[110];
void solve()
{
    ll x,y; cin>>x>>y;
    cout<<min(x%y,y-x%y)<<"\n";
}
int main()
{
    #ifndef local
    IOS
    #endif
    cout<<fixed<<setprecision(10);
    int t=1; 
    //cin>>t; 
    while(t--) {
        solve();
    }
}




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

const double PI=acos(-1.0);

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

struct Coor
{
    int y;
    int x;
    int depth;
};


int main() {
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];

    queue<Coor> q;
    rep(i, h) {
        rep(j, w){
            if(g[i][j] == '#') {
                Coor tmp = {i, j, 0};
                q.emplace(tmp);
            }
        } 
    }

    int ans = -1;
    while(!q.empty()) {
        Coor now = q.front(); q.pop();
        int y = now.y, x = now.x, d = now.depth;
        ans = max(ans, d);

        //if(y == gh && x == gw) cnt = d;

        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i], nd = d + 1;
            Coor next = {ny, nx, nd};

            if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if(g[ny][nx] == '#') continue;

            g[ny][nx] = '#';
            q.emplace(next);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13456
from collections import deque
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    num = 0

    #先頭から砕かない個数を数える
    for i in range(N):
        if num > N - 1:
            print(-1)
            exit()
        elif A[i] == num+1:
            num += 1
    if num == 0:
        print(-1)
    else:
        print(N-num)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 26780
#include<bits/stdc++.h>
using namespace std;
int main(){
string x[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
string s;cin>>s;
if(s=="SUN"||s=="MON"||s=="TUE"||s=="WED"||s=="THU"||s=="FRI"||s=="SAT"){
for(int i=0;i<7;i++)
    if(s==x[i])
        cout<<(7-i)<<endl;}
return 0;}


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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve() 
{
	int n;
	
	cin >> n;
	
	vector< pair<int,int> > a(n);
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i].S >> a[i].F;
	}
	
	sort(ALL(a));
	
	int tim = 0;
	
	for(int i = 0; i < n; ++i) {
		tim += a[i].S;
		
		if(tim > a[i].F) {
			cout << "No";
			return;
		}
	}
	
	cout << "Yes";
}

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


Measured memory_bytes: 6240
#include <iostream>
using namespace std;
int main(){

	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	//n=必要な本数
	//a=セットxの本数
	//b=セットxの値段
	//c=セットyの本数
	//d=セットyの値段

	int e;
	if(n%a==0){
		e=n/a;
	}
	else{
		e=n/a+1;
	}
	//xを選んだ時のセット数
		e=e*b;
		//xを選んだ時の値段

	int f;
	if(n%c==0){
		f=n/c;
	}
	else{
		f=n/c+1;
	}
	//yを選んだ時のセット数
	f=f*d;
	//yを選んだ時の値段

	if(e<f){
		cout<<e<<endl;
	}
	if(f<=e){
		cout<<f<<endl;
	}

	return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner text = new Scanner(System.in);
		int i = 1;
		
		while(true){
			int x = text.nextInt();
			if(x == 0){
				break;
			}else{
				System.out.println("Case"+" "+i+":"+" "+x);
				i= i + 1;
			}
		}
	}

}

Measured memory_bytes: 41596
def check_order(arr)
  arr.each_index do |idx|
    # ????????????????????§??\????????????
    break if idx == arr.length-1

    # ???????????????????????§???????????°false
    return false if arr[idx] > arr[idx+1]
  end
  return true
end

n = gets.chomp.to_i
n.times do
  l = gets
  arr = l.split(" ").map { |x| x.to_i }

  # ?????????????????\?????????????????????????????????
  b = false
  for i in 0..5 do
    arr.combination(i).each do |arr_b|
      arr_c = arr - arr_b # ?????????

      # puts "#{arr_b} #{arr_c}"

      # arr_b????°?????????????????????§?????????????????????
      if check_order(arr_b) && check_order(arr_c) then
        b = true
        break
      end
    end
  end

  if b then
    puts "YES"
  else
    puts "NO"
  end
end

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

int main()
{

int n,s=0,i;
cin >> n;
float h[n],t,a,k=9999.99,p;
cin >> t >> a;
for(i=0;i<n;i++)cin >> h[i];
for(i=0;i<n;i++)
{
if(t-h[i]*0.006-a>0)
{
    p=t-h[i]*0.006-a;
}else
{
    p=a-t+h[i]*0.006;
}
if(k>p)
{
    k=p;
    s=i;
}
}
cout << s+1 << endl;
return 0;
}

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

 
int main(void)
{
    int n,a,w,t,r,i;
    string c1,c2,c3,c4,in;
    c1 = "AC";
    c2 = "WA";
    c3 = "TLE";
    c4 = "RE";
    a = 0;
    w = 0;
    t = 0;
    r = 0;

    cin >> n;

    for(i=0;i<n;i++){
        cin >> in;
        if(in == c1)a++;
        if(in == c2)w++;
        if(in == c3)t++;
        if(in == c4)r++;
    }

    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}

Measured memory_bytes: 3628
def solve():
    X,Y,A,B,C = map(int, input().split())

    red = list(map(int, input().split()))
    red.sort(reverse=True)

    green = list(map(int, input().split()))
    green.sort(reverse=True)

    colorless = list(map(int, input().split()))
    colorless.sort(reverse=True)

    chosen = red[:X] + green[:Y]
    chosen.sort(reverse=True)

    colorless_idx = 0
    for i in range(X+Y-1, -1, -1):
        if chosen[i] < colorless[colorless_idx]:
            chosen[i] = colorless[colorless_idx]
            colorless_idx += 1
        if colorless_idx == C:
            break
        
    print(sum(chosen))



if __name__ == '__main__':
    solve()

Measured memory_bytes: 105444
# ABC071C - Make a Rectangle (ARC081C)
from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(
        {k: v for k, v in Counter(lst).items() if v >= 2}.items(), reverse=True
    )
    if cnt == []:
        print(0)
    elif cnt[0][1] >= 4:
        print(cnt[0][0] ** 2)
    else:
        print(cnt[0][0] * cnt[1][0])


if __name__ == "__main__":
    main()

Measured memory_bytes: 18592
#include <stdio.h>
#include <math.h>

struct Point { double x, y; };

void koch(int n, Point a, Point b){
    if(n==0) return;

    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;

    u.x = (t.x - s.x)*cos(th) - (t.y-s.y)*sin(th) + s.x;
    u.y = (t.x - s.x)*sin(th) + (t.y-s.y)*cos(th) + s.y;

    koch(n-1, a, s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1, s, u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1, u, t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1, t, b);

}

int main(){
    Point a, b;
    int n;

    scanf("%d",&n);

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n",a.x,a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n",b.x,b.y);

    return 0;
}


Measured memory_bytes: 2692
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    let (a,b) = {
        let xs = read_vec_i64();
        (xs[0], xs[1])
    };
    let res = max(max(a+b,a-b),a*b);
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec_i64<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;

LL n,a[15],cnc = 0;

void dfs(LL dep,LL num){
	if(dep >= n){
		cnc ++;
		for(LL i = 0;i < n;i ++) cout << (char)(a[i] + 'a' - 1);
		cout << '\n'; 
		return;
	}
	for(LL i = 1;i <= num + 1;i ++){
		a[dep] = i;
		dfs(dep + 1,max(num,i));
		a[dep] = 0;
	}
}

int main(){
	cin >> n; a[0] = 1;
	dfs(1,1);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        vector<int> a(n);
        REP(i,n) {
                cin >> a[i];
                h -= a[i];
        }

        if (h <= 0) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
    int n, ans = 0;
    int a[20], b[20], c[20];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n-1; i++){
        cin >> c[i];
    }
    for(int i = 0; i < n; i++){
        ans += b[a[i]];
        if(i != 0){
            if(a[i-1] + 1 == a[i]){
                ans += c[a[i-1]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

for num in a:
    d[num]+=1

ans=0
for num in sorted(d,reverse=True):
    while d[num]>=1:
        d[num]-=1

        now=1
        while now<=num:
            now*=2

        cand = now - num
        if d[cand]>=1:
            d[cand]-=1
            ans+=1
        else:
            break
print(ans)

Measured memory_bytes: 111956
/*******************************
Author:Morning_Glory
LANG:C++
Created Time:2019年09月01日 星期日 19时59分51秒
*******************************/
#include <cstdio>
#include <fstream>
using namespace std;
//{{{cin
struct IO{
	template<typename T>
	IO & operator>>(T&res){
		res=0;
		bool flag=false;
		char ch;
		while((ch=getchar())>'9'||ch<'0')	 flag|=ch=='-';
		while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^'0'),ch=getchar();
		if (flag)	 res=~res+1;
		return *this;
	}
}cin;
//}}}
int n,m,ans;
int main()
{
	cin>>n>>m;
	int t=1;
	while (t<m)	++ans,t+=n-1;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


const int MAX_N = (2e+5)+10;
vec nCm(MAX_N+1,0);
vec fact(MAX_N+1,0),fact_inv(MAX_N+1,0);

ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}
void makefact(ll n){//MODは素数かつnより大きい
    ll ans = 1;
    fact.at(0) = ans;
    fact_inv.at(0) = ans;
    reps(i,1,n+1){
        (ans *= i)%=MOD;
        fact.at(i) = ans;
        fact_inv.at(i) = fastpow(ans,MOD-2);
    }
    return;
}
void makenCm(ll n){
    rep(i,n+1){
        ll ans = fact.at(n);
        (((ans*=fact_inv.at(n-i))%=MOD)*=fact_inv.at(i))%=MOD;
        nCm.at(i) = ans;
        //cout<<i<<endl;
    }
    return;
}

int main() {
    cin>>N;
    vec memo(N,-1);
    ll I, J;
    rep(i,N+1){
        cin>>A;
        --A;
        if(memo[A] == -1){
            memo[A] = i;
        }else{
            I = memo[A];
            J = i;
            break;
        }
    }
    makefact(N+1);
    //cout<<'a'<<endl;
    makenCm(I);
    vec sum(I+1);
    rep(i,I+1){
        sum[i] = nCm[i];
        if(i != 0) (sum[i] += sum[i-1])%=MOD;
    }
    makenCm(N+I-J);
    vec minus(N+1);
    rep(i,N+1) {
        //minus[0] は K = 1 に対して
        minus[i] = (i > N + I - J) ? -1 : nCm[i];
    }
    makenCm(N+1);
    //cout<<I<<' '<<J<<endl;
    reps(k,1,N+2){
        ll ans = nCm[k];
        if((minus[k-1] != -1) && (I >= k - 1 - N + J)){
            /*ll temp = sum[min(I, ll(k-1))];
            if(ll(k) - 1 - N + J > 0) (temp += MOD - sum[(ll(k) - 1 - N + J) - 1])%=MOD;
            (temp *= minus[k-1])%=MOD;*/
            ll temp = minus[k-1];
            (ans += MOD - temp)%=MOD;
            //cout<<k<<' '<<temp<<endl;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 7552
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
string S;
ll N;




int main(){
    cin >> S;
    N = S.length();
    ll ans = 0;
    ll b = 0;
    for (ll i=N-1;i>=0;i--){
        ll k = S[i]-'0';
        if(k>5){
            if(b>=5){
                ans += 10 - k-1;
                b = k+1;
            }else{
                ans += 10 - k;
                b = k;
            }
        } else if(k==5){
            if(b>=5){
                ans += 10 - k-1;
                b = k+1;
            }else{
                ans += k;
                b = k;
            }
        }else{
            if(b>5){
                ans += k+1;
                b = k+1;
            }else{
                ans += k;
                b = k;
            }
        }
    }
    if(b>5){
        ans++;
    }
    cout << ans << endl;
}



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


int P[10010]; // 0 から 10000 までの頂点を取り扱い可能
void init(int N) { // 初期化 はじめは全ての頂点はバラバラ
  for (int i=0; i<N; i++) P[i] = i;
}
int root (int a) { //aの大表現を求める
  if (P[a] == a) return a;
  return (P[a] = root(P[a]));
}
bool is_same_set (int a, int b){
  return root(a) == root(b);
}
void unite(int a, int b){
  P[root(a)] = root(b);
}


int main(){
  int n;
  cin >> n;
  tuple<int,int,int> cost[10010]; //Array for cost
  int count = 0;
  for (int i = 0; i < n; i ++){
    for (int j = 0; j < n; j++){
      int t;
      cin >> t;
      if (t >= 0){
      get<1>(cost[count]) = i;
      get<2>(cost[count]) = j;
      get<0>(cost[count]) = t;
      count++;
    }
    }
  }
  sort(cost,cost + n*n);//sortする

  init(n + 10);

  int ans = 0;
  int anscount = 0;//このcountがnになった時点で終了する
  int k = 0;
  while (anscount != n-1){
    if (is_same_set(get<1>(cost[k]), get<2>(cost[k]))) {
      k ++;
    }
    else{
      unite(get<1>(cost[k]), get<2>(cost[k]));
      ans += get<0>(cost[k]);
      k++;
      anscount++;
    }
  }


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



Measured memory_bytes: 3240
#include <iostream>
#include <queue>
using namespace std;
int n, v[100005];
struct st{int x,s;} k;
deque<st> dq;

int main() {
	cin>>n;
	dq.push_back({1,1});
	while(1) {
		k = dq.front(); dq.pop_front();
		if(v[k.x]) continue;
		v[k.x] = 1;
		if(!k.x) break;
		dq.push_front({k.x*10 % n, k.s});
		dq.push_back({(k.x+1) % n, k.s+1});
	}
	cout<<k.s;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;
int cnt;
string s;
int main()
{
	cin >> s;
	for(int i = 0; i < 4; i++){
		if(s[i] != s[i + 1]){
			cnt++;
		}
	}
	if(cnt > 3){
			cout << "Good";
	}else{
			cout << "Bad";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=2*100000;

ll N,a[MAX_N];

int main(){
  ll N;
  cin>>N;
  for(ll i=0;i<N;i++){
    cin>>a[i];
    a[i]-=(i+1);
  }
  sort(a,a+N);
  ll b=a[N/2];
  ll ans=0;
  for(ll i=0;i<N;i++){
    ans+=abs(a[i]-b);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	rep(i,ty-sy)cout << "U";
	rep(i,tx-sx)cout << "R";
	rep(i,ty-sy)cout << "D";
	rep(i,tx-sx)cout << "L";
	cout << "L";
	rep(i,ty-sy+1)cout << "U";
	rep(i,tx-sx+1)cout << "R";
	cout << "D";
	cout << "R";
	rep(i,ty-sy+1)cout << "D";
	rep(i,tx-sx+1)cout << "L";
	cout << "U";
	cout << endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys
import math
import collections
#sys.setrecursionlimit(100000)

tmp = input().split()
a,b = list(map(lambda a: int(a), tmp))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(x, y):
    return (x * y) // gcd(x, y)

print(lcm(a, b))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k,_;
    std::cin>>n>>k;
    for(lint i=0;i<n;i++)std::cin>>_;
    std::cout<<(n-1+k-1-1)/(k-1)<<'\n';
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;


int main(){
    int k;
    while(cin>>k){
        if(k==0)break;
        int sum=0;
        rep(i,k*(k-1)/2){
            int a;
            cin>>a;
            sum+=a;
        }
        cout<<sum/(k-1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
n = input()
k = int(input())

def take_k_comb(a, b):
    if b == 0:
        return 1
    if b == 1 and a >= 1:
        return a * 9
    if b == 2 and a >= 2:
        return a*(a-1)//2 * 9 * 9
    if b == 3 and a >= 3:
        return a*(a-1)*(a-2)//6*9*9*9
    return 0

def constrained_nk(n, k):
    if k == 0:
        return 1
    if n == "":
        if k == 0:
            return 1
        else:
            return 0
    h = int(n[0])
    rest = n[1:]
    if h == 0:
        return constrained_nk(rest, k)
    s = take_k_comb(len(rest), k)
    s += (h-1) * take_k_comb(len(rest), k - 1)
    s += constrained_nk(rest, k-1)
    return s

print(constrained_nk(n, k))




Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,z;
	z=0;
	scanf("%d",&a);
	scanf("%d",&s);
	scanf("%d",&d);
	scanf("%d",&f);
	scanf("%d",&g);
	a=a*g;
	if(d<g){
		h=g-d;
		z=h*f;
	}
	s=s+z;
	if(a<=s){
		printf("%d\n",a);
	}
	else{
		printf("%d\n",s);
	}
	return 0;
}	

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
const int mod= 1e9+7;
long long int S[maxn], A, B;
int lima[maxn], limb[maxn];
int n;
long long int dp[maxn][2], suf[maxn][2];
int main(){
	cin>>n>>A>>B;
	for (int i=1; i<=n; i++) cin>>S[i];
	lima[1]=1;
	limb[1]=1;	
	for (int i=2; i<=n; i++){
		if (S[i]-S[i-1]<A) lima[i]=i;
		else lima[i]=lima[i-1];
		if (S[i]-S[i-1]<B) limb[i]= i;
		else limb[i]= limb[i-1];
	}
	//dp[i][0]:- (i-1)th is A, ith is B
	//dp[j][1];- (i-1)th is B, ith is A
	dp[1][0]= dp[1][1]= 1;
	suf[1][0]= suf[1][1]= 1;
	for (int i=2; i<=n; i++){
		int cur=1, tmp;
		for (int j=20; j>=0; j--){
			tmp= cur+(1<<j);
			if (tmp>=i) continue;
			if (S[i]-S[tmp-1]>=B) cur=tmp;
		}	
		if (cur>=lima[i-1]){
			/*for (int j=lima[i-1]; j<=cur; j++){
				dp[i][0]+=dp[j][1];
				dp[i][0]%=mod;
			}*/
			dp[i][0]+=suf[cur][1]-suf[lima[i-1]-1][1];	
			dp[i][0]%=mod;
			if (dp[i][0]<mod) dp[i][0]+=mod;
		}	
		cur= 1;
		for (int j=20; j>=0; j--){
			tmp= cur+(1<<j);
			if (tmp>=i) continue;
			if (S[i]-S[tmp-1]>=A) cur=tmp;
		}	
		if (cur>=limb[i-1]){
			/*for (int j=limb[i-1]; j<=cur; j++){
				dp[i][1]+=dp[j][0];
				dp[i][1]%=mod;
			}*/
			dp[i][1]+=suf[cur][0]-suf[limb[i-1]-1][0];
			dp[i][1]%=mod;
			if (dp[i][1]<0) dp[i][1]+=mod;
		}
		suf[i][1]= (suf[i-1][1]+dp[i][1])%mod;
		suf[i][0]= (suf[i-1][0]+dp[i][0])%mod;
	}
	long long int ans=0;	
	for (int i=1; i<=n; i++){
		if (i>=lima[n]){
			ans+=dp[i][1];
			ans%=mod;
		}
		if (i>=limb[n]){
			ans+=dp[i][0];
			ans%=mod;
		}
	}
	cout<<ans<<endl;
}

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

void add(pair<int, int> &p, int cur) {
    if (cur >= p.first) {
        swap(p.first, p.second);
        p.first = cur;
    } else if (cur > p.second) {
        p.second = cur;
    }
    return;
}

int v[1<<18];
int ans[1<<18];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for (int i = 0; i < (1 << n); i++) cin >> v[i];
    for (int bit = 1; bit < (1 << n); bit++) {
        pair<int, int> w = {0, 0};
        for (int i = bit; i >= 0; i = bit & (i-1)) {
            add(w, v[i]);
            if (i == 0) break;
        }
        ans[bit] = w.first + w.second;
    }
    int ret = 0;
    for (int i = 1; i < (1 << n); i++) {
        ret = max(ret, ans[i]);
        printf("%d\n", ret);
    }
    return 0;
}

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

int main() {
	char c[4], d[4];
	cin >> c >> d;

	if (c[0] == d[2] && c[1] == d[1] && c[2] == d[0]) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    a = [0]+list(map(int, input().split()))
    box = [0]*(N+1)
    for i in range(N//2+1, N+1):
        box[i]=a[i]
    for i in range(1, N//2+1)[::-1]:
        res = 0
        for j in range(2, N//i+1):
            res+=box[j*i]
        box[i] = (res+a[i])%2
        
    print(sum(box))
    for i in range(1, N+1):
        if box[i]==1:
            print(i)
solve()    
        

Measured memory_bytes: 64220
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long y = sc.nextLong();
    int ans = 0;
    for (long i = x; i <= y; i *= 2) {
      ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844