akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}
 
int par[100000];
void init(int n){
	rep(i,n){
		par[i]=i;
	}
}
 
int root(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x] = root(par[x]);
	}
}
 
void unite(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y)return;
	par[x]=y;
}
 
 
 
struct a{
	ll a;
	int num;
	int par;
	bool use;
};
 
bool operator< (const a& left,const a& right){
        return left.a < right.a;
}

/*
rep(i,n){
	cin>>aa[i].a;
	aa[i].num=i;
}*/
 
 
 
int main(void){
	int a,b;
	cin >> a >> b;
	if(b%a == 0){
		cout<<a+b<<endl;
	}else{
		cout<<b-a<<endl;
	}
	
 
	return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int64_t A[100000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		in >> A[i];
	}

	std::sort(A, A + N);

	if (N & 1)
	{
		int n1 = N / 2;
		int n2 = n1 + 1;

		int64_t res = 0;
		int64_t tmp = 0;
		tmp -= A[n2 - 1];
		tmp -= A[n2 - 2];
		for (int32_t i = 0; i < n2-2; i++)
		{
			tmp -= A[i]*2;
		}
		for (int32_t i = n2; i < N; i++)
		{
			tmp += A[i] * 2;
		}
		res = std::max(res, tmp);


		tmp = 0;
		for (int32_t i = 0; i < n1; i++)
		{
			tmp -= A[i] * 2;
		}
		tmp += A[n1];
		tmp += A[n1 +1];
		for (int32_t i = n1+2; i < N; i++)
		{
			tmp += A[i] * 2;
		}
		res = std::max(res, tmp);
		out << res << endl;
	}
	else
	{
		int64_t res = 0;
		int64_t tmp = 0;
		tmp = 0;
		for (int32_t i = 0; i < N / 2-1; i++)
		{
			tmp -= A[i] * 2;
		}
		tmp -= A[N / 2 - 1];
		tmp += A[N / 2];
		for (int32_t i = N / 2+1; i < N; i++)
		{
			tmp += A[i] * 2;
		}
		res = std::max(res, tmp);
		out << res << endl;
	}


	return 0;
}
#endif


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

const long long MOD=998244353;

int main(){
  int N,S; cin >> N >> S;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i];
  
  vector<vector<long long>> dp(N+1,vector<long long>(S+1,0));
  dp[0][0]=1;
  for(int i=0; i<N; i++){
    dp[0][0]=(dp[0][0]*2)%MOD;
  }
  
  for(int i=0; i<N; i++){
    for(int j=0; j<=S; j++){
      dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
      if(j+A[i]<=S){
        if(dp[i][j]%2==0){
          dp[i+1][j+A[i]] = (dp[i+1][j+A[i]]+dp[i][j]/2)%MOD;
        }else{
          dp[i+1][j+A[i]] = (dp[i+1][j+A[i]]+(dp[i][j]+MOD)/2)%MOD;
        }
      }
    }
  }
  
  cout << dp[N][S] << endl;
}

Measured memory_bytes: 73656
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int N;
	cin >> N;
	vi A(N);
	vector<ll> sum(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
		sum[i] = (i ? sum[i - 1] : 0) + A[i];
	}

	ll ans = 1e15;
	int l = 1, r = 3;
	for (int i = 1; i < N - 2; i++) {
		while (l < i && sum[l] <= sum[i] - sum[l]) {
			l++;
		}
		while (r < N - 1 && sum[r] - sum[i] <= sum[N - 1] - sum[r]) {
			r++;
		}
		if (sum[l] - (sum[i] - sum[l]) < sum[i] - sum[l - 1] - sum[l - 1]) {
			l++;
		}
		if (sum[r] - sum[i] - (sum[N - 1] - sum[r]) < sum[N - 1] - sum[r - 1] - (sum[r - 1] - sum[i])) {
			r++;
		}
		ll P = sum[l - 1], Q = sum[i] - sum[l - 1], R = sum[r - 1] - sum[i], S = sum[N - 1] - sum[r - 1];
		ll _max = max({ P, Q, R, S });
		ll _min = min({ P, Q, R, S });
		ans = min(ans, _max - _min);
	}


	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int research(int n, int s, int v, int t)
{
	if(n == 0 && v == s){
		return 1;
	}
	if(v > s || n < 0){
		return 0;
	}
	int c = 0;
	for(int i = t+1; i <= 9; i++){
		c += research(n-1, s, i+v, i);
	}
	
	return c;
}

