akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

const long M = 1046527;
string H[M];

long getKey(string str){
    long sum = 0, p = 1, digit = 0;
    for (long i = 0; i < str.size() ; i++) {
        if(str[i] == 'A') digit = 1;
        else if(str[i] == 'C' ) digit = 2;
        else if(str[i] == 'G' ) digit = 3;
        else if(str[i] == 'T' ) digit = 4;
        else digit = 0;
        sum += p * digit;
        p *= 5;
    }
    return sum;
}

long h1(long key){return key % M;}
long h2(long key){return 1 + (key % (M - 1));}

long find(string str){
    long key = getKey(str);
    for (long i = 0;  ; i++) {
        long h = (h1(key) + i * h2(key)) % M;
        if(H[h] == str) return 1;
        else if(H[h].size() == 0) return 0;
    }
}

long insert(string str){
    long key = getKey(str);
    for (long i = 0;  ; i++) {
        long h = (h1(key) + i * h2(key))% M;
        if(H[h] == str) return 1;
        else if (H[h].size() == 0){
            H[h] = str;
            return 0;
        }
    }
}

int main(){
    long n;
    string str,com;
    cin >> n;
    for (long i = 0; i < n ; i++) {
        cin >> com >> str;
        if(com[0] == 'i')insert(str);
        else{
            if(find(str))cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25872
s = gets.chomp! + "T"
x,y = gets.split.map(&:to_i)

dpx = Hash.new(false)
i = s.index('T')
dpx[i] = true
s.slice!(0,i)

dpy = Hash.new(false)
dpy[0] = true

j = false
count = 0
s.each_char do |c|
    if c == 'F'
        count += 1
        next
    end

    j ^= true
    next if count == 0
    
    h = Hash.new(false)
    if j
        dpx.each_key do |key|
            h[key+count] = h[key-count] = true
        end
        dpx.clear
        dpx = h
    else
        dpy.each_key do |key|
            h[key+count] = h[key-count] = true
        end
        dpy.clear
        dpy = h
    end

    count = 0
end
#p dpx,dpy

puts dpx[x] && dpy[y] ? "Yes" : "No"

Measured memory_bytes: 5500
#include <bits/stdc++.h>
using namespace std;
long long n,m,a,b,x,ans;
int main() 
{
  cin>>a>>b>>n;
  if(n>=b) x=b-1;
  else x=n;
  ans=((a*x)/b)-a*(x/b);
  cout<<ans;
}

Measured memory_bytes: 3644
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int Q;
  string S, A, B;

  cin >> S >> Q;

  bool rev = false;

  for (int i = 0; i < Q; i++) {
    int T;
    scanf("%d", &T);

    if (T == 1) {
      rev = !rev;
    } else {
      int F;
      char C;
      scanf("%d %c", &F, &C);
      if ((F == 2) ^ rev) {
        B += C;
      } else {
        A += C;
      }
    }
  }

  reverse(A.begin(), A.end());

  string ans = A + S + B;

  if (rev) reverse(ans.begin(), ans.end());

  printf("%s\n", ans.c_str());

  return 0;
}


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




int main() {
    int N;  cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; ++i) cin >> L[i];
    sort(L.begin(), L.end());
    // DUMP(L);
    long long ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            // DUMP(pair<int, int>(i, j));
            ans += lower_bound(L.begin(), L.end(), L[i] + L[j]) - lower_bound(L.begin(), L.end(), L[j] - L[i] + 1);
            --ans;
            if (L[j] < 2 * L[i]) --ans;
            // DUMP(ans);
        }
    }
    cout << ans / 3 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=200000+10,maxv=5000+10,mo=1000000007,inv2=(mo+1)/2;
