akhauriyash/Code-Regression huggingface dataset:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    d = [0] * 60
    for a in A:
        b = 0
        while a:
            if a&1: d[b] += 1
            a >>= 1
            b += 1

    ans = Mint()
    for i in range(60):
        ans += Mint(d[i]) * (N-d[i]) * (1<<i)
    print(ans)

class Mint:
    def __init__(self, value=0, mod=10**9+7):
        self.value = ((value % mod) + mod) % mod
        self.mod = mod

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, self.mod
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        return (u + self.mod) % self.mod

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.val
    def __neg__(self): return Mint(-self.value, self.mod)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % self.mod
        return self
    def __add__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % self.mod
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other, self.mod)
        self *= other.inverse
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()

Measured memory_bytes: 123148
#include <stdio.h>
#include <string.h>

typedef struct {
  char card[36][3];
}Record;



Record Bubble(Record, int);
Record Select(Record, int);
int Stable(Record, Record, int);

int main () {
  int i, j, n = 0, h =0;
  Record data, bub, sel;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
      scanf("%s",&data.card[i]);
  }


  
  bub = Bubble(data, n);
   for(i = 0 ; i < n ; i++) {
    if(i == n - 1) printf("%s\n",bub.card[i]);
    else printf("%s ",bub.card[i]);
  }
  printf("Stable\n");

  
  sel = Select(data, n);
  for(i = 0 ; i < n ; i++) {
    if(i == n - 1) printf("%s\n",sel.card[i]);
    else printf("%s ",sel.card[i]);
  }

  if(Stable(bub, sel, n) == 1) printf("Stable\n");
    else printf("Not stable\n"); 
  
  return 0;
}


Record Bubble(Record data, int n) {
  int i, j;
  char c[3];

  for(i = 0 ; i < n ; i++) {
    for(j = n - 1 ; j >= i + 1 ; j--) {
      if(atoi(&data.card[j][1]) < atoi(&data.card[j-1][1])) {
	strcpy(c, data.card[j]);
	strcpy(data.card[j], data.card[j-1]);
	strcpy(data.card[j-1], c);
      }
    }
  }
  return data;
}



Record Select(Record data, int n) {
  int i, j, min = 0;
  char c[3];
  
  for(i = 0 ; i < n ; i++) {
    min = i;

    for(j = i ; j < n ; j++) {
      if(atoi(&data.card[j][1]) < atoi(&data.card[min][1])) min = j;
    }
    strcpy(c, data.card[i]);
    strcpy(data.card[i], data.card[min]);
    strcpy(data.card[min], c);
  }
  
  return data;
}


int Stable(Record data, Record str, int n) {
  int i;

  for(i = 0 ; i < n ; i++) {
    if(strcmp(data.card[i], str.card[i]) != 0) return 0;
  }

  return 1;

}



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

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll; 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

