akhauriyash/Code-Regression huggingface dataset:
#include <iostream>//for cin cout endl
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;
long long W,weight[110],value[110];
long long dp[110][100010]={0};
int main(){

    cin>>N>>W;
    for (int i =0 ; i<N;++i)cin>>weight[i]>>value[i];

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

            if(sum_w-weight[i]>=0){
                chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
            };
            chmax(dp[i+1][sum_w],dp[i][sum_w]);

        }
    }

    cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 79488
#include <stdio.h>

char res[101][101];
int n=100, m=100;

int main() {
	int a, b;
	scanf("%d %d",&a,&b);
	puts("100 100");
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(j<50) res[i][j]='.';
			else res[i][j]='#';
		}
	}
	a--; b--;
	for(int i=1;i<n;i+=2) {
		for(int j=1;j<49;j+=2) {
			if(b) {
				res[i][j]='#';
				b--;
			}
		}
	}
	for(int i=1;i<n;i+=2) {
		for(int j=51;j<100;j+=2) {
			if(a) {
				res[i][j]='.';
				a--;
			}
		}
	}
	for(int i=0;i<n;i++)
		puts(res[i]);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int N , K ;
    cin >> N >> K ;
    int a[N];
     for(int i = 0; i < N ; i++ )
       cin >> a[i];
    
    sort(a,a+N);

    int ans = 0 ;
     for(int j = 0; j < K ; j++)
       ans += a[N-j-1] ;
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> ss(h);
	for (int i = 0; i < h; i++) {
		cin >> ss[i];
	}
	for (int i = 0; i < h; i++) {
		cout << ss[i] << endl;
		cout << ss[i] << endl;
	}
	return 0;
}

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

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    int l = 0;
    ll sum = 0, bit = 0;
    ll res = 0;
    rep(r,n){
        sum += a[r];
        bit ^= a[r];
        while(l<=r && sum != bit){
            sum -= a[l];
            bit ^= a[l];
            l++;
        }
        res += r-l+1;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int cards[4][14]={};
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		char c;int a;
		cin>>c>>a;
		for(int j=0;j<n;j++){
			if(c=='S'){
				cards[0][a]=1;
			}
			else if(c=='H'){
				cards[1][a]=1;
			}
			else if(c=='C'){
				cards[2][a]=1;
			}
			else {
				cards[3][a]=1;
			}		
		}
	}
	for(int k=0;k<=3;k++){
		for(int l=1;l<=13;l++){
			if (cards[k][l]==0){
				if(k==0){
					cout<<"S "<<l<<endl;
				}
				if(k==1){
					cout<<"H "<<l<<endl;
				}	
				if(k==2){
					cout<<"C "<<l<<endl;
				}
				if(k==3){
					cout<<"D "<<l<<endl;
				}
			}
		}
	}	
	return 0;
}






Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n,T,ans,c,t;
    cin>>n>>T;
    bool found=false;
    for(int i=0;i<n;i++)
    {
        cin>>c>>t;
        if(t<=T)
        {
            if(!found)
            {
                found=true;
                ans=c;
            }
            else if(ans>c)
                ans=c;
        }
    }
    if(found)
        cout<<ans<<endl;
    else
        cout<<"TLE"<<endl;
    return 0;
}


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

