akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>   
int main()
{        
	int a,b,i,j;       
	while(1)
	{
		scanf("%d %d",&a,&b);         
		if(a==0&&b==0)             
		break;         
		for(i=0;i<a;i++)
		{             
			if(i==0||i==(a-1))
			{                 
				for(j=0;j<b;j++)                     
				printf("#");             
			}             
				else 
				{                 
					printf("#");                 
					for(j=1;j<b-1;j++)                     
					printf(".");                 
					printf("#");             
				}                 
				printf("\n");         
			}         
				printf("\n");     
		}     
				return 0; 
}

Measured memory_bytes: 572
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
maru=111
flag=0
n=int(input())
for k in range(0,n):
    e=int(input())
    for i in range(0,3):    
        if e==a[i]:
            a[i]=maru
        if e==b[i]:
            b[i]=maru
        if e==c[i]:
            c[i]=maru

for j in range(0,3):
    if a[j]==b[j] and b[j]==c[j]:
        if c[j]==maru:
            flag=1
            
if a[0]==a[1] and a[1]==a[2]:
    if a[0]==maru:
        flag=1
if b[0]==b[1] and b[1]==b[2]:
    if b[0]==maru:
        flag=1
if c[0]==c[1] and c[1]==c[2]:
    if c[0]==maru:
        flag=1

if a[0]==b[1] and b[1]==c[2]:
    if c[2]==maru:
        flag=1

if a[2]==b[1] and b[1]==c[0]:
    if c[0]==maru:
        flag=1



if flag==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
def main():
    N, M, V, P = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)

    def is_ok(x):
        if x <= P-1:
            return True
        elif A[x-1] + M < A[P-1]:
            return False

        votes = M*(P-1 + N-x) + M
        for i in range(P-1, x-1):
            votes += A[x-1] + M - A[i]
        if M*V <= votes:
            return True
        else:
            return False

    def binary_search_meguru():
        ng = N+1
        ok = -1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search_meguru())


if __name__ == '__main__':
    main()