vector<pair<long long, long long> > prime_factorize(long long N) {
	vector<pair<long long, long long> > res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; // 指数

		// 割れる限り割り続ける
		while (N % a == 0) {
			++ex;
			N /= a;
		}

		// その結果を push
		res.push_back({ a, ex });
	}

	// 最後に残った数について
	if (N != 1) res.push_back({ N, 1 });
	return res;
}


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

	ll n;
	cin >> n;
	vector<pair<ll,ll>> sosu;
	ll ans = 0;
	ll now = 1;
	
	sosu = prime_factorize(n);

	for (int j = 1; j <= 70; j++)
	{
		for (int i = 0; i < sosu.size(); i++)
		{
			if (sosu[i].second >= j)
			{
				sosu[i].second -= j;
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int mi = N+1, res = 0;
    for (int i = 0; i < N; ++i) {
        int p; cin >> p;
        if (mi >= p) ++res;
        mi = min(mi, p);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<set>
#include<sstream>
#include<string>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i )

int n, k;
int card[10];

std::string intToStr( int n )
{
	std::ostringstream oss;
	oss << n;

	return oss.str();
}

int main()
{
	while( scanf( "%d%d", &n, &k ), n|k )
	{
		rep( i, n )
			scanf( "%d", card+i );

		int comb = (1<<k)-1;
		std::set<std::string> s;
	
		while( comb < 1<<n )
		{
			std::vector<int> v;
			rep( i, n )
				if( comb >> i & 1 )
					v.push_back( i );

			do
			{
				std::string str;
				rep( i, k )
					str += intToStr( card[v[i]] );
				s.insert( str );
			}while( std::next_permutation( v.begin(), v.end() ) );

			int x = comb & -comb, y = comb + x;
			comb = ( (comb & ~y) / x >> 1 ) | y;
		}

		printf( "%d\n", s.size() );
	}

	return 0;
}

Measured memory_bytes: 1516
N=int(input())
D=[list(map(int,input().split())) for i in range(N)]
m=0
x=0
for d,d2 in D:
    if d==d2:
        x+=1
    else:
        m=max(m,x)
        x=0
m=max(m,x)
print(['No','Yes'][m>=3])

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

int main() {
    
    long long dp[100];
    dp[0] = 2; dp[1] = 1;
    for (int i=2; i<100; i++) dp[i] = dp[i-1] + dp[i-2];
    int x;
    cin >> x;
    cout << dp[x] << endl;
    
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    S = input()
    T = input()
    reslut = 'No'
    for s in S:
        if S == T:
            reslut = 'Yes'
            break
        else:
            S = S[-1] + S[:-1]
    print(reslut)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
int a[1111], b[1111];
int cnt[1000010];
const int mod = 1000'000'000 + 7;

int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d", &n, &m);
	
	set <int> s;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if(s.find(a[i]) == s.end()) s.insert(a[i]);
		else {
			printf("0\n");
			exit(0);
		}
		cnt[a[i]] += 1;
	}
	s.clear();
	for(int i = 1; i <= m; i++) {
		scanf("%d", &b[i]);
		if(s.find(b[i]) == s.end()) s.insert(b[i]);
		else {
			printf("0\n");
			exit(0);
		}
		cnt[b[i]] += 2;
	}

	int tot = 0;
	int row = 0;
	int col = 0;
	long long ans = 1;
	for(int i = n*m; i >= 1; i--) {
		if(cnt[i] == 1) {
			ans *= col;
			row += 1;
		} else if (cnt[i] == 2) {
			ans *= row;
			col += 1;
		} else if (cnt[i] == 3){
			row += 1;
			col += 1;
		} else {
			ans *= (row * col - tot);
		}
		ans %= mod;
		++tot;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.util.Map.Entry;


import java.io.*;

public class Main{
	static int mod;
	static long dp1[];
	static long dp2[];
	static ArrayList<Integer> g[];

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		mod = scn.nextInt();
		dp1 = new long[n + 1];
		dp2 = new long[n + 1];
		g = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
			int x = scn.nextInt() - 1;
			int y = scn.nextInt() - 1;
			g[x].add(y);
			g[y].add(x);
		}
		solve(0, -1);
		solve2(0, -1, 0L);
		for (int i = 0; i < n; i++) {
			System.out.println(dp2[i]);
		}

	}

	private static void solve2(int sr, int pa, long pa_ans) {
		dp2[sr] = ((1 + pa_ans) * dp1[sr]) % mod;
		long pf[] = new long[g[sr].size()+((sr==0)?1:0)];
		long sf[] = new long[g[sr].size()+((sr==0)?1:0)];
		pf[0] = 1;
		sf[sf.length-1] = 1;
		int x = 1;
		for (int i = 0; i < g[sr].size(); i++) {
			int nei = g[sr].get(i);
			if (sr==0 ||nei != pa) {
				pf[x] = ((dp1[nei] + 1) * pf[x - 1]) % mod;
				x++;
			}

		}
		x = sf.length - 2;
		for (int i = g[sr].size()-1; i >= 0; i--) {
			int nei = g[sr].get(i);
			if (nei != pa || sr==0) {
				sf[x] = ((dp1[nei] + 1) * sf[x + 1]) % mod;
				x--;
			}
		}

		
		x = 1;
		for (int i = 0; i < g[sr].size(); i++) {
			int nei = g[sr].get(i);
			if (nei != pa) {
				long ways = pa_ans + 1;
				ways = (ways * ((x > 0) ? pf[x - 1] : 1)) % mod;
				ways = (ways * ((x <sf.length) ? sf[x] : 1)) % mod;
				solve2(nei, sr, ways);
				x++;
			}
		}

	}

	private static long solve(int sr, int pa) {
		long ans = 1;
		for (int nei : g[sr]) {
			if (nei != pa) {
				ans = (ans * (1 + solve(nei, sr))) % mod;
			}
		}
		dp1[sr] = ans % mod;
		return ans;
	}

}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////

string S;
ll i, j, k;

int main(){
    cin >> S;
    cout << S + (S[S.length() - 1] == 's' ? "es" : "s") << endl;
    return 0;
}

Measured memory_bytes: 3592
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll T;
    cin >> T;
    vector<ll> N(T), D(T);
    for (ll i = 0; i < T; i++) {
        cin >> N[i] >> D[i];
        cout << 127 * (N[i] - 1) + (N[i] % 2 ? D[i] : 127 - D[i]) << endl;
    }
}

Measured memory_bytes: 256
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."						*/
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define ld double 
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define deb cerr << "Line no." << __LINE__
#define nl '\n'
#define pb push_back
#define all(a) a.begin(),a.end()
#define P pair<ll,ll> 
#define F first
#define S second
const ll p_mod=9999999999999983;
const long double pi = 3.14159265358979323;
const ll N=1e6+9;
const ll mod=1e9+7;
typedef double f80;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){uniform_int_distribution<int> uid(l, r); return uid(rng); }
ll powerk(ll x, ll y);

ll a[N],dp[N];

void solve()
{    
	ll n,m;
	cin>>n>>m;
	rep(i,1,n)cin>>a[i];
	dp[1]=0;
	rep(i,2,n)
	{
		dp[i] = dp[i-1]+abs(a[i]-a[i-1]);
		repd(j,i-1,max(i-m,(ll)1))
		{
			dp[i] = min(dp[i] ,dp[j]+ abs(a[i]-a[j]));
		}
		//cout<<dp[i]<<" ";
	}

	cout<<dp[n];
}


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}
ll powerk(ll x, ll y)
{
  if(y==0)return 1;
  if(y==1)return x%mod;
  if(y&1)
    return ((powerk((x*x)%mod, y/2)%mod)*x)%mod;
  else return powerk((x*x)%mod,y/2)%mod;
}

