akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int N; cin >> N;
  string s; cin >> s;
  int ans = 0;
  FOR(i,0,N) {
    string old; cin >> old;
    // j????????????????????????
    FOR(j,0,old.length()) {
      bool next = false;
      // old???st???????????????
      FOR(st,0,old.length()) {
        if((j+1)*(s.length()-1)+st >= old.length()) break;
        bool ok = true;
        // s???k??????
        FOR(k,0,s.length()) {
          if((j+1)*k+st >= old.length()){
            ok = false;
            break;
          }
          if(s[k] != old[(j+1)*k+st]) {
            ok = false;
            break;
          }
        }
        if(ok) {
          ans++;
          next = true;
          break;
        }
      }
      if(next) break;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    VEC(int) A(N);
    READVEC(A);

    int pick = 0, total = accumulate(ALL(A), 0);
    for (int a : A)
        if (a * 4 * M >= total)
            pick++;
    cout << (pick >= M ? "Yes": "No") << endl;
    return 0;
};

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

int main() {
    int k;
    cin >> k;
    vector<pair<int, int> > in(k);
    rep(i, k) cin >> in[i].first >> in[i].second;
    
    
    vector<int> p(8);
    rep(i, 8) p[i] = i;
    
    do{
        bool check = true;
        rep(i, k){
            if(p[in[i].first] != in[i].second){
                check = false;
                break;
            }
        }
        if(!check) continue;
        
        bool flag = true;
        rep(i, 7){
            // (1, 1)方向チェック
            for(int j = i + 1; j < 8; ++j){
                int r_dif = j - i;
                int l_dif = p[i] + r_dif;
                if(l_dif == p[j]) flag = false;
            }
            // (1, -1)方向チェック
            for(int j = i + 1; j < 8; ++j){
                int r_dif = j - i;
                int l_dif = p[i] - r_dif;
                if(l_dif == p[j]) flag = false;
            }
        }
        if(flag) break;
    }while(next_permutation(p.begin(), p.end()));
    
    rep(i, 8){
        rep(j, 8){
            if(p[i] == j){
                cout << "Q";
            }else{
                cout << ".";
            }
        }
        cout << endl;
    }
    
    return 0;
}


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

const int maxn = 105;
int n, a[maxn], papu, popa;
int main(){
	cin >> n;
	for(int i = 0; i<n; i++) cin >> a[i];
	sort(a, a+n); 
	bool turno_popa = true;
	for(int i = n-1; i>=0; i--){
		if (turno_popa) popa+= a[i];
		else papu += a[i];
		turno_popa = !turno_popa;
	}
	cout << popa-papu << '\n';
	
    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
def takoyaki(n,h):
    x = 0
    for i in range(0,n-1):
        for j in range(i + 1, n):
            x = x + h[i]*h[j]
    return x
print(takoyaki(n, h)) 

Measured memory_bytes: 3060
#include<cstring>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
map <string,bool> mp;
int n;
string s;
char c;
int main()
{
	mp.clear();
	scanf("%d",&n);
	n--;
	cin>>s;
	c=s[s.size()-1],mp[s]=1;
	int i;
	for(i=1;i<=n;i++)
	{
		cin>>s;
		if(mp[s] || c!=s[0]) {printf("No");return 0;}
		c=s[s.size()-1];mp[s]=1;
	}
	printf("Yes");
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int a, b;
    char s1[10], s2[10];
    cin >> a >> b;
    memset(s1, 48+a, b);
    s1[b]=0;
    memset(s2, 48+b, a);
    s2[a]=0;
    if(strcmp(s1, s2)>0) cout << s2 << endl;
    else cout << s1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

string t[] = {"dream", "dreamer", "erase", "eraser"};
string s;

int main() {
	cin >> s;
	int now = s.size();
	while (now > 0) {
		int fl = 0;
		for (int i = 0; i < 4; ++i) {
			if (now >= (int)t[i].size() && s.substr(now - t[i].size(), t[i].size()) == t[i]) {
				fl = 1;
				now -= t[i].size();
				break;
			}
		}
		if (!fl) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}




Measured memory_bytes: 512
import java.util.*; 
 
public class Main{
    public static void main(String[] args){
	    Scanner sc=new Scanner(System.in);
            int N =sc.nextInt();
  		    long[] A = new long[N];
  		    long ans=1;
		    for(int i=0; i<N; i++){
    		    A[i]=sc.nextLong();
          	    if(A[i]==0){
            	    ans=0;
                }
    	    }
  	    	if(ans!=0){
		    	for(int i=0; i<N; i++){
            	if(A[i] <= (long)Math.pow(10,18)/ans){
                	ans *= A[i];
            	}else{
          	    	ans=-1;
                	break;
            	}
    		}
  	    }
    	System.out.println(ans);
    }
}

Measured memory_bytes: 61864
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int main(){

	int T,D,L,current,ans,pre_wet = BIG_NUM;

	while(true){
		scanf("%d %d %d",&T,&D,&L);
		if(T == 0 && D == 0 && L == 0)break;

		pre_wet = BIG_NUM;
		ans = 0;

		scanf("%d",&current);
		if(current >= L){
			pre_wet = 1;
		}

		for(int loop = 2; loop <= T; loop++){
			scanf("%d",&current);
			if(current >= L){
				if(pre_wet != BIG_NUM){
					ans += min(D,loop-pre_wet);
				}
				pre_wet = loop;
			}else{
				if(pre_wet+D == loop){
					ans += D;
					pre_wet = BIG_NUM;
				}
			}
		}

		if(pre_wet < T){
			ans += min(D,(T-pre_wet));
		}

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

   return 0;
}

Measured memory_bytes: 2572
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;


int main(){
    long long X ; cin >> X;
    long long cnt500 = X/500;
    long long cnt5 = (X%500)/5;
    cout << cnt500*1000 + cnt5*5 << endl;
}


Measured memory_bytes: 256
while true
    n,x = gets.chomp.split(" ").map{|item| item.to_i}
    
    if n==0 && x==0
        break
    end

    array=Array.new(n){|i| i+1}
    cnt=0
    array.combination(3) {|a, b, c|
        if a+b+c==x
            cnt+=1
        end
    }
    puts cnt
end

Measured memory_bytes: 8692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10, mod = 1e9 + 7;

int dp[maxn][15];
//dp[i][j]到第i位，当前余数是j的数量，枚举第i - 1位的余数和第i位的选择转移
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);

    string s;
    cin >> s;
    if (s[0] == '?'){
        for (int i = 0; i <= 9; ++i) dp[0][i] = 1;
    }else dp[0][s[0] - '0'] = 1;

    for (int i = 1; i < s.size(); ++i){
        if (s[i] == '?'){
            for (int j = 0; j < 13; ++j){
                for (int k = 0; k <= 9; ++k){
                    dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
                    dp[i][(j * 10 + k) % 13] %= mod;
                }
            }
        }else{
            for (int j = 0; j < 13; ++j){
                dp[i][(j * 10 + s[i] - '0') % 13] += dp[i - 1][j];
                dp[i][(j * 10 + s[i] - '0') % 13] %= mod;
            }
        }
    }

    cout << dp[s.size() - 1][5] << endl;
    return 0;
}

Measured memory_bytes: 6352
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int n;
	cin>>n;
	string s,t,x;
	cin>>s;
	cin>>t;
	for0(i,n){
		x += s[i];
		x += t[i];
		}
	cout<<x<<nw;
	
	return 0;
}

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

class Abc156c
{
    static int n;
    static List<int> x;

    static void Solve()
    {
        var max = x.Max();
        var min = x.Min();
        var t = int.MaxValue;
        for(var i = min; i <= max; ++i) {
            var p = 0;
            foreach(var x0 in x) {
                p += (x0 - i) * (x0 - i);
            }
            t = Math.Min(t,p);
        }

        System.Console.WriteLine(t);
    }

    static void Scan()
    {
        n = int.Parse(Console.ReadLine());
        x = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
    }

    static void Main()
    {
        Scan();
        Solve();
    }
}

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

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

if(N[0] == N[1] && N[1] == N[2]) cout << "Yes" << endl; 
else if(N[1] == N[2] && N[2] == N[3]) cout << "Yes" << endl; 
else cout << "No" << endl; 
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], _ = map(int, input().split())
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

    INF = 10 ** 18
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9320
d = []
n = gets.to_i
t = Array.new()
n.times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  t.push([a, 0, i])
  t.push([b, 1, i])
end
t.sort!

used = Array.new(1e5, false)
c = [0, 0]

a = 0
for i in 0...n
  a += t[i][0]
  c[t[i][1]] += 1
  used[t[i][2]] = true
end

if c[0] > 0 && c[1] > 0 && used.select{|i| i}.length == n
  if t[n-1][2] == t[n][2] && c[t[n-1][1]] > 1
    a += [t[n+1][0] - t[n-1][0], t[n][0] - t[n-2][0]].min
  else
    a += t[n][0] - t[n-1][0]
  end
end
puts a

Measured memory_bytes: 19344
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll K;
  cin >> K;
  
  if(K==1) {
    fin(1);
    return 0;
  }
  ll ct = 0;
  
  queue<ll> q;
  rep(i, 9) q.push(i+1);
  ll num;
  while(true) {
    ll x = q.front(); q.pop();
    if(x%10 != 0) q.push(x*10 + (x%10 - 1));
    q.push(x*10 + x%10);
    if(x%10 != 9) q.push(x*10 + x%10 + 1);
    num = x;
    ct++;
    
    if(ct>=K) break;
  }
  
  fin(num);
}