Measured memory_bytes: 62804
#include <cstdio>
#include <stdio.h>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
    int X, A, B, C;

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    int ans = 0;
    for(int i = 0; i <= A; i++) {
        for(int j = 0; j <= B; j++) {
            for(int k = 0; k <= C; k++) {
                if(i * 500 + j * 100 + k * 50 == X) {
                    //printf("%d %d %d\n", i, j, k);
                    ans++;
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    string s;
    cin >> s;
    int zero = 0, one = 0;
    rep(i, s.size())
    {
        if (s[i] == '1')
            one++;
        else
            zero++;
    }
    cout << 2 * min(one, zero) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100005;
int n,pos1,pos2; 
ll C,x[N],w[N],sum,Max,Max1[N],Max2[N];
int main()
{
	scanf("%d%lld",&n,&C);
	for (int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&w[i]);
	for (int i=1;i<=n;i++) 
	  sum+=w[i],Max1[i]=max(Max1[i-1],sum-x[i]);
	sum=0;
	for (int i=n;i>=1;i--) 
	   sum+=w[i],Max2[i]=max(Max2[i+1],sum-(C-x[i]));
	Max=max(Max1[n],Max2[1]);
	sum=0;
	for (int i=1;i<=n;i++) sum+=w[i],Max=max(Max,Max2[i+1]+sum-x[i]*2); 
	sum=0;
	for (int i=n;i>=1;i--) sum+=w[i],Max=max(Max,Max1[i-1]+sum-(C-x[i])*2);
	printf("%lld\n",Max);
	return 0;
}

Measured memory_bytes: 3328
import math

def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            tmp = math.gcd(i,j)
            for k in range(1,n+1):
                ans += math.gcd(tmp,k)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const int N = 1e5;
const int INF = 2e9;
const double PI = acos(-1);

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

    int n,a,b,x;
    sf("%d %d %d",&n,&a,&b);

    int ans = 0;
    for(int i = 0; i < n; ++i){
        sf("%d",&x);
        if(x < a || x >= b) ans++;
    }

    pf("%d\n",ans);

    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;
  map<string, int> mp;
  string s;
  rep(i, n) {
    cin >> s;
    mp[s]++;
  }
  int cnt = 0;
  for (auto x : mp) cnt = max(cnt, x.second);
  for (auto x : mp)
    if (x.second == cnt) cout << x.first << endl;
  return 0;
}


Measured memory_bytes: 25216
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    while True:
        n,x=map(int,readline().split())
        if n==0 and x==0:
            break
        ans=0
        for a in range(1,n+1):
            for b in range(a+1,n+1):
                for c in range(b+1,n+1):
                    if a+b+c==x:
                        ans+=1

        print(ans)

if __name__=="__main__":
    main()


Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    cout << n * 800 - n / 15 * 200 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		String S = scan.next();
		String result = null;

		if(S.length()>K) {
			result = S.substring(0,K)+"...";
		}else {
			result = S;
		}

		System.out.println(result);

	}
}

Measured memory_bytes: 38588
#include <stdio.h>

int main(void)
{
	int i,n,j,a,wa;
		scanf("%d %d %d %d",&n,&j,&i,&a);
		if(n==j && i==a || n==a && j==i){
			printf("yes\n");
		}
		else{
			printf("no\n");
		}

	return 0;
}


Measured memory_bytes: 2056
#include<stdio.h>
#include<string.h>
char s[200200];
int main(){
	scanf("%s", s);
	int l = strlen(s), f = 0;
	for(int i=0; i<l; i++){
		f += s[i]-3;
		f %= 9;
	}
	puts(f?"No":"Yes");
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    if (s.at(0) == s.at(1) && s.at(0) == s.at(2) && s.at(2) == s.at(1)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<bool> dp(n+1,false);
  dp[0] = true;
  rep(i,n){
    if(!dp[i]) continue;
    if(i+4 <= n) dp[i+4] = true;
    if(i+7 <= n) dp[i+7] = true;
  }
  cout << (dp[n] ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 51000
using namespace std;
int dp[maxn],n,a[maxn];
int main(){
	cin>>n;
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		 cin>>a[i];
		 //if(a[i]%10!=0)
		//  dp[a[i]]=1;
	}	
	dp[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=10000;j>=a[i];j--){
			if(dp[j-a[i]]==1) dp[j]=1;
		}
	}
	int i;
	for(i=10000;i>=0;i--) if(dp[i]==1&&i%10!=0) break;
	if(i<0) i=0;
	cout<<i;
	return 0; 
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
const bool DEBUG = false;
#define MAX 110
signed main() {
	int a[MAX] = {};
	int cnt[MAX] = {};
	for (int n; cin >> n&&n;) {
		memset(cnt, 0, sizeof(cnt));
		memset(a, 0, sizeof(a));
		rep(i, 0, n + 1)cin >> a[i];
		unordered_map<int, int> m;
		bool flag = false;
		rep(i, 1, n + 1) {
			if (m.count(a[i] - a[i - 1]))m[a[i] - a[i - 1]]++;
			else m[a[i] - a[i - 1]] = 1;
		}
		if (flag)continue;
		int M = 0, diff;
		for (auto it = m.begin(); it != m.end(); it++) {
			if (M < it->second) {
				M = it->second;
				diff = it->first;
			}
			else if (M == it->second) {
				diff = max(diff, it->first);
			}
		}
		dump(diff);
		rep(i, 0, n) {
			if (a[i] + diff != a[i + 1]) {
				cnt[i]++;
				cnt[i + 1]++;
			}
		}
		dumpc(cnt);
		if (*max_element(cnt, cnt + MAX) == 2) {
			cout << a[max_element(cnt, cnt + MAX) - cnt] << endl;
		}
		else {
			if (cnt[0] == 1)cout << a[0] << endl;
			else if (cnt[n] == 1)cout << a[n] << endl;
			else {
				cout << a[max_element(cnt, cnt + MAX) - cnt] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B == C + D){
  	cout << "Balanced" << endl;
  }else if( A + B < C + D ){
  	cout << "Right" << endl;
  }else if( A + B > C + D){
  	cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll MOD = 1000000007;

ll f[101010];
void factInit() {
  f[0] = 1;
  for (ll i = 1; i < 101010; i++)
    f[i] = (f[i - 1] * i) % MOD;
}

ll inv(ll x) {
  ll res = 1;
  ll k   = MOD - 2;
  ll y   = x;
  while (k) {
    if (k & 1) res = (res * y) % MOD;
    y = (y * y) % MOD;
    k /= 2;
  }
  return res;
}

ll combination(ll n, ll r) {
  if (n < r) return 0;
  // nCk = n! / ((n-k)! * k!)
  ll a = f[n];     // = n!
  ll b = f[n - r]; // = (n-k)!
  ll c = f[r];     // = k!

  ll bc = (b % MOD * c % MOD) % MOD;

  // return (a / bc) % MOD;
  return (a * inv(bc)) % MOD;
}

int main() {
  ll n, k;
  cin >> n >> k;

  ll blue = k;
  ll red  = n - k;
  factInit();

  for (ll i = 1; i <= blue; i++) {
    ll c  = combination(red + 1, i);
    ll c2 = combination(k - 1, i - 1);

    ll res = c % MOD * c2 % MOD;
    cout << res % MOD << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  long long sum = 0;
  int n = s.size();
  for(int i=0; i<n; ++i) sum += s[i]-'0';
  if(sum%9==0) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3732
#! /usr/bin/env python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N = input()

hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]

if int(N[-1]) in hon:
    print("hon")
elif int(N[-1]) in pon:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 10364
n,m,x = map(int, input().split())
ca = []
for i in range(n):
    ca.append(list(map(int,input().split())))
ans = -1
for i in range(1, 1<<n):
    tmp_ca = [0] * len(ca[0])
    for j in range(n):
        if (i>>j)&1:
            tmp_ca[0] += ca[j][0]
            for k in range(len(tmp_ca) - 1):
                tmp_ca[k+1] += ca[j][k+1]
    ok_num = 0
    for j in range(len(tmp_ca) - 1):
        if tmp_ca[j+1] >= x:
            ok_num += 1
    if ok_num == m:
        if ans == -1:
            ans = tmp_ca[0]
        else:
            ans = min(ans, tmp_ca[0])
print (ans)


Measured memory_bytes: 9084
from math import *
n = int(input())
a = [int(x) for x in input().split()]
ans = 1
ok = False
fail = False
for x in a:
  if (x == 0):
    ok = True
    break
for x in a:
  if (ans * x > 1000000000000000000):
    fail = True
    break
  ans *= x
if (ok):
  print(0)
else:
  if (fail):
    print("-1")
  else:
    print(ans)


Measured memory_bytes: 22704
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }
    
    vector<int>a(MAX,0);
    for(int i = 0;i < MAX;++i){
        if(i%2==0)continue;
        if(is_prime[i] && is_prime[(i+1)/2] ) a[i] = 1;
    }
    vector<int>p(MAX+1,0);
    for(int i = 0;i < MAX;++i) p[i+1] = p[i] + a[i];
    
    int Q;cin >> Q;
    for(int i = 0;i < Q;++i){
        int l,r;
        cin >> l >> r;
        r++;
        cout << p[r] - p[l] << endl;
    }
}

Measured memory_bytes: 1792
N = int(input())
H = list(map(int,input().split()))

H_=H.copy()

def get_zero_idx(H_):
    zero_idx = []
    for i in range(len(H_)):
        if H_[i] == 0:
            zero_idx.append(i)
    return zero_idx

zero_idx = get_zero_idx(H_)
# print(zero_idx)
# print(H_)

ans=0

while True:
    zero_idx = get_zero_idx(H_)
#     print(zero_idx)
    #終了判定(全てのHが所定の高さを満たす)
    if len(zero_idx) == len(H_):
        break

    if len(zero_idx)==0:
        s=0
        e=N
        if s<e:
            for _ in range(s,e):
                H_[_]=H_[_]-1   
            ans +=1

    elif len(zero_idx)>=1:
        s=0
        e=zero_idx[0]
        if s<e:
            for _ in range(s,e):
                H_[_]=H_[_]-1   
            ans +=1
#         print('b',s,e,H_)

        for _ in range(1,len(zero_idx)):
            s=zero_idx[_-1]+1
            e=zero_idx[_]
            if s<e:
                for _ in range(s,e):
                    H_[_]=H_[_]-1   
                ans +=1
#             print('c',s,e,H_)

        s=zero_idx[-1]+1
        e=N
        if s < e:
            for _ in range(s,e):
                H_[_]=H_[_]-1   
            ans +=1
#         print('b-',s,e,H_)

print(ans)

Measured memory_bytes: 9276
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

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

    vector<int> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec[i];
    }

    int cnt;
    sort(vec.begin(), vec.end());

    for (int i = 0; i < N - 2; i++)
    {
        for (int j = i + 1; j < N - 1; j++)
        {
            auto itr = lower_bound(vec.begin(), vec.end(), vec[i] + vec[j]) - vec.begin();
            cnt += itr - (j + 1);
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

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

  constexpr int64_t kN = 26;
  int64_t D;
  cin >> D;
  vector<int64_t> C(kN + 1, 0);
  for (int64_t c = 1; c <= kN; ++c) {
    cin >> C[c];
  }
  vector<vector<int64_t>> S(D + 1, vector<int64_t>(kN + 1));
  for (int64_t d = 1; d <= D; ++d) {
    for (int64_t c = 1; c <= kN; ++c) {
      cin >> S[d][c];
    }
  }
  vector<vector<int64_t>> last(D + 1, vector<int64_t>(kN + 1, 0));

  auto ModifyScore = [&](const int64_t acquired_score, const int64_t day) -> int64_t {
    int64_t result = acquired_score;
    return result;
  };

  int64_t score = 0;
  for (int64_t d = 1; d <= D; ++d) {
    int64_t contest;
    cin >> contest;
    last[d] = last[d - 1];
    last[d][contest] = d;
    score += S[d][contest];
    for (int64_t c = 1; c <= kN; ++c) {
      score -= C[c] * (d - last[d][c]);
    }
    cout << ModifyScore(score, d) << endl;
  }
  return 0;
}


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

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

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] cnt = new int[100001];
		int[] cntm = new int[m];
		for (int i = 0; i < n; i++) {
			cnt[x[i]]++;
			cntm[x[i] % m]++;
		}

		int ans = cntm[0] / 2;
		cntm[0] = 0;
		for (int i = 1; i < (m + 1) / 2; i++) {
			int v = Math.min(cntm[i], cntm[m - i]);
			ans += v;
			cntm[i] -= v;
			cntm[m - i] -= v;
		}
		if (m % 2 == 0) {
			ans += cntm[m / 2] / 2;
			cntm[m / 2] = 0;
		}

		for (int i = 0; i < 100000; i++) {
			while (cnt[i] >= 2 && cntm[i % m] >= 2) {
				cnt[i] -= 2;
				cntm[i % m] -= 2;
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 37900
n=int(input())
xu=[input().split() for _ in range(n)]
x=[float(t[0]) for t in xu]
u=[t[1] for t in xu]
t=0
for i in range(n):
    if u[i]=="JPY":
        t+=x[i]
    else:
        t+=x[i]*380000
print(t)

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, k, x[100000],out;
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> x[i];
	out =max(abs(x[n-1]),abs(x[0]))+ x[n - 1] - x[0];
	for (int i = 0; i + k - 1 < n; i++) {
		out = min(min(abs(x[i]),abs(x[i+k-1]))+x[i+k-1]-x[i],out);
	}
	cout << out << endl;
}


Measured memory_bytes: 640
use std::io;
use std::collections::VecDeque;

fn main() {
    let (n, q) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut node = vec![Vec::new(); n];
    for _ in 1..n {
        let (a, b) = {
            let i = read::<usize>();
            (i[0] - 1, i[1] - 1)
        };
        node[a].push(b);
        node[b].push(a);
    }

    let mut subtree = vec![0; n];
    for _ in 0..q {
        let (p, x) = {
            let i = read::<usize>();
            (i[0] - 1, i[1])
        };
        subtree[p] += x;
    }

    let mut q = VecDeque::new();
    q.push_back((0, 0));
    while let Some((v, p)) = q.pop_front() {
        for &u in &node[v] {
            if u == p { continue; }
            q.push_back((u, v));
            subtree[u] += subtree[v];
        }
    }

    let ans = subtree.iter()
        .map(|score| score.to_string())
        .collect::<Vec<_>>()
        .join(" ");
    println!("{}", ans);
}

#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 31984
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int arr[10];
bool visited[10];

int main() {
    int n;
    scanf("%d", &n);
    for (int t = 0; t < n; t++) {
        for (int i = 0; i < 10; i++) scanf("%d", &arr[i]);
        memset(visited, 0, sizeof(visited));
        stack<int>st;
        st.push(arr[0]); visited[0] = true;
        for (int i = 1; i < 10; i++) {
            if (arr[i] > st.top()) { st.push(arr[i]); visited[i] = true; }
        }
        if (st.size() >= 9) printf("YES\n");
        else {
            int minv, mini;
            for (int i = 0; i < 10; i++) if (!visited[i]) { minv = arr[i], mini = i; break; }
            bool flag = true;
            for (int i = mini+1; i < 10; i++) {
                if (!visited[i] && arr[i] > minv) { minv = arr[i]; }
                else if (!visited[i] && arr[i] < minv) { flag = false; break; }
            }
            (flag) ? printf("YES\n") : printf("NO\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2544
#include <cstdio>
#include <algorithm>
int a[100002][3];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
    for (int i = 1; i < n; i++)
    {
        a[i][0] = a[i][0] + std::max(a[i - 1][1], a[i - 1][2]);
        a[i][1] = a[i][1] + std::max(a[i - 1][0], a[i - 1][2]);
        a[i][2] = a[i][2] + std::max(a[i - 1][0], a[i - 1][1]);
    }
    printf("%d", std::max(a[n - 1][0], std::max(a[n - 1][1], a[n - 1][2])));
}

Measured memory_bytes: 1280
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define INF (1LL<<60)
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))
typedef vector<int> vec;
typedef vector< vector<int> > mat;


class ECrestedIbisVsMonster {
public:
  template<class T> inline bool chmin(T& a, T b) {
      if (a > b) {
          a = b;
          return true;
      }
      return false;
  }
	void solve(std::istream& in, std::ostream& out) {
    int h,n;
    in >> h >> n;
    vector<int> a(n), b(n);
    REP(i,n) in >> a[i] >> b[i];
    mat dp(n + 1, vec(h + 1, INF));
    dp[0][0] = 0;
    REP(i, n) REP(j, h + 1){
      chmin(dp[i + 1][j], dp[i][j]);
      chmin(dp[i + 1][min(j + a[i], h)], dp[i + 1][j] + b[i]);
    }
    out << dp[n][h] << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	ECrestedIbisVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 78592
import Data.List

solve a b c d e f =
  let
    (_,x,y) = maximum [(10000*s`div`(w+s),w+s,s)|t<-[i|i<-[0..f],i`mod`(a*100)==0],w<-[i|i<-[t..f],(i-t)`mod`(b*100)==0,i>0],m<-[min (f-w) (w*e`div`100)],u<-[i|i<-[0..m],i`mod`c==0],s<-[i|i<-[u..m],(i-u)`mod`d==0]]
  in
    intercalate " " $ map show [x,y]

main = do
  [a,b,c,d,e,f] <- map read . words <$> getLine
  putStrLn $ solve a b c d e f

Measured memory_bytes: 2428
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int d[200][200];
const int INF = 1e9;

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

    VI p(r);
    REP(i,r) cin >> p[i];
    REP(i,r) p[i]--;
    sort(ALL(p)); 

    REP(i,n) REP(j,n) d[i][j] = INF * (i != j);
    REP(i,m){
        int u, v, l;
        scanf("%d %d %d", &u, &v, &l);
        u--;
        v--;
        d[u][v] = d[v][u] = l;
    }

    REP(i,n) REP(j,n) REP(k,n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

    // REP(i,n) REP(j,n) cout << d[i][j];
    // cout << endl;

    int ans = INF;
    do{
        int tmp = 0;
        REP(i,r-1) tmp += d[p[i]][p[i+1]];
        ans = min(ans, tmp);
    }while (next_permutation(ALL(p)));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

x, y, z = 0, 0, 0
for i in range(n):
    if a[i] % 4 == 0:
        x += 1
    elif a[i] % 2 == 0:
        y += 1
    else:
        z += 1

if x >= z:
    print("Yes")
elif x == z - 1 and y == 0:
    print("Yes")
else:
    print("No")


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >>d;
    if(a+b == c+d){
        cout << "Balanced" << endl;
        return 0;
    } else if(a+b > c+d){
        cout << "Left" << endl;
        return 0;
    } else {
        cout << "Right" << endl;
    } 
    return 0;
}

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

vector<int> d, ans, c, par;
vector<pair<int, int>> edge;
vector<vector<int>> g;

void dfs(int x, int last) {
  if (~c[x]) return ;
  int v = edge[par[x]].second;
  if (v == last) {
    c[x] = 0;
    return ;
  }
 
  dfs(v, x);
  ans[par[x] - (par[x]&1)] = d[x];
  c[x] = c[v]^1;
}

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

  int n, m;
  cin >> n >> m;
  
  g.resize(n);
  d.resize(n);
  c.resize(n, -1);
  par.resize(n, -1);
  ans.resize(2 * m, 1e9);

  for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
  
    g[u].push_back(edge.size());
    g[v].push_back(edge.size()+1);
    edge.emplace_back(u, v);
    edge.emplace_back(v, u);
  }

  for (int i = 0; i < n; ++i) {
    int p = -1, val = 1e9 + 5;
    for (auto e : g[i]) {
      int v = edge[e].second;
      if (d[v] < val) {
        val = d[v];
        p = e;
      } else if (d[v] == val) p = min(p, e);
    }
    if (val > d[i]) {
      cout << -1 << '\n';
      return 0;
    }
    par[i] = p;
  }

  for (int i = 0; i < n; ++i) {
    dfs(i, i);
  }
  
  for (int i = 0; i < n; ++i) cout << (c[i] ? 'B' : 'W');
  cout << '\n';
  for (int i = 0; i < m; ++i) cout << ans[2 * i] << '\n';
}


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



int main() {
    string S, T; cin >> S >> T;
    int N = S.size();
    vector<set<int>> s(26), t(26);
    for(int i = 0; i < N; i++){
        char x = S[i];
        s[x-97].insert(i);
    }
    for(int i = 0; i < N; i++){
        char x = T[i];
        t[x-97].insert(i);
    }
    for(int i = 0; i < 26; i++){
        bool flag = false;
        for(int j = 0; j < 26; j++){
            if(s[i] == t[j]) flag = true;
        }
        if(!flag){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
}

Measured memory_bytes: 19336
ndays = [31,29,31,30,31,30,31,31,30,31,30,31]
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
offset = 3
while(1):
	m,d = [int(i) for i in input().split()]
	if m == 0 and d == 0:
		break
	tot_d = sum(ndays[:m-1]) + d 
	print(days[(tot_d + offset - 1)%7])



Measured memory_bytes: 5600
s=readline()|>chomp
d=Dict{Char,Int}()
for i in 1:4
  if haskey(d,s[i])
    d[s[i]] += 1
  else
    d[s[i]] = 1
  end
end
f = 0
for i in values(d)
  if i!=2
    f = 1
    break
  end
end
println(f==0?"Yes":"No")
  

Measured memory_bytes: 171012
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=rdsp;foreach(ref j;v.tupleof)pick(r,j);}}

void main()
{
  int n; long k; readV(n, k);
  struct D { int a, b; }
  D[] d; readS(n, d);

  d.sort!"a.a<b.a";

  auto c = 0L;
  foreach (di; d) {
    c += di.b;
    if (c >= k) {
      writeln(di.a);
      return;
    }
  }
}


Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

typedef pair<int,string> P;




int main(){
  int n,m,a;

  while(cin >> n ,n){
    vector<P> v;
    vector<int> d[n],point[n];
    string s[n];

    rep(i,n){
      cin >> s[i] >> m;

      rep(j,m){
	cin >> a;
	d[i].push_back(a);
	point[i].push_back(n);
      }

      sort(d[i].begin(),d[i].end());
    }

    rep(i,n){
      rep(j,n){
	if(i == j) continue;

	int len1 = (int)d[i].size();
	int len2 = (int)d[j].size();	

        rep(k,len1){
	  rep(l,len2){
	    if(d[i][k] == d[j][l]){
	      point[i][k]--;
	      break;
	    }
	  }
	}

      }
    }

    rep(i,n){
      int len = (int)point[i].size();
      int sum = 0;
      rep(j,len){
	sum += point[i][j];
      }
      v.push_back(P(sum,s[i]));
    }

    sort(v.begin(),v.end());
    cout << v[0].first << " " << v[0].second << endl;
  }

  return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define MOD 1000000007
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    ll n, m; cin >> n >> m;
    map<int, int> prime;
    ll tmp = m;
    FOR(i,2,m+1){
        while(tmp%i==0){
            prime[i]++;
            tmp/=i;
        }
        if(tmp==1) break;
    }
    COMinit();
    ll ans = 1;
    auto it = prime.begin();
    while(it!=prime.end()){
        int l = it->second;
        ans *= COM(n+l-1, l);
        ans %= MOD;
        it++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 12160
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        // s >= t
        s: String,
        t: String,
    };
    let diff = substr_imitate(&s.as_bytes(), &t.as_bytes()).unwrap();
    println!("{}", diff);
}

fn diff_chars(t: &[u8], p: &[u8]) -> usize {
    let mut count = 0;
    for i in 0..p.len() {
        if t[i] != p[i] {
            count += 1;
        };
    }
    count
}

fn substr_imitate(text: &[u8], ptrn: &[u8]) -> Option<usize> {
    if text.len() < ptrn.len() {
        None
    } else {
        let tl = text.len();
        let pl = ptrn.len();
        let mut count = 1000;
        for i in 0..tl - pl + 1 {
            let substr = &text[i..i + pl];
            let temp = diff_chars(substr, &ptrn[..]);
            if temp < count {
                count = temp;
            };
        }
        Some(count)
    }
}


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

int main()
{
    vector<char>ss;
    int n;cin>>n;
    string s1,s2;cin>>s1>>s2;
    for(int i=0;i<n;i++)
    {
        ss.emplace_back(s1[i]);
        ss.emplace_back(s2[i]);
    }
    string s(n*2,0);
    for(int i=0;i<n*2;i++)
    {
        char a = ss[i];
        s[i]=a;
    }
    cout<<s;
}


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

int main(){

    int length[3];
    int n,i, max_index, tmp, tmp2;

    fscanf(stdin, "%d", &n);
    while ( (fscanf(stdin, "%d %d %d", &length[0], &length[1], &length[2])) != EOF){
        max_index = 0;
        tmp = 0;

        for(i=1; i<3; ++i){
            if(length[max_index] < length[i]){
                max_index = i;
            }
        }

        for (i=0; i<3; i++){
            tmp += length[i] * length[i];
        }
        tmp2 = length[max_index] * length[max_index];

        if ( (tmp - tmp2 * 2) == 0) {
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }

    return 0;
}

Measured memory_bytes: 584
arry = [0]
arry.clear()

while line = gets.chomp
  if( line.empty? == false )
    num = line.to_i()
    if( num >= 1 ) && (num <= 100)
      arry.push( num )
    else
    end
  else
  end
  if( arry.length >11)
    break;
  end
end

most_appear_val = [0]
appear_cnt = 0
for i in 1..100 do
  count = arry.count(i)
  if( appear_cnt < count )
    most_appear_val.clear()
    most_appear_val.push(i)
    appear_cnt = count
  elsif( appear_cnt == count )
    most_appear_val.push(i)
  end
end

puts most_appear_val

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int L;

bool bit(int m, int i) {
	return (1 & (m >> i));
}

struct Edge {
	int a, b, w;
	Edge () {};
	Edge (int a, int b, int w) : a(a), b(b), w(w) {};
};

int n;

vector<Edge> ans;

void solve() {
	n = 20;

	vi vb;
	int x = L;
	while (x) {
		vb.pb((x & 1));
		x >>= 1;
	}

	fi(2, 19) {
		ans.pb(Edge(i, i + 1, 0));
		ans.pb(Edge(i, i + 1, (1 << (n - i) )));
	}
	ans.pb(Edge(19, 20, 1));
	ans.pb(Edge(19, 20, 3));
	
	int sum = 0;
	fdi(sz(vb) - 1, 0) {
		if (!vb[i]) continue;

		int k = n - (i - 1);
		if (i == 0) {
			ans.pb(Edge(1, n, sum));
		} else if (i == 1) {
			ans.pb(Edge(1, k, sum));
			ans.pb(Edge(1, k, sum + 1));
		} else {
			ans.pb(Edge(1, k, sum));			
		}
		sum += (1 << i);
	}

	//
	assert(sz(ans) <= 60);
	for (auto z : ans) {
		assert(z.a <= z.b);
		assert(z.a <= n && z.a >= 1);
		assert(z.b <= n && z.b >= 1);
	}
	//

	printf("%d %d\n", n, sz(ans));
	for (auto z : ans) {
		printf("%d %d %d\n", z.a, z.b, z.w);
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf("%d", &L);
  //for (L = 2; L <= 1000 * 1000; L++) {		  	
		solve();		
//	}

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

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

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

    int n;
    cin >> n;

    vector< LL >a(n);
    for (LL &x : a) cin >> x;

    LL ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] > a[i]) {
            ans += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }

    cout << ans << "\n";

    return 0;
}




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

int main() {
	string s;
	cin >> s;
	s = '5' + s;
	bool ok1 = true, ok2 = true;
	for(int i = 1; i < (int)s.size(); ++i) {
		if(i % 2)
			ok1 &= s[i] != 'L';
		else
			ok2 &= s[i] != 'R';
	}
	cout << (ok1 & ok2 ? "Yes" : "No");
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
string a, b, c;
char d, e, f;

int main(){
  cin>>a>>b>>c;
  d=a[0] - 32;
  e=b[0] - 32;
  f=c[0] - 32;
  cout<<d<<e<<f<<endl;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  string s[h];
  rep(i,h) cin >> s[i];
  vector<vector<bool>> f(h,vector<bool>(w,false));
  int x[4] = {1,0,-1,0}, y[4] = {0,-1,0,1};
  ll ans = 0;
  rep(i,h) {
    rep(j,w) {
      if(s[i][j] == '#' && f[i][j] == false) {
        f[i][j] = true;
        ll k = 1, n = 0;
        queue<P> que;
        que.push(P(i,j));
        while(!que.empty()) {
          P p = que.front(); que.pop();
          if(s[p.first][p.second] == '#') {
            rep(l,4) {
              int nx = p.first + x[l], ny = p.second + y[l];
              if(nx >= 0 && nx < h && ny >= 0 && ny < w && s[nx][ny] == '.' && f[nx][ny] == false){
                f[nx][ny] = true;
                n++;
                que.push(P(nx,ny));
              }
            }
          } else {
            rep(l,4) {
              int nx = p.first + x[l], ny = p.second + y[l];
              if(nx >= 0 && nx < h && ny >= 0 && ny < w && s[nx][ny] == '#' && f[nx][ny] == false){
                f[nx][ny] = true;
                k++;
                que.push(P(nx,ny));
              }
            }
          } 
        }
        ans += k*n;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

static const int MAX_N = 100;

struct Card {
    char suit, value;
};

void bubbleSort(Card A[], int N) {
    for (int i = 0; i < N; ++i) {
        for (int j = N-1; j >= i+1; --j) {
            if (A[j].value < A[j-1].value) {
                swap(A[j], A[j-1]);
            }
        }
    }
}

void selectionSort(Card A[], int N) {
    for (int i = 0; i < N; ++i) {
        int minj = i;
        for (int j = i; j < N; ++j) {
            if (A[minj].value > A[j].value) {
                minj = j;
            }
        }
        swap(A[minj], A[i]);
    }
}

void print(Card A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i == N-1) cout << A[i].suit << A[i].value << endl;
        else cout << A[i].suit << A[i].value << " ";
    }
}

bool isStable(Card C1[], Card C2[], int N) {
    for (int i = 0; i < N; ++i) {
        if (C1[i].suit != C2[i].suit) {
            return false;
        }
    }
    return true;
}

int main() {
    Card C1[MAX_N], C2[MAX_N];
    int N;
    char ch;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> C1[i].suit >> C1[i].value;
        C2[i].suit = C1[i].suit;
        C2[i].value = C1[i].value;
    }

    bubbleSort(C1, N);
    selectionSort(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if (isStable(C1, C2, N)) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
using namespace std;
main(){
  string a,b,c;
  int int_a,int_b;
  cin>>a>>b>>int_a>>int_b>>c;
  if(c==a)cout<<int_a-1<<" "<<int_b<<endl;
  else cout<<int_a<<" "<<int_b-1<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var scaner = new Scanner();

        var a = scaner.ReadInt();
        var b = scaner.ReadInt();

        var p = a + b;
        var m = a - b;
        var x = a * b;

        var ans = Math.Max(p, Math.Max(m, x));
        Console.WriteLine(ans);
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<ll,ll> pll;
typedef vector <pll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define coutif(a,b,c) cout<<(a?b:c)

int main(){
    ll n,m,j,k=0,ans=0,t=0,x,y,i;
    cin>>n;
    ll a[n],b[n];
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n;i++) cin>>b[i];
    for(j=0;j<100;j++){
        for(i=0;i<n;i++){
            x=(i+n-1)%n,y=(i+1)%n;
            k=b[x]+b[y];
            if(k<b[i]){
                t=(b[i]-a[i])/k;
                b[i]-=k*t; 
                ans+=t;
            }
        }
    }
    for(i=0;i<n;i++) if(a[i]!=b[i]) out(-1);
    cout<<ans;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n, W;
	cin >> n >> W;
	int v[1001], w[1001];
	for (int i = 1; i <= n; i++)
		cin >> v[i] >> w[i];
	int dp[101][10001] = {};
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= W; j++) {
			if (w[i] <= j)
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}

Measured memory_bytes: 5120
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
int main(){
    int n,a,b;
    read(n),read(a),read(b);
    cout<<min(n*a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
const int mod=(1e9)+7;
const int M=(1e7)+9;
int n,m,tot,d[maxn],iv[maxn],ivjc[maxn],jc[maxn];
int dp[40][maxn],ans;
vector<int> g[maxn];
struct Haxi {
	int to[maxn],tot,head[M],nxt[maxn],w[maxn];
	void insert(int x,int y) {
		tot++; nxt[tot]=head[x%M];
		head[x%M]=tot; to[tot]=x; w[tot]=y;
	}
	int find(int x) {
		for (int i=head[x%M];i;i=nxt[i])
			if (to[i]==x) return w[i];
		return 0;
	}
} Map;
int C(int x,int y) {
	if (x<y||y<0) return 0;
	return (ll)jc[x]*ivjc[y]%mod*ivjc[x-y]%mod;
}
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}
int main() {
	
	read(n); read(m);
	iv[0]=jc[0]=ivjc[0]=iv[1]=jc[1]=ivjc[1]=1;
	for (int i=2;i<maxn;i++) {
		jc[i]=(ll)jc[i-1]*i%mod;
		iv[i]=(ll)(mod-mod/i)*iv[mod%i]%mod;
		ivjc[i]=(ll)ivjc[i-1]*iv[i]%mod;
	}
	for (int i=1;(ll)i*i<=m;i++)
		if (m%i==0) {
			d[++tot]=i;
			if (m/i!=i) d[++tot]=m/i;
		}
	sort(d+1,d+tot+1);
	int x;
	for (int i=1;i<=tot;i++) {
		Map.insert(d[i],i);
		x=d[i];
		for (int j=1;(ll)j*j<=d[i];j++)
			if (x%j==0) {
				g[Map.find(j)].push_back(i);
				if (x/j!=j) g[Map.find(x/j)].push_back(i);
			}
	}
	int mx=min(n,35);
	dp[0][1]=1;
	for (int i=0;i<mx;i++)
	for (int j=1;j<=tot;j++) if (dp[i][j]) {
		for (int k=0;k<g[j].size();k++) if (g[j][k]!=j) {
			update(dp[i+1][g[j][k]],dp[i][j]);
		}
	}
	for (int i=0;i<=mx;i++) {
		update(ans,(ll)dp[i][tot]*C(n,i)%mod);
	}
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

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

using namespace std;

#define td typedef
td long long ll;

ll in()
{
    ll a;
    scanf("%lld",&a);
    return a;
}

bitset <2005*2005> ase;

int main()
{
    int n=in(),a[2005],sum=0;
    for(int i=0;i<n;i++){
        a[i]=in();
        sum+=a[i];
    }
    ase.set(0);
    for(int i=1;i<=n;i++)
        ase=ase|(ase<<a[i-1]);
    for(int i=(sum+1)/2;i<=sum;i++)
    {
        if(ase[i])
        {
            printf("%d\n",i);
            return 0;
        }
    }
}


Measured memory_bytes: 2304