using namespace std;

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

	int hl = h[0];
	int c = 1;

	for (int i = 1; i < n; i++) {
		if (h[i] >= hl) {
			c++;
			hl = h[i];
		}
	}

	cout << c;

}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    LL S;
    cin >> S;
    LL c;
    cin >> c;
    LL ans = 0;
    if (S <= c / 2)
    {
        ans += S;
        c -= S * 2;
        ans += c / 4;
    }
    else
    {
        ans = c / 2;
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
    long long k;
    cin >> k;

    long long i = 0;
    long long val = 0;
    long long first = -1;

    while (true) {
        i++;
        val = val * 10 + 7;
        long long rem = val % k;
        if (rem == 0) {
            break;
        }
        if (first == rem) {
            i = -1;
            break;
        }
        if (i > 2 * k) {
            i = -1;
            break;
        }
        val = rem;
    }
    cout << i << endl;

    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
typedef pair<ll,ll> P;
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,k=0,a=0,ans=0;cin>>n>>m;
  lvector v(m,0);
  rep(i,n) {
    cin>>k;
    rep(i,k) {
      cin>>a;
      v[a-1]++;
    }
  }
  rep(i,m) if(v[i]==n) ans++;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
n=int(input())
lr=[[int(i) for i in input().split()] for j in range(n)]
lr=sorted(lr)
li_test=[]

for x,y in lr:
    li_test.append(y)

li=[li_test[0]]
a=li_test[0]
for i in range(1,n):
    a=min(li_test[i],a)
    li.append(a)

li_test=li_test[::-1]
li2=[li_test[0]]
a=li_test[0]
for i in range(1,n):
    a=min(li_test[i],a)
    li2.append(a)
li2=li2[::-1]
    
ans=0


maxi=lr[-1][0]
for i in range(n-1):
    one = max(0,li[i]-lr[i][0]+1)
    two = max(0,li2[i+1]-maxi+1)
    tokubetu=lr[i][1]-lr[i][0]+1
    tokubetu2=max(0,li2[0]-maxi+1)
    check=max(one+two,tokubetu+tokubetu2)
    ans=max(ans,check)
print(ans)    

Measured memory_bytes: 72312
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-12;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
bool solve(void){
	
	int w,n,i;cin>>w>>n;
	if(w==0){return 0;}
	vector<int>x(n);
	for(i=0;i<n;i++){cin>>x[i];}
	llint bmin=0,bmax=w;
	while(bmax-bmin>1){
		vector<int>table(n+1);
		llint bgen=(bmax+bmin)/2;
		vector<llint> Lwa(n+1),Rwa(n+1);
		for(i=0;i<n;i++){
			Lwa[i+1]=Lwa[i]+x[i]+bgen;
			Rwa[i+1]=Rwa[i]+x[i]+1;
		}
		//cerr<<"bgen="<<bgen<<endl;
		bool can=false;
		for(i=0;i<n;i++){
			if(table[i]<i){continue;}//不可能
			maxeq(table[i+1],table[i]);
			llint L=LBI(Lwa,Lwa[i]+w+bgen);
			llint R=UBI(Rwa,Rwa[i]+w+1)-1;
			if(n<=R){can=true;break;}
			//cerr<<"i="<<i<<"L="<<L<<"R="<<R<<endl;
			maxeq(table[L],R);
		}
		if(can){bmax=bgen;}
		else{bmin=bgen;}
	}
	cout<<bmax<<endl;
	return 1;
}

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	while(solve()){}
	return 0;
}



Measured memory_bytes: 4140
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <vector>
using namespace std;


const int N = 26;


int decide(int d, vector<vector<int>>& s, vector<int>& c, vector<int>& last) {
  int ans = 0;
  int tmpV, maxV = -10000000;
  for (int t = 0; t < N; t++) {
    tmpV = s[d][t];
    for (int i = 0; i < N; i++) if (i != t) tmpV -= c[i] * (d - last[i]);
    if (tmpV > maxV) {
      maxV = tmpV;
      ans = t;
    }
  }
  return ans;
}


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

  vector<int> c(N, 0);
  for (int i = 0; i < N; i++) cin >> c[i];

  vector<vector<int>> s(D, vector<int> (N, 0));
  for (int d = 0; d < D; d++) {
    for (int i = 0; i < N; i++) {
      cin >> s[d][i];
    }
  }

  vector<int> t(D, 0);
  // Choose t[] greedily ans calc score
  vector<int> last(N, -1);
  vector<int> v(D, 0);
  for (int d = 0; d < D; d++) {
    t[d] = decide(d, s, c, last);
    last[t[d]] = d;
  }

  for (int x : t) cout << x + 1 << endl;

  return 0;
}


Measured memory_bytes: 3652
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

def main():
    return


if __name__ == '__main__':
    if 'LOCAL' in os.environ:
        # ローカル実行時のみ通る処理
        # テストしたい入力を入れておく
        input_values = [
                """
                """.strip(),
                """
                """.strip()
                ]
        for input_value in input_values:
            input_value = input_value.split('\n')
            #  N = int(input_value[0])
            #  A = list(map(int, input_value[1].split()))
            ans = main()
            expected_value = int(input_value[2])
            assert ans == expected_value, 'failed: ans: {ans}, exp: {exp}'.format(ans=ans, exp=expected_value)
    else:
        A, B, C = LI()
        ans = C- (A-B)
        if ans < 0:
            ans = 0
        print(ans)
        #  print(main())



Measured memory_bytes: 66924
#include<bits/stdc++.h>
//#define endl "\n"
using namespace std;

const int C = 2600, maks = 2600;
long long x, v, dp[10*C], n;