// Xorawar

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

int main() {
    int i,h,m,s;
    cin >> i;
    h = floor(i / 3600);
    m = floor((i - h * 3600)/60);
    s = i - h * 3600 - m * 60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/


ll n;
int main(){FAST;
cin>>n;
ll mx = 0;
ll ans = 0;
for(ll i=0;i<n;++i){
  ll x;cin>>x;
  mx = max(mx,x);
  ans+=mx-x;
}
cout<<ans;
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod 1000000007
#define pi 3.14159265358979323
using namespace std;
int a[200005],b[200005];

int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    int c1 = 1;
    int c2 = n;
    for(int i=n;i>=1;i--)
    {
        if(n%2 == i%2)
            b[c1++] = a[i];
        else
            b[c2--] = a[i];
    }
        for(int i=1;i<=n;i++)
            cout << b[i] << " ";



    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll n;
cin>>n;
cout<<"ABC";
cout<<n<<endl;
}









Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    for(int i=sy+1;i<=ty;i++) 
		cout<<"U";
    for(int i=sx+1;i<=tx;i++) 
		cout<<"R";
    for(int i=ty-1;i>=sy;i--) 
		cout<<"D";
    for(int i=tx-1;i>=sx;i--) 
		cout<<"L";
    cout<<"L";
    for(int i=sy;i<=ty;i++) 
		cout<<"U";
    for(int i=sx;i<=tx;i++) 
		cout<<"R";
    cout<<"DR";
    for(int i=ty;i>=sy;i--) 
		cout<<"D";
    for(int i=tx;i>=sx;i--) 
		cout<<"L";
    cout<<"U"<<endl;
	return 0;
} 

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

int main() {
    int n;
    cin >> n;
    map<pair<string, int>, int> mp;
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        mp[make_pair(s, -p)] = i + 1;
    }
    for(pair<pair<string, int>, int> pr : mp) cout << pr.second << endl;
}

Measured memory_bytes: 256
let rec f c s =
  try let _ = String.index s (char_of_int c) in f (c+1) s
  with _ -> char_of_int c
let _ = Scanf.scanf "%s" @@ fun s ->
  let l = String.length s in
  let rec g i = if s.[i-1] < s.[i] then i-1 else g (i-1) in
  let rec h t c i = if i >= l then c else
    if t >= s.[i] then h t c (i+1) else h t (min c s.[i]) (i+1) in
  if s = "zyxwvutsrqponmlkjihgfedcba" then print_endline "-1"
  else if l < 26 then
    Printf.printf "%s%c\n" s (f 97 s)
  else
    let j = g (l-1) in
    Printf.printf "%s%c\n" (String.sub s 0 j) (h s.[j] 'z' (j+1))


Measured memory_bytes: 384
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Data.Char

solve1 :: Int -> [(Int, Int, Int)] -> Int
solve1 t [] = t
solve1 t ((c, s, f):xs)
    | t < s          = solve1 (s + c) xs
    | t `mod` f == 0 = solve1 (t + c) xs
    | otherwise      = solve1 (k + c) xs
  where
    k = t + f - (t `mod` f)

main :: IO ()
main = do
    n <- readLn
    csf <- replicateM (n - 1) $ do
        [c, s, f] <- fmap read . words <$> getLine :: IO [Int]
        return (c, s, f)
    let qs = init $ tails csf
    forM_ qs $ \xs -> do
        print $ solve1 0 xs
    print 0

Measured memory_bytes: 1276
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char A[110];
char B[110];
char C[110];

int main(){
	int n;scanf("%d",&n);
	scanf("%s%s%s",A,B,C);
	int ret=0;
	for(int i=0;A[i];i++){
		if(A[i]==B[i]&&B[i]==C[i])continue;
		if(A[i]==B[i]||A[i]==C[i]||C[i]==B[i])ret++;
		else ret+=2;
	}printf("%d\n",ret);

}

Measured memory_bytes: 128
N=int(input())
l=list(map(int,input().split()))
sum_n=sum(l)
first=sum_n-(2*sum([l[i] for i in range(1,N,2)]))
ans=[first]
for i in range(N-1):
   ans.append(2*l[i]-ans[-1])