int main()
{
	int n, s, c;
	
	while(1){
		cin >> n >> s;
		if(n == 0 && s == 0){
			break;
		}

		c = 0;
		for(int i = 0; i <= 9; i++){
			c += research(n-1, s, i, i);
		}
		
		cout << c << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

int masu[10][10] = {0};

int dp[10] = {0};

void dykstra(int i){

    priority_queue<int, vector<int>> pq;
    rep(i, 10) dp[i] = MOD; // enough large
    dp[1] = 0;

    pq.push(i);
    while(!pq.empty()){
        int p = pq.top(); pq.pop();
        rep(i, 10){
            if (p == i) continue;
            if (dp[i] > dp[p] + masu[i][p]){
                pq.push(i);
                dp[i] = dp[p] + masu[i][p];
            }
        }
    }    
}


int main()
{
    int h, w;
    cin >> h >> w;

    rep(i, 10)rep(j, 10){
        cin >> masu[i][j];
    }

    dykstra(1);
    //rep(i, 10) cout << dp[i] << endl;
    int ans = 0;
    rep(i, h)rep(j, w){
        int tmp; cin >> tmp;
        if (tmp != -1) ans += dp[tmp];
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
s = input()
k = int(input())

len_s = len(s)
moji = [0]*(len_s)

for i in range(len_s):
    num = 26-(ord(s[i])-ord('a'))
    if num <= k and num != 26:
        moji[i] = 'a'
        k -= num
    else:
        moji[i] = s[i]

     
if k != 0:
    #print(k)
    moji[len_s-1] = chr(ord(moji[len_s-1])+k%26)
        
print(*moji,sep='')

Measured memory_bytes: 7156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
long long sum[200001];
int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
	int x;
	scanf("%d",&x);
	sum[i]=sum[i-1]+x;
    }
    sort(sum,sum+n+1);
    long long ans=0;
    for (int i=0;i<=n;) {
	int j=i;
	while (j<=n&&sum[j]==sum[i]) j++;
	ans+=(long long)(j-i)*(j-i-1)/2;
	i=j;
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
    while(1){
        long long sale[4001], a, b, c, i, j, n;
        int k = 0;
        cin >> n;
        if(n == 0)break;
        for(i = 0; i < 4001; i++){
            sale[i] = 0;
        }
        for(i = 0; i < n; i++){
            cin >> a >> b >> c;
            if(sale[a] >= 0){
                sale[a] += b*c;
                if(sale[a] >= 1000000){
                    cout << a << endl;
                    sale[a] = -1;
                    k++;
                }
            }
        }
        if(k == 0){
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1184
#pragma GCC optimize ("-Ofast")
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define F(i,b) for(int i= 0; i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define MOD 1000000007
const int N = 2e5+7 ;
string s ;

int32_t main(){_
	int n,k ;
	cin >> n ;
	vi a(n) ;
	inp(a) 
	int ans = 0 ;
	FI(i,1,n-1){
		if(a[i] < a[i-1])
			ans += (a[i-1]-a[i]) ;
	}
	cout << ans + a[n-1] << endl ; 
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

def dfs(v, d=0):
    seen[v] = True
    dist[v] = d

    for i in graph[v]:
        next_v = i[0]
        l = i[1]
        if seen[next_v] == True:
            continue
        dfs(next_v, d+l)

    return

N = int(input())

graph = [[] for i in range(N + 1)]

for i in range(N - 1):
    a, b, c = map(int, input().split())
    graph[a].append([b, c])
    graph[b].append([a, c])

Q, K = map(int, input().split())

seen = [False for i in range(N + 1)]
dist = [0 for i in range(N + 1)]
dfs(K)

for i in range(Q):
    x, y = map(int, input().split())
    print(dist[x] + dist[y])


Measured memory_bytes: 157468
class SegTree
    def initialize(init_ary, lim, &block)
        n = init_ary.size
        @m = 1 << (n-1).bit_length
        @n = @m << 1

        @lim = lim
        @ary = Array.new(@n, @lim)
        @fanc = block

        init_ary.each_with_index {|e,i| @ary[@m+i] = e}
        (@m-1).downto(1) {|i| @ary[i] = @fanc.call(@ary[i*2], @ary[i*2+1])}
    end

    def set(i, x)
        i += @m
        @ary[i] = x
        i >>= 1

        while i >= 1
            @ary[i] = @fanc.call(@ary[i*2], @ary[i*2+1])
            i >>= 1
        end
    end

    def find(i, a, b)
        return @lim if @t < a || b < @s
        return @ary[i] if @s <= a && b <= @t

        m = (a + b) >> 1
        return @fanc.call(find(i*2, a, m), find(i*2+1, m+1, b))
    end

    def find_start(s, t)
        @s = s
        @t = t
        find(1, 0, @m-1)
    end

    def calc3(i, a, b)
        return @lim if @t < a || b < @s || @ary[i][0] < @v
        return @ary[i] if a == b

        m = (a + b) >> 1
        x = calc3(i*2, a, m)
        return x if x[1] != @lim[1]
        return calc3(i*2+1, m+1, b)
    end

    def calc3_start(s, t, v)
        @s = s
        @t = t
        @v = v
        calc3(1, 0, @m-1)
    end
end

n, q = gets.split.map(&:to_i)
a = gets.split.map.with_index{|e,i| [e.to_i, i]}

st = SegTree.new(a, [0, n]) {|ch1, ch2| ch1[0] > ch2[0] ? ch1 : ch2}

q.times do
    t, x, v = gets.split.map(&:to_i)
    if t == 1
        st.set(x-1, [v, x-1])
    elsif t == 2
        puts st.find_start(x-1, v-1)[0]
    else
        puts st.calc3_start(x-1, n-1, v)[1] + 1
    end
end

Measured memory_bytes: 50620
n = int(input())
h = [int(x) for x in input().split()]

dp = [10 ** 10] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, n):
    cost1 = abs(h[i - 1] - h[i])
    cost2 = abs(h[i - 2] - h[i])
    dp[i] = min(dp[i - 1] + cost1, dp[i - 2] + cost2)

print(dp[n - 1])


Measured memory_bytes: 13776
//Insertion Sort
#include<stdio.h>

int length;
int A[1000]={0};

void intput()
{
  int i;
  scanf("%d",&length);
  for(i=1;i<=length;i++)
    scanf("%d",&A[i]);
}

void output()
{
  int i,j;
  for(i=1;i<length;i++){
    printf("%d ",A[i]);
   }
   printf("%d\n",A[i]);
}

void Sort()
{
  int i,j;
  int key;
  for(i=1;i<=length;i++){
    key = A[i];
    for(j=i-1;j>=0;j--){
      if(A[j]<=key){
        A[j+1]=key;
        break;
      }
      
      A[j+1] = A[j];
    }
    output();
  }
}

int main()
{
  intput();
  Sort();
  return 0;
}




Measured memory_bytes: 2040
import sys
import copy
input = sys.stdin.readline


X,K,D=map(int,input().split())

if X>=0:

    if X-(K*D)>=0:
        print(X-(K*D))
    else:
        tmp= X//D
        tmp2= X//D+1
        
        #print(tmp)
        #print(tmp2)
        
        if abs(X-D*tmp)<abs(X-D*tmp2):
            if (K-tmp)%2==0:
                print(abs(X-(D*tmp)))
            else:
                print(abs(abs(X-D*tmp)-D))
        else:
            if (K-tmp2)%2==0:
                print(abs(X-(D*tmp2)))
            else:
                print(abs(abs(X-D*tmp2)-D))
    
else:
    
    if X+(K*D)<=0:
        print(abs(X+(K*D)))
    else:
        tmp= abs(X//D)-1
        tmp2= abs(X//D)
        
        #print(tmp)
        #print(tmp2)
        
        if abs(X+D*tmp)<abs(X+D*tmp2):
            if (K-tmp)%2==0:
                print(abs(X+(D*tmp)))
            else:
                print(abs(abs(X+D*tmp)-D))
        else:
            if (K-tmp2)%2==0:
                print(abs(X+(D*tmp2)))
            else:
                print(abs(abs(X+D*tmp2)-D))

Measured memory_bytes: 9316
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
typedef pair<int, int> P;
struct info{int x, y, p, t; };
const int MAX_W = 1005;
const int MAX_N = 10;
const int INF = MAX_W * MAX_W * MAX_N;
int W;
int H;
int N;  //チーズの数
int tile[MAX_W][MAX_W];  //障害物
int arrived[MAX_N];  //チーズ
int checked[MAX_N+1][MAX_W][MAX_W];
//上、右、下、左
const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};

bool C(int x, int y) {
    return (x >= 0 && x < W && y >= 0 && y < H);
}

int main(int argc, const char * argv[])
{
    scanf("%d %d %d", &H, &W, &N);
    fill(arrived, arrived+N+1, INF);
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < W; j++) {
            fill(checked[i][j], checked[i][j] + H, INF);
        }
    }
    int sx, sy;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c;
            scanf(" %c", &c);
            if (c == '.') {  //空き地
                tile[j][i] = 0;
            } else if (c == 'X') {  //障害物
                tile[j][i] = INF;
            } else if (c == 'S') {
                sx = j;
                sy = i;
                tile[j][i] = 0;
            } else {
                int num = c - '0';
                tile[j][i] = num;
            }
        }
    }
    queue<info> que;
    que.push((info){sx, sy, 1, 0});
    while (!que.empty()) {
        info in = que.front(); que.pop();
        int px = in.x;
        int py = in.y;
        int pp = in.p;
        int pt = in.t;
        if (pt > arrived[pp]) continue;  //最短ではない
        if (pt >= checked[pp][px][py]) continue;  //既に訪れている
        checked[pp][px][py] = pt;  //最短経路
        if (tile[px][py] == pp) {  //工場ppに到着
            arrived[pp] = pt;
            pp++;  //体力がアップ
            checked[pp][px][py] = pt;
            if (pp == N+1) break;  //最後の工場に到着
        }
        for (int i = 0; i < 4; i++) {
            int nx = px + dx[i];
            int ny = py + dy[i];
            if (C(nx, ny) && tile[nx][ny] != INF) {  //範囲内かつ障害物ではない
                que.push((info){nx, ny, pp, pt+1});
            }
        }
    }
    printf("%d\n", arrived[N]);
    return 0;
}

Measured memory_bytes: 46496
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 116：C - Grand Garden
import numpy as np

def op(hlist):
    if len(hlist) == 0:
        return 0
    elif len(hlist) == 1:
        return hlist[0]
    min_h = min(hlist)
    hlist -= min_h
    s = min_h
    bi = 0
    for i in range(len(hlist)):
        if hlist[i] == 0:
            s += op(hlist[bi:i])
            bi = i + 1
    s += op(hlist[bi:])
    return s


def main():
    N = int(raw_input().strip())
    h = np.array([int(i) for i in raw_input().strip().split(' ')])
    print op(h)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10416
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int a,b,c;cin>>a>>b>>c;
    if(b-a == c-b)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 3632
def main():
    import sys
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    T = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(1, n):
        cnt += min(T[i] - T[i-1], t)
    print(cnt + t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78064
lines = readlines.map{|line| line.split(' ').map(&:to_i)}
a=[]
a.push(lines[1][0])
for i in 0..lines[0][0]-2
  if lines[1][i+1]==nil then
    a.push(lines[1][i])
  else
    a.push([lines[1][i],lines[1][i+1]].min)
  end
end
puts a.inject(:+)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main(){
  int n;cin >> n;
  bool a[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  vector<int> dp(1<<n);
  dp[0]=1;
  for(int i=0;i<(1<<n);i++){
    int t=0;
    for(int j=0;j<n;j++){
      if((i>>j)&1){
        t++;
      }
    }
    for(int j=0;j<n;j++){
      if(!((i>>j)&1)&&a[t][j]){
        dp[i|(1<<j)]+=dp[i];
        dp[i|(1<<j)]%=mod;
      }
    }
  }
  cout << dp[(1<<n)-1] << endl;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ans=0;

    for(int i=1;i<=n;i++)
    {
        if(i<10 or i>99 and i<1000 or i>9999 and i<100000 or i>999999)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    exit(0);
}


Measured memory_bytes: 3556
//This disgusting code is wriiten by Juruo D0zingbear
//Please don't hack me! 0v0 <3
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: ｌｌｄ
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const long long mod=1e9+7;
const int Maxn=55;
char c[2][Maxn];
long long dp[Maxn][10];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",c[0]);
	scanf("%s",c[1]);
	long long ans=1,kk=-1;
	for (int i=0;i<n;i++){
		if (c[0][i]!=c[1][i]){
			if (!i) ans*=6;
			else if (kk==1) ans*=2;
			else ans*=3;
			ans%=mod;
			i++;
			kk=2;
		}
		else{
			if (!i) ans*=3;
			else if (kk==1) ans*=2;
			else ans*=1;
			kk=1;
			ans%=mod;
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;

int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}



int main(){
	ll N,M,ans1=0,ans2=0;
	cin>>N>>M;
	vll p(M),AC(N),WA(N);
	vstr S(M);
	REP(i,M) cin>>p[i]>>S[i];
	REP(i,N) {
		AC[i]=0;
		WA[i]=0;
	}
	
	REP(i,M){
		if(AC[p[i]-1]==0&&S[i]=="WA") {
		    WA[p[i]-1]++;
		}
		else if(AC[p[i]-1]==0){
			AC[p[i]-1]++;
		}
	}
    REP(i,N){
      if(AC[i]!=0) ans2+=WA[i];
      ans1+=AC[i];
    }
	cout<<ans1<<endl<<ans2<<endl;
	
}

Measured memory_bytes: 8064
N = int(input())
v = list(map(int, input().split()))

last = 0

odd = [0 for _ in range(10**5+1)]
even = [0 for _ in range(10**5+1)]

even_max = 0
odd_max = 0
even_max_index = 0
odd_max_index = 0
for i in range(N):
    if i%2 == 0:
        even[v[i]] += 1
        if even[v[i]] > even_max:
            even_max = even[v[i]]
            even_max_index = v[i]
    else:
        odd[v[i]] += 1
        if odd[v[i]] > odd_max:
            odd_max = odd[v[i]]
            odd_max_index = v[i]

ans = even_max + odd_max
if even_max_index == odd_max_index:
    even[even_max_index] = 0
    odd[odd_max_index] = 0
    ans = max(max(even)+odd_max, max(odd)+even_max)

print(N-ans)

Measured memory_bytes: 14404
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u){
    if(u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u){
    if(u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u){
    if(u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main(){
    int  i, v, l, r, root;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        T[i].p = NIL;
    }
    
    for(i = 0; i < n; i++){
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }
    
    for(i = 0; i < n; i++) if(T[i].p == NIL) root = i;
    
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 2712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	vector<ll> vl;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		vl.push_back(a);
	} 
	while(vl.size()>1)
	{
		sort(vl.begin(),vl.end());
		for(int i=1;i<vl.size();i++)
		{
			ll k = vl[i]%vl[0];
			if(k == 0)
				vl.erase(vl.begin()+i);
			else
				vl[i] = k;
		}
	}
	cout<<vl[0]<<endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    vector<int> b(n-1);
    rep(i,n-1){
        cin>>b[i];
    }
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(b[i]<b[i+1]){
            ans+=b[i];
        }else{
            ans+=b[i+1];
        }
    }
    ans+=b[0]+b[n-2];
    cout<<ans<<endl;




    return 0;
}


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

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

  	int count = 1;
  	for(int i = 0; i < D; i++){
         count *= 100;
    }
    
          if(N != 100){
              cout << count * N << endl;
          }else{
              int X = 101;
              cout <<  X * count << endl;
          }
     
}
           

Measured memory_bytes: 256
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
 
// ------------------------------------------------------------------------------------------------

ll a, b, c;

int main() {
    fast_io; cout_precision;
    cin >> a >> b >> c;
    cout << max(ll(0), b + c - a) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, r;
    cin >> n >> r;
    if (n >= 10)
        cout << r << endl;
    else
        cout << r + 100 * (10 - n) << endl;
    GAME_OVER;
}

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

int main() {
    int n; cin >> n;
    int h[n];
    for (int i=0; i<n; i++) cin >> h[i];
    int ans = 0;
    while (1) {
        bool all = true;
        for (int i=0; i<n; i++) {
            if (h[i] != 0) all = false;
        }
        if (all) break;
        int i = 0;
        while (i<n) {
            if (h[i] == 0) i++;
            else {
                ans++;
                while (i<n && h[i]>0) {
                    h[i]--;
                    i++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  set<char>st;
  st.insert(s[0]);
  st.insert(s[1]);
  st.insert(s[2]);
  st.insert(s[3]);
  if(st.size()==2)
    cout<<"Yes";
  else
    cout<<"No";
  
}

Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 3540
# -*- coding: utf-8 -*-
'''
20
'''

N = int(input())


class Prime(object):
    @staticmethod
    def is_prime(n: int) -> bool:
        """
        素数判定
        >>> p = Prime()
        >>> p.is_prime(2)
        True
        >>> p.is_prime(43)
        True
        >>> p.is_prime(4)
        False
        """

        if n == 1:
            return False
        if n == 2:
            return True

        for i in range(2, n):
            if n % i == 0:
                return False
            if i * i > n:
                return True

    @staticmethod
    def divisor(n: int, sort: bool = False) -> list:
        """
        約数列挙
        >>> p = Prime()
        >>> p.divisor(6)
        [1, 2, 3, 6]
        """
        res = []
        if n == 1:
            return [1]

        for i in range(1, n):
            if n % i == 0:
                res.append(i)
                if i != n / i:
                    res.append(int(n / i))
            if (i+1) * (i+1) > n:
                if sort:
                    res.sort()
                return res


# N-1の約数：1以外が全て当てはまる
temp1 = Prime.divisor(N - 1, sort=False)
# print(temp1)
cnt1 = len(temp1) - 1

# Nの約数K：Kで割り切った後でN % K == 1かどうかを見る
temp2 = Prime.divisor(N, sort=True)[1:]
# print(temp2)
cnt2 = 0

for temp in temp2:
    a = N
    while a % temp == 0:
        a = a / temp
    if a % temp == 1:
        cnt2 += 1

print(cnt1 + cnt2)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define forn(i,n) for(int i=0;i!=n;i++)
ll n,c,g,a,ac,L[7],m,k,dp[500][500];
int main(){
cin>>n>>c,c*=n,m=n-1,k=1<<m;
forn(i,n)cin>>L[i],L[i]*=n;
sort(L,L+n);
do{
    memset(dp,0,sizeof(dp)),dp[L[m]][0]=1;
    forn(i,c)if(i%n){
        forn(mask,k)if(!((1<<(i%n-1))&mask))
            for(ac=i;ac<=c;ac++)dp[max(ac,min(c,L[i%n-1]+i))][mask+(1<<(i%n-1))]+=dp[ac][mask];
    }g+=dp[c][k-1],a++;
}while(next_permutation(L,L+m));
printf("%.15f",g/pow(c/n,m)/a);
}


Measured memory_bytes: 2176
# coding: utf-8
# Your code here!

#l,a,b,m = [int(i) for i in input().split()]


# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!

n=input()
MOD = 10**9+7
dp = [[0 for _ in range(2)] for _ in range(len(n)+1)] # 上からi桁まで、is_less

dp[0][0] = 1
for i,ni in enumerate(n): #i桁目からi+1桁目に遷移
    ni = int(ni)
    dp[i+1][1] += 3*dp[i][1]
    dp[i+1][1] %= MOD
    if ni == 1:
        dp[i+1][1] += dp[i][0]
        dp[i+1][0] += 2*dp[i][0]
    else:
        dp[i+1][0] += 1*dp[i][0]
    dp[i+1][1] %= MOD
    dp[i+1][0] %= MOD
        
#    print(dp)


print(sum(dp[len(n)])%MOD)



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n * 3);
    for (int i = 0; i < n * 3; i++) {
        scanf("%d", &a[i]);
    }

    partial_sort(a.begin(), a.begin() + n * 2, a.end(), greater<>());
    int64_t r = 0;
    for (int i = 1; i < n * 2; i += 2) {
        r += a[i];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Ordered set
//pbds s1
 
void testCase() {
    int n;
    ll k;
    cin >> n >> k;
    int tel[n+3];
    for (int i=1; i<=n; i++)
        cin >> tel[i];
    int ans = -1;
    vector <int> nodes;
    int vis[n+2] = {0};
    int st = 1;
    nodes.push_back (st);
    vis[1] = 1;
    ll cnt = 0;
    int ok = 0;
    while (1) {
        cnt++;
        if (cnt == k) {
            ok = 1;
            st = tel[st];
            nodes.push_back (st);
            break;
        }
        int nxt = tel[st];
        if (vis[nxt]==1) {
            st = nxt;
            break;
        }
        vis[nxt] = 1;
        nodes.push_back (nxt);
        st = nxt;
    }
    if (ok == 1) {
        cout << st << endl;
    }
    else {
        //cycle detected
        vector <int> fnode;
        for (int v : nodes) {
            if (v == st) {
                ok = 1;
                fnode.push_back (v);
            }
            else if (ok == 1) {
                fnode.push_back (v);
            }
        }
        k -= cnt;
        k = k % (fnode.size());
        cout << fnode[k] << endl;
    }
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 6200
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
 
const int N = 4e7 + 10; 
 
typedef  long long ll;

int ans[200005];
 
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for (int i = 0 ; i < n;i++){
        scanf("%d",&ans[i]);
    }
    int l = 0;
    int res = 0;
    int mx = 0;
    for (int i = 0; i < n;i++){
        if (i - l + 1 > k){
            mx = max(mx,res);
            res -= ans[l++];
            res += ans[i];
        }
        else{
            res += ans[i];
        }
    }
    mx = max(mx,res);
    double t = (double)(mx  + k )  / 2;
    printf("%.12f\n",t);
    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int main(){
	
	long long int N, K, L, R, a[100];
	cin >> N >> K >> L >> R;
	
	int n1 = N / 2;
	int n2 = N - n1;
	
	for(int i = 0; i < n1; i++){
		cin >> a[i];
	}
	
	vector<long long int> v[N];
	
	for(int i = 0; i < (1 << n1); i++){
		int cnt = 0;
		long long int S = 0;
		for(int j = 0; j < n1; j++){
			if(i & (1 << j)){
				cnt++;
				S += a[j];
			}
		}
		v[cnt].push_back(S);
	}
	
	for(int i = 0; i < N; i++){
		sort(v[i].begin(), v[i].end());
	}
	
	for(int i = 0; i < n2; i++){
		cin >> a[i];
	}
	
	long long int ans = 0;
	
	for(int i = 0; i < (1 << n2); i++){
		int cnt = 0;
		long long int S = 0;
		for(int j = 0; j < n2; j++){
			if(i & (1 << j)){
				cnt++;
				S += a[j];
			}
		}
		if(K < cnt){
			continue;
		}
		ans += upper_bound(v[K - cnt].begin(), v[K - cnt].end(), R - S) - 
			lower_bound(v[K - cnt].begin(), v[K - cnt].end(), L - S);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 12308
#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, M;
    cin >> N >> M;

    cout << int((N * (N-1) / 2) + (M * (M - 1) / 2)) << endl;

    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    X = I()
    for i in range(2, 11):
        if i * 200 <= X < (i + 1) * 200:
            print(10 - i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 72596
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
 
mod = 10**9+7
 
N,M = map(int,input().split())
 
facterint = [1]
for i in range(1,max(N,M)+1):
    facterint.append(facterint[-1]*i%mod)
 
 
if abs(N-M) > 1:
    print(0)
    exit()
 
if N==M:
    ans = 2*facterint[N]*facterint[M]%mod
else:
    ans = facterint[N]*facterint[M]%mod
 
print(ans)

Measured memory_bytes: 9556
N,M = gets.split.map(&:to_i)
ab_list = []
N.times do
  ab_list << gets.split.map(&:to_i)
end

ab_list.sort_by!{|ab| ab[0]}
remainder = M
ans = 0
ab_list.each do |ab|
  a, b = ab
  break if remainder == 0
  if b >= remainder
    ans += remainder * a
    remainder = 0
  else
    ans += b * a
    remainder -= b
  end
end

puts ans

Measured memory_bytes: 12664
#include <boost/algorithm/string/join.hpp>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

using namespace std;
using namespace boost;

typedef int64_t INT;

int table[]{ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

void chMax(string &a, const string &b)
{
    if(a == "-") {}
    else if(a.size() > b.size()) return;
    else if(a.size() == b.size() && a > b) return;
    a = b;
}
void Resolve(istream &is, ostream &os) {
    INT N, M;
    is >> N >> M;
    vector<int> list(M);
    for(int i = 0;i < M;i++)
    {
        is >> list[i];
    }

    vector<string> dp(N+1, "-");
    dp[0] = "";
    for(int i = 0;i <= N; i++)
    {
        if(dp[i]=="-") continue;
        for(auto c: list){
            auto useCount = i+table[c];
            if(useCount>=dp.size()) continue;

            auto ns = dp[i]+(char)(c+'0');
            chMax(dp[useCount], ns);
        }
    }
    os << dp[N];
}

#if !TEST
int main() { cin.tie(0); ios::sync_with_stdio(false); Resolve(cin, cout); cout.flush(); return 0;}
#endif

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

void maxHeapify(vector<int> &T, int i){
	// n == H
	int n = T.size() - 1;
	if(n == 0 ||n == 1) return;
	
	// 	index of left son and right son;
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;
	
	if(l <= n && T[i] < T[l]) largest = l;
	else largest = i;
	if(r <= n && T[largest] < T[r]) largest = r;
	
	if(largest != i){
		swap(T[largest], T[i]);
		maxHeapify(T, largest);
	}
	
}

int main(int argc, char** argv) {
	int H;
	cin >> H; 
	vector<int> T(H+1);
	for(int i = 1; i <= H; i++){
		cin >> T[i];
	}
	
	for(int i = H/2; i>=1; i--){
		maxHeapify(T, i);
	}

	for(int i = 1; i <= H; i++){
		cout << " " << T[i];
	}	
	cout << endl;
	return 0;
}


Measured memory_bytes: 4692
H, W = list(map(int, input().strip().split(" ")))

field = []
hist = [0 for w in range(W)]

def shrink():
    newField = []
    for h in range(H):
        line = []
        for w in range(W):
            if(hist[w] != H):
                line.append(field[h][w])
        newField.append(line)        
    return newField            

for h in range(H):
    line = list(input().strip())
    if(line.count(".") != len(line)):
        field.append(list(line))
        for w in range(W):
            hist[w] += 1 if field[-1][w] == "." else 0 
H = len(field)

newField = shrink()

for h in newField:
    print("".join(h))

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

int main()
{
    int H, W;
    long f=0, s=0;
    long p=0;
    cin  >> H >> W;
    if (W%2==0) 
    {
        f = W/2; 
        s=W/2;
    }
    else 
    {
        f = (long) W/2 + 1; 
        s=(long) W/2;
    }
    if(H%2==0)
    {
        p += f * (H/2);
        p += s * (H/2);
    }
    else
    {
        p += f * ((long)(H/2)+1);
        p += s * (long)(H/2);
    }
    if (H==1 || W==1) p = 1;
    // p += (ceil) (H/2) * (ceil) (W/2);
    // p += (floor) (H/2) * (floor) (W/2);
    cout << p;
}

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

int main() {
    string s;
    cin >> s;
    if(((s[0]=='0' && s[1]!='0') || (s[0]=='1' && (s[1]=='0' || s[1]=='1' || s[1]=='2')))&&((s[2]=='0' && s[3]!='0') || (s[2]=='1' && (s[3]=='0' || s[3]=='1' || s[3]=='2')))) {
      cout << "AMBIGUOUS" << endl;
    }
    else if ((s[0]=='0' && s[1]!='0') || (s[0]=='1' && (s[1]=='0' || s[1]=='1' || s[1]=='2'))) {
      cout << "MMYY" << endl;
    }
    else if ((s[2]=='0' && s[3]!='0') || (s[2]=='1' && (s[3]=='0' || s[3]=='1' || s[3]=='2'))) {
      cout << "YYMM" << endl;
    }
    else cout << "NA" << endl;
}


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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int d=b-a-1;
  // a+=d-d/2;
  // b-=d/2;
  if ( d%2 ) {
    puts("Alice");
  } else {
    puts("Borys");
  }
  return 0;
}

Measured memory_bytes: 384
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;

vector<int> tree[100001];
int dp[100001][2];

int solve(int u, bool constraint, int pr)
{
    if (dp[u][constraint] != -1)
        return dp[u][constraint];
    int ans = 0;
    int w1 = 1;
    for (int child : tree[u])
    {
        if (child != pr)
            w1 = (w1 * solve(child, 0, u)) % MOD;
    }
    ans += w1;
    if (!constraint)
    {
        int w2 = 1;
        for (int child : tree[u])
        {
            if (child != pr)
                w2 = (w2 * solve(child, 1, u)) % MOD;
        }
        ans = (ans + w2) % MOD;
    }
    return dp[u][constraint] = ans;
}


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

    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        memset(dp, -1, sizeof dp);
        for (int i = 0; i < n - 1; i++)
        {
            int u, v;
            cin >> u >> v;
            tree[u].push_back(v);
            tree[v].push_back(u);
        }
        cout << solve(1, 0, -1);
    }
    return 0;

}



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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    long long int N,A,B,R,ans;

    cin>>N>>A>>B;

    if(A<N%(A+B))
        ans=(N/(A+B)+1)*A;
    else{
        ans=(N/(A+B))*A+N%(A+B);
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
fish = [[], []]
point = [[], []]
fish[0] = gets.chomp.split.map(&:to_i)
fish[1] = gets.chomp.split.map(&:to_i)
point[0][0], point[1][0], point[0][1], point[1][1] = gets.chomp.split.map(&:to_i)

score = [0, 0]
2.times{|i|
    score[i] += point[0][0] *  fish[i][0]
    score[i] += point[0][1] * (fish[i][0] / 10)
    score[i] += point[1][0] *  fish[i][1]
    score[i] += point[1][1] * (fish[i][1] / 20)
}

puts (score[0] > score[1]) ? "hiroshi" : (score[0] < score[1]) ? "kenjiro" : "even"


Measured memory_bytes: 6884
open System
let readInt () = stdin.ReadLine() |> int

let A = readInt ();
let B = readInt ();
let C = readInt ();
let X = readInt ();

[ for i in [0..A] do
    for j in [0..B] do
        for k in [0..C] do
           yield i * 500 + j * 100 + 50 * k]
|> List.sumBy (fun v -> if v = X then 1 else 0)
|> printfn "%d"


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

As = []
for _ in range(0, N):
    x, y = input().split()
    As.append((int(x), int(y)))

Cs = []
for _ in range(0, M):
    x, y = input().split()
    Cs.append((int(x), int(y)))

for a in As:
    d = {}
    minI = -1
    minM = float('inf')
    for i, c in enumerate(Cs):
        ax, ay = a
        cx, cy = c
        m = abs(ax - cx) + abs(ay - cy)
        if m < minM:
            minI = i + 1
            minM = m

    print(minI)


Measured memory_bytes: 9148
#include<iostream>
#include<string>

using namespace std;

int main(){
 string n;
  cin >> n;
  
  if((n[0]==n[1]&&n[1]==n[2])||(n[2]==n[3]&&n[1]==n[2])) cout << "Yes" << endl;
  else cout << "No" << endl;


}

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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  i64 ans = (N >= 3) ? N - 1 : 0;
  for (i64 k = 2; k * k <= N; ++k) {
    if (N % k == 0) {
      i64 r = N / k;
      assert(r >= k);
      DEBUG(N, k, r);
      i64 m = k - 1;
      if (N % m == r && r == N / m) {
        ans += m;
      }
      if (r - 1 != m) {
        m = r - 1;
        if (N % m == k && k == N / m) {
          ans += m;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
using System;
using System.Globalization;
using System.Threading;

namespace atcoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            string[] input2 = new string[n];
            int accnt = 0, wacnt = 0, tlecnt = 0, recnt = 0;
            for(int i = 0; i < n; i++)
            {
                input2[i] = Console.ReadLine();
                switch (input2[i])
                {
                    case "AC":
                        accnt++;
                        break;
                    case "WA":
                        wacnt++;
                        break;
                    case "TLE":
                        tlecnt++;
                        break;
                    case "RE":
                        recnt++;
                        break;
                }
            }
            Console.WriteLine("AC x " + accnt);
            Console.WriteLine("WA x " + wacnt);
            Console.WriteLine("TLE x " + tlecnt);
            Console.WriteLine("RE x " + recnt);
        }
    }
}



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

int main()
{    
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    vector<vector<int>> x(26);
    int p = -1;
    ll cnt = 0;
    rep(i,n) {
        x[s[i]-'a'].push_back(i);
    }        
    rep(i,m) {
        int dt = t[i]-'a';
        if(x[dt].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto itr = lower_bound(x[dt].begin(), x[dt].end(), p+1);
        if(itr != x[dt].end()) {           
            p = *itr;
        }
        else {
            ++cnt;
            p = x[dt][0];
        }
    }

    cout << cnt*n+p+1 << endl;
    return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<string>

using namespace std;

int main(){

	string line;
	getline(cin, line);
	for(int i=0; i < line.length(); ++i){
		if( int(line[i]) >= 97 && int(line[i]) <= 122 )
		{cout << char(line[i]-32);}
		else if( int(line[i])>= 65 && int(line[i]) <= 90)
		{cout << char(line[i]+32);}
		else {cout << char(line[i]);}
	}
	cout << endl;
	return 0;

}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int dp[k+1];
  memset(dp,0,sizeof(dp));
  for(int i=1;i<=k;i++)
    for(int j=0;j<n;j++)
      if(a[j]<=i&&dp[i-a[j]]==0)
        dp[i]=1;
  string res=dp[k]==1?"First":"Second";
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 640