int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>n>>v;
	dp[0+C] = 1;
	for( int a = 1; a <= n; a++ )
	{
		cin>>x;
		x -= v;
		if( x >= 0 )
		{
			for( int b = maks; b >= -maks; b-- )
			{
					dp[b+x+C] += dp[b+C];
			}
		}
		if( x < 0 )
		{
			for( int b = -maks; b <= maks; b++ )
			{
					dp[b+x+C] += dp[b+C];
			}
		}
	}
	cout<<dp[C]-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int count[26],i;
    char in;
    for(i=0;i<26;i++)
    {
        count[i] = 0;
    }
    while( scanf("%c",&in)!= EOF )
    {
        if(in>='a' && in<='z') count[in-'a']++;
        else if(in>='A' && in<='Z') count[in-'A']++;
    }
    for(i=0;i<26;i++)
    {
        printf("%c : %d\n",97+i,count[i]);
    }
    return 0;
}

Measured memory_bytes: 540
// Vicfred
// https://atcoder.jp/contests/abc050/tasks/arc066_a
// math, combinatorics
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    const int mod = 10^^9+7;
    const long n = readln.chomp.to!long;
    long[] as = readln.split.map!(to!long).array;
    as.sort;

    if(n%2 == 1) as = as[1..n];

    long[long] count;
    foreach(item; as) {
        if(item in count) {
            count[item] += 1;
        } else {
            count[item] = 1;
        }
    }

    foreach(item; count.values()) {
        if(item != 2) {
            0.writeln;
            return;
        }
    }

    long ans = 1;
    for(int i = 0; i < n/2; i++) {
        ans *= 2;
        ans %= mod;
    }
    ans.writeln;
}




Measured memory_bytes: 9932
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int64_t MODULO    = 1000000007;

typedef int64_t ll;

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

#define SPRE(x) setprecision(x) // 精度を指定


int64_t pow_Mod(int64_t x, int64_t n)
{
	int64_t answer = 1;
	int64_t now_pow = x;
	while(n > 0)
	{
		if((n & 1 )== 1)
		{
			answer *= now_pow;
			answer %= MODULO;
		}
		now_pow *= now_pow;
		now_pow %= MODULO;

		n >>= 1;
	}
	return answer;
}

int64_t fact(int64_t x)
{
	int64_t answer = 1;
	while(x > 0)
	{
		answer *= x;
		answer %= MODULO;
		x--;
	}
	return answer;
}

int64_t comb(int64_t n, int64_t k)
// $n C $k (mod $MODULO)
{
	int64_t numerator = fact(n);
	int64_t denominator_n = pow_Mod(fact(n-k), MODULO - 2);
	int64_t denominator_k = pow_Mod(fact(k), MODULO - 2);

	numerator = numerator * denominator_n % MODULO;
	numerator = numerator * denominator_k % MODULO;
	return numerator;
}

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> x,y;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        x.push_back(t);
    }
    for (int i = 0; i < m; i++) {
        int t;
        cin >> t;
        y.push_back(t);
    }
    ll xs = 0;
    ll ys = 0;
    for (int i = 1; i < n; i++) {
        xs += (x[i]-x[i-1])* i * (n-i);
        xs %= MODULO;
    }
    for (int i = 1; i < m; i++) {
        ys  += (y[i]-y[i-1])* i * (m-i);
        ys  %= MODULO;
    }
    ll ans = xs * ys;
    ans %= MODULO;
    cout << ans << '\n';

}



Measured memory_bytes: 2548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	cout << ((r * 100 + g * 10 + b) % 4 == 0 ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
while True:
    h = int(input())
    if h == 0:
        break
    h = [h] + [int(input()) for _ in range(4)]
    if len(set(h)) == 3 or len(set(h)) == 1:
        print(*[3]*5, sep='\n')
        continue
    d = {1:2, 2:3, 3:1}
    for c in h:
        print([2, 1][d[c] in h])

Measured memory_bytes: 7568
a,b,k = map(int, input().split())
left_n = a+k if a+k-1<=b else b+1
right_n = b-k+1 if b-k+1>=a else a

left = [i for i in range(a, left_n)]
right = [i for i in range(right_n, b+1)]

print(*sorted(set(left+right)), sep='\n')

Measured memory_bytes: 3060
import math


# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


def isPrime(n):
    if n < 2:
        return False
    limit = int(math.sqrt(n+1))
    for i in range(2, limit):
        if n % i == 0:
            return False

    return True


n = inp()

while True:
    if isPrime(n):
        print(n)
        break
    n += 1


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  for(int i=0;i<m;i++) cin >> a[i];

  ll sum = 0;
  for(int i=0;i<m;i++) sum += a[i];

  if(sum > n){
    cout << -1 << endl;
  }else{
    cout << n-sum << endl;
  }
}


Measured memory_bytes: 3672
#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>;

vector<int64_t> make_divisors(int64_t n) {
    vector<int64_t> divisors;
    for (int64_t i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            divisors.push_back(i);
            if(i!=1 && i*i!=n)
				divisors.push_back(n/i);
        }
    }
    sort(divisors.begin(), divisors.end());
    if (n != 1) divisors.push_back(n);
    // int div_size = divisors.size();
    return divisors;
}