print(*ans)

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    ll x, k, d;
    cin >> x >> k >> d;

    ll ans;
    x = abs(x);

    if(x/d >= k) {
        ans = x - k*d;
    } else {
        ll cnt = x/d;
        ll diff1 = abs(x - cnt * d);
        ll diff2 = abs(x - (cnt+1) * d);
        if(diff1 < diff2 || k < cnt+1) {
            k -= cnt;
            if(k % 2 == 0) {
                ans = diff1;
            } else {
                ans = diff2;
            }
        } else {
            k -= cnt+1;
            if(k % 2 == 0) {
                ans = diff2;
            } else {
                ans = diff1;
            }
        }
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/




Measured memory_bytes: 3624
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std; 

int64_t
gcd(int64_t a, int64_t b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int
main(int argc, char const *argv[])
{
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    vector<int64_t> pre(n);
    vector<int64_t> post(n);

    for (int64_t i = 0; i < n; ++i) {
	cin >> a[i];
    }

    for (int64_t i = 0; i < n; ++i) {
	if (i == 0) {
	    pre[i] = a[i];
	} else {
	    pre[i] = gcd(pre[i-1], a[i]);
	}
    }

    for (int64_t i = n-1; i >= 0; --i) {
	if (i == (n-1)) {
	    post[i] = a[i];
	} else {
	    post[i] = gcd(post[i+1], a[i]);
	}
    }

    int64_t res = 0;
    int64_t tmp;
    
    for (int64_t i = 0; i < n; ++i) {
	if (i == 0) {
	    tmp = post[1];
	} else if (i == (n - 1)) {
	    tmp = pre[n-2];
	} else {
	    tmp = gcd(pre[i-1], post[i+1]);
	}
	if (tmp > res) res = tmp;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)

using namespace std;
const int N = 1e5 + 5, MI = 1e6;
typedef long long ll;
int read() {
	static streambuf* in = cin.rdbuf();
	#define gc (p1 == p2 && (p2 = (p1 = buf) + in -> sgetn(buf, MI), p1 == p2) ? -1 : *p1++)
	static char buf[MI], *p1, *p2;
	int c = gc, r = 0;
	while(c < 48) c = gc;
	while(c > 47) r = (r << 3) + (r << 1) + (c & 15), c = gc;
	return r;
}
int n, q, tot, A[N], B[N]; ll m;
int cnt, fa[N], vis[N]; ll ml, mr;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
	#ifdef local
		freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> q;
	per(i, cnt = n, 0) fa[i] = i;
	while(q--) {
		int u = read(), v = read(), op = read();
		if(op) A[++tot] = u, B[tot] = v;
		else if((u = find(u)) ^ (v = find(v)))
			fa[u] = v, cnt--, m--;
	}
	rep(i, 1, tot) if(find(A[i]) == find(B[i]))
		return puts("No"), 0;
	if(tot && cnt == 2) return puts("No"), 0;
	mr = cnt * (cnt - 1LL) / 2;
	if(tot == 1) cnt -= 2;
	else if(tot) {
		rep(i, 1, tot) if(find(A[i]) ^ find(B[i])) {
			if(!vis[fa[A[i]]]) ml++, cnt--, vis[fa[A[i]]] = 1;
			if(!vis[fa[B[i]]]) ml++, cnt--, vis[fa[B[i]]] = 1;
		}
		cnt++;
	}
	return puts(ml + cnt - 1 <= m && m <= mr ? "Yes" : "No"), 0;
}

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

from collections import defaultdict
E = []

for i in range(M):
  a,b,c = map(int, input().split())
  a,b = a-1, b-1
  E += [(a,b,c)]

def reachable_vertices(neighbor, s):
  V = set()
  V.add(s)
  stack=[s]
  while stack:
    v = stack.pop()
    for u in neighbor[v]:
      if u not in V:
        V.add(u)
        stack.append(u)
  return V

def neighbor_dict(E):
  neighbor = defaultdict(list)
  for a,b,c in E:
    neighbor[a].append(b)
  return neighbor

def rev_neighbor_dict(E):
  neighbor = defaultdict(list)
  for a,b,c in E:
    neighbor[b].append(a)
  return neighbor

def degenerate_graph(V, E):
  d = {v:i for i,v in enumerate(sorted(V))}
  return len(V), [(d[a],d[b],c) for a,b,c in E if a in V and b in V]

# only vertices that are reachable from 1 or N
N,E = degenerate_graph(reachable_vertices(neighbor_dict(E), 0), E)
N,E = degenerate_graph(reachable_vertices(rev_neighbor_dict(E), N-1), E)
score = [float('-inf')]*N
score[0] = 0


i = 0
updated=True
while updated:
  if i == N:
    print('inf')
    break

  updated = False
  for a,b,w in E:
    if score[b] < score[a] + w:
      score[b] = score[a] + w
      updated = True
  i += 1
else:
  print(score[N-1])

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

int main(int argc, char const *argv[])
{
	int H,W=0;
	int i,j=0;
	string a,b="";

	while(true){

		cin >> H >> W;
		if((H == 0) && (W == 0))
		{
			break;
		}

		string a,b="";
		for(i=0;i<W;i++){
			if(i%2 == 0){
				a += '#';
			}else{
				a += '.';
			}
		}
		for(i=0;i<W;i++)
		{
			if(i%2 == 1)
			{
				b += '#';
			}
			else
			{
				b += '.';
			}
		}
		
		for(i=0;i<H;i++){
				if (i%2 == 0){
					cout << a << endl;
				}else{
					cout << b << endl;
				}
		}
		cout << endl;

	}
	return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;
int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    if(a%k==0||b%k==0)
    {
        cout<<"OK"<<endl;
    }
    else
    {
        int c=a%k;
        if(b-a+1>k-c)
        {
            cout<<"OK"<<endl;
        }
        else
        {
            cout<<"NG"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
n=int(input())
a=list(map(int,input().split())) 
count=0
for j in range(1,36):
  k=0  
  for i in range(n):
    if a[i]%2==0:
      a[i]=a[i]/2
    else:
      k=k+1
  if k==0:
    count=count+1
  else:
    break
print(count)

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

int main() {
  int N;
  cin >> N;
  int sum1 = 0;
  int sum2 = 0;
  for(int i = 0; i < N; i++) {
    int d;
    cin >> d;
    sum1 += d;
    sum2 += d * d;
  }
  cout << (sum1 * sum1 - sum2) / 2 << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedLists     #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Monad
--import           Control.Monad.Loops
import           Data.IORef
import           Data.Maybe
import qualified Data.Text     as T
import qualified Data.Text.IO  as T
import           GHC.Base
import           System.IO

import qualified Data.Array    as A
import           Data.Char
import qualified Data.IntMap   as I
import           Data.List
import qualified Data.Map      as M
import qualified Data.Set      as S
import qualified Data.Vector   as V

-- for Text
(+.+) = T.append
(!.!) = T.index

-- for Vector
count :: (a -> Bool) -> V.Vector a -> Int
count p = V.length . V.filter p

-- for IO
readT :: Read a => T.Text -> a
readT = read . T.unpack

getLineSpc :: Read a => IO [a]
getLineSpc = do
  t <- T.getLine
  let xs = map readT $ T.split (== ' ') t
  return xs

getLineSpcVec :: Read a => IO (V.Vector a)
getLineSpcVec = do
  t <- T.getLine
  let xs = V.fromList $ map readT $ T.split (== ' ') t
  return xs

----------
-- main --
----------
main :: IO ()
main = twoAnagrams

twoAnagrams :: IO ()
twoAnagrams = do
  s <- getLine
  t <- getLine
  let s' = sort s
      t' = sortBy (flip compare) t
  if s' < t'
    then
    putStrLn "Yes"
    else
    putStrLn "No"


Measured memory_bytes: 508
n,k= map(int,input().split())
l = []
for i in range(n):
  l.append(int(input()))
b = sorted(l)
ans = b[k-1] - b[0]
for i in range(n-k+1):
  ans = min(ans,b[i+k-1] - b[i])
print(ans)

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

int main(void){
	int N,sum=0;
	int L[200];
	cin>>N;
	rep(i,2*N)cin>>L[i];
	sort(L,L+2*N);
	rep(i,N)sum+=L[i*2];
	cout<<sum<<endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n+2] = {};  // a[0] = a[n+1] = 0 
    rep(i,n) cin >> a[i+1];
    int cost_change[n+1];
    for (int i = 1; i < n+1; i++) {
        int pre = abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]);
        int post = abs(a[i+1] - a[i-1]);
        cost_change[i] = post - pre;
    }
    int64_t standard_cost = 0;
    rep(i,n+1) {
        standard_cost += abs(a[i+1] - a[i]);
    }
    for (int i = 1; i < n+1; i++) {
        int64_t cost = standard_cost + cost_change[i];
        cout << cost << endl;
    }
}

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

int main(){
    long long N, A, B;
    cin>>N>>A>>B;
    long long numset = N / (A+B);
    long long numrem = N % (A+B);
    long long k;
    if(A<numrem)    k=A;
    if(A>=numrem)   k=numrem;
    cout<<A*numset + k;
}

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

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N + 1, 0);

  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    v[l]++;
    v[r]--;
  }

  for (int i = 0; i < N; i++) v[i + 1] += v[i];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (v[i] >= M) {
      ans++;
    }
  }

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


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int A = int.Parse(s[0]);
        int B = int.Parse(s[1]);
        int C = int.Parse(s[2]);
        int D = int.Parse(s[3]);
        Console.WriteLine(Math.Max(A * B, C * D));
    }
}