//16 4 3
/*
1234567890123456
ooxxoxoxxxoxoxxo

5 2 3
12345
ooxoo
00001
*/
//
/*
11 3 2
12345678901
ooxxxoxxxoo
00000111122
12222666601
<- up時のo = 最後のoより後．= 最後のoを記録できる
v.s. 貪欲


*/

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


void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
     Egriiiiiiiii() ;
     int n ;
     cin>>n ;
     float x;
     double ans=0 ;
     for(int i=0 ;i<n ;i++)
     {
         cin>>x;
         ans+=(1/x) ;

     }
     cout<<(1/ans);

     return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const unsigned long long maxn=1e18;
const int maxx=1e5+10;
int main()
{
	unsigned long long a[maxx],ans=1;
	int n;
	cin>>n;
	int flag=0;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	if(a[i]==0)
    	 flag=1;
    }
    if(flag)
    {
    	cout<<0<<endl;
    	return 0;
	}
    for(int i=0;i<n;++i)
    {
        if(a[i]<=maxn/ans) 
		 ans*=a[i];
        else
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
int main(){
    //入力
    int n,m,ans = 0;
    cin>>n>>m;
    vector<int>k(m),p(m);
    vector<vector<int>>s(m,vector<int>(n));
    for(int i = 0;i < m;i++){
        cin>>k[i];
        for(int j = 0;j < k[i];j++){
            cin>>s[i][j];
            //スイッチの番号は1~なので、0~にする。
            s[i][j]--;
        }
    }
    for(int i = 0;i < m;i++){
        cin>>p[i];
    }

    //N個のスイッチのON/OFFを全てシュミレート
    for(int sw = 0;sw < (1LL << n);sw++){
        bool flag = true;//電球が全て点灯しているか
        for(int i = 0;i < m;i++){//それぞれの電球の繋がっているスイッチの状態を見る
            int cnt = 0;//スイッチがONの個数
            for(int j = 0;j < k[i];j++){
                if(sw & (1LL << s[i][j])){//繋がっているスイッチがONのとき
                    cnt++;
                }
            } 
            if(cnt % 2 != p[i]){//2で割った余りがp[i]と等しくないとき
                //電球は消灯しているため、flagにはfalseが入る。
                flag = false;
            }
        }
        if(flag){
            //全ての電球が点灯しているので、組み合わせに1を足す。
            ans++;
        }
    }
    //出力
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    string s; cin >> s;
    int K; cin >> K;

    for(ll i=0; i<min(K, (ll)s.length()); i++) {
        if(i == K-1 or s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  bool dp[k + 1];
  rep(i, k + 1) dp[i] = false;

  rep(i, k) rep(j, n) {
    if (i + 1 >= a[j]) dp[i + 1] |= !dp[i + 1 - a[j]];
  }

  if (dp[k])
    cout << "First" << endl;
  else
    cout << "Second" << endl;

  return 0;
}

Measured memory_bytes: 384
N = int(input())
from math import sqrt
def get_divs(n):
  divs = []
  for i in range(1, int(sqrt(N)) + 1):
    if n % i == 0:
      divs.append((i, n // i))
  return divs
ans = float('inf')
divs = get_divs(N)
for x, y in divs:
  ans = min(ans, x + y - 2)
print(ans)

Measured memory_bytes: 3444
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# トポロジカルソート(頂点数、辺集合(DAG, 0-indexed))
def topological_sort(N: int, edges: list) -> list:
    # ここからトポロジカルソート準備
    incnts = [0] * N
    outnodes = [[] for i in range(N)]
    for i in range(len(edges)):
        # 流入するノード数
        incnts[edges[i][1]] += 1
        # 流出先ノードのリスト
        outnodes[edges[i][0]].append(edges[i][1])
    # 流入ノード数が0であるノードのセットS
    S = set()
    for i in range(N):
        if incnts[i] == 0:
            S.add(i)

    # ここからトポロジカルソート
    L = []
    # 暫定セットが空になるまでループ
    i = 0
    while S:
        # 暫定セットから結果リストへ1つ入れる
        L.append(S.pop())
        # 確定させたノードから流出するノードでループ
        for node in outnodes[L[-1]]:
            # 流入ノード数を1減らす
            incnts[node] -= 1
            # 流入ノードが0なら暫定セットへ
            if incnts[node] == 0:
                S.add(node)
        # 各頂点が何番目かを保持しておく
        ts2[L[-1]] = i
        i += 1
    # ソートされた頂点のリストを返却
    return L

N, M = MAP()
edges = [None] * (N+M-1)
nodes2 = [[] for i in range(N)]
for i in range(N+M-1):
    u, v = MAP()
    edges[i] = (u-1, v-1)
    # node[到着点] = 出発点 の隣接リスト
    nodes2[v-1].append(u-1)

ts2 = [0] * N
ts = topological_sort(N, edges)

ans = [-1] * N
for v in range(N):
    mx = -1
    for u in nodes2[v]:
        # トポソ順で自分に近い(大きい)方を優先して残す
        if mx < ts2[u]:
            mx = ts2[u]
            ans[v] = u

for i in range(N):
    print(ans[i]+1)


Measured memory_bytes: 51516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
ll dp[100100][13];

int main() {
    string a,b;
    cin >> a >> b;
    if(a.size() > b.size()){
        cout << "GREATER" << endl;
        return 0;
    }else if(a.size() < b.size()){
        cout << "LESS" << endl;
        return 0;
    }else{
        for (int i = 0; i < a.size(); ++i) {
            if(a[i] > b[i]){
                cout << "GREATER" << endl;
                return 0;
            }else if(a[i] < b[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
    }
    cout << "EQUAL" << endl;
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce

N=int(input())
A=[i for i in map(int,input().split())]

ans=[]
L={}
L[0]=0
R={}
R[N+1]=0
R[N+2]=0

def gcd2(x,a):
    if x==0:
        return a
    else:
        return gcd(x,a)

for i in  range(N):
    L[i+1]=gcd2(L[i],A[i])
    R[N-i]=gcd2(R[N-i+1],A[-(i+1)])

for i in range(N):
    ans.append(gcd2(L[i],R[i+2]))
print(max(ans))

Measured memory_bytes: 32588
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N,ans=0;
  cin>>N;
  ll n=N;
  for(ll i=2;i*i<=n;i++){
    ll count=0;
    if(N%i!=0 || prime(i)==0){continue;}
    while(N%i==0){
      N/=i;
      count++;
    }
    ll j=1;
    while(count-j>=0){
      count-=j;
      j++;
    }
    j--;
    ans+=j;
  }
  if(prime(N)==1){
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    string s, res;
	cin >> s;
    cout << s[0]+to_string(s.size()-2)+s[s.size()-1] << endl;
	return 0;
}


Measured memory_bytes: 256
#! coding: UTF-8
num = int(input())
#桁数
def digit(x):
    point = 0
    while int(x) > 0:
        x /= 10
        point += 1
    return point
#num=A*Bの時の最小桁数
def Multi(num):
    y = digit(num)
    A = 1
    while A*A <= num:
        if num%A == 0:
            B = num/A
            C = max(digit(A),digit(B))
            if y > C:
                y = C
        A += 1
    print(y)
Multi(num)


Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            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<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}
fn gcd(a: u64, b: u64) -> u64 {
    if a == u64::default() {
        b
    } else {
        gcd(b % a, a)
    }
}

fn solve() {
    let (a, b, k) = get!(u64, u64, u64);
    let mx = gcd(a, b);
    let mut count = 0;
    for i in (0..(mx+1)).rev() {
        if mx % i == 0 {
            count += 1;
        }
        if count == k {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 8572
#include<cstdio>
const static int MAX_N = 500;
int imos[MAX_N][MAX_N];

int main(){
	unsigned N, M, Q;
	scanf("%u %u %u", &N, &M, &Q);
	for (unsigned i = 0; i < M; i++){
		unsigned l, r;
		scanf("%u %u", &l, &r);
		r--;
		imos[0][r]++;
		imos[l][r]--;
	}
	for (unsigned i = 1; i < N; i++){
		for (unsigned j = 0; j < N; j++){
			imos[i][j] += imos[i-1][j];
		}
	}
	for (unsigned i = 0; i < N; i++){
		for (unsigned j = 1; j < N; j++){
			imos[i][j] += imos[i][j-1];
		}
	}
	for (unsigned i = 0; i < Q; i++){
		unsigned p, q;
		scanf("%u %u", &p, &q);
		printf("%d\n", imos[p-1][q-1]);
	}
	return 0;
}

Measured memory_bytes: 2668
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MAXN = 500005;
using namespace std;
int arr[MAXN],dp[MAXN];
int main() {
  /* ifstream cin("input.txt");
   ofstream cout("output.txt");*/
   fast_io;
   bool flag=true;
   set<int>set1;
   int n,count=0;cin>>n;
   int arr[n];
   for(int i=0;i<n;i++){
   		cin>>arr[i];
   }
   int i=0;
   while(set1.size()<=n){

   		if(arr[i]==2){
   			break;
   		}
   		else{
   		if(set1.find(i)==set1.end()){
   			//cout<<arr[i]-1<<endl;
   			set1.insert(i);
   			count++;
   			i=(arr[i]-1);
   			//cout<<count<<" "<<i<<endl;
   		}
   		else{
   			flag=false;
   			break;
   		}
   	  }
   }
   if(flag){
   		cout<<count+1<<endl;
   }
   else{
   		cout<<-1<<endl;
   }
   return 0;
}


   	



Measured memory_bytes: 8660
#include<stdio.h>
#include<limits.h>

//Size以下の素数リストをエラストテネスのふるいで作る
void Sieve(int Size, int *output_size, int out[]){
  *output_size = 0;
  int List[1001]={};
  int i, j;
  for(i=2; i<=Size; i++)
    List[i] = i;
  i=2;
  while(i*i <= Size){
    //List[i]が残っていれば素数
    if(List[i]){
      for(j=i+1; j<=Size; j++){
        //List[i]より大きい数のうちList[i]で割り切れるなら0にする
        if(!(List[j]%List[i]))
          List[j] = 0;
      }
    }
    i++;
  }
  //この時点で穴の空いた素数リストが完成する
  for(i=2; i<=Size; i++){
    if(List[i]){
	  out[*output_size] = List[i];
      (*output_size)++;
    }
  }
}

int main(){
  int N;
  int P[1001];//素数リスト
  int Length_Prime;//素数リストの長さ
  int N_Prime[1001];//それぞれの素数の個数(ただし配列の番号に対応した素数はPと一緒)
  long N_Divisor;//(正の)約数の個数
  scanf("%d", &N);
  Sieve(N, &Length_Prime, P);
  int i, j;
  for(i=2; i<=N; i++){
    int i_temp;
    for(j=0; j<Length_Prime; j++){
      i_temp = i;
      while(!(i_temp%P[j])){
        i_temp /= P[j];
        N_Prime[j]++;
      }
    }
  }
  long DIV, ANS;
  DIV = 1e9 + 7;
  N_Divisor = 1;
  for(i=0; i<Length_Prime; i++){
    N_Divisor *= (1+N_Prime[i]);
    N_Divisor %= DIV;
  }
  ANS = N_Divisor%DIV;
  printf("%ld\n", ANS);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <numeric>
#include <cmath>
#include <cctype>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


ll lenb[51];
ll nump[51];

ll func(ll N,ll X){
  if(N==0){
    return (X>=1?1:0);
  }else if(X<=1+lenb[N-1]){
    return func(N-1,X-1);
  }else{
    return nump[N-1] + 1 + func(N-1,X-2-lenb[N-1]);
  }
}

int main(){
  ll N,X; cin>>N>>X;
  //長さとパティの数
  lenb[0] = 1;
  nump[0] = 1;
  for(int i=1;i<=N;++i){
    lenb[i] = lenb[i-1]*2 + 3;
    nump[i] = nump[i-1]*2 + 1;
  }
  cout << func(N,X) <<"\n";
}

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

count = 0
multi = 1

while len(A) > 0:
    i = 0
    sign = A[min(1, len(A)-1)] - A[0]
    multi = 0
    if len(A) != 1:
        while multi >= 0:
            if len(A) <= i+2:
                i = len(A)-1
                break
            else:
                i += 1
                multi = (A[i+1] - A[i]) * sign
                if sign == 0:
                    sign = (A[i+1]-A[i])
        del A[0:i+1]
        count += 1
    else:
        del A[0]
        count += 1

print(count)


Measured memory_bytes: 14252
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&c^-1;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
string a[2020];
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n,l;cin>>n>>l;
for (int i=1;i<=n;++i) cin>>a[i];
sort(a+1,a+n+1);
string ans="";
for (int i=1;i<=n;++i) ans+=a[i];
cout<<ans<<endl;
}

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

using namespace std;


int fn(int n){
	if(n%2==0){
		return n/2;
	}else{
		return 3*n+1;
	}
}

int main(){

	int s;
	int flag=0;
	vector<int> a(1);

	cin>> s;
	a[0]=s;

	for(int i=1;i<1000000;i++){
		a.emplace_back(fn(a[i-1]));
		//cout<< a[i-1] << "\n";
		for(int j=0;j<i;j++){
			if(a[i]==a[j]){
				cout<< i+1 << "\n";
				flag=1;
				break;
			}
		}

		if(flag==1) break;
	}

}

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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

bool comp(ll a, ll b) {
  return a > b;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  int negAll = 0;
  rep(i, n) {
    cin >> a[i];
    if (a[i] < 0) negAll++;
  }
  mint ans = 1;

  if (n == k) {
    rep(i, n) {
      ans *= (a[i] + 1000000007);
    }
    cout << ans.x << endl;
    return 0;
  }

  sort(a.begin(), a.end(), comp);
  //reverse(a.begin(), a.end());

  if (negAll == n && k % 2) {
    rep(i, k) {
      ans *= (a[i] + 1000000007);
    }
    cout << ans.x << endl;
    return 0;
  }

  int head = 0, tail = n - 1;
  if (k % 2) { ans *= a[0]; head++; k--; }

  while (k > 0) {
    ll pos = a[head] * a[head + 1], neg = a[tail] * a[tail - 1];
    if (pos > neg) {
      ans *= pos;
      head += 2;
    } else {
      ans *= neg;
      tail -= 2;
    }
    k -= 2;
  }

  cout << ans.x << endl;

  return 0;
}
/*
*/


Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int N,c[500],s[500],f[500];
int main(){
    int n;
    cin >> n;
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
    rep(i,n){
        int t=0;
        for(int j=i;j<n-1;j++){
            if(t<s[j]) t= s[j];
            else if(t%f[j]==0);
            else t= t+f[j]-t%f[j];
            t+=c[j];
        }
        cout << t << newl;
    }
}

Measured memory_bytes: 256
abc = input().split()
r = int(abc[0])
g = int(abc[1])
b = int(abc[2])
k = int(input())

while k > 0 and g <= r:
    k -= 1
    g *= 2
while k > 0 and b <= g:
    k -= 1
    b *= 2
if r < g < b:
    print("Yes")
else:
    print("No")

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	sort(a.begin(),a.end(),greater<int>());
	int64_t ans=1; int cnt=0;
	for(int i=1;i<n&&cnt!=2;++i){
		if(a.at(i-1)==a.at(i))ans*=a.at(i),++i,++cnt;
	}
	cout<<(cnt==2?ans:0)<<"\n"s;
}

Measured memory_bytes: 640
using System;

namespace ConsoleApp7
{
  class Solution
    {
    static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var strnums = Console.ReadLine().Split(' ');
            var weights = Array.ConvertAll(strnums, s => int.Parse(s));
            int total = 0; int s1 = 0; int option1 = 0; 
            foreach (int w in weights)
            {
                total += w;
            }
            for(int i = 0; i < weights.Length; i++)
            {             
                s1 += weights[i];
                if (s1 < total / 2 && total / 2 <= s1 + weights[i + 1])
                {
                    option1 = Math.Min(Math.Abs(total - 2 * s1), Math.Abs(2 * (s1 + weights[i + 1]) - total));
                    break;
                }               
            }
            Console.WriteLine(option1);
        }
    }
}

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

using namespace std;

int main(){

	int n,bob=0,alice=0;
	cin >> n;

	vector<int>v(n);
	
	for(int i=0;i<n;i++)
		cin >> v[i];

	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i=0;i<n;i++){
		if(i%2==0) alice+=v[i];
		else bob+=v[i];


	}

	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using std::sort;

int n,a[200],ans;

int main(void){
	register int i;
	scanf("%d",&n);
	n<<=1;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	for(i=0;i<n;i+=2)
		ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
	int n;
	string s, t;
	
	cin >> n;
	cin >> s >> t;
	
	for (int i=1; i<=n; i++)
	{
		cout << s[i-1] << t[i-1];
	}
	
	return 0;
}

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

int n, start[200005], endd[200005];

int main(){
    scanf("%d", &n);
    for (int i=1; i<=n; ++i){
        scanf("%d%d", &start[i], &endd[i]);
    }
    start[0] = 0; endd[0] = 0;
    sort(start, start+n+1); sort(endd, endd+n+1);
    if (n%2==1) printf("%d", endd[(n+1)/2] - start[(n+1)/2] + 1);
    else{
        int start1 = start[n/2], start2 = start[n/2+1], endd1 = endd[n/2], endd2 = endd[n/2+1];
        printf("%d", (endd2+endd1) - (start2+start1) + 1);
    }
    return 0;
}


Measured memory_bytes: 5380
#include<bits/stdc++.h>
using namespace std;
int main (){
	int NUM_R,NUM_G,R,G,M;
  	cin >> NUM_R >> NUM_G >> R >> G >> M;
  	vector<long>rData(R),gData(G),mData(M);
  	for(int i = 0;i < R;i++){
    	cin >> rData[i];
    }
  	for(int i = 0;i < G;i++){
    	cin >> gData[i];
    }
 	for(int i = 0;i < M;i++){
    	cin >> mData[i];
   	}
  
  	sort(rData.begin(),rData.end(),greater<int>());
  	sort(gData.begin(),gData.end(),greater<int>());
  	sort(mData.begin(),mData.end(),greater<int>());
  
  	vector<int>rEat(NUM_R),gEat(NUM_G);
  	
  	for(int i = 0;i < NUM_R;i++){
    	rEat[i] = rData[i];
    }
  	for(int i = 0;i < NUM_G;i++){
    	gEat[i] = gData[i];
    }
  	
  	int rIdx = NUM_R - 1;
  	int gIdx = NUM_G - 1;
  	for(int i = 0;i < mData.size();i++){
    	if(rIdx >= 0){
        	if(gIdx >= 0){
            	if(rEat[rIdx] >= gEat[gIdx]){
                	if(mData[i] > gEat[gIdx]){
                    	gEat[gIdx] = mData[i];
                      	gIdx--;
                    }else{
                    	break;
                    }             
                }else {
                	if(mData[i] > rEat[rIdx]){
                    	rEat[rIdx] = mData[i];
                      	rIdx--;
                    }else{
                    	break;
                    }         
                }            	
            }else{
                 	if(mData[i] > rEat[rIdx]){
                    	rEat[rIdx] = mData[i];
                      	rIdx--;
                    }else{
                    	break;
                    }      
            }
        }else{
       		 if(mData[i] > gEat[gIdx]){
                   	gEat[gIdx] = mData[i];
                  	gIdx--;
             }else{
                   	break;
            }          
             
        }
    }
  	long sum  =0;
    for(int i = 0;i < NUM_R;i++){
    	sum += rEat[i];
    }
  	for(int i = 0;i < NUM_G;i++){
    	sum += gEat[i];
    }
  cout << sum<<endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

const int N = 2e+5+5;

int n;
char s[N*2];
LL l,r;
LL cnt[30],ans[30];
int nxt[N*2];

void prepare(){
	fo(i,1,n)nxt[i]=0;
	int w=0;
	fo(i,2,n){
		if (w+nxt[w]-1>=i)nxt[i]=min(nxt[i-w+1],w+nxt[w]-i);
		while(i+nxt[i]<=n&&s[i+nxt[i]]==s[nxt[i]+1])nxt[i]++;
		if (i+nxt[i]-1>=w+nxt[w]-1)w=i;
	}
}

void trs(){
	prepare();
	fo(i,n/2+2,n)
	if(i+nxt[i]-1==n){n=i-1;break;}
}

struct number{
	LL x,y,val;
	number(const LL x_=0,const LL y_=0,const LL val_=0){x=x_;y=y_;val=val_;}
}a[100];
number operator + (number a,number b){return number(a.x+b.x,a.y+b.y,a.val+b.val);}

int key,k;

void add(LL lim){
	if (lim<=n){
		fo(i,1,lim)cnt[s[i]-'a']++;
		return;
	}
	int w;
	fd(i,key,1)
	if(lim>=a[i].val){w=i;break;}
	fo(i,1,n)cnt[s[i]-'a']+=a[w].x;
	fo(i,1,k)cnt[s[i]-'a']+=a[w].y;
	add(lim-a[w].val);
}

void solve(LL lim){
	fo(i,0,25)cnt[i]=0;
	k=n;
	fo(i,1,n)
	if (i+nxt[i]-1==n){k=i-1;break;}
	if (n%k==0){
		LL tim=lim/k;
		fo(i,1,k)cnt[s[i]-'a']+=tim;
		fo(i,1,lim%k)cnt[s[i]-'a']++;
	}
	else{
		a[0]=number(0,1,k);
		a[1]=number(1,0,n);
		key=0;
		fo(i,2,100){
			a[i]=a[i-1]+a[i-2];
			if (a[i].val>lim){key=i-1;break;}
		}
		add(lim);
	}
}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%lld%lld",&l,&r);
	trs();
	prepare();
	solve(r);
	fo(i,0,25)ans[i]=cnt[i];
	solve(l-1);
	fo(i,0,25)ans[i]-=cnt[i];
	fo(i,0,25)printf("%lld ",ans[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

#define INFTY 1000000000;

int A[500000];

int marge(int left,int mid,int right){
  int i,j,k;
  static int count=0;
  int n1=mid-left;
  int n2=right-mid;
  int L[250001];
  int R[250001];
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
    count++;
  }
  return count;
}


int margesort(int left,int right){
  int a;
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    margesort(left,mid);
    margesort(mid,right);
    a=marge(left,mid,right);
  }
  return a;
}

int main(){
  int i,count,N;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  count=margesort(0,N);
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=N-1) printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}



Measured memory_bytes: 5748
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  string ret;
  int x = max({a, b, c});
  int y = min({a, b, c});
  if ((x == 7) && (y == 5) && ((a + b + c) - (x + y) == 5)) {
    ret = "YES";
  } else {
    ret = "NO";
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int a,b,c,d,e,f,g;
    scanf("%lld %lld",&a,&b);
    scanf("%lld %lld",&c,&d);
    scanf("%lld",&e);
    f=b-d;
    g=c-a;
    if(g<0) g=-g;
    if(f*e>=g)
        printf("YES\n");
    else printf("NO\n");
    return 0;
}

Measured memory_bytes: 2092
while True:
    try:
        s=raw_input()
    except EOFError:
        break
    L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[(0,4\
,8),(2,4,6)]
    for i,j,k in L:
        if s[i]==s[j]==s[k]!="s":
            print "o" if s[i]=="o" else "x"
            break
    else:
        print "d"

Measured memory_bytes: 4240
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N;
    scanf("%d", &N);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int A, K;
        scanf("%d %d", &A, &K);
        int cur_ans = 0;
        while (1) {
            int cnt = A / K;
            if (cnt == 0) break;
            if ((A % K) == 0) {
                cur_ans = A / K;
                break;
            }
            int x = (A - cnt * K) / (cnt + 1);
            if (!x) x++;
            A -= x * (cnt + 1);
        }
        ans ^= cur_ans;
    }
    if (ans) puts("Takahashi");
    else puts("Aoki");
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

type DisjointSet struct {
	rank []int
	p    []int
}

func New(size int) *DisjointSet {
	ds := &DisjointSet{
		rank: make([]int, size),
		p:    make([]int, size),
	}

	for i := 0; i < size; i++ {
		ds.p[i] = i
		ds.rank[i] = 0
	}

	return ds
}

func (ds *DisjointSet) same(x, y int) bool {
	return ds.findSet(x) == ds.findSet(y)
}

func (ds *DisjointSet) unite(x, y int) {
	ds.link(ds.findSet(x), ds.findSet(y))
}

func (ds *DisjointSet) link(x, y int) {
	if ds.rank[x] > ds.rank[y] {
		ds.p[y] = x
	} else {
		ds.p[x] = y
		if ds.rank[x] == ds.rank[y] {
			ds.rank[y]++
		}
	}
}

func (ds *DisjointSet) findSet(x int) int {
	if x != ds.p[x] {
		ds.p[x] = ds.findSet(ds.p[x])
	}
	return ds.p[x]
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	ds := New(n)

	var out bytes.Buffer
	for i := 0; i < q; i++ {
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())

		if t == 0 {
			ds.unite(a, b)
			continue
		} else if ds.same(a, b) {
			out.WriteString("1\n")
			continue
		}
		out.WriteString("0\n")
	}

	return strings.TrimRight(out.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}



Measured memory_bytes: 2880