int main() {
    int64_t n, m;
    cin >> n >> m;
    const auto &d = make_divisors(m);
    int64_t a = *lower_bound(d.begin(), d.end(), n);
    cout << m / a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 205
using namespace std;
inline int read(){
  int x = 0, f = 0;char ch = getchar();
  for (; ch <'0' || ch>'9'; ch = getchar()) if (ch == '-') f = 1;
  for (; ch >= '0'&& ch<='9'; ch = getchar()) x = (x<<1) + (x<<3) + ch - 48;
  return f ?-x :x;
}
int n, A, B;
int main() {
  n = read();
  A = read();
  B = read();
  if ((A - B)%2 == 0) puts("Alice");
  else puts("Borys");
  return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, K = MI()
    ans = 0
    l = [i for i in range(N+1)]
    acc = list(accumulate(l))

    ans1 = 0

    for i in range(K, N+2):
        # a = cmb(N+1, i, MOD)
        # ans += a
        # ans %= MOD
        if i == N+1:
            mx = acc[N]
        else:
            mx = acc[N] - acc[N-i]
        mn = acc[i-1]
        # print('k', i)
        # print('=============')
        # print('mn', mn, 'mx', mx)
        # mx = sum(l[N-i+1:N+1])
        # mn = sum(l[0:i])
        # print('mn', mn, 'mx', mx)
        ans1 += mx - mn + 1
        ans1 %= MOD
        # print('=========')

    print(ans1 % MOD)


if __name__ == '__main__':
    main()


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N,A,B,C;
    cin >> N >> A >> B >> C;
    
    vector<i64> l(N);
    rep(i,0,N){
        cin >> l[i];
    }
    
    auto choose=[&](i64 b){
        vector<i64> res;
        rep(i,0,N){
            if((b&(1<<i))==0) continue;
            res.emplace_back(l[i]);
        }
        return res;
    };
    
    auto cost=[&](vector<i64> vs,i64 len){
        if(vs.empty()) return inf64;
        
        i64 res=0,sum=vs[0];
        rep(i,1,vs.size()){
            sum+=vs[i];
            res+=10;
        }
        
        if(sum<len) return res+len-sum;
        if(sum>len) return res+sum-len;
        return res;
    };
    
    i64 ans=inf64;
    rep(i,1,1<<N){
        rep(j,1,1<<N){
            if((i&j)!=0) continue;
            rep(k,1,1<<N){
                if((i&k)!=0) continue;
                if((j&k)!=0) continue;
                ans=min(ans,cost(choose(i),A)+cost(choose(j),B)+cost(choose(k),C));
            }
        }
    }
    
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
import itertools

if __name__ == "__main__":
    N = int(input())
    P = [int(x) for x in input().split(" ")]
    Q = [int(x) for x in input().split(" ")]

    a = 1
    b = 1
    for x in itertools.permutations(range(1, N + 1)):
        if list(x) == P:
            break
        a += 1

    for x in itertools.permutations(range(1, N + 1)):
        if list(x) == Q:
            break
        b += 1
    print(abs(a - b))


Measured memory_bytes: 9184
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	string s;
	while(getline(cin,s))
	{
		replace(s.begin(),s.end(),',',' ');
		replace(s.begin(),s.end(),'.',' ');
		int count=0;
		bool up=true;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]!=' ')
			{
				count++;
			}
			else
			{
				if(3<=count&&count<=6)
				{
					if(up)
					{
						up=false;
					}
					else
					{
						cout << ' ';
					}
					for(int j=i-count;j<i;j++)
					{
						cout << s[j];
					}
					count=0;
				}
				else
				{
					count=0;
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#define ll long long
ll max(ll a, ll b){
	if(a>b)return a;
	else return b;
}

int main(void){
	int N;
	int H[100001][3];
	int i;

	scanf("%d",&N);
	for(i=0; i<N; i++)scanf("%d %d %d",&H[i][0],&H[i][1],&H[i][2]);

	long long dp[100001][3];
	dp[0][0]=0;
	dp[0][1]=0;
	dp[0][2]=0;
	for(i=1; i<=N; i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+H[i-1][0];
		dp[i][1]=max(dp[i-1][2],dp[i-1][0])+H[i-1][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+H[i-1][2];
	}
	printf("%lld\n",max(dp[N][0],max(dp[N][1],dp[N][2])) );
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }

    int cnt = 0;

    REP(i,n){
        if(a[i] == cnt + 1){
            cnt++;
        }
    }

    if(cnt == 0){
        cout << -1 << endl;
    }
    else{
        cout << n - cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    var num = StdIn.readLine().split(" ").map(a => a.toInt)
    val N = num(0)
    val K = num(1)
    val result = if( N % K == 0 ) 0 else 1

    println(result)
  }
}

Measured memory_bytes: 25292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int n;

	int xp = 0, yp = 0, t0 = 0;

	std::cin >> n;

	for (size_t i = 0; i < n; i++)
	{
		int t, x, y;

		std::cin >> t >> x >> y;

		int tmp = t0;
		t0 = t;
		t -= tmp;

		t -= abs(x - xp);
		t -= abs(y - yp);

		if (t < 0 || t % 2 != 0) {
			std::cout << "No" << std::endl;
			return 0;
		}

		xp = x;
		yp = y;
	}

	std::cout << "Yes" << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

int n, m;
int lhs[2001];
int rhs[2001];
int w[2001];
ll dp[2001];

const ll NEG_INF = -1e18;
const ll POS_INF = 1e18;

void solve() {
  cin >> n >> m;
  for(int i = 2; i <= n; i++) dp[i] = NEG_INF;
  for(int i = 0; i < m; i++) {
    cin >> lhs[i] >> rhs[i] >> w[i];
  }
  for(int qq = 0; qq < n; qq++) {
    for(int i = 0; i < m; i++) {
      if(dp[lhs[i]] == NEG_INF) continue;
      dp[rhs[i]] = max(dp[rhs[i]], dp[lhs[i]] + w[i]);
    }
  }
  while(true) {
    bool upd = false;
    for(int i = 0; i < m; i++) {
      if(dp[lhs[i]] == NEG_INF) continue;
      if(dp[lhs[i]] == POS_INF) {
        if(dp[rhs[i]] != POS_INF) {
          dp[rhs[i]] = POS_INF;
          upd = true;
        }
      }
      else if(dp[rhs[i]] < dp[lhs[i]] + w[i]) {
        dp[rhs[i]] = POS_INF;
        upd = true;
      }
    }
    if(!upd) break;
  }
  if(dp[n] == POS_INF) cout << "inf\n";
  else cout << dp[n] << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y) {
    if (!a) {*x = 0; *y = 1; return b;}
    ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd;
}
ll modI(ll b, ll m)      {ll x, y; gcdEx(b, m, &x, &y); return (x % m + m) % m;}
typedef pair<ll, ll>      pii;
typedef vector<ll>         vi;
typedef vector<pii>         vii;
typedef set<ll>            si;
typedef map<string, ll>    msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define loop(i,b,n)           for(ll i=b;i<n;i++)
#define loopv(i,b,n,a)         for(ll i=b;i<n;i+=a)
#define loopr(i,b,n)           for(ll i=n;i>=0;i--)

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define start_routine() ll begtime = clock();
#define end_routine() ll endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define pb                  push_back
#define MOD                 1000000007
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(ll)(MOD+((a%MOD)-(b%MOD))%MOD):(ll)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (ll)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}
ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a, b;
    ll ans;
    cin >> a >> b;
    ans = a * b;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

int n,A[50];

int solve(int i, int m){
  if( m == 0) return 1;
  if( i >= n) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main(){
  int q, M, i;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &M);
    if( solve(0,M) ) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



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

const long long int MOD = 1000000007;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

long long int nCr(int n, int r){
    if(n < r || r < 0) return 0;
    if (n >= f.size()){
        factorial_Initialize(n);
    }
    return f[n] * f_inverse[r] % MOD * f_inverse[n-r] % MOD;
}

vector<pair<long long int, long long int>> prime_factorize(long long int n){// (prime, power)'s vector
    
    vector<pair<long long int, long long int>> prime_power;
    for (long long int p=2; p*p<=n; p++) {
        if(n % p != 0) continue;// break and proceed to p+1

        int power = 0;
        while(n % p == 0){
            power += 1;
            n /= p;
        }
        prime_power.push_back(make_pair(p, power));
    }

    // n has been divided by all primes (with power) smaller than sqrt(n)
    if(n != 1){
        prime_power.push_back(make_pair(n, 1));
    }

    return prime_power;
}

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

    long long int ans = 1;
    vector<pair<long long int, long long int>> p = prime_factorize(m);
    for(int i=0; i<p.size(); i++){
        ans = ans * nCr((n-1) + p[i].second, p[i].second) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4208
#include<stdio.h>
int main(void)
{
  int a=0;
  int b=0;
  scanf("%d %d",&a,&b);
  if(a<b){
    puts("a < b");
  }else if(a>b){
    puts("a > b");
  }else if(a==b){
    puts("a == b");
  }
  return 0;
}



Measured memory_bytes: 1972
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
typedef long int li;

int main(){
  int n; cin >>n;
  vector<li> a(n);
  for(li& x: a) cin >>x;
  if(df){
    for(li x: a) cout << x;
    cout << "\n";
  } 
  
  li cnt=0,sum=0,xsum=0;
  int right=0;
  rep(left,n){
    while(right<n and (sum+a[right])==(xsum^a[right])){
      sum +=a[right];
      xsum^=a[right];
      right++;
      if(df) printf("sum:%d,xsum:%d\n",sum,xsum);
    } 
    cnt+=right-left;
    if(df) printf("(%d,%d]",left,right);
    sum -=a[left];
    xsum^=a[left];
  }
  cout << cnt << "\n";
}


Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	ans := 0
	for i := 1; i*i <= m; i++ {
		if m%i != 0 {
			continue
		}

		if i*n <= m {
			ans = max(ans, i)
		}

		j := m / i
		if j*n <= m {
			ans = max(ans, j)
		}
	}

	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    auto g = make_vec<int>(n, 0);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n) {
            if (s[j] == '1') g[i].push_back(j);
        }
    }

    vector<int> col(n, -1);

    auto dfs = [&](auto self, int v=0, int c=0) -> bool {
        if (col[v] != -1) return col[v] == c;
        col[v] = c;
        for (int u : g[v]) if (!self(self, u, 1-c)) return false;
        return true;
    };
    
    if (!dfs(dfs)) {
        cout << -1 << '\n';
        return 0;
    }
    
    const int inf = 1001001001;
    auto d = make_vec<int>(n, n);
    fill_v<int>(d, inf);

    rep(i, n) d[i][i] = 0;
    rep(i, n) rep(j, g[i].size()) d[i][g[i][j]] = 1;

    rep(k, n) rep(i, n) rep(j, n) chmin(d[i][j], d[i][k] + d[k][j]);
    
    int dmax = 0;
    rep(i, n) rep(j, n) chmax(dmax, d[i][j]);
    cout << dmax + 1 << '\n';
}


Measured memory_bytes: 3904
package main

import (
	"fmt"
	"strings"
)

func rotN(n int, s string) string {
	stack := make([]string, len(s))

	for i, v := range s {
		r := v + rune(n)
		if r > 90 {
			r -= 26
		}
		stack[i] = string(r)
	}
	return strings.Join(stack, "")
}

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)
	fmt.Println(rotN(n, s))
}


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