int c[maxv][maxv],a[maxn],b[maxn],fac[maxv*2],inv[maxv*2];
int i,j,k,l,t,n,m,ans,mxa,mxb;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int qsm(int x,int y){
	if (!y) return 1;
	int t=qsm(x,y/2);
	t=(ll)t*t%mo;
	if (y%2) t=(ll)t*x%mo;
	return t;
}
int C(int n,int m){
	if (m<0||n<m) return 0;
	return (ll)fac[n]*inv[m]%mo*inv[n-m]%mo;
}
int main(){
	n=read();
	fo(i,1,n){
		a[i]=read();b[i]=read();
		mxa=max(mxa,a[i]);mxb=max(mxb,b[i]);
	}
	fac[0]=1;
	fo(i,1,mxa*2+mxb*2) fac[i]=(ll)fac[i-1]*i%mo;
	inv[mxa*2+mxb*2]=qsm(fac[mxa*2+mxb*2],mo-2);
	fd(i,mxa*2+mxb*2-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;
	fo(i,1,n) c[mxa-a[i]][mxb-b[i]]++;
	fo(i,0,mxa*2)
		fo(j,0,mxb*2){
			if (j) (c[i][j]+=c[i][j-1])%=mo;
			if (i) (c[i][j]+=c[i-1][j])%=mo;
		}
	fo(i,1,n) (ans+=c[mxa+a[i]][mxb+b[i]])%=mo;
	fo(i,1,n) (ans-=C(a[i]*2+b[i]*2,a[i]*2))%=mo;
	ans=(ll)ans*inv2%mo;
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 82048
import sys

tscore = hscore = 0
n = int( sys.stdin.readline() )
for i in range( n ):
	tcard, hcard = sys.stdin.readline().rstrip().split( " " )
	if tcard < hcard:
		hscore += 3
	elif hcard < tcard:
		tscore += 3
	else:
		hscore += 1
		tscore += 1

print( "{:d} {:d}".format( tscore, hscore ) )

Measured memory_bytes: 4216
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define prev prev228
#define all(x) (x).begin(), (x).end()

int n;
int a, k;

int res = 0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> k;
        while (1)
        {
            if (a % k == 0)
            {
                res ^= a / k;
                break;
            }
            int d = a / k;
            int x = d * k;
            int md = a % (d + 1);
            if (x % (d + 1) >= md) x -= x % (d + 1) - md;
            else {x -= x % (d + 1); x -= (d + 1) - md;}
            a = x;
        }
    }
    if (res == 0)
    {
        cout << "Aoki";
    }
    else
    {
        cout << "Takahashi";
    }
}


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

using namespace std;

int main(void) {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for(int i = 0; i < m; i++) cin >> a[i];

    int sum1 = 0;
    for(int i = x; i < n+1; i++) {
        for(int j = 0; j < m; j++) {
            if(a[j] == i) {
                sum1++;
            }
        }
    }

    int sum2 = 0;
    for(int i = 0; i < x+1; i++) {
        for(int j = 0; j < m; j++) {
            if(a[j] == i) {
                sum2++;
            }
        }

    }

    cout << (sum1 >= sum2 ? sum2 : sum1);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
stack<LL> sta;
int main(){
    string str;
    string s;
    getline(cin,str);
    for(char ch : str) {
        if(ch == '+'){
            if(!s.empty())sta.push(stoi(s));
            s.clear();
            int a = sta.top();
            sta.pop();
            int b = sta.top();
            sta.pop();
            sta.push(b + a);
        }else
        if(ch == '-'){
            if(!s.empty())sta.push(stoi(s));
            s.clear();
            int a = sta.top();
            sta.pop();
            int b = sta.top();
            sta.pop();
            sta.push(b - a);
        }else
        if(ch == '*'){

            if(!s.empty())sta.push(stoi(s));
            s.clear();
            int a = sta.top();
            sta.pop();
            int b = sta.top();
            sta.pop();
            sta.push(a * b);
        }else if(ch != ' '){
            s += ch;
        }else{
            if(!s.empty())sta.push(stoi(s));
            s.clear();
        }
    }
    COUT(sta.top());
    return 0;
}



Measured memory_bytes: 3224
#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() {
  ll n;
  cin >> n;
  
  ll a = 100;
  int count=1;
  
  while(true){
    a+=a/100;
    if(a>=n)
      break;
    count++;
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3636
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
    }

    let mut x: Vec<usize> = Vec::new();
    let mut y: Vec<usize> = Vec::new();
    let mut a: Vec<i64> = Vec::new();
    let mut b: Vec<i64> = Vec::new();
    for i in 0..n {
        input!{
            x_tmp: usize,
            y_tmp: usize,
        }
        x.push(x_tmp);
        y.push(y_tmp);
    }

    for i in 0..n {
        a.push(x[i] as i64 - y[i] as i64);
        b.push(x[i] as i64 + y[i] as i64);
    }

    a.sort();
    b.sort();

    println!("{}", max((a[0] - a[n-1]).abs(),
                       (b[0] - b[n-1]).abs()));

}


Measured memory_bytes: 12892
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <math.h>
#include <iomanip>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,y;
   	cin>>n>>y;
   	int a,b,c;
   	for(int i=0;i<=min(y/10000+1,n)+1;++i){
   		for(int j=0;j<=min((y-10000*i)/5000+1,n-i)+1;++j){
   			for(int k=0;k<=min((y-10000*i-5000*j)/1000+1,n-i-j)+1;++k){
   				if(i+j+k==n&&10000*i+5000*j+1000*k==y){cout<<i<<" "<<j<<" "<<k<<endl;goto end;}
   			}	
   		}
   	}
   	cout<<-1<<" "<<-1<<" "<<-1<<endl;
   	end:
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