Measured memory_bytes: 11092
local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local n = io.read("*n", "*l")
local s = io.read()
local t = {}
for i = 1, 60 do
  t[i] = {}
end
do
  local j = 0
  for w in s:gmatch("%d+") do
    j = j + 1
    local v = lltonumber(w)
    for k = 1, 60 do
      t[k][j] = v % 2LL == 1LL
      v = v / 2LL
    end
  end
end
local flag = {}
for i = 1, 60 do
  flag[i] = 1
end
local pow2 = {}
pow2[1] = 1LL
for i = 2, 60 do
  pow2[i] = pow2[i - 1] * 2LL
end
local ret = 0LL

for ib = 60, 1, -1 do
  local right = false
  local cnt = 0
  local tib = t[ib]
  for i = 1, n do
    if tib[i] then
      cnt = cnt + 1
      right = i
    end
  end
  if flag[ib] == 1 then
    if cnt == 0 then
      -- nothing
    elseif cnt % 2 == 1 then
      ret = ret + pow2[ib]
    else
      ret = ret + 2LL * pow2[ib]
      for ic = ib - 1, 1, -1 do
        if t[ic][right] then
          flag[ic] = 1 - flag[ic]
          for i = 1, n do
            if tib[i] then
              t[ic][i] = not t[ic][i]
            end
          end
        end
      end
    end
  else--flag[ib] == 0
    if cnt == 0 then
      ret = ret + 2LL * pow2[ib]
      -- nothing
    elseif cnt % 2 == 1 then
      ret = ret + pow2[ib]
    else
      ret = ret + 2LL * pow2[ib]
      for ic = ib - 1, 1, -1 do
        if t[ic][right] then
          for i = 1, n do
            if tib[i] then
              t[ic][i] = not t[ic][i]
            end
          end
        end
      end
    end
  end