int mp[30];

int main(){
  string s, t;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    if(mp[s[i] - 'a'] != t[i]){
      if(mp[s[i] - 'a']){
        puts("No");
        return 0;
      }else mp[s[i] - 'a'] = t[i];
    }
  }
  sort(mp, mp+26);
  for(int i = 1; i < 26; i++){
    if(mp[i] && mp[i] == mp[i-1]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	double a[n][3];
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	int b[m],sum=0;
	for(int i=0;i<m;i++){
		b[i]=i;
		sum=sum+i;
	}
	double mk=0,k;
	do{
		k=0;
		for(int i=0;i<m-1;i++){
			for(int j=i+1;j<m;j++){
				k=k+pow(a[b[i]][0]-a[b[j]][0],2)+pow(a[b[i]][1]-a[b[j]][1],2)+pow(a[b[i]][2]-a[b[j]][2],2);
			}
		}
		mk=max(mk,k);
		for(int i=m-1;i>=0;i--){
			if(b[i]!=i-m+n){
				b[i]++;
				for(int j=i+1;j<m;j++){
					b[j]=b[j-1]+1;
				}
				break;
			}
		}
		sum=0;
		for(int i=0;i<m;i++){
			sum=sum+b[i];
		}
	}while(sum<((2*n-m-1)*m)/2);
	cout.setf(ios::fixed, ios::floatfield);
	cout<<mk<<endl;
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

ll ans = 0;

void attack(ll x, ll cnt)
{
    if (x == 1)
    {
        ans += pow(2, cnt);
        return;
    }
    ans += pow(2, cnt);
    attack(x / 2, cnt + 1);
}

int main()
{
    ll h;
    cin >> h;
    attack(h, 0);
    OP(ans);

    return 0;
}

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

public class Main {

    public static void main(String[] args) throws IOException {

        int a = 0;

        ArrayList<String> list1 = new ArrayList<>();

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        a = Integer.parseInt(br.readLine());

        for (int i = 0; i < a; i++) {
            list1.add(br.readLine());
        }

        for (int i = 1; i < 14; i++) {
            if (list1.contains("S " + i) == false) {
                System.out.println("S " + i);
            }
        }

        for (int i = 1; i < 14; i++) {
            if (list1.contains("H " + i) == false) {
                System.out.println("H " + i);
            }
        }

        for (int i = 1; i < 14; i++) {
            if (list1.contains("C " + i) == false) {
                System.out.println("C " + i);
            }
        }

        for (int i = 1; i < 14; i++) {
            if (list1.contains("D " + i) == false) {
                System.out.println("D " + i);
            }
        }

    }

}

Measured memory_bytes: 24216
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, D = 87*87*2;

int a[87][87], b[87][87], dp[87][87][87*87*4];

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin >> a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin >> b[i][j];
	for(int i=-(n+m)*87;i<=(n+m)*87;i++) {
		int c1 = a[1][1] - b[1][1] + i;
		int c2 = b[1][1] - a[1][1] + i;
		if(abs(c1) < abs(c2)) dp[1][1][i+D] = c1;
		else dp[1][1][i+D] = c2;
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++) {
			if(i == 1 && j == 1) continue;
			for(int k=-(n+m)*87;k<=(n+m)*87;k++) {
				int c1 = INF, c2 = INF;
				if(i - 1) {
					int c11 = INF, c12 = INF;
					if(k+a[i][j]-b[i][j]+D < 87*87*4 && k+a[i][j]-b[i][j]+D >= 0) c11 = dp[i-1][j][k+a[i][j]-b[i][j]+D];
					if(k+b[i][j]-a[i][j]+D < 87*87*4 && k+b[i][j]-a[i][j]+D >= 0) c12 = dp[i-1][j][k+b[i][j]-a[i][j]+D];
					if(abs(c11) < abs(c12)) c1 = c11;
					else c1 = c12;
				}
				if(j - 1) {
					int c21 = INF, c22 = INF;
					if(k+a[i][j]-b[i][j]+D < 87*87*4 && k+a[i][j]-b[i][j]+D >= 0) c21 = dp[i][j-1][k+a[i][j]-b[i][j]+D];
					if(k+b[i][j]-a[i][j]+D < 87*87*4 && k+b[i][j]-a[i][j]+D >= 0) c22 = dp[i][j-1][k+b[i][j]-a[i][j]+D];
					if(abs(c21) < abs(c22)) c2 = c21;
					else c2 = c22;
				}
				if(abs(c1) < abs(c2)) dp[i][j][k+D] = c1;
				else dp[i][j][k+D] = c2;
			}
		}
	}
	cout << abs(dp[n][m][0+D]) << endl;
}



	