class MainClass
{
    public static void Main(string[] args)
    {
        string[] str=Console.ReadLine().Split(' ');

        int a=Convert.ToInt32(str[0]);
        int b=Convert.ToInt32(str[1]);
        int c=Convert.ToInt32(str[2]);
        int count=0;

        for(int i=a;i<=b;i++)
        {
            if(c%i==0) count++;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 9224
import bisect

n, h = map(int, input().split())
a = []
b = []
for i in range(n):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)
b = sorted(b)
nage = b[bisect.bisect_right(b, max(a)):]
ans = 0
for i in nage[::-1]:
    h -= i
    ans += 1
    if h <= 0:
        break
ans += max(-(-h // max(a)), 0)
print(ans)


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


int main () {
  int n ; 
  cin >> n ;
  
  long long pre = 0 ;
  
  vector<int> line(n) ;
  
  for ( int i = 0 ; i < n ; i++ ) {
    int a , b ;
    cin >> a >> b ;
    line.at(i) = a + b ;
    pre -= b ;
  }
  
  sort(line.begin(),line.end()) ;
  reverse(line.begin(),line.end()) ;
  
  long long answer = 0 ;
  
  for (int i = 0 ; i < (n+1)/2 ; i++ ){
    answer += line.at(2*i) ;
  }
  
  cout << answer + pre << endl ;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3e5 + 5;
int n, m, a[N];
char s[N];
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	ll ans = 0;
	int w = 0;
	for (int i = 1; i <= n; ++i) {
		if (s[i] == 'W') {
			++w;
			ans += i - w;
		}
	}
	cout << ans;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

using Graph=vector<vector<int>>;

signed main(void) {
	int n, x, y;
	cin >> n >> x >> y;
	x--;
	y--;
	vector<int> ans(n,0);

	Graph G(n);
	rep(j, n) {
		if (j != n - 1)G[j].pb(j + 1);
		if (j != 0)G[j].pb(j - 1);
		if (j == x)G[j].pb(y);
		if (j == y)G[j].pb(x);
	}

	rep(i, n) {//始点を0からn-2までずらす
		//cout << "i= " << i << endl;
		vector<int>dist(n, -1);
		queue<int>que;
		dist[i] = 0;
		que.push(i);
		while (!que.empty()) {
			int v = que.front();
			//cout << " v= " << v << endl;
			que.pop();
			for (int nv : G[v]) {
				if (dist[nv] != -1) continue;
				//if (nv < v)continue;
				//cout << " nv=" << nv << "v=" << v << endl;
					dist[nv] = dist[v] + 1;
					que.push(nv);
			}
		}
		//println(i);
		//for (auto a : dist)cout << a;
		//println("");
		rep(i, n) {
			ans[dist[i]]++;
		}

	}
	rep(i, n)ans[i] /= 2;
	//for (auto a : ans)cout<<a<<endl;
	rep1(i, n)println(ans[i]);
}

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

#define MAX (int)1e6

using namespace std;

bool A[MAX+1];

int main(void){
  vector<int> v;
  int N;
  cin >> N;
  for(int i=0;i<=MAX;i++){
    A[i] = true;
  }
  
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  v.push_back(-1);
  int pre = -1;
  for(int i=0;i<v.size()-1;i++){
    if(v[i] != pre){
      pre = v[i];
      int n=2;
      while(n*v[i] <= MAX){
        A[n*v[i]] = false;
        n++;
      }
    }
  }
  int ans = 0;
  int i;
  for(i=0;i<v.size()-1;i++){
    if(v[i] == v[i+1]){
      for(int n=0;;n++){
        if(v[i] != v[i+n]){
          i = i + n - 1;
          break;
        }
      }
    }else{
      if(A[v[i]] == true){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5292
//😄😄😄😄😄😄😄😄😄😄😄😄😄
//Apno Swagat che//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>
#define mod 10000007
#define ciN cin
#define XX INT_MAX
#define NN INT_MIN
////////////////////////////////////////////////////////////////
//Ha Moj Ha///
////////////////////////////////////////////////////////////////
////TEST CASES ATTACHED CHE BHULTO NAI......///////////////////


void jabru() {
	int n; cin >> n;
	vi a(n), b(n), c(n);
	int dp[n][3];
	For(i, 0, n) {
		For(j, 0, 3) {
			dp[i][j] = 0;
		}
	}
	For(i, 0, n) {
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	For(i, 1, n) {
		For(j, 0, 3) {
			if (j == 0) {
				dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
			}
			else if (j == 1) {
				dp[i][j] = max(dp[i - 1][2], dp[i - 1][0]) + b[i];
			}
			else {
				dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
			}
		}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
}




////////////////////////////////////////////////////////////////
//Bas aabaju nai javanu///
////////////////////////////////////////////////////////////////

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

//	int t; cin >> t;
	//while (t--)
	jabru();

	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//Kai baju bhai???


Measured memory_bytes: 5580
#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>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
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 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;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(string, S);
  invar(string, T);
  
  int teki = 0;
  for(int i=0; i<3; ++i) {
    teki += S[i] == T[i];
  } 
  fin(teki);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define readInt(x) scanf("%d", &x)
#define readStr(x) scanf("%s", x)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1 << 28;
const int MAX = 1e5 + 10;

int ABCD;

int main()
{
    cin >> ABCD;
    int D = ABCD % 10;
    int C = (ABCD % 100) / 10;
    int B = (ABCD % 1000) / 100;
    int A = ABCD / 1000;

    rep(i, 0b1000) {
        int val = A
            + (i % 2 ? -1 : 1) * B
            + ((i >> 1) % 2 ? -1 : 1) * C
            + ((i >> 2) % 2 ? -1 : 1) * D;
        if (val == 7) {
            cout << A
                << (i % 2 ? "-" : "+") << B
                << ((i >> 1) % 2 ? "-" : "+") << C
                << ((i >> 2) % 2 ? "-" : "+") << D
                << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0: break
    step = input().split()
    ans = 0
    for i in range(0, len(step), 2):
        if i+1 == len(step): break
        if (step[i] == 'lu' and step[i+1] == 'ru') or (step[i] == 'ru' and step[i+1] == 'lu') or (step[i] == 'ld' and step[i+1] == 'rd') or (step[i] == 'rd' and step[i+1] == 'ld'):
            ans += 1
    print(ans)

Measured memory_bytes: 6720
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int Q = sc.nextInt();
		while (Q-- > 0) {
			/*
			 * make follow team CCA CCC CAN
			 */
			int c = sc.nextInt();
			int a = sc.nextInt();
			int n = sc.nextInt();
			int cnt = 0;
			while (true) {
				if (c > 0 && a > 0) {
					if (n > 0) {
						c--;
						a--;
						n--;
						cnt++;
					} else {
						if (c > 1) {
							c -= 2;
							a--;
							cnt++;
						} else {
							break;
						}
					}
				} else if (c > 2) {
					c -= 3;
					cnt++;
				} else {
					break;
				}
			}
			System.out.println(cnt);
		}
	}

}

Measured memory_bytes: 20712
#include <iostream>

using namespace std;

const int kMaxN = 2011;
const int kM = 1000000007;

int f[kMaxN][kMaxN];
int n, ans;

int main() {
  cin >> n;
  f[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (f[i][j]) {
        for (int k = 3; k <= n - j; k++) {
          f[i + 1][j + k] = (f[i + 1][j + k] + f[i][j]) % kM;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    ans = (ans + f[i][n]) % kM;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 8176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 3001
ll f[N][N];
int a[N], n;
int main() {
    scanf("%d", &n);
    bool sign = n & 1 ? 1 : -1;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        f[i][i] = a[i] * sign;
    }
    for (int len = 1; len <= n; len++)
        for (int i = 1; i + len <= n; i++) {
            int j = i + len;
            f[i][j] = max(a[i] - f[i + 1][j], a[j] - f[i][j - 1]);
        }
    printf("%lld\n", f[1][n]);
    return 0;
}

Measured memory_bytes: 70016
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

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

    // [i][0]: x1 位置 [i][1]: y1 位置
    int[][] student = new int[N][2];

    // [i][0]: x2 位置 [i][1]: y2 位置
    int[][] checkpoint = new int[M][2];

    for (int i = 0; i < N; i++) {
      student[i][0] = sc.nextInt();
      student[i][1] = sc.nextInt();
    }

    for (int i = 0; i < M; i++) {
      checkpoint[i][0] = sc.nextInt();
      checkpoint[i][1] = sc.nextInt();
    }

    sc.close();

    for (int i = 0; i < N; i++) {
      int min = Integer.MAX_VALUE;
      int n = Integer.MAX_VALUE;
      for (int j = 0; j < M; j++) {
        int d = Math.abs(student[i][0] - checkpoint[j][0]) + Math.abs(student[i][1] - checkpoint[j][1]);
        if (d < min){
          min = d;
          n = j + 1;
        }
      }
      System.out.println(n);
    }

  }

}

Measured memory_bytes: 21972
S = input()
flag = 0
S = S[::-1]
while True:
    if S.startswith("maerd") or S.startswith("esare"):
        S = S[5:]
    elif S.startswith("remaerd"):
        S = S[7:]
    elif S.startswith("resare"):
        S = S[6:]
    elif S == "":
        break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")


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

int gp[5005];
ll gp_sc[5005];
ll gp_size[5005];

int main(){
  ll N,K;
  cin >> N >> K;
  vector< int > P(N+1);
  vector< ll > C(N+1);
  REP(i,N) cin >> P[i], P[i]--;
  REP(i,N) cin >> C[i];

  // グループ番号付与 1から始まる数字
  //  グループごとのサイズとスコア合計も計算
  int gn = 1;
  REP(i,N) {
    if ( gp[i] != 0 ) continue;
    ll tmp_sc= 0;
    ll tmp_size = 0;
    int j = i;
    while ( gp[j] == 0 ) {
      gp[j] = gn;
      tmp_sc += C[j];
//      cout << " " << j << " " << gn << " " << tmp_sc << endl;
      tmp_size++;
      j = P[j];
    }
    gp_sc[gn] = tmp_sc;
    gp_size[gn] = tmp_size;
    gn++;
  }
/*
  REP(i,10) cout << gp[i] << " ";
  cout << endl;
  REP(i,10) cout << gp_size[i] << " ";
  cout << endl;
  REP(i,10) cout << gp_sc[i] << " ";
  cout << endl;
*/
  ll ans = -10000000000LL;

  // マスごとにスコア計算
  REP(i,N) {
    // 必ず1回は動かす
    ll k1 = K - 1;
    ll nowsc = C[ P[i] ];
//    cout << i << " : " << k1 << " " << nowsc << endl;
    // 所属グループの一周のスコアを見て、プラスなら何回も回る。
    if ( gp_sc[ gp[i] ] > 0 ) {
      if ( k1 >= gp_size[ gp[i] ] ) 
        nowsc += (gp_sc[ gp[i] ] * (k1 / gp_size[ gp[i] ]));
      k1 = k1 % gp_size[ gp[i] ];
//    cout << i << "  : " << k1 << " " << nowsc << endl;
    } else {
      // マイナスなら、最大でも一周
      k1 = min(k1, gp_size[ gp[i] ]);
    }
    // 残りステップ数を回って、最大スコアを残す
    ll tmpsc = nowsc;
    int ni = P[i];
    REP(j, k1) {
      tmpsc += C[ P[ni] ];
      nowsc = max( nowsc, tmpsc );
      ni = P[ni];
//      cout << i << "  :  " << j << " : " << nowsc << endl;
    }
    ans = max( nowsc, ans );
  }
  cout << ans << endl;
}


Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define inf 1e15+1

using namespace std;

signed main() {
  IOS;
  int n, a, mi=inf, t[6], c[7]={0}, i, ans=0;
  cin >> n;
  for (i = 1; i <= 5; i++) {
    cin >> a;
    t[i] = mi = min(a, mi);
  }

  ans = (n + mi - 1)/mi + 4;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
int MOD=1000000000+7;
int INF=1e6;
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    int p=pow(2,k);
    int t=max(max(a,b),c);
    cout<<t*(p-1)+a+b+c;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long Int;
typedef pair<Int, Int> P;

int n;
Int x;
vector<int> nums;
vector<P> combinations;
bool comp(P a, P b){
	int x[3], y[3];
	x[0] = a.first;
	x[1] = b.first - b.second;
	x[2] = b.second;
	y[0] = b.first;
	y[1] = a.first - a.second;
	y[2] = a.second;

	sort(x, x + 3);
	sort(y, y + 3);
	if(x[0] > y[0])return true;
	else if(x[0] < y[0])return false;
	if(x[1] > y[1])return true;
	else if(x[1] < y[1])return false;
	if(x[2] > y[2])return true;
	else if(x[2] < y[2])return false;
	return true;
}

int main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x;
		nums.push_back(x);
	}
	sort(nums.begin(), nums.end());
	for(int i = 0;i < n;i++){
		int p = lower_bound(nums.begin(), nums.end(), nums[i] / 2) - nums.begin();
		int q = max(p-1, 0);
		int r = min(p + 1,n-1);
		if(nums[i] > nums[p])combinations.push_back(P(nums[i], nums[p]));
		if(nums[i] > nums[q])combinations.push_back(P(nums[i], nums[q]));
		if(nums[i] > nums[r])combinations.push_back(P(nums[i], nums[r]));
	}

	sort(combinations.rbegin(), combinations.rend(), comp);
	cout << combinations[0].first << " " << combinations[0].second << endl;
	return 0;
				
}


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N + 1);
    for (int64_t& a : A) {
        cin >> a;
    }

    vector<int64_t> node_num(N + 1);
    node_num[N] = A[N];
    for (int64_t i = N - 1; i >= 0; i--) {
        node_num[i] = node_num[i + 1] + A[i];
    }

    node_num[0] = 1;
    for (int64_t i = 0; i < N; i++) {
        node_num[i + 1] = min(node_num[i + 1], 2 * (node_num[i] - A[i]));
    }

    if (node_num[N] != A[N]) {
        cout << -1 << endl;
        return 0;
    }

    bool appear_zero = false;
    for (int64_t i = 0; i <= N; i++) {
        if (node_num[i] < 0 || (node_num[i] > 0 && appear_zero)) {
            cout << -1 << endl;
            return 0;
        } else if (node_num[i] == 0) {
            appear_zero = true;
        }
    }

    cout << accumulate(node_num.begin(), node_num.end(), (int64_t)0) << endl;
}

Measured memory_bytes: 4792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans;
  if (k%2 == 0) ans = a-b;
  else ans = b-a;
  if (abs(ans) > 1e18) puts("Unfair");
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = 10**9

def ketawa(b):
  if b < 10:
    return b
  return ketawa(b//10) + b%10

for i in range(1, N):
  tmp = ketawa(i) + ketawa(N-i)
  if tmp < ans:
    ans = tmp
print(ans)
    
  

Measured memory_bytes: 2940
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    var ans = ""
    s.forEach { ch ->
        if (ch == 'B') {
            ans = ans.substring(0, Math.max(0, ans.length - 1))
        } else {
            ans += ch
        }
    }
    println(ans)
}

Measured memory_bytes: 31140
class Dice
	
	def initialize(aryDice)
    	@dice = aryDice;
    end
    
    #???????¢????
    def checkOperation(operation)
    	case operation
    	when "E" then
    		moveE;
    	when "N" then
    		moveN;
    	when "S" then
    		moveS;
    	when "W" then
    		moveW;
    	end
    end
    
    #E???????????????????§????
    def moveE
    	tmp = @dice[0];
        @dice[0] = @dice[3];
        @dice[3] = @dice[5];
        @dice[5] = @dice[2];
        @dice[2] = tmp;
    end
    
    #N???????????????????§????
    def moveN
    	tmp = @dice[0];
        @dice[0] = @dice[1];
        @dice[1] = @dice[5];
        @dice[5] = @dice[4];
        @dice[4] = tmp;
    end
    
    #S???????????????????§????
    def moveS
    	tmp = @dice[0];
        @dice[0] = @dice[4];
        @dice[4] = @dice[5];
        @dice[5] = @dice[1];
        @dice[1] = tmp;
    end
    
    #W???????????????????§????
    def moveW
    	tmp = @dice[0];
        @dice[0] = @dice[2];
        @dice[2] = @dice[5];
        @dice[5] = @dice[3];
        @dice[3] = tmp;
    end
    
    #???????????????????????????????????¨???
    def dispDice
    	puts @dice[0];
    end
    
end


aryDice = gets.split(' ').map(&:to_i);
operation = gets;

insDice = Dice.new(aryDice);

for index in 0..operation.length - 1 do
	
	insDice.checkOperation(operation[index]);
	
end

insDice.dispDice

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
int64_t MOD=1000000007;


int main() {

  int n; cin>>n;
  if (n>=30) cout<< "Yes" <<endl;
  else cout<< "No" <<endl;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;
long long cur;
int w;
long long p[18],po[18];
int bs(int x)
{
	int l=-1,r=10;
	if(x==1)l=0;
	while(l+1<r)
	{
		int m=(l+r)/2;
		printf("? %lld\n",(cur*10LL+m)*po[13-x]+p[13-x]);
		char op;
		cin>>op;
		if(op=='N')l=m;else r=m;
	}
	return l;
}
int main()
{
	po[0]=1LL;
	for(int i=1;i<=17;i++)p[i]=p[i-1]*10LL+9,po[i]=po[i-1]*10LL;
	w=1;
	printf("? %lld\n",po[10]);
	char op;
	cin>>op;
	if(op=='Y')
	{
		int s=0;
		do
		{
			printf("? %lld\n",2*po[s]);
			cin>>op;
			s++;
		}
		while(op=='N');
		s--;
		printf("! %lld",po[s]);
		return 0;
	}
	while(1)
	{
		if(w>10)
		{
			long long t=1LL;
			int s=1;
			do
			{
				printf("? %lld\n",po[s]);
				cin>>op;
				s++;
			}
			while(op=='Y');
			s--;
			printf("! %lld",cur/po[10-s]);
			return 0;
		}
		int k=bs(w);
		cur=cur*10LL+k+1;
		w++;
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 500;
const int inf = (1<<20);
int cap[N][N];
int flow[N][N];
bool vis[N];

int fordFulkerson(const int n,const int t,int now,int fl){
  if (now == t)return fl;
  if (vis[now])return 0;
  vis[now]=true;
  int tmp=0;
  rep(i,n){
    int &next=i;
    if (cap[now][i] - flow[now][i] > 0){
      tmp=fordFulkerson(n,t,next,min(fl,cap[now][i]-flow[now][i]));
      if (tmp != 0){
	flow[now][next]+=tmp;
	flow[next][now]=-flow[now][next];
	return tmp;
      }
    }
  }
  return 0;
}

int maxFlow(int n,int s,int t){
  int tmp=0,ret=0;
  rep(i,n)vis[i]=false;
  while((tmp = fordFulkerson(n,t,s,inf)) != 0){
    ret+=tmp;
    rep(i,n)vis[i]=false;
  }
  return ret;
}

main(){
  int n,e,q;
  while(cin>>n>>e>>q){
    const int s = 0,t=n-1;
    rep(i,n)rep(j,n)cap[i][j]=0,flow[i][j]=0;
    rep(i,e){
      int f,t;
      cin>>f>>t;
      f--;t--;
      cap[f][t]=1;
      cap[t][f]=1;
    }
    int prev=maxFlow(n,s,t);
    rep(i,q){
      int a,from,to,tmp;
      cin>>a>>from>>to;
      from--;to--;
      if (a == 1){//add
	cap[from][to]=cap[to][from]=1;
	tmp = maxFlow(n,s,t);
#ifdef DEBUG1
	cout <<"add:";
#endif
	cout << prev+tmp << endl;
	prev=prev+tmp;
      }else if (flow[from][to] == 0){
#ifdef DEBUG1
	cout <<"noflow:";
#endif
	cap[from][to]=cap[to][from]=0;
	cout << prev << endl;
      }else {//delete
#ifdef DEBUG1
	cout <<"del:";
#endif
	if (flow[from][to] < 0)swap(from,to);
	cap[from][to]=cap[to][from]=0;
	flow[from][to]=flow[to][from]=0;
	rep(j,n)vis[j]=false;
	int fordFulkerson(const int n,const int t,int now,int fl);
	tmp=fordFulkerson(n,to,from,1);
	if (tmp != 0){
	  cout << prev << endl;
	  prev=prev;//keep
	}else {
	  rep(j,n)vis[j]=false;
	  //dfs(n,from,s);
	  fordFulkerson(n,s,from,1);
	  rep(j,n)vis[j]=false;
	  //dfs(n,t,to);
	  fordFulkerson(n,to,t,1);
	  cout << prev-1 << endl;
	  prev=prev-1;
	}
      }
    }
#ifdef DEBUG
    cout << "end " << endl;
#endif
  }
}

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

int main(){
	int m, n;
	cin>>m>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	sort(vec.begin(), vec.end());
	vector<int> table(n, 0);
	for(int i = 1; i < n; ++i){
		table[i] = abs(vec[i] - vec[i - 1]);
	}
	int sum = 0;
	for(int i = 0; i < n; ++i){
		sum += table[i];
	}
	sort(table.begin(), table.end(), greater<int> ());
	if(m >= n){
		cout<<0<<endl;
		return 0;
	}
	for(int i = 0; i < m - 1; ++i){
		sum -= table[i];
	}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<string,int> p;
    string word[n]; 
    rep(i,n)
    {
        cin >> word[i];
        p[word[i]]++;
    }
    int t=0;
    rep(i,n)
    {
        if(p[word[i]]>t)t=p[word[i]];
    }
    vector<string> k;
    rep(i,n)
    {
        if(p[word[i]]==t) k.push_back(word[i]);
    }
    sort(k.begin(),k.end());
    rep(i,k.size())
    {
        if(i!=0)
        {
            if(k[i]!=k[i-1]) cout << k[i] << endl;
        }else cout << k[i] << endl;
        
    }

    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, K;

int main() {
    cin >> N >> K;
    cout << N - K + 1 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
using namespace std;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int N) : par(N){
        for (int i = 0; i < N; i++) par[i] = i;
    }
    
    int root (int x){
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
    
    bool same (int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    
    UnionFind tree(N);
    
    vector<int> p(N);
    rep(i, 0, N) cin >> p.at(i);
    vector<int> x(M), y(M);
    rep(i, 0, M){
        int x, y;
        cin >> x >> y;
        tree.unite(x - 1, y - 1);
    }
    int cnt = 0;
    rep(i, 0, N){
        if (tree.same(i, p.at(i) - 1)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

constexpr int D = 365;
constexpr int K = 26;

int penalty(array<int, K>& c, array<int, K>& last, int use, int now) {
    int res = 0;
    rep(i, K)if (i != use)res += c[i] * (now - last[i]);
    return res;
}

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

    array<int, K> c, last;
    array<array<int, K>, D> s;
    rep(i, K)cin >> c[i];
    rep(i, K)last[i] = 0;
    rep(i, D)rep(j, K)cin >> s[i][j];

    array<int, D> schedule;
    rep(i, D) {
        int score = -INF, res = -1;
        rep(j, K) {
            int tscore = s[i][j] - penalty(c, last, j, i);
            if (tscore > score) {
                score = tscore;
                res = j;
            }
        }
        schedule[i] = res;
        last[res] = i;
    }
    for (auto t : schedule)cout << t + 1 << endl;
    return 0;;
}


Measured memory_bytes: 3708
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long n = stdIn.nextLong();
		long m = stdIn.nextLong();
		if( n < m/2 ){
		System.out.println( n + (m - 2*n)/4 );
		}
		else{
		System.out.println( m/2 );
		}
	}
}

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

vector < vector <int> > aa;

bool cmp(vector<int> a, vector<int> b) {
	return a[0] < b[0];
}

int main (void) {
	cin.tie(0);
	cin.sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	aa.assign(n, vector<int> (2, 0));
	for (int i = 0; i < n; i ++) {
		int a, b;
		for (int j = 0; j < 2; j ++)
			cin >> aa[i][j];
	}
	sort(aa.begin(), aa.end(), cmp);
	long long int cost = 0;
	for (int i = 0; i < n; i ++) {
		cost += (long long int)min(m, aa[i][1]) * aa[i][0];
		m -= min(m, aa[i][1]);
		if (!n)
			break;
	}
	cout << cost << '\n';
	return 0;
}

Measured memory_bytes: 5760
using System.Text;

namespace aoj
{
    using System;

    class Node
    {
        public int key;
        public Node parent, left, right;

        public Node(int x)
        {
            key = x;
        }
    }

    class Tree
    {
        private Node root;

        public void Insert(Node z)
        {
            Node y = null;
            Node x = root;
            while (x != null)
            {
                y = x;
                x = z.key < y.key ? x.left : x.right;
            }

            z.parent = y;
            if (y == null)
            {
                root = z;
            }
            else if (z.key < y.key)
            {
                y.left = z;
            }
            else
            {
                y.right = z;
            }
        }

        public void Preorder()
        {
            Func<StringBuilder, Node, StringBuilder> f = null;
            f = (sb, n) =>
            {
                if (n == null) return sb;
                sb.Append(String.Format(" {0}", n.key));
                f(sb, n.left);
                f(sb, n.right);
                return sb;
            };
            var sb1 = new StringBuilder();
            f(sb1, root);
            Console.WriteLine(sb1.ToString().TrimEnd());
        }

        public void Inorder()
        {
            Func<StringBuilder, Node, StringBuilder> f = null;
            f = (sb, n) =>
            {
                if (n == null) return sb;
                f(sb, n.left);
                sb.Append(String.Format(" {0}", n.key));
                f(sb, n.right);
                return sb;
            };
            var sb1 = new StringBuilder();
            f(sb1, root);
            Console.WriteLine(sb1.ToString().TrimEnd());
        }
    }


    class Program
    {
        void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var tree = new Tree();
            for (var i = 0; i < n; i++)
            {
                var lines = Console.ReadLine().Split();
                switch (lines[0])
                {
                    case "insert":
                        var nn = int.Parse(lines[1]);
                        tree.Insert(new Node(nn));
                        break;
                    default:
                        tree.Inorder();
                        tree.Preorder();
                        break;
                }
            }
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}


Measured memory_bytes: 77100
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

int main()
{
	int taro = 0, hanako = 0;
	int n;
	cin >> n;
	string ta, ha;
	for(int i = 0; i < n; ++i) {
		cin >> ta >> ha;
		if(ta > ha)
			taro += 3;
		else if(ta == ha)
			++taro, ++hanako;
		else
			hanako += 3;
	}
	cout << taro << ' ' << hanako << endl;
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#define MOD 1000000007
using namespace std;
int n,i,rez,F[100005];
char c;
int main()
{
    cin>>n;
	rez=1;
	for(i=1; i<=n; i++)
	{
        cin>>c;
        F[c-'a']++;
	}
    for(i=0; i<26; i++)
        rez=(1LL*rez*(F[i]+1))%MOD;
	cout<<(rez-1+MOD)%MOD<<"\n";
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()
	M, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	if N == M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 1832
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;

//vector<vector<ll>> vec(100000,vector<ll>(3,0));

int main(){
  string s;
  string t;
  cin >> s >> t;
  vector<ll> words[26];
  ll lens = s.length();
  ll lent = t.length();
  rep(i,lens){
    words[s[i]-'a'].push_back(i);
  }
  rep(i,26){
    words[i].push_back(lens);
  }
  ll sum = -1;
  rep(i,lent){
    ll num = t[i]-'a';
    auto Iter1 = upper_bound(all(words[num]),sum%lens);
    if(*Iter1 == lens){
      if(words[num][0] == lens){sum = -2;break;}
      sum = sum / lens * lens + lens + words[num][0];
    }else{
      sum = sum / lens * lens + *Iter1;
    }
    //cout << sum << " ";
  }
  cout << sum+1;
}


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

int main(){
  int N,M,ans=0;
  cin >> N >> M;
  vector<vector<int>> G(N+1,vector<int>(0));
  for(int i=0;i<M;i++){
    int x,y,z;
    cin >> x >> y >> z;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  
  vector<bool> state(N+1,false);
  for(int r=1;r<=N;r++){
    if(state[r]==true) continue;
    ans++;
    queue<int> Q;
    Q.push(r);
    state[r] = true;
    while(!Q.empty()){
      int u = Q.front();
      Q.pop();
      for(int i=0;i<G[u].size();i++){
        int v = G[u][i];
        if(state[v]==false){
          Q.push(v);
          state[v] = true;
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6520
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String w = sc.next();
    int[] num = new int[26];
    for (int i = 0; i < w.length(); i++) {
      num[w.charAt(i) - 'a']++;
    }
    for (int i = 0; i < 26; i++) {
      if (num[i] % 2 == 1) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 21204