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

using namespace std;

int f(string s) {

    int result = 700;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'o') {
            result += 100;
        }
    }

    return result;
}

int main() {

    string s;
    cin >> s;

    int result = f(s);
    cout << result << endl;

    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    ll x, y;
    cin >> x >> y;
    const ll INF = LLONG_MAX/3;
    ll res = INF;
    res = min(res, (y-x>=0?y-x:INF));
    res = min(res, (y-(-x)>=0?y-(-x)+1:INF));
    res = min(res, (-y-x>=0?-y-x+1:INF));
    res = min(res, (-y-(-x)>=0?-y-(-x)+2:INF));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
//package A;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line = in.readLine();
        int input = Integer.valueOf(line);
        int a = input % 10;
        String ans = "";
        switch (a) {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                ans = "hon";
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                ans = "pon";
                break;
            case 3:
                ans = "bon";
                break;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 32400
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  while(ifs>>data)
int main (){
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string u;
    cin >> u;

    int n1 = a;
    int n2 = b;

    if(s==u) n1 -= 1;
    else n2 -= 1;

    cout << n1 <<endl;
    cout << n2;
}

Measured memory_bytes: 256
use utf8;
use warnings;
use strict;

sub is_doubly_contained {
    my ($s) = @_;
    my %hash = ();
    for my $ch (split(//, $s)) {
        if (exists $hash{$ch}){
            return 0;
        }else{
            $hash{$ch} = 1;
        }
    }
    return 1;
}

chomp(my $s= <STDIN>);
is_doubly_contained($s) ? print "yes\n" : print "no\n";

Measured memory_bytes: 640
#include<iostream>
using namespace std;
 
int main(){
  int n1,n2,n3;
  int T=0,S=0;
  char s;
  while(cin>>n1>>s>>n2>>s>>n3){
    if(n1==n2)T++;
    else if((n1*n1)+(n2*n2)==(n3*n3))S++;
  }
  cout<<S<<endl<<T<<endl;   
 
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define se second
#define fi first
#define pb push_back
#define mp make_pair
using namespace std;

const int N = 30010;
const int MX = 1000000;

int n;

char read(int id) {
	char tmp[12];
	printf("%d\n", id);
	fflush(stdout);
	scanf("%s", tmp);
	if (tmp[0] == 'V')
		exit(0);
	return tmp[0];
}
char a,b,c;

bool check(int mid) {
	char t = read(mid);
	if (t == b)
		return (mid % 2 != 0);
	if (t == a)
		return (mid % 2 == 0);
}
int main() {
	cin >> n;
	a = read(n - 1), b = read(0), c = read(1);
	int lo = 2 , hi = n - 2;
	while (lo <= hi) {
		int mid = (lo + hi) / 2;
		if (check(mid)) {
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
	}
	return 0;
}


Measured memory_bytes: 852
/* All men have limits. They learn what they are and learn
   not to exceed them, I ignore mine. -Batman           */
#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
//#include <Windows.h>
using namespace std;

int main(){
int a,b,c,d,e,f;
double x,y;
while(cin>>a>>b>>c>>d>>e>>f){
	x=(double)(c*e-f*b)/(a*e-d*b);
	y=(double)(c*d-f*a)/(b*d-e*a);
	if(x>-0.001&&y>-0.001)printf("%.3lf %.3lf\n",abs(x),abs(y));
	else if(x>-0.001)printf("%.3lf %.3lf\n",abs(x),y);
	else if(y>-0.001)printf("%.3lf %.3lf\n",x,abs(y));
	else printf("%.3lf %.3lf\n",x,y);
		
}
return 0;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for(int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for(int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
    int x, y, ans = 0;
    cin >> x >> y;

    rep(i, x + 1) {
        ans = 2 * i + 4 * (x - i);
        if(ans == y) {
            cout << "Yes" << endl;
            return 0;
        }
        // cout << "ans:" << ans << endl;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3132
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
char s[1000][9];
int a[1000][4],b[1000],n;
int fi(int p,int i){
  static char t[4][4][9]={
    {{"0xxxxxxx"},{},{},{}},
    {{"110yyyyx"},{"10xxxxxx"},{},{}},
    {{"1110yyyy"},{"10yxxxxx"},{"10xxxxxx"},{}},
    {{"11110yyy"},{"10yyxxxx"},{"10xxxxxx"},{"10xxxxxx"}}
  };
  int j,k;
  int xct=0,yct=0,yfl=1;
  for(j=0;j<i+1;++j){
    for(k=0;k<8;++k){
      if(0){
      }else if(t[i][j][k]=='0'){
	if(s[p+j][k]=='1'){
	  break;
	}
      }else if(t[i][j][k]=='1'){
	if(s[p+j][k]=='0'){
	  break;
	}
      }else if(t[i][j][k]=='y'){
	if(0){
	}else if(s[p+j][k]=='1'){
	  yfl=0;
	}else if(s[p+j][k]=='x'){
	  ++yct;
	}
      }else if(t[i][j][k]=='x'){
	if(s[p+j][k]=='x'){
	  ++xct;
	}
      }
    }
    if(k<8)
      break;
  }
  if(j>=i+1){
    if(i&&yfl){
      if(yct){
	return (1ll<<xct)*((1ll<<yct)-1)%1000000;
      }
    }else{
      return (1ll<<xct)*(1ll<<yct)%1000000;
    }
  }
  return 0;
}
int fj(int p){
  int i;
  int sm=0;
  if(p==n){
    sm=1;
  }else{
    if(b[p]>=0){
      sm=b[p];
    }else{
      for(i=0;i<min(4,n-p);++i){
	if(a[p][i])
	  sm=(sm+(long long)a[p][i]*fj(p+i+1))%1000000;
      }
      b[p]=sm;
    }
  }
  return sm;
}
int main(){
  int i,j;
  while(cin>>n,n){
    for(i=0;i<n;++i)
      cin>>s[i];
    for(i=0;i<4;++i)
      for(j=0;j<1000-i;++j)
	a[j][i]=fi(j,i);
    memset(b,-1,sizeof(b));
    cout<<fj(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 952
#include<iostream>
using namespace std;
int a[200010];
int main() {
	int N,cnt=0;
	scanf("%d",&N);
	for (int i=1; i<=N; i++) scanf("%d", &a[i]);
	for (int i=N; i>=1; i--) {
		for (int j=i+i; j<=N; j+=i) {
			a[i] ^= a[j];
		}
		if ( a[i] ) cnt++;
	}
	printf("%d\n", cnt);
	for (int i=1; i<=N; i++) {
        if ( a[i] ) printf("%d ", i);
    }
	return 0;
}


Measured memory_bytes: 1792
// By Atul Rathore

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	


int main()
{
	fastio;
	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
	
	
	
}


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

int main(){

  int N;
  int ans=0,num=0;
  cin >> N;
  long long H[N];
  for(int i=0; i<N; i++) cin >> H[i];
  for(int i=0; i<N-1; i++){
    if(H[i]>=H[i+1]){
      num++;
    } else {
      ans = max(ans,num);
      num = 0;
    }
  }
  ans = max(ans,num);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
using namespace std;

const double PI=acos(-1);

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

    int t, x, y, tp = 0, xp = 0, yp = 0;
    bool z = true;
    for(int i = 0; i < n; i++){
        cin >> t >> x >> y;
        t -= tp;
        x = abs(x - xp);
        y = abs(y - yp);
        if(t < x + y){
            z = false;
            break;
        }
        if((t+x+y)%2 == 0 || t == x + y){
            tp = t;
            xp = x;
            yp = y;
            continue;
        }
        
        z = false;
        break;
    }

    if(z) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
a =int(input())
b =int(input())
c =int(input())
d =int(input())
e =int(input())
sample_list = []
sample_list.append(a)
sample_list.append(b)
sample_list.append(c)
sample_list.append(d)
sample_list.append(e)
x = []
for i in sample_list:
    if i % 10 == 0:
        x.append(0)
    else:
        x.append(10-(i%10))
print(sum(sample_list)+sum(x)-max(x))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;

//////検証する数,超えられない数////
long long cine(long long a, long long b) {
	if (a <= b) {
		return a;
	}
	else {
		return b;
	}
};
//vector型の初期化
void vec_initialize(vector<ll>& a, const ll N) {
	ll c;

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

		cin >> c;
		a.push_back(c);

	}

};
void vec_pair_initialize(vector<pair<ll, ll>>& a, const ll N) {
	ll c, d;
	for (int i = 0; i < N; i++) {
		cin >> c >> d;
		a.push_back(make_pair(c, d));
	}
};
bool Pinching_In(ll a, ll x, ll b) {

	if (a <= x && x <b) {


		return true;
	}
	return false;
}
int main() {
	string S;
	cin >> S;
	string key = "keyence";
	if (S.substr(0, 7) == key) {
		cout << "YES";
		return 0;
	}
	if (S.substr(S.size() - 7, 7)==key ){
		cout << "YES";
		return 0;

	}
	if (S[0] != 'k') {


		cout << "NO";
		return 0;
	}
	for (int i = 0; i < 7; i++) {

		if (S[i] != key[i]) {

			if (S.substr(S.size() - 7 + i, 7 - i) == key.substr(i, 7 - i))
			{

				cout << "YES";
				return 0;

			}else{

				cout << "NO";
				return 0;
			}
		}

	}


}

Measured memory_bytes: 256
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    a*=n;
    cout<<min(a,b);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[30];
int b[30];
set<int>x,y;
int n1,n2;
int main(){
	string s,t;
	cin>>s>>t;
	int len=s.length();
	for(int i=0;i<len;i++){
		a[s[i]-'a']++;
		b[t[i]-'a']++;
	}
	/*for(int i=0;i<26;i++){
		cout<<a[i]<<" ";
	}cout<<endl;
	for(int i=0;i<26;i++){
		cout<<b[i]<<" ";
	}cout<<endl;*/
	for(int i=0;i<30;i++){
		if(a[i]==0)continue;
		for(int j=0;j<30;j++){
			if(a[i]==b[j]){
				a[i]=b[j]=0;
			}
		}
	}
/*	for(int i=0;i<26;i++){
		cout<<a[i]<<" ";
	}cout<<endl;
	for(int i=0;i<26;i++){
		cout<<b[i]<<" ";
	}cout<<endl;*/
	for(int i=0;i<30;i++){
		n1+=a[i];
		n2+=b[i];
	}
	if(n1!=n2){
		cout<<"No"<<endl;
	}else if(n1==0&&n2==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 776
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in(), k = in();
    double ans = 0;
    REP1(i, n) {
        if (i < k) {
            ans += pow(0.5, ceil(log2((double)k / i)));
        } else {
            ans += 1;
        }
    }
    SETP(20);
    cout << ans / n << endl;
}

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

#define INF 0x3f3f3f3f
#define MOD 10000

typedef long long ll;
typedef pair<int, string> P;

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

	int n, m;
	cin >> n >> m;
	int c[m];
	for (int i = 0; i < m; i++) cin >> c[i];
	int dp[m+1][n+1];

	for (int i = 0; i <= m; i++)
		for (int j = 0; j <= n; j++)
			dp[i][j] = 0;

	for(int j = 0 ; j <= n ; j++) dp[0][j] = INF;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (c[i-1] > j) dp[i][j] = dp[i-1][j];
			else dp[i][j] = min(dp[i-1][j], dp[i][j-c[i-1]]+1);
		}
	}

	cout << dp[m][n] << endl;

	return 0;
}

Measured memory_bytes: 7232
n = int(input())
ab_s = [[int(v) for v in input().split()] for _ in range(n)]

ab_s.sort(key=lambda x:x[1])
c = 0
for i in range(n):
  c += ab_s[i][0]
  if c > ab_s[i][1]:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 41180
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
      	char[] slist = s.toCharArray();
      	Arrays.sort(slist);
      	String sss = new String(slist);
      	char[] tlist = t.toCharArray();
      	Arrays.sort(tlist);
      	String T = new String(tlist);
      	String ttt = new StringBuilder(T).reverse().toString();
      	if (sss.compareTo(ttt) < 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 35572
n=int(input())
a=list(map(int,input().split()))
c=0
d=0
for i in range(n):
    if(a[i]==0):
        d=1
    if(a[i]<=0):
        c+=1
if(c%2==0):
    d=1
for i in range(n):
    a[i]=abs(a[i])
b=min(a)
if(d==1):
    print('{0}'.format(sum(a)))
else:
    print('{0}'.format(sum(a)-2*b))

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    vector<ll>t(n);
    rep(0,i,n)cin>>t[i];
    ll m;
    cin>>m;
    vector<ll>d(m);
    rep(0,i,m)cin>>d[i];
    sort(t.begin(),t.end());
    sort(d.begin(),d.end());
    ll c=0;
    rep(0,i,n){
        if(c!=m&&t[i]==d[c])++c;
    }
    if(c==m)cout<<"YES";
    else cout<<"NO";
}

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

using namespace std;

char mp[8][9];

int A[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
int B[4][2] = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
int C[4][2] = {{0, 0}, {0, 1}, {0, 2}, {0, 3}};
int D[4][2] = {{0, 1}, {1, 0}, {1, 1}, {2, 0}};
int E[4][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 2}};
int F[4][2] = {{0, 0}, {1, 0}, {1, 1}, {2, 1}};
int G[4][2] = {{1, 0}, {1, 1}, {0, 1}, {0, 2}};

int main()
{
    int nyan = 0;
    while (1) {
        int i = 0;
        while (1) {
            int res = scanf("%s", mp[i++]);
            if (res == EOF) return 0;
            if (i == 8) break;
        }

        int cnt;

        for (int i = 0; i < 8; ++i) for (int j = 0; j < 8; ++j) {
            cnt = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + A[k][0], nx = j + A[k][1];
                if (ny < 0 || ny >= 8 || nx < 0 || nx >= 8 || mp[ny][nx] == '0') break;
                cnt++;
            }
            if (cnt == 4) {
                puts("A");
                continue;
            }

            cnt = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + B[k][0], nx = j + B[k][1];
                if (ny < 0 || ny >= 8 || nx < 0 || nx >= 8 || mp[ny][nx] == '0') break;
                cnt++;
            }
            if (cnt == 4) {
                puts("B");
                continue;
            }

            cnt = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + C[k][0], nx = j + C[k][1];
                if (ny < 0 || ny >= 8 || nx < 0 || nx >= 8 || mp[ny][nx] == '0') break;
                cnt++;
            }
            if (cnt == 4) {
                puts("C");
                continue;
            }

            cnt = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + D[k][0], nx = j + D[k][1];
                if (ny < 0 || ny >= 8 || nx < 0 || nx >= 8 || mp[ny][nx] == '0') break;
                cnt++;
            }
            if (cnt == 4) {
                puts("D");
                continue;
            }

            cnt = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + E[k][0], nx = j + E[k][1];
                if (ny < 0 || ny >= 8 || nx < 0 || nx >= 8 || mp[ny][nx] == '0') break;
                cnt++;
            }
            if (cnt == 4) {
                puts("E");
                continue;
            }

            cnt = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + F[k][0], nx = j + F[k][1];
                if (ny < 0 || ny >= 8 || nx < 0 || nx >= 8 || mp[ny][nx] == '0') break;
                cnt++;
            }
            if (cnt == 4) {
                puts("F");
                continue;
            }

            cnt = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + G[k][0], nx = j + G[k][1];
                if (ny < 0 || ny >= 8 || nx < 0 || nx >= 8 || mp[ny][nx] == '0') break;
                cnt++;
            }
            if (cnt == 4) {
                puts("G");
                continue;
            }
        }
    }
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n,l;cin>>n>>l;
    int sum=0;
    for(int i=1;i<=n;i++)
        sum+=(l+i-1);

    int absdiff=1e18;
    int reqsum=-1;

    for(int i=1;i<=n;i++)
    {
        int left=sum-(l+i-1);
        int diff=abs(sum-left);
        if(diff<absdiff)
            absdiff=diff,reqsum=left;
    }
    cout<<reqsum;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int k;
ll a[100000];

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

	cin>>k;
	REP(i,k) cin>>a[i];
	if(a[k-1]!=2) {
		cout<<-1<<endl;
		return 0;
	}

	ll mi=2,ma=2;
	for(int i=k-1;i>=0;i--) {
		mi=a[i]*((mi/a[i])+!!(mi%a[i]));
		ma=a[i]*(ma/a[i])+a[i]-1;
		if(mi>ma) {
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<mi<<' '<<ma<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< tuple< string, int, int > > v;
  for (int i=0; i<n; ++i) {
    string s;
    int p;
    cin >> s >> p;
    v.push_back(make_tuple(s, -p, i+1));
  }
  sort(v.begin(), v.end());
  for (int i=0; i<n; ++i) {
    cout << get<2>(v[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// 問題の URL を書いておく
// https://atcoder.jp/contests/dp/tasks/dp_a

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = int64_t;

int main(int, const char**)
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n)
    {
        cin >> h[i];
    }
    vector<ll> dp(n + k + 5, numeric_limits<ll>::max());
    dp[0] = 0;
    rep(i, n)
    {
        rep(j, k)
        {
            dp[i + 1 + j] = min(dp[i + 1 + j], dp[i] + abs(h[i] - h[i + 1 + j]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 4552
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int m,k;
	cin >> m >> k;
	int n = 1<<m;
	if(m==0){
		if(k==0){
			cout << "0 0" << endl;
		}else{
			cout << -1 << endl;
		}
		return 0;
	}
	if(m==1){
		if(k==0){
			cout << "0 0 1 1" << endl;
		}else{
			cout << -1 << endl;
		}
		return 0;
	}
	if(k>=n){
		cout << -1 << endl;
		return 0;
	}
	if(k == 0){
		for(int i=0; i<n-1; i++){
			cout << i << " " << i << " ";
		}
		cout << n-1 << " " << n-1 << endl;
		return 0;
	}
	cout << "0 " << k << " 0";
	for(int i=1; i<n; i++){
		if(i == k) continue;
		cout << " " << i;
	}
	cout << " " << k;
	for(int i=n-1; i>0; i--){
		if(i == k) continue;
		cout << " " << i;
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 1792
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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>
#include <bitset>
using namespace std;

#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;

vector< pair<int, int> > G[100010];
signed main() {
    int N; cin >> N;
    for(int i=0; i<N-1; i++) {
        int u, v, w; cin >> u >> v >> w;
        u--; v--; w %= 2;
        G[u].emplace_back(v, w);
        G[v].emplace_back(u, w);
    }

    // 0 番目はかならず 0
    vector<int> ans(N);
    queue<int> que;
    que.emplace(0);

    vector<int> used(N);
    used[0] = true;
    while(que.size()) {
        int cur = que.front(); que.pop();
        for(auto e : G[cur]) {
            int to, cost; tie(to, cost) = e;
            if(used[to]) continue;
            used[to] = true;
            ans[to] = (cost - ans[cur] + 2) % 2;
            que.push(to);
        }
    }

    for(int i=0; i<N; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct cl{
	int A, B, C;
};
int max( int p, int q ) {
	if( p > q ) return p;
	return q;
}
int abs( int a ) {
	if( a < 0 ) return -a;
	return a;
}

int main(void){

	int D, N;
	cin >> D >> N;
	vector< int > temp( D, 0 );
	vector< cl > cloth( N );

	// dp[日にち][今日着る服のID] = 派手さの絶対値の和の最大値
	vector< vector< int > > dp =
		( vector< vector< int > > ( D,  vector< int >( N, 0 ) ) );

	//データ入力
	for( int i = 0; i < D; i++ ) {
		cin >> temp[ i ];
	}
	for( int i = 0; i < N; i++ ) {
		cin >> cloth[i].A >> cloth[i].B >> cloth[i].C;
	}

	//初期化
	for( int i = 0; i < N; i++ ) {
		if( !( cloth[ i ].A <= temp[ 0 ] && temp[ 0 ] <= cloth[ i ].B ) ) {
			dp[ 0 ][ i ] = -1;
		}
	}

	for( int d = 1; d < D; d++ ) {
		for( int i = 0; i < N; i++ ) {
			if( dp[ d - 1 ][ i ] != -1 ) {
				for( int j = 0; j < N; j++ ) {
					if( cloth[j].A <= temp[d] && temp[d] <= cloth[j].B ) {
						dp[ d ][ j ] = max( dp[ d ][ j ], dp[ d - 1 ][ i ] + abs( cloth[ i ].C - cloth[ j ].C ) );
					} else {
						dp[ d ][ j ] = -1;
					}
				}
			}
		}
	}

	int ans = 0;
	for( int i = 0; i < N; i++ ) {
		ans = max( ans, dp[ D - 1 ][ i ] );
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1344
import sys
import math
time=0
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
if(a<0):
    a_temperature=abs(a)
    time=a_temperature*c
    time=time+d
    time=time+b*e
    
if(a>=0):
    if(a==0):
        time=time+d
    time=time+(b-a)*e
print(time)


Measured memory_bytes: 5652
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    int sum = 1;
    while(H>1){
      if(H%2 ==0){
        H = H/2;
      }else{
        H = (H-1)/2;
      }
        sum ++; 
    }
    long total =0;
    for(int i = 0; i < sum; i++){
      total = total + (long)Math.pow(2, i);
    }
    System.out.println(total);
    return;
  }
}


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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> G[n];
  int deg[n] = { };
  REP(i, m){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    deg[x]++;
    deg[y]++;
    G[x].pb(y);
    G[y].pb(x);
  }
  vector<int> ans;
  int c = 0;
  while(deg[c] == 0) c++;
    int tmp = c;
    bool visit[n] = { };
    ans.pb(c);
    while(!visit[c]){
      visit[c] = true;
      for(int i: G[c]){
        if(!visit[i]){
          c = i;
          ans.pb(i);
          break;
        }
      }
    }
    reverse(ALL(ans));
    c = tmp;
    for(int v: G[c]) if(!visit[v]) c = v;
    if(c != tmp) ans.pb(c);
    while(!visit[c]){
      visit[c] = true;
      for(int i: G[c]){
        if(!visit[i]){
          c = i;
          ans.pb(i);
          break;
        }
      }
    }
    cout << ans.size() << endl;
    REP(i, ans.size()){
      cout << ans[i]+1;
      if(i == ans.size()-1) cout << endl;
      else cout << " ";
    }
	return 0;
}


Measured memory_bytes: 7288
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            if (s.equals("AC")) ac++;
            else if (s.equals("WA")) wa++;
            else if (s.equals("TLE")) tle++;
            else if (s.equals("RE")) re++;
        }
        System.out.println(String.format("AC x %d\nWA x %d\nTLE x %d\nRE x %d", ac, wa, tle, re));
    }
}

Measured memory_bytes: 49288
#include<bits/stdc++.h>
using namespace std;
int main() {
	int h, w; cin >> h >> w;
	char c[h][w];
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> c[i][j];
		}
	}

	for (int i = 0; i < 2 * h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cout << c[i/2][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int n = in.ni();
    Set<String> set = new HashSet<>();
    while(n-- > 0) set.add(in.next());
    out.println(set.size());
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


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

count = 0

for i in range(N):
  if B[i] >= A[i]:
    count += A[i]
    B[i] -= A[i]
    if B[i] >= A[i+1]:
      count += A[i+1]
      A[i+1] = 0
    else:
      count += B[i]
      A[i+1] -= B[i]
  else:
     count += B[i]
print(count)





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

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

	cout << n*(n-1)/2 + m*(m-1)/2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define eol '\n';
using namespace std;

class Node {
public:
  int k;
  Node* p;
  Node* l;
  Node* r;
  Node(): k(-1),p(nullptr),l(nullptr),r(nullptr){};
};

Node* root;

void insert(int k) {
  Node* y = nullptr;
  Node* x = root;
  while (x != nullptr) {
    y = x;
    if (k < x->k) {
      x = x->l;
    } else {
      x = x->r;
    }
  }

  Node* z = new Node();
  z->k = k;
  z->p = y;

  if (y == nullptr) {
    root = z;
  } else if (k < y->k){
    y->l = z;
  } else {
    y->r = z;
  }
}

bool find(int k) {
  Node* x = root;
  while (x != nullptr) {
    if (x->k == k) {
      return true;
    } else if(k < x->k) {
      x = x->l;
    } else {
      x = x->r;
    }
  }
  return false;
}

void remove(int k) {
  Node* z = nullptr;
  Node* x = root;
  while (x != nullptr) {
    if (x->k == k) {
      z = x;
      break;
    } else if(k < x->k) {
      x = x->l;
    } else {
      x = x->r;
    }
  }
  
  if (z->l == nullptr && z->r == nullptr) {
    // has not child
    if (z->p->l == z) {
      z->p->l = nullptr;
    } else {
      z->p->r = nullptr;
    }
  } else if (z->l == nullptr) {
    // has one child
    if (z->p->l == z) {
      z->p->l = z->r;
      z->r->p = z->p;
    } else {
      z->p->r = z->r;
      z->r->p = z->p;
    }
  } else if (z->r == nullptr) {
    if (z->p->l == z) {
      z->p->l = z->l;
      z->l->p = z->p;
    } else {
      z->p->r = z->l;
      z->l->p = z->p;
    }
  } else {
    Node* w = z->r;
    while (w->l != nullptr) {
      w = w->l;
    }

    // まずwを取り除く
    remove(w->k);

    // 次にzの親の子をwに更新する
    if (z->p->l == z) {
      z->p->l = w;
    } else {
      z->p->r = w;
    }
    // wの親をzの親に
    w->p = z->p;
    // wの子をzの子に
    w->l = z->l;
    w->r = z->r;
    // zの子の親をwに(ただし、w自身の場合は更新せず)
    z->l->p = w;
    if (z->r != nullptr)
      z->r->p = w;
  }
}

void inorder(Node* x) {
  if (x == nullptr) return;
    
  inorder(x->l);
  cout << " " << x->k;
  inorder(x->r);
  if (x->k == root->k)
    cout << eol;
}

void preorder(Node* x) {
  if (x == nullptr) return;
  cout << " " << x->k;
  preorder(x->l);
  preorder(x->r);
  if (x->k == root->k)
    cout << eol;
}

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

  int m,k;
  string cmd;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> k;
      insert(k);
    } else if (cmd == "find") {
      cin >> k;
      if (find(k)) {
        cout << "yes" << eol;
      } else {
        cout << "no" << eol;
      }
    } else if (cmd == "print") {
      inorder(root);
      preorder(root);
    } else if (cmd == "delete") {
      cin >> k;
      remove(k);
    }
  }

  return 0;
}

Measured memory_bytes: 19976
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's') cout << s + "es" << endl;
	else cout << s + "s" << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int h, w; cin >> h >> w;
	char d[h][w];
	Rep(i, h) Rep(j, w){
		cin >> d[i][j];
	}
	bool ok = false;
	Rep(i, h) Rep(j, w){
		if(d[i][j] != '#') continue;
		bool flag = false;
		Rep(k, 4){
			if(i + dx[k] >= 0 && i + dx[k] < h && j + dy[k] >= 0 && j + dy[k] < w){
				if(d[i + dx[k]][j + dy[k]] == '#'){
					flag = true;
				}
			}
		}
		if(!flag) ok = true;
	}
	if(ok){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 384
def f(a,b):
  p,q=a,b
  while q!=0: p,q=q,p%q
  return a/p*b
  
while 1:
  x=map(int,raw_input().split())
  if any(x)==0: break
  A=[]
  for i in range(0,6,2):
    a,b=x[i:i+2]
    c=1
    for j in range(1,b):
      c=(c*a)%b
      if c==1: break
    A.append(j)
  a,b,c=A
  print f(f(a,b),c)

Measured memory_bytes: 5260
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N,L;
	cin>>N>>L;
	vector<string>vec(N);
	for(int i=0;i<N;i++) {
		string s;
		cin>>s;
		vec[i]=s;
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<N;i++) {
		cout<<vec[i];
	}
	cout<<endl;
}


Measured memory_bytes: 256
def P(m):
	if m.isdigit():
		next = int(m) - 1
		if next < 0: return "9"
		return str(next)
	return m
def M(m):
	if m.isdigit():
		return str((int(m) + 1) % 10)
	return m
n = input()
for i in xrange(n):
	order = raw_input()
	msg = raw_input()
	for c in reversed(order):
		if c == "J":
			msg = msg[-1] + msg[:-1]
		if c == "C":
			msg = msg[1:] + msg[0]
		if c == "E":
			l = len(msg) / 2
			if len(msg) % 2 == 1:
				msg = msg[l + 1:] + msg[l] + msg[:l]
			else:
				msg = msg[l:] + msg[:l]
		if c == "A":
			msg = msg[::-1]
		if c == "P":
			msg = "".join(P(m) for m in msg)
		if c == "M":
			msg = "".join(M(m) for m in msg)
	print msg

Measured memory_bytes: 4268
N, K = map(int, input().split())
S = input()
x, y = 0, 0
if S[0] == "L":
    y += 1
if S[-1] == "R":
    y += 1
x = S.count("RL")
if x:
    if x > K:
        x -= K
        K = 0
    else:
        K -= x
        x = 0
if K > 0:
    y = max(1, y - K)
print(N - 2 * x - y)

Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



long long dp[3][110][10000];

int main() {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            for (int k = 0; k <= 5050; ++k) {
                dp[(i+1)%2][j][k] += dp[i%2][j][k];
                dp[(i+1)%2][j+1][k+i] += dp[i%2][j][k];
            }
        }
        for (int j = 0; j <= 100; ++j) for (int k = 0; k <= 5050; ++k) dp[(i%2)][j][k] = 0;
    }
    
    int n, s;
    while (cin >> n >> s) {
        if (n == 0 && s == 0) break;
        cout << dp[1][n][s] << endl;
    }
    return 0;
}


Measured memory_bytes: 26944
#include <stdio.h>

#define Mod 1000000007

int main()
{	
	int N, M;
	scanf("%d %d", &N, &M);
	
	int i, j, k;
	long long dp[2][302][302] = {};
	for (k = 1, dp[0][1][1] = 1; k <= M; k++) {
		for (i = 1; i <= N; i++) {
			for (j = 1; j <= i; j++) {				
				dp[k%2][i+1][j] += dp[1-k%2][i][j] * (N - i);
				dp[k%2][i][i] += dp[1-k%2][i][j] * j;
				dp[k%2][i][j] += dp[1-k%2][i][j] * (i - j);
				
				dp[1-k%2][i][j] = 0;
				dp[k%2][i][j] %= Mod;
			}
		}
	}
	
	printf("%lld\n", dp[M%2][N][N]);
	fflush(stdout);
	return 0;
}

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

bitset<4000010> dp;

int main(){
	int n,sum = 0,a[2000];
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		sum += a[i];
	}
	dp.set(0);
	for(int i = 0;i < n;i++) dp |= (dp << a[i]);
	for(int i = (sum + 1) / 2;i <= sum;i++){
		if(dp[i]){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>

void MergeSort(int *A,int length);
void Merge(int *A, int *Left, int *Right, int length);

int track = 0;
/*
 * 
 */
int main(int argc, char** argv) {

    int n;
    scanf("%d",&n);
    int *A = (int*)malloc(n*sizeof(int));
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
    }
    MergeSort(A,n);
    
    for(int i= 0; i < n; i++){
        printf("%d",A[i]);
        if(i < n - 1)printf(" ");
    }
    printf("\n%d",track);
    printf("\n");
    return (0);
}

void MergeSort(int *A, int length){
    
    int *Left, *Right;
    int mid = length/2;
    int i = 0;
    if(length < 2)return;
    else{
        Left = (int*)malloc(mid*sizeof(int));
        Right = (int*)malloc((length - mid)*sizeof(int));
        
    for(int i = 0; i < mid; i++){
        Left[i] = A[i];
    }
    for(int i = mid; i < length; i++){
        Right[i - mid] = A[i];
    }
    }
    MergeSort(Left,mid);
    MergeSort(Right,length-mid);
    Merge(A,Left,Right,length);
}

void Merge(int *A, int *Left, int *Right, int length){
    int i= 0, j=0, k=0;
    int Leftmid, Rightmid;
    Leftmid = length/2;
    Rightmid = length - Leftmid;
    
    while(i < Leftmid && j < Rightmid){
        if(Left[i] < Right[j]){
            A[k] = Left[i];
            i++;
            track++;
        }
        else{
                A[k] = Right[j];
                j++;
                track++;
        }
        k++;
        
    }
        
        while(i < Leftmid){
            A[k]=Left[i];
            i++;
            k++;
            track++;
        }
        while(j<Rightmid){
            A[k]=Right[j];
            j++;
            k++;
            track++;
        }
    }



Measured memory_bytes: 64280
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
    int n;
    cin >> n;
    multiset<long double> f;
    for (int i = 0; i < n; ++i) {
        int cur;
        cin >> cur;
        f.insert(cur);
    }
    for (int i = 0; i < n - 1; ++i) {
        long double a = *f.begin();
        long double b = *(++f.begin());
        f.erase(f.begin());
        f.erase(f.begin());
        f.insert((a + b) / 2);
    }
    cout.precision(20);
    cout << *f.begin() << '\n';
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    print(sum(A)-N)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void push(int);
int pop(void);

int S[100];
int top;

int main()
{
  int a,b,n;
  char c[100];
  top=0;
  while(scanf("%s",c)!=EOF)
    {
      if(c[0]=='+')
	{
	  a=pop();
	  b=pop();
	  push(a+b);
	}
      else if(c[0] == '-')
	{
	  b=pop();
	  a=pop();
	  push(a-b);
	}
      else if(c[0] == '*')
	{
	  a=pop();
	  b=pop();
	  push(a*b);
	}
      else 
	{
	  n=atoi(c);
	  push(n);
	}
    }
  printf("%d\n",pop());
  return 0;
}

void push(int x)
{
  S[++top]=x;

}

int pop(void )
{
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if (B-A)%2 == 0:
        between = (B-A)//2
        print(between)

    else: #端でしか会えない
        answer = 0
        if A-1<=N-B:
            answer += A
            B -= A
            A = 1
            answer += (B-A)//2
        else:
            answer += N-B+1
            A += N-B+1
            B = N
            answer += (B-A)//2

        print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath> 
using namespace std;
int n,a[55];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int mx=1;
	for(int i=2;i<=n;i++)
		if(abs(a[i])>abs(a[mx])) mx=i;
	printf("%d\n",2*n);	
	if(a[mx]>=0)
	{
		printf("%d %d\n",mx,n);
		printf("%d %d\n",mx,n);
		for(int i=1;i<n;i++)
		{
			printf("%d %d\n",n,i);
			printf("%d %d\n",n,n);
		}
	}
	else
	{
		printf("%d %d\n",mx,1);
		printf("%d %d\n",mx,1);
		for(int i=n;i>1;i--)
		{
			printf("%d %d\n",1,i);
			printf("%d %d\n",1,1);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,ans;
struct st{int s;int e;};
bool cmp(st p,st q)
{
    return p.e<q.e;
}
st a[100010];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x,l;
        scanf("%d%d",&x,&l);
        a[i].s=x-l;
        a[i].e=x+l;
    }
    sort(a,a+n,cmp);
    int e=a[0].e;
    ans++;
    for(int i=1;i<n;i++)
    {
        if(a[i].s>=e)
        {
            e=a[i].e;
            ans++;
        }
    }
    printf("%d",ans);
}

Measured memory_bytes: 1024
#include<stdio.h>
  
#define AMAX 20
#define MMAX 200
 
int A[AMAX+1];
int n, q;

int solve_loop( int p, int t, int res )
{
	return  ( n < p ) ? res: solve_loop( p+1, t-A[p], !t||res  ) || solve_loop( p+1, t, !t||res );
}
int solve( int p, int t )
{
	return  solve_loop( p, t, 0 );
}
 
int main( void ) 
{
    int i;
    int num;
     
    scanf( "%d", &n );  
    for( i=0; i<n; i++ ) {
        scanf( "%d", &A[i] );
    }   
    scanf( "%d", &q );
    for( i=0; i<q; i++ ) {
        scanf( "%d", &num );
        if( solve( 0, num ) ) {
            printf( "yes\n" );      
        } else {
            printf( "no\n" );
        }
    }
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>
using namespace std;
char a[10005];
char b[10005];
int main()
{
    int n;
    set<string> s;
    while(cin>>n){
        string str;
        for(int i=0;i<n;i++){
            cin>>str;
            s.insert(str);
            a[i]=str[0];
            int len=str.length();
            b[i]=str[len-1];
        }
        int flag=1;
        if(s.size()!=n) flag=0;
        for(int i=0;i<n-1;i++){
            if(a[i+1]!=b[i]){
                flag=0;
                break;
            }
        }
//        for(int i=0;i<n;i++){
//            cout<<a[i]<<endl;
//            cout<<"------"<<endl;
//            cout<<b[i]<<endl;
//        }
        if(flag) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256