Measured memory_bytes: 823680
#include <stdio.h>
int main()
{
	int a,b,c,d1,d2,d3;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b&&a<c){
		d1=a;
		if(b<c){
			d2=b;d3=c;
			}
		else {
	d2=c;d3=b;
}
		
	}
	else if(b<a&&b<c){
		d1=b;
		if(a<c){
			d2=a;d3=c;
		}
		else{
		d2=c;d3=a;
	}
		
	}
	else {
		d1=c;
		if(b<a){
			d2=b;d3=a;
			}
		else{
		d2=a;d3=b;
	}
		
	}
	
	printf("%d %d %d\n",d1,d2,d3);
	return 0;

}


Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            String str = sc.next();
            if(str.equals("-")) break;
            int n = sc.nextInt();
            for(int i=0;i<n;i++){
                int s = sc.nextInt();
                String former = str.substring(0,s);
                String latter = str.substring(s);
                str = latter + former;
            }
            System.out.println(str);
        }
        sc.close();
    }
}


Measured memory_bytes: 26188
def get_answer(input_list):
    d = input_list[0]
    f1 = True
    f2 = True
    for i in range(len(d)):
        s = d[i]
        if (i + 1) % 2 == 1:
            if s not in ["R","U","D"]:
                f1 = False
        else:
            if s not in ["L","U","D"]:
                f2 = False

    if f1 and f2:
        return "Yes"
    return "No"