end
ret = tostring(ret):gsub("LL", "")
print(ret)


Measured memory_bytes: 135060
N = int(input())
A = list(map(int,input().split()))
ans=0
for i in range(N):
    if A[i] % 2 == 0:
        if (A[i] % 3) * (A[i] % 5) != 0:
            ans += 1

print("DENIED" if ans >= 1 else "APPROVED")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	vector<ll> A(N, 0LL);
	rep (i, N) cin >> A[i];
	
	ll res = 0LL;
	res += A[0] / 2LL;
	A[0] %= 2LL;

	for (int i = 1; i < N; ++i){
		if (A[i] > 0LL){
			if (A[i-1] == 1LL){
				res += 1LL;
				--A[i];
			} // end if
			res += A[i] / 2LL;
			A[i] %= 2LL;
		} // end if
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int n; cin >> n;
	vector<int> v(n);
	vector<vector<int>> d(n, vector<int>(20, -1));
	rep(i, n) cin >> v[i];
	int l; cin >> l;
	rep(i, n) d[i][0] = upper_bound(v.begin(), v.end(), v[i]+l) - v.begin() -1;
	rep(i, 19) rep(j, n) d[j][i+1] = d[d[j][i]][i];

	int q; cin >> q;
	rep(i, 	q){
		int a, b, ans = 0; cin >> a >> b; a--; b--;
		if(a > b) swap(a, b);
		while(a < b){
			int p = lower_bound(d[a].begin(), d[a].end(), b) - d[a].begin();
			if(d[a][p] >= b && p == 0){
				ans += 1<<p;
				break;
			}else{
				ans += 1<<(p-1);
				a = d[a][p-1];
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 12928
import queue
import copy
import math
from collections import deque
import bisect
from decimal import Decimal

# そのまま入力文字列の入力
n, k = map(int, input().split())

s = set()

# 空白区切りの数値をリスト化
for i in range(0, 2 * k):
    if i % 2 == 0:
        d = int(input())
        continue
    l = input().split()
    for v in l:
        s.add(v)

print(n-len(s))


Measured memory_bytes: 10188
n,d = map(int,input().split())
dl = []

for x in range(n):
    dd = []
    d1,d2 = map(int,input().split())
    dd.append(d1)
    dd.append(d2)
    dl.append(dd)

count = 0
for dd in dl:
    if (dd[0]**2 + dd[1]**2) <= d**2:
        count += 1
    
print(count)

Measured memory_bytes: 42256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string a;
  string b;
  int n;
  cin>>n;
  cin>>a;
  cin>>b;
  string s="";
  
 for(int i=0;i<n;i++)
 {
   s=s+a[i];
   s=s+b[i];
   
 }
  cout<<s;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int N=5e5+5;
int n,l,r;
double ans,ll,v,d[N][2];
void merge(int x)
{
	d[x][0]=(d[x][0]*d[x][1]+d[x+1][0]*d[x+1][1])/(d[x][1]+d[x+1][1]);
	d[x][1]+=d[x+1][1];
}
int main()
{
	scanf("%d%lf",&n,&ll),l=1;
	for (int i=1;i<=n;i++)
	{
		r++,scanf("%lf%lf",&d[r][0],&d[r][1]);
		v+=d[r][1],ans+=d[r][0]*d[r][1];
		while (v>ll)
		{
			if (v-d[l][1]>=ll)
			{
				v-=d[l][1];
				ans-=d[l][0]*d[l][1];
				l++;
			}
			else
			{
				d[l][1]-=v-ll;
				ans-=(v-ll)*d[l][0];
				v=ll;
			}
		}
		while (r>l && d[r][0]<=d[r-1][0]) merge(--r);
		printf("%lf\n",ans/ll);
	}
	return 0;
}


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

const int N = 510, P = 1e9 + 7;
inline int mpow(int a, int b) {
    int ans = 1;
    for (; b; b >>= 1, a = (ll) a * a % P)
        if (b & 1) ans = (ll) ans * a % P;
    return ans;
}
inline void upd(int &x, int y) { x = x + y - P; x += x >> 31 & P; }

int fac[N], ifac[N];

void genfac(int n) {
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = (ll) fac[i - 1] * i % P;
    ifac[n] = mpow(fac[n], P - 2);
    for (int i = n - 1; i >= 0; --i) ifac[i] = (ll) ifac[i + 1] * (i + 1) % P;
}

int n, X, l[N], cnt[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    genfac(501);
    cin >> n >> X;
    for (int i = 1; i <= n; ++i) {
        cin >> l[i];
        ++cnt[l[i]];
    }
    ++X;
    vector<vector<int>> dp(X + 1, vector<int>(X + 1, 0));
    dp[0][0] = 1;
    for (int len = X; len >= 1; --len) {
        vector<vector<int>> new_dp(X + 1, vector<int>(X + 1, 0));
        for (int c = 0; c <= X; ++c)
            for (int x = 0; x <= X; ++x) if (dp[c][x] != 0) {
                // cerr << "FF (" << c << ',' << x << ")\n";
                for (int i = 0; x + i * len <= X && c + i <= X; ++i) {
                    // cerr << "(" << c << ',' << x << ") -> " << "(" << c + i << ',' << x + i * len << ")\n";
                    upd(new_dp[c + i][x + i * len], (ll) dp[c][x] * ifac[i] % P);
                }
            }
        for (int c = 0; c <= X; ++c)
            for (int x = X; x >= c * len; --x)
                new_dp[c][x] = (ll) new_dp[c][x] * mpow(x - c * len, cnt[len]) % P;
        swap(dp, new_dp);
        /*
        for (int c = 0; c <= X; ++c) {
            for (int x = 0; x <= X; ++x) {
                cerr << dp[c][x] << " ";
            }
            cerr << '\n';
        }
        */
    }
    int ans = 0, coeff = 1;
    for (int i = 1; i <= X; ++i) {
        // cerr << (ll) fac[i] * dp[i][X] % P << '\n';
        upd(ans, (ll) fac[i] * coeff % P * dp[i][X] % P);
        coeff = P - coeff;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5288
#include<iostream>
using namespace std;
 
class Cube{
public:
 int f[6];
 Cube(){}
 void roll_z(){
   roll(1,2,4,3);
 }
 void roll_y(){
   roll(0,2,5,3);
 }
 void roll_x(){
   roll(0,1,5,4);
 }
 void roll(int i, int j, int k, int l){
  int t=f[i];
  f[i]=f[j];
  f[j]=f[k];
  f[k]=f[l];
  f[l]=t;
 }
};
 
bool eq(Cube c1,Cube c2){
 for(int i=0;i<6;i++)
  if(c1.f[i]!=c2.f[i]) return false;
 return true;
}
 
bool equal(Cube c1,Cube c2){
 for(int i=0;i<6;i++){
  for(int j=0;j<4;j++){
   if(eq(c1,c2)) return true;
   c1.roll_z();
  }
  if(i%2==0)c1.roll_y();
  else c1.roll_x();
 }
 return false;
}
 
Cube C[100]; int n;
 
bool check(){
 for(int i=0;i<n-1;i++)
  for(int j=i+1;j<n;j++) if(equal(C[i],C[j])) return false;
 return true;
}
 
int main(){
 cin >>n;
  for(int j=0;j<n;j++)
   for(int i=0;i<6;i++) cin >> C[j].f[i];
 
 if(check()) cout << "Yes" << endl;
 else cout << "No" << endl;
}

Measured memory_bytes: 3092
<?php
  list($n, $a, $b) = explode(" ", fgets(STDIN));

  $m = 1000000007;

  // 全体
  $all_pattern = repeatSqrt(2, $n, $m);
  // １を引く
  $all_pattern -= 1;
  // nCaを求める
  $all_pattern = ($all_pattern + $m - combination($n, $a, $m)) % $m;
  // nCbを求める
  $all_pattern = ($all_pattern + $m - combination($n, $b, $m)) % $m;

echo $all_pattern;
exit;

/**
 * 繰り返し二乗法
 * @param $n 
 * @param $p
 * @param $m mod P
 * @param $a 
 */
function repeatSqrt($b, $p, $m){
  if($p==1)
  {
    return $b;
  }
  else if($p%2 == 0)
  {
    $t = repeatSqrt($b, floor($p/2), $m);
    return ($t * $t) % $m;
  }
  else
  {
    return ($b * repeatSqrt($b, $p-1, $m)) % $m;
  }
}


function combination($n, $a, $m)
{
    $x=1; // bunbo
    $y=1; // bunshi
    for($i=0;$i<$a;$i++)
    {
        $x=$x*($n-$i)%$m;
        $y=$y*($i+1)%$m;
    }
    $y=repeatSqrt($y, $m-2, $m);
    return ($x*$y)%$m;
}


Measured memory_bytes: 3576
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        Integer[] red = new Integer[a];
        Integer[] green = new Integer[b];
        Integer[] noc = new Integer[c];

        for (int i = 0; i < a; i++) {
            red[i] = scan.nextInt();
        }

        for (int i = 0; i < b; i++) {
            green[i] = scan.nextInt();
        }

        for (int i = 0; i < c; i++) {
            noc[i] = scan.nextInt();
        }

        Arrays.sort(red, Collections.reverseOrder());
        Arrays.sort(green, Collections.reverseOrder());
        Arrays.sort(noc, Collections.reverseOrder());
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < Math.min(x, a); i++) {
            result.add(red[i]);
        }

        for (int i = 0; i < Math.min(b, y); i++) {
            result.add(green[i]);
        }

        for (int i = 0; i < noc.length; i++) {
            result.add(noc[i]);
        }

        result.sort(Collections.reverseOrder());

        int t = x + y;
        long sum = 0;
        for (int i = 0; i < t; i++) {
            sum += result.get(i);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 102496
N = int(input())
a = list(map(int, input().split()))

i = 0
odd = 0
while odd == 0:
    for n in range(N):
        if a[n] % 2 == 0:
            a[n] /= 2
        else:
            odd = 1
            break
    if odd == 0:
        i += 1
print(i)

Measured memory_bytes: 2940
import scala.collection.mutable.ListBuffer
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val S = in.next
  val Q = in.nextInt
  val pattern = "2 (.) (.)".r
  val (s, rev) = (1 to Q).foldLeft((ListBuffer(S: _*), false)){case ((s, rev), i) =>
    in.nextInt match {
      case 1 => (s, !rev)
      case _ =>
        val f = in.nextInt
        val c = in.next.charAt(0)
        // val next = if ((f == 1 && !rev) || (f == 2 && rev)) s.prepend(c) else s.append(c)
        if ((f == 1 && !rev) || (f == 2 && rev)) s.prepend(c) else s.append(c)
        (s, rev)
    }
  }

  println((if (rev) s.reverse else s).mkString)
}

Measured memory_bytes: 132248
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  pair<pair<string,int>,int> memo[n];
  for(int i=0;i<n;i++){
    string s;
    int p;
    cin>>s>>p;
    memo[i]=make_pair(make_pair(s,-p),i+1);
  }
  sort(memo,memo+n);
  for(int i=0;i<n;i++){
    cout<<memo[i].second<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
var sub_fn = (ary)=>{
  
}
reader.on('close', () => {
  var x = 1*lines[0].split(' ')[0]
  var y = 1*lines[0].split(' ')[1]
  var cnt = [];
  if(x > y && x != y){
    console.log("No")
  }else{
  console.log("Yes")}

  
});


Measured memory_bytes: 7628
import math

Manhattan = 0
Euclid = 0
Three = 0
Chebychev = []
num = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))

# ???????????????????????¢
for i in range(num):
	Manhattan += math.fabs(x[i] - y[i]) 
	Euclid += math.fabs((x[i] - y[i])**2)
	Three += math.fabs((x[i] - y[i])**3)
	Chebychev.append(math.fabs((x[i] - y[i])))

print(Manhattan)
print(math.sqrt(Euclid))
print(math.pow(Three,1/3))
print(max(Chebychev))

Measured memory_bytes: 7824
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
#define ll long long

int main(){
        int A,B;
        cin >> A >> B;
        if(A+B==15) {
                cout << '+' << endl;
        }else if(A*B==15) {
                cout << '*' << endl;

        }else{
                cout << 'x' << endl;

        }



        return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];

    sort(all(v));

    cout << v.back() - v.front() << endl;



    return 0;
}


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

int f(ll a,ll b){
    int ca=0,cb=0;
    while(a){
        ca++;
        a/=10;
    }
    while(b){
        cb++;
        b/=10;
    }
    return max(ca,cb);
}

int main(){

    ll n;
    cin >> n;

    int ans=10;

    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ll t=n/i;
            ans=min(ans,f(i,t));
        }
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256