if __name__ == "__main__":
    input_list = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            input_list.append(input1)
        except EOFError:
            break
    print(get_answer(input_list))



Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        HashMap<Integer, TreeNode> nodes = new HashMap<>();
        int rootID = 0;
        ArrayList<Integer> notRoots = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int id = in.nextInt();
            int leftID = in.nextInt();
            int rightID = in.nextInt();
            if (leftID != -1) notRoots.add(leftID);
            if (rightID != -1) notRoots.add(rightID);
            TreeNode node = new TreeNode(id, leftID, rightID);
            nodes.put(node.id, node);
        }
        notRoots.sort(Integer::compareTo);
        for (Integer i : notRoots) {
            if (rootID == i) {
                rootID++;
            }
        }
        updateNodes(nodes, rootID, -1, 0, -1);

        int id = 0;
        TreeNode node = nodes.get(id);
        while (node != null) {
            System.out.println("node " + id + ": parent = " + node.parent + ", sibling = " + node.sibling
                    + ", degree = " + node.degree + ", depth = " + node.depth + ", height = " + node.height + ", "
                    + node.getType());
            node = nodes.get(++id);
        }
    }

    private static int updateNodes(HashMap<Integer, TreeNode> nodes, int currentID, int parent, int depth, int sibling) {
        TreeNode node = nodes.get(currentID);
        node.parent = parent;
        node.depth = depth;
        node.sibling = sibling;

        if (node.isLeaf()) {
            node.height = 0;
            return node.height;
        } else {
            int heightLeft = 0, heightRight = 0;
            if (node.left != -1) {
                heightLeft = updateNodes(nodes, node.left, currentID, depth + 1, node.right);
            }
            if (node.right != -1) {
                heightRight = updateNodes(nodes, node.right, currentID, depth + 1, node.left);
            }
            node.height = heightLeft > heightRight ? heightLeft + 1 : heightRight + 1;
            return node.height;
        }
    }
}

class TreeNode {
    int id;
    int degree;
    int parent;
    int depth;
    int sibling;
    int height;
    int left;
    int right;

    public TreeNode(int id, int left, int right) {
        this.id = id;
        this.left = left;
        this.right = right;
        if (left == -1 && right == -1) {
            degree = 0;
        } else if (left == -1 || right == -1) {
            degree = 1;
        } else {
            degree = 2;
        }
    }

    boolean isLeaf() {
        return degree == 0;
    }

    String getType() {
        if (depth == 0) {
            return "root";
        } else if (isLeaf()) {
            return "leaf";
        } else {
            return "internal node";
        }
    }
}


Measured memory_bytes: 32188
n, k = gets.chomp.split.map(&:to_i)
h = gets.chomp.split.map(&:to_i)
h = h.sort.reverse!
nomalAtack = 0

h.each do |h|
  if (k > 0) then
    h = 0
    k -= 1
  else
    nomalAtack += h
  end
end

puts "#{nomalAtack}"


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

int main(){
  int n,maxn,minn,ave,sum = 0;

  while(cin >> n){
    if(n == 0) break;
    
    int *s = new int[n];

    cin >> s[0];
    maxn = minn = 0;
    for(int i = 1; i<n ; ++i){
      cin >> s[i];

      if(s[maxn]  <= s[i]){
	maxn = i;
      }
      if(s[minn] >= s[i]){
	minn = i;
      }

      
    }

    for(int i=0; i<n ; ++i){
      if(i != maxn && i != minn){
	sum += s[i];
      }
    }


    
    ave = sum/(n - 2);

    cout << ave << endl;

    sum = 0;
    ave = 0;
    
    delete[] s;
  }
  
  
  return 0;
}



Measured memory_bytes: 3088
from scipy.special import comb
S = int(input())
MOD = 10**9+7


N = S // 3
ans = 0

for i in range(1,N+1):
    amari = S - 3 * i
    ans += comb(i+amari-1, amari, exact=True) % MOD
    #print(i,ans,amari)

print(ans % MOD)

Measured memory_bytes: 42300
N = int(input())
S = list(map(int,input().split(" ")))
Ss = sum(S)

ans = []
for i in range(N):
  Ss_flont = sum(S[0:i:])
  Ss_back  = Ss - Ss_flont
  ans.append(abs(Ss_flont - Ss_back))

print(min(ans))
  

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

int main()
{
    int a,b;
    cin >> a >> b;

    if(a == 1) a += 13;
    if(b == 1) b += 13;

    if(a > b) cout << "Alice";
    else if (a < b) cout << "Bob";
    else cout << "Draw";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import sys; readline = sys.stdin.readline
from collections import deque

N = int(readline())
S = readline().rstrip()

e1, e2, e3 = set([]), set([]), set([])

for i in range(N):
    for s2 in e2:
        e3.add(s2 + S[i])
    
    for s1 in e1:
        e2.add(s1 + S[i])

    e1.add(S[i])

print(len(e3))

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

int main() {
    //エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0;
    is_prime[1] = 0;
    for(int i = 2; i < MAX; ++i) {
        if(!is_prime[i]) continue;
        for(int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }
    //
    vector<int> a(MAX, 0);
    for(int i = 0; i < MAX; ++i) {
        if(i % 2 == 0) continue;
        if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    //累積和
    vector<int> s(MAX+1, 0);
    for(int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];
    //クエリ処理
    int Q;
    cin >> Q;
    for(int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;
        
        cout << s[r] - s[l] << endl;
    }
}


Measured memory_bytes: 1792