akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc063/tasks/arc075_b
# 問題文あなたが散歩していると、突然 N 体の魔物が出現しました。
# それぞれの魔物は 体力 という値を持ち、i 体目の魔物の出現時の体力は hi です。
# 体力が 0以下となった魔物は直ちに消滅します。
# 幸い、あなたは熟練の魔法使いであり、爆発を引き起こして魔物を攻撃できます。
# 一回の爆発では、以下のように魔物の体力を減らすことができます。
# 生存している魔物を一体選び、その魔物を中心に爆発を引き起こす。
# 爆発の中心となる魔物の体力は A 減り、
# その他の魔物の体力はそれぞれ B 減る。
# ここで、A と B はあらかじめ定まった値であり、A>B である。
# すべての魔物を消し去るためには、最小で何回の爆発を引き起こす必要があるでしょうか？
# 制約入力値はすべて整数である。
# 1≤N≤10^5
# 1≤B<A≤10^9
# 1≤hi≤10^9

# N A B
# h1
# h2
# :
# hN

# 4 5 3
# 8
# 7
# 4
# 2

# 2

# 2 10 4
# 20
# 20

# 4

# 5 2 1
# 900000000
# 900000000
# 1000000000
# 1000000000
# 1000000000

# 800000000

N, A, B = gets.split.map(&:to_i)
H = []
N.times { H << gets.to_i }

A_B = A - B

class Integer
  def able?
    counter = self
    bself = B * self
    H.each do |value|
      next if value <= bself
      counter -= ((value - bself + A_B - 1)/(A_B))
      break if counter < 0
    end
    counter >= 0
  end
end

# T回で倒しきれるか？ を二分探索
# ng = 0, ok = h.max
ng = 0
ok = 10**9
mid = 0
while (ok - ng) > 1
  mid = (ng + ok)/2
  if mid.able?
    ok = mid
  else
    ng = mid
  end
end
puts ok

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr ll MOD = 1e12;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i,n) cin >> lr[i].first >> lr[i].second;
    int l_max = 0,r_min = INF+2;
    int l_max_cnt = 0,r_min_cnt = 0;
    rep(i,n){
        if(l_max < lr[i].first){
            l_max_cnt = 1;
            l_max = lr[i].first;
        }else if(l_max == lr[i].first){
            l_max_cnt ++;
        }

        if(r_min > lr[i].second){
            r_min_cnt = 1;
            r_min = lr[i].second;
        }else if(r_min == lr[i].second){
            r_min_cnt ++;
        }
    }

    int mx = 0;
    rep(i,n){
        if(l_max == lr[i].first && l_max_cnt == 1) continue;
        if(r_min == lr[i].second && r_min_cnt == 1) continue;
        mx = max(mx,lr[i].second - lr[i].first + 1);
    }
    int ans = max(r_min - l_max + 1,0) + mx;

    sort(lr.begin(),lr.end(),greater<P>());
    vector<int> cumrmin(n);
    rep(i,n) cumrmin[i] = lr[i].second;
    rep(i,n-1) cumrmin[i+1] = min(cumrmin[i],cumrmin[i+1]);

    int l_max_r_max = 0;
    int r_min_l_min = INF+2;

    rep(i,n){
        if(lr[i].first == l_max) l_max_r_max = max(l_max_r_max,lr[i].second);
        if(lr[i].second == r_min) r_min_l_min = min(r_min_l_min,lr[i].first);
    } 

    rep(i,n-1){
        int res = 0;
        res += max(min(cumrmin[i],l_max_r_max) - l_max + 1,0);
        res += max(r_min - max(lr[i+1].first,r_min_l_min) + 1,0);
        ans = max(ans,res);
    } 

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

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e8;
using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")

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

	int n;
	cin >> n;
	string s;
	cin >> s;
	int r=0;
	int b = 0;

	for (int i = 0;i < n;i++)
	{
		if (s[i] == 'B')
		{
			b++;
		}
		else
			r++;
	}

	if (r > b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
 
int main() {
  string n;
    cin>>n;
  if( n[0] == n[1] && n[1]==n[2])
  {
  	cout<< "Yes" <<endl;}
  else if(n[2] == n[3] && n[2]==n[1] )
  {
  	cout<< "Yes" <<endl;}
  else {cout<<"No"<<endl;}
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

string norm(string str) {
	int ind = 0;
	for (int i = 0; i < str.length() && str[i] == '0'; ++i) {
		++ind;
	}
	if (ind > 0) {
		return str.substr(ind,str.length()-ind);
	}
	return str;
}

string str_max(string s1, string s2) {
	s1 = norm(s1);
	s2 = norm(s2);
	if (s1.length() > s2.length()) {
		return s1;
	}
	if (s2.length() > s1.length()) {
		return s2;
	}

	if (s1 > s2) {
		return s1;
	}
	return s2;
}

int main(void) {
	int W,H;
	while (cin >> W >> H, W) {
		vector< vector<string> > mat(H,vector<string>(W));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				string temp = "";
				char c;
				cin >> c;
				if (c >= '0' && c <= '9') {
					temp += c;
				}
				else {
					temp = " ";
				}
				mat[i][j] = temp;
			}
		}

		string res = "0";
		vector< vector<string> > dp(H,vector<string>(W,""));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (mat[i][j] != " ") {
					if (dp[i][j] == "") {
						dp[i][j] = mat[i][j];
						res = str_max(res,dp[i][j]);
					}
					if (j+1 < W && mat[i][j+1] != " ") {
						dp[i][j+1] = str_max(dp[i][j]+mat[i][j+1],dp[i][j+1]);
						res = str_max(dp[i][j+1],res);
					}
					if (i+1 < H && mat[i+1][j] != " ") {
						dp[i+1][j] = str_max(dp[i][j]+mat[i+1][j],dp[i+1][j]);
						res = str_max(dp[i+1][j],res);
					}
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 3340
#include<stdio.h>

#define MAX 100000

int parent(int i){
    return i/2;
}

int left(int i){
    return 2*i;
}

int right(int i){
    return 2*i+1;
}


int main(){
    int H, A[MAX+1];
    int i;

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

    for(i=1; i<H+1; i++){
        printf("node %d: key = %d, ", i, A[i]);

        if(parent(i) > 0){
            printf("parent key = %d, ", A[parent(i)]);
        }
        if(left(i) < H+1){
            printf("left key = %d, ", A[left(i)]);
        }
        if(right(i) < H+1){
            printf("right key = %d, ", A[right(i)]);
        }
        printf("\n");
    }

    return 0;
}



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

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int W, H, K;
int fact[1000001];

int modpow(int x, int k) {
  int a = 1;
  while (k > 0) {
    if (k & 1) a = (1LL*a*x) % MOD;
    x = (1LL*x*x) % MOD;
    k >>= 1;
  }
  return a;
}

int inv(int x) {
  return modpow(x, MOD-2);
}

int nCr(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  return (1LL * fact[n] * inv((1LL*fact[k]*fact[n-k]) % MOD)) % MOD;
}
int cat(int n) {
  return (1LL * nCr(2*n, n) * inv(n+1)) % MOD;
}

int f(int n, int s) {
  long long all = (0LL + nCr(n, s) - nCr(n, s-1) + MOD) % MOD;
  return all;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> W >> H >> K;

  fact[0] = 1;
  for (int i=1; i<=1000000; i++) {
    fact[i] = (1LL*i*fact[i-1]) % MOD;
  }

  int s = 0;
  for (int kw=0; kw<=K; kw++) {
    int kh = K - kw;
    s += (1LL*((1LL*f(W+2*kw, kw)*f(H+2*kh, kh))%MOD)*nCr(H+W+2*K, W+2*kw)) % MOD;
    s %= MOD;
  }
  cout << s << "\n";
  return 0;
}

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

int main(){
    long N;cin>>N;
    vector<long> a(N);
    long sum=0;
    for(long i=0;i<N;i++){
        cin>>a[i];
        sum+=a[i];
    }
    vector<long> asum(N);
    asum[0]=(sum-a[0])%1000000007;
    long vsum=a[0];
    for(long i=1;i<N;i++){
        vsum+=a[i];
        asum[i]=(sum-vsum)%1000000007;
    }
    long res=0;
    for(long i=0;i<N;i++){
        res=(res+(asum[i]*a[i])%1000000007)%1000000007;
    }
    cout<<res<<endl;
}

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

#define x first
#define y second
#define int64 long long
#define MaxN 200000

pair<int64, int> sum[MaxN+1];
int aib[MaxN+1];
int v[MaxN+1];
int N, K;

void Update(int p, int x)
{
    while(p <= N){
        aib[p] += x;
        p += p & (-p);
    }
}

int Query(int p)
{
    int sum = 0;
    while(p > 0){
        sum += aib[p];
        p -= p & (-p);
    }

    return sum;
}

int main(){


    int i;
    int64 temp, res = 0;

    scanf("%d %d", &N, &K);
    for(i = 1; i <= N; ++i) scanf("%d", &v[i]);
    for(i = 1; i <= N; ++i) v[i] = v[i] - K;

    temp = 0;
    for(i = 1; i <= N; ++i){
        temp = temp + v[i];
        sum[i] = {temp, i};

        if(temp >= 0) ++res;
    }

    sort(sum + 1, sum + N + 1);
    for(i = 1; i <= N; ++i)
    {
        res = res + Query(sum[i].y);
        Update(sum[i].y, 1);
    }

    printf("%lld\n", res);



return 0;
}


Measured memory_bytes: 4992
n = int(input())
a = list(map(int,input().split()))
M = max(a)+1
if M == 2:
    print("pairwise coprime")
    exit()
count = [0]*(M)
prime = [2,3,5,7,11,13]
for i in range(14,int(M**0.5)+2):
    check = True
    for j in prime:
        if i%j == 0:
            check = False
            break
    if check:
        prime.append(i)
 
for i in a:
    for j in prime:
        if i < j:
            break
        if i%j==0:
            while i%j == 0:
                i //= j
            count[j] += 1
    if i > 1:
        count[i] += 1
 
ans = max(count)
 
if ans == 1:
    print("pairwise coprime")
elif ans == n:
    print("not coprime")
else:
    print("setwise coprime")

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

#define FOR(i,N) for(int i=0;i<N;i++)

int main(){
    long long N,K,X,D,S,T,X1,X2,ans=0,keep1,keep2;
    cin >> D>>T>>S;
    if(T*S>=D){
        cout << "Yes";
    }else{
        cout << "No";
    }

}

Measured memory_bytes: 3636
<?php
list($a, $b, $kth) = explode(' ', trim(fgets(STDIN)));

if ($a == 1 || $b ==1) {
	echo 1, PHP_EOL;
    exit();
}

$array = [];
$i = min($a, $b);
while ($i > 0) {
	if ($a % $i === 0 && $b % $i ===0) {
    	$array[] = $i;
    }
    $i--;
}

echo $array[$kth - 1], PHP_EOL;

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

Measured memory_bytes: 3076
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] a = {1,3,5,7,8,10,12};
        int[] b = {4,6,9,11};
        
        if(x==2 || y==2){
            System.out.println("No");
            return;
        }
        for(int i = 0; i < a.length; i++){
            if(x==a[i]){
                for(int j = 0; j < a.length; j++){
                    if(y==a[j]){
                        System.out.println("Yes");
                        return;
                    }
                }
            }
        }
        for(int i = 0; i < b.length; i++){
            if(x==b[i]){
                for(int j = 0; j < b.length; j++){
                    if(y==b[j]){
                        System.out.println("Yes");
                        return;
                    }
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;
  for(ll b=60; b>=0; b--){
    map<ll,ll> m;
    rep(i,N){
      m[(v[i]>>b)&1]++;
    }

    ll tmp = ((m[0] % MOD) * (m[1] % MOD)) % MOD;
    tmp *= (1LL<<b) % MOD;
    tmp %= MOD;
    
    ret += tmp;
    ret %= MOD;
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 6384
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

S = input()

set_ = set(S)
for c in [chr(i) for i in range(97, 97+26)]:
    if c not in set_:
        print(c)
        quit()
print('None')

Measured memory_bytes: 9104
from math import sqrt, factorial
from itertools import permutations


def main():
    n = int(input())
    pos = []

    for i in range(n):
        x, y = map(int, input().split())
        pos.append([x, y])

    sum = 0
    for i in permutations(pos, 2):
        # 例:i=([x0,y0],[x1,y1])
        """
        1箇所線分を固定した場合のパス(経路)は(n-1)!通り
        例えば、全パスn!通りのうち、1→2の線分が出てくるパスは(n-1)!通り
        各線分の距離*(n-1)!を全線分加算すると全パスの合計がでる
        """
        sum += sqrt((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2)*factorial(n-1)

    # 全パスの平均
    print(sum/factorial(n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define fr first
#define sc second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define int long long
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
const int inf = 1e9+7;
const int nmax = 500005;
const ll linf = LLONG_MAX;

int n;
string s;

int32_t main(){
    cin >> n;
    cin >> s;
    int r = 0;
    for(int i = 0 ; i + 2 < n ; i++){
        if(s[i] == 'A' && s[i+1] == 'B'&& s[i+2] == 'C')r++;
    }
    cout << r;

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,b,a) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
#define SUPbl 1002
#define SUPrt 1002
#define SUPut 1002


int bl;
bool dp[SUPrt];	//dp[t] = rs no bubun syuugou no wa de t ga tukureru ka
int rs[SUPbl];
int us[SUPbl];
int sumr, sumu;
int maxr, maxu;
int T;

int solve(){
	sumr=0; sumu=0; maxr=0; maxu=0;
	REP(bi,bl){ sumr+=rs[bi]; sumu+=us[bi]; maxr=max(maxr,rs[bi]); maxu=max(maxu,us[bi]);}
	T=maxr*2-sumr;
	if(T<=0){
		return sumr+sumu;
	}else{
		FOR(t,0,T+1) dp[t]=false;
		dp[0]=true;
		FOR(bi,0,bl){
			if(rs[bi]==maxr) continue;
			ROF(t,T+1,0){
				if(t>=us[bi]) dp[t] = dp[t] || dp[t-us[bi]];
			}
		}
		int t=T;
		for(;t>=0;--t){
			if(dp[t]) break;
		}
		return sumr+sumu+(T-t);
	}

}

int main(){
	while(true){
		cin >> bl;			if(!bl) return 0;
		REP(bi,bl) cin>>rs[bi]>>us[bi];
		cout<<solve()<<endl;
	}
}

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

def gen(n):
  if n < 10:
    yield n
  else:
    for m in gen(n/10):
      yield m
    yield n%10

ans = 0
for i in range(0, a[0]+1):
    num = [int(j) for j in gen(i)]
    sumed = sum(num)
    if (a[1] <= sumed) and (sumed <= a[2]):
        ans = ans + i

print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 2000010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int main()
{
	int n=read(),m=read();
	printf("%d\n",(n-1)*(m-1));
}

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

int main() {
    int n, c = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        while(a % 2 == 0){
            a /= 2;
            c++;
        }
    }
    cout << c << endl;
	return 0;
}

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

using namespace std;
int main(){
  long n, ans;
  cin >> n;
  ans = 0;  

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

  for(int i=0;i<n;i++){
    int b;
    cin >> b;
     
    if(a[i] >= b){ 
      ans += b;
    } else{
       if(a[i] + a[i+1] >= b){
         ans += b;      
        //  ans += 
         a[i+1] -= b - a[i];
       }else{
         ans += a[i];
         ans += a[i+1];
         a[i+1] = 0;
       } 
    }
  }
 cout << ans << endl;
}


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

int main(){
    int n, x[100], y[100];
    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> x[i];
    for ( int i = 0; i < n; i++ ) cin >> y[i];
    
    double d[4];
    for ( int i = 0; i < 4; i ++ ) d[i] = 0.0;
    
    for ( int p =1; p <= 3; p++ ){
        for ( int i = 0; i < n; i++ ){
            d[p] += pow(fabs(x[i] - y[i]), p);
        }
        d[p] = pow(d[p], 1.0/p);
    }
    
    for ( int i = 0; i < n; i++ ){
        d[0] = (d[0] < fabs(x[i] -y[i])?fabs(x[i] - y[i]):d[0]);
    }
    
    printf("%lf\n", d[1]);
    printf("%lf\n", d[2]);
    printf("%lf\n", d[3]);
    printf("%lf\n", d[0]);
}


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

int x ;

void input ( ) {
    scanf ( "%d" , &x ) ;
}

void solve ( ) {
    int sm = 360 ;
    while ( ( sm % x ) != 0 ) { sm += 360 ; }
    printf ( "%d\n" , sm / x ) ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 3764
W, H, N = map(int, raw_input().split())
xmax = W
xmin = 0
ymax = H
ymin = 0

for _ in range(N):
    x, y, a = map(int, raw_input().split())
    if a == 1:
        xmin = max(xmin, x)
    if a == 2:
        xmax = min(xmax, x)
    if a == 3:
        ymin = max(ymin, y)
    if a == 4:
        ymax = min(ymax, y)

print max(0, xmax-xmin) * max(0, ymax-ymin)


Measured memory_bytes: 2568
#include <cstdio>
using namespace std;
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    if(n < m){
        for(int i = 0; i < m; i ++){
            printf("%d", n);
        }
    }
    else{
        for(int i = 0; i < n; i ++){
            printf("%d", m);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=100005;

int n,m,cnt,t;
int a[N],b[N];

int main(){
	int i; cnt=0;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++){
		scanf("%d",&a[i]);
		if (a[i]&1) cnt++;
	}
	if (cnt>2){
		printf("Impossible\n");
		return 0;
	}
	for (i=2;i<=m;i++)
		if (a[i]&1) (a[1]&1)?swap(a[m],a[i]):swap(a[1],a[i]);
	if (m==1){
		if (a[1]==1) printf("%d\n1\n%d\n",1,1);
		else printf("%d\n2\n%d %d\n",a[1],a[1]-1,1);
		return 0;
	}
	for (i=1;i<=m;i++) printf("%d ",a[i]); printf("\n");
	t=0;
	if (a[1]>1) b[++t]=a[1]-1;
	for (i=2;i<m;i++) b[++t]=a[i];
	b[++t]=a[m]+1;
	printf("%d\n",t);
	for (i=1;i<=t;i++) printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 256
import itertools
try:
    while(True):
        n = int(input())
        cnt = 0
        rng = range(10)
        for i,j,k,l in itertools.product(rng,rng,rng,rng):
            if i + j + k + l == n:
                cnt = cnt + 1
        print(cnt)
except:
    pass


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

ll l , r ;

int main() {
  fast
  cin >> l >> r ;
  ll mn = Int_max ;
    forn( ll , i , l , min( l + 4 * 3000 , r ) ){
       forn( ll , j , l + 1 , min( l + 4 * 3000 , r + 1 ) ){
            mn = min( mn , ( i * j ) % 2019 ) ;
       }
    }
  cout << mn ;

  return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i,sum=0;
	char weathr[4];
	scanf("%s",weathr);
	//全てR
	for(i=0;i!='\0';i++){
		if(weathr[i]=='R')
			sum++;
		if(sum==3){
			printf("%d\n",sum);
		return 0;
		}
	}
	sum=0;
	
	for(i=0;i<3;i++)
		if(weathr[i]=='R')
			sum++;
	
	if(sum==2&&weathr[1]=='S')
		sum--;
		
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 2148
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  ll X;
  cin >> X;
  vector<ll> D;
  ll i {0};
  ll A, B;
  bool is_find = false;
  while (true) {
    D.push_back(i*i*i*i*i);
    rep(j, i) {
      if (X == D[i] - D[j]) {
        A = i;
        B = j;
        is_find = true;
        break;
      } else if (X == D[i] + D[j]) {
        A = i;
        B = -j;
        is_find = true;
        break;
      } else if (X == -D[i] - D[j]) {
        A = -i;
        B = j;
        is_find = true;
        break;
      } else if (X == -D[i] + D[j]) {
        A = -i;
        B = -j;
        is_find = true;
        break;
      }
    }
    if (is_find == true) break;
    ++i;
  }
  cout << A << ' ' << B << '\n';
}


Measured memory_bytes: 3624
use io::*;
use std::cmp::Ordering;
use std::*;

fn solve(A: i64, B: i64) {
    match A.cmp(&B) {
        Ordering::Less if A == 1 => println!("Alice"),
        Ordering::Less => println!("Bob"),
        Ordering::Greater if B == 1 => println!("Bob"),
        Ordering::Greater => println!("Alice"),
        Ordering::Equal => println!("Draw"),
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut A: i64;
    A = scanner.next();
    let mut B: i64;
    B = scanner.next();
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(A, B)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8572
import sys
from collections import Counter
input = sys.stdin.readline
N,K,Q = map(int,input().split())
QCounter = Counter([int(input()) for _ in range(Q)]).most_common()
defult_over = Q-K #突破に必要な正解数

if defult_over>=0:
    s = set()
    for win in QCounter:
        if win[1]>defult_over:
            s.add(win[0]-1)
    for i in range(N):
        if i in s:
            print("Yes")
        else:
            print("No")
else:
    for _ in range(N):
        print("Yes")

Measured memory_bytes: 14708
input_list = list(map(int, input().split(" ")))

n = input_list[0]
m = input_list[1]
a_i_list = list(map(int, input().split(" ")))


a_i_sum = sum(a_i_list)

result = n - a_i_sum

if result < 0:
    result = -1

print(result)

Measured memory_bytes: 10052
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 1;

int rup(int a, int d) {
    return (a+d-1)/d;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k; cin>>n>>k;
    /*int p=-1;
    F(i,n) {
        int x; cin>>x;
        if (x == 1)
            p = i;
    }*/
    cout<<rup(n-1,k-1)<<"\n";
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
ll n;
set<ll>q;
bool ck(ll x,ll y){
	if(y==1) return false;
	while(x%y==0) x/=y;
	if(x%y==1) return true;
	return false;
}
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	ll ans=0;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			if(ck(n,i)) q.insert(i);
			if(ck(n,n/i)) q.insert(n/i);
		}
	}
	--n;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			if(i!=1) q.insert(i);
			if(n/i!=1) q.insert(n/i);
		}
	}
	cout<<q.size()<<endl;
	return 0;
}
/*
n%k=1;
(n/k)%k=1;
*/

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int k, n;
    cin >> n >> k;
    vector<double> e(n);
    rep(i, n)
    {
        double a;
        cin >> a;
        e[i] = (a * (a + 1) / 2) / a;
    }
    vector<double> q(n - k + 1);
    rep(i, k)
    {
        q[0] += e[i];
    }
    rep(i, n - k)
    {
        q[i + 1] = q[i] + e[k + i] - e[i];
    }

    sort(All(q));
    double ans = 0;
    ans = q.back();
    c(ans);
    return 0;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int M;

vector< vector<ll> > matmul(vector< vector<ll> >& A, vector< vector<ll> >& B) {
	int n = A.size();
	vector< vector<ll> > C(n, vector<ll>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
	return C;
}

vector< vector<ll> > matpow(vector< vector<ll> > A, ll x) {
	int n = A.size();
	vector< vector<ll> > B(n, vector<ll>(n));
	for (int i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {
		if (x % 2) B = matmul(B, A);
		x /= 2;
		A = matmul(A, A);
	}
	return B;
}

int main() {
	for (;;) {
		int N, A, B, C, T;
		cin >> N >> M >> A >> B >> C >> T;
		if (N == 0) break;
		vector< vector<ll> > a(N, vector<ll>(N));
		for (int i = 0; i < N; i++) {
			if (i - 1 >= 0) a[i][i - 1] = A;
			a[i][i] = B;
			if (i + 1 < N) a[i][i + 1] = C;
		}
		a = matpow(a, T);
		vector<int> S(N);
		for (int i = 0; i < N; i++) cin >> S[i];
		for (int i = 0; i < N; i++) {
			int ans = 0;
			for (int j = 0; j < N; j++) 
				ans = (ans + a[i][j] * S[j]) % M;
			cout << ans << (i + 1 < N ? ' ' : '\n');
		}
	}
}

Measured memory_bytes: 1304
x = int(input())
if 400 <= x < 600:
    print(8)
elif 600 <= x < 800:
    print(7)
elif 800 <= x < 1000:
    print(6)
elif 1000 <= x < 1200:
    print(5)
elif 1200 <= x < 1400:
    print(4)
elif 1400 <= x < 1600:
    print(3)
elif 1600 <= x < 1800:
    print(2)
else:
    print(1)

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

int main(){
	int n; cin >> n;
	int m; cin >> m;
	int a[2*n],b[2*n];
	for(int i=0;i<2*n;i++){
		a[i]=i+1;
	}
	for(int j=0;j<m;j++){
		int k; cin >> k;
		if(k==0){
			for(int i=0;i<n;i++){
				b[2*i]=a[i];
				b[2*i+1]=a[i+n];
			}
		}
		else{
			for(int i=k;i<2*n;i++){
				b[i-k]=a[i];
			}
			for(int i=0;i<k;i++){
				b[2*n-k+i]=a[i];
			}
		}
		for(int i=0;i<2*n;i++){
			a[i]=b[i];
		}
	}
	for(int i=0;i<2*n;i++){
		cout << b[i] << endl;
	}
}


Measured memory_bytes: 3080
#include<iostream>
using namespace std;
int main(){
  long n,a,b;
  cin >> n >> a >> b;
  if( a==0 ){
    cout << 0 << endl;
    return 0;
  }
  if( b==0 ){
    cout << n << endl;
    return 0;
  }
  long bl = (long)(n/(a+b))*a;
  if( n%(a+b) > a ){
    bl += a;
  } else {
    bl += n%(a+b);
  }
  cout << bl << endl;
  return 0;
}


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

vector<string> split_string(string);

int arr[223556];

int main()
{
   ll n, k;
   cin >> n >> k;
   for(int i = 1; i <= n; i++) cin >> arr[i];

   ll cnt = 0;
   ll val = 1LL;
   vector <int> vec;
   set <ll> se;
   while(!se.count(val)){
       //cout << val << endl;
       se.insert(val);
       vec.push_back(val);
       val = arr[val];
   }
   //cout << val << "|" << endl;
   for(int i = 0 ; i < vec.size(); i++){
       if(i == k){
           cout << vec[i];
           break;
       }
       if(vec[i] == val){
          k -= i;
          ll dist = vec.size()-i;
          k %= dist;
          cout << vec[i+k];
          break;
       }
   }
}


Measured memory_bytes: 13944
#include <iostream>
#include <algorithm>
using namespace std;
int N,X,Y;
long long dist(int a, int b){
	if(a==X&&b<Y){
		return min(1+Y-b,b-a);
	}else if(a==X&&b>=Y){
		return b-Y+1;
	}else if(a<X&&b<X){
		return b-a;
	}else if(a<X&&b<Y){
		return min(X-a+1+Y-b,b-a);
	}else if(a<X&&b>=Y){
		return X-a+1+b-Y;
	}else if(a>X&&b<Y){
		return min(a-X+1+Y-b,b-a);
	}else if(a>=Y&&b>Y){
		return b-a;
	}else if(a>X&&b>=Y){
		return min(a-X+1+b-Y,b-a);
	}
}
int main(){
	cin>>N>>X>>Y;
	int arr[N];
	for(int i=1; i<=N; i++){
		arr[i]=0;
	}
	for(int i=1; i<N; i++){
		for(int j=i+1; j<=N; j++){
			arr[dist(i,j)]++;
		}
	}
	for(int i=1; i<N; i++){
		cout<<arr[i]<<'\n';
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string k; int d;
    cin >> k >> d;
    int n = k.length();
    ll dp[n+1][d] = {};
    dp[0][0] = 1;
    for(int m = 1; m <= n; m++)
        for(int x = 0; x < d; ++x)
            for (int i = 0; i <= 9; i++)
                dp[m][x] = (dp[m][x] + dp[m-1][((x-i)%d+d)%d]) % mod;
    ll ans = 0;
    ll sum = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < k[i]-'0'; ++j) {
            ans = (ans + dp[n-i-1][((-sum-j)%d+d)%d])%mod;
        }
        sum = (sum + k[i]-'0') % d;
    }
    if(sum % d == 0)
        ans = (ans + 1)%mod;
    ans = (ans - 1) % mod;
    cout << (ans+ mod) % mod;
    return 0;
}


Measured memory_bytes: 8064
s=input()
i=0
maxlv=0
while i<len(s):
    lbuf=0
    if s[i]=='J':
        j=1
        while i+j<len(s) and s[i+j]=="J":j+=1
        lbuf=j
        i=i+j
        j=0
        while i+j<len(s) and j<lbuf and s[i+j]=="O":j+=1
        lbuf=min((lbuf,j))
        if lbuf==0:continue
        i=i+j
        j=0
        while i+j<len(s) and j<lbuf and s[i+j]=="I":j+=1
        i=i+j
        if j!=lbuf:continue
        elif lbuf>maxlv:
            maxlv=lbuf
    else:i+=1
print(maxlv)

Measured memory_bytes: 9464
n, m = map(int, input().split(' '))
a = []
for i in range(n):
    a.append([item for item in map(int, input().split(' '))])
b = []
for i in range(m):
    b.append(int(input()))

for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)



Measured memory_bytes: 6012
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <tuple>

int main()
{
    int64_t n;
    scanf("%" PRId64, &n);

    std::vector<std::tuple<std::string, int64_t, int64_t>> list;
    for (int64_t i = 0; i < n; i++)
    {
        char sv[101] = {};
        int64_t pv;
        scanf("%s %" PRId64, sv, &pv);

        list.push_back(std::make_tuple(std::string(sv), 100 - pv, i + 1));
    }
    std::sort(list.begin(), list.end());

    for (auto i : list)
    {
        printf("%" PRId64 "\n", std::get<2>(i));
    }
    return 0;
}


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

const long MAX = 200000;
const long SENTINEL = 1000000001;

long L[MAX / 2 + 2], R[MAX / 2 + 2];

long merge(long A[], long n, long left, long mid, long right){
	long cnt = 0;
	long n1 = mid - left;
	long n2 = right - mid;
	for (long i = 0; i < n1; i++) L[i] = A[left + i];
	for (long i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	long i = 0, j = 0;
	for (long k = left; k < right; k++){
		if (L[i] <= R[j]) A[k] = L[i++];
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

long mergeSort(long A[], long n, long left, long right){
	if (left + 1 < right){
		long mid = (left + right) / 2;
		long v1 = mergeSort(A, n, left, mid);
		long v2 = mergeSort(A, n, mid, right);
		long v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else return 0;
}

int main(){
	long A[MAX], n;
	cin >> n;
	for (long i = 0; i < n; i++) cin >> A[i];
	long ans = mergeSort(A, n, 0, n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4280
#include<stdio.h>
#include<string.h>
char card[3][1000];
int noc[3];
int uc[3];
int main(void){
    for(int i = 0;i<3;i++)
    {
        scanf("%s",&card[i]);
        noc[i] = strlen(card[i]);
    }

    int turn = 0;
    for(;;)
    {
        if(noc[turn] == uc[turn])
        {
            printf("%c",('A'+turn));
            break;
        }
        int tmp = card[turn][uc[turn]] - 'a';
        uc[turn]++;
        turn = tmp;
    }
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int N;
	int i;
	int min, max;
	int *a;
	int rate[9] = {0,0,0,0,0,0,0,0,0};
	char buf[1024], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);

	a = (int *)calloc(N, sizeof(int));

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	a[0] = atoi(ch);
	for(i = 1; i < N; i += 1) {
		ch = strtok(NULL, " ");
		a[i] = atoi(ch);
	}

	for(i = 0; i < N; i += 1) {
		if(a[i] >= 3200) {
			rate[8] += 1;
		} else {
			rate[a[i] / 400] = 1;
		}
	}

	min = 0;
	max = 0;

	for(i = 0; i < 8; i += 1) {
		min += rate[i];
		max += rate[i];
	}
	if(rate[8] != 0 && min == 0) {
		min = 1;
	}
	max += rate[8];

	printf("%d %d\n", min, max);

	free(a);
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define f first
#define s second

using namespace std;

long long tab[100005];
long long tab2[100005];

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m, k;
	cin>>n>>m>>k;
	
	long long x = 1e18;
	long long y = 1e18;
	
	for (int i = 1; i <= n; i ++) cin >> tab[i], x = min(x, tab[i]);
	for (int j = 1; j <= m; j ++) cin >> tab2[j], y = min(y, tab2[j]);
	
	long long ans = x + y;
	
	while (k--) {
		long long a, b, c; cin >> a >> b >> c;
		ans = min(ans, (tab[a]+tab2[b]-c));
	} 
	cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

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



	
int main() {

	ll n;
	cin >> n;

	ll a = n / 100;
	ll b = n % 100;

	ll ans = 0;
	if (b > 0 && b <= 12) { ans += 2; }
	if (a > 0 && a <= 12) { ans += 1; }

	if (ans == 0) { cout << "NA"; }
	if (ans == 1) { cout << "MMYY"; }
	if (ans == 2) { cout << "YYMM"; }
	if (ans == 3) { cout << "AMBIGUOUS"; }

	system("PAUSE");


}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main()
{queue<long long int> q;
int k;
cin>>k;
for(int i=1;i<=9;i++)
q.push(i);

int count=0;
int ans;
long long int x ;
while(true)
{
    
    long long int x  = q.front(); 
   count++;
   
    if(count ==  k)
    {
      cout<<x<<endl;
      return 0;
    }
   
    q.pop();
    if(x%10!=0)
        q.push(x*10+(x%10)-1);
        
        q.push(x*10+(x%10));

    if(x%10!=9)
        q.push(x*10 + (x%10) +1);
}
   
    
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, L;
    cin >> N >> L;

    int R = L + N - 1;
    auto sigma = [&](int l, int r) { return (l + r) * (r - l + 1) / 2; };

    if (R <= 0) {
        R--;
    } else if (L >= 0) {
        L++;
    }

    cout << sigma(L, R) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int Q;
#define MAX 100001
int l[MAX],r[MAX];
bool prime[MAX];
int main(){
    cin >> Q;
    fill(prime,prime+MAX,true);
    prime[0] = false;
    prime[1] = false;
    for(int i=2;i*i<=MAX;i++){
        if(prime[i]){
            for(int j=2;j*i<=MAX;j++){
                prime[i*j]=false;
            }
        }
    }
    bool ans[MAX];
    for(int i=0;i<=MAX;i++){
        if(i%2==1&&prime[i]&&prime[(i+1)/2]){
            ans[i] = true;
        }else{
            ans[i] = false;
        }
    }
    int anse[MAX];
    fill(anse,anse+MAX,0);
    for(int i=1;i<MAX;i++){
        if(ans[i]){
            anse[i] = 1;
        }
        anse[i] += anse[i-1];
    }
    rep(i,Q){
        cin >> l[i] >> r[i];
    }
    rep(i,Q){
        cout << anse[r[i]]-anse[l[i]-1]<< endl;
    }
    return 0;

}

Measured memory_bytes: 2048
/*
 * 未だ解けていない
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


const int MAX = 3000 + 10;

int dp[MAX][MAX];


int main() {

    string s1;
    string s2;

    cin >> s1 >> s2;


    // vector<vector<int>> dp(s1.length() + 10, vector<int>(s2.length() + 10, 0));


    for(int i = 1; i <= s1.length(); ++i) {
        for(int j = 1; j <= s2.length(); ++j) {

            int si = i - 1;
            int sj = j - 1;

            if(s1[si] == s2[sj] && dp[i - 1][j - 1] + 1 > dp[i - 1][j]) 
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else {
                int aboveSize = dp[i - 1][j];
                int leftSize = dp[i][j - 1];


                if(aboveSize > leftSize)
                    dp[i][j] = dp[i - 1][j];
                else
                    dp[i][j] = dp[i][j - 1];
                         
            }
             
        }
    }

    /*
    for(int i = 0; i <= s1.length(); ++i) {
        
        if(i != 0)
            cout << s1[i - 1];

        for(int j = 0; j <= s2.length(); ++j) {

            if(i == 0) {
                if(j == 0)
                    cout << "\t";
                else
                    cout << s2[j - 1] << "\t";
            }

            else {
                if(j == 0)
                    cout << "";
                else
                    cout << "\t" << dp[i][j];

            }
        }
        cout << endl;
    }
*/
    string s;
    int i = s1.length(), j = s2.length();
    while(i != 0 && j != 0) {

        while(j != 0 && dp[i][j - 1] == dp[i][j])
            j--;
        while(i != 0 && dp[i - 1][j] == dp[i][j])
            i--;

        if(j == 0)
            break;
        s = s2[j - 1] + s;
      //  cout << s2[j - 1] << endl;
        i--;
        j--;
    }

    cout << s << endl;
    //cout << dp[s1.length()][s2.length()] << endl;

    return 0;

}

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 7;

int n, m, a[N];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i ++) {
        cin >> a[i];
    }
    int res = 0, pre = 0;
    while (n --) {
        int id = 0;
        if (a[pre]) id = pre;
        for (int i = 1; i <= m; i ++) {
            if (i != pre && a[i]) {
                if (id == 0 || id == pre) id = i;
                else if (a[i] > a[id]) id = i;
            }
        }
        res += pre == id;
        a[id] --;
        pre = id;
    }
    cout << res << endl;
}


Measured memory_bytes: 384
n, y = list(map(int, input().split()))
a = -1
b = -1
c = -1
for i in range(n+1):
  for j in range(n - i+1):
    k = n-i-j
    if 10000*i + 5000*j + 1000*k == y and k >= 0:
      a = i
      b = j
      c = k
      break
      
print(a, b, c)


Measured memory_bytes: 3316
#include <stdio.h>

int gcd(int asumi, int iguti) {
	while (iguti > 0) {
		int sumipe = asumi % iguti;
		asumi = iguti;
		iguti = sumipe;
	}
	return asumi;
}

int N, K;
int A[114514];

int main(void) {
	int i;
	int mizuhasu;
	int mareitaso;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	mizuhasu = mareitaso = A[0];
	for (i = 1; i < N; i++) {
		mizuhasu = gcd(mizuhasu, A[i]);
		if (A[i] > mareitaso) mareitaso = A[i];
	}
	printf("%sPOSSIBLE\n", K <= mareitaso && (mareitaso - K) % mizuhasu == 0 ? "" : "IM");
	return 0;
}


Measured memory_bytes: 2076
#include<cstdio>
#include<cstring>
#include<queue>
# define N 1000010
# define M 4000050
# define WQD 0x7f7f7f7f
int n,m;
struct Edge{int next,to,w;} e[M];
int head[N+1];
int dis[N+1];
int vis[N+1];
int book[N+1];
bool spfa(int s);
using namespace std;
int main()
{
    int u,v,w;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        e[i].next=head[u];
        e[i].to=v;
        e[i].w=w;	
        head[u]=i; 
        e[m+i].next=head[v];
        e[m+i].to=u;
        e[m+i].w=-w;
        head[v]=m+i;
    }
    memset(book,0,sizeof(book));
    memset(vis,0,sizeof(vis));
    memset(dis,0x7f,sizeof(dis));
    for(int i=1;i<=n;i++)
      if(vis[i]==0)
      {
      	vis[i]=1;
      	if(!spfa(i)) 
      	{	
      	printf("No");
          return 0;
        }
      }
      
    printf("Yes");return 0;	
}
bool spfa(int s)
{
    queue<int>q;
    dis[s]=0;
    q.push(s);book[s]=1;
    while(q.size()>0)
    {
        int k=q.front();q.pop();
        book[k]=0;//出队列 
        for(int i=head[k];i!=-1;i=e[i].next)
        {
            if(dis[e[i].to]<WQD&&dis[k]<WQD&& dis[e[i].to]!=dis[k]+e[i].w) return false;
            else if(dis[k]<WQD&&dis[e[i].to]==WQD)
            {
                dis[e[i].to]=dis[k]+e[i].w;
                if(book[e[i].to]==0)
                {
                q.push(e[i].to);
                book[e[i].to]=1;
                }
                vis[e[i].to]=1;
            }
        } 
    }
    return true;
}















Measured memory_bytes: 21120
# coding: utf-8

# input
n = int(input())
li = [list(map(int, input().split())) for i in range(n)]

def check(li):
    before = [0, 0, 0]
    for i in li:
        n, x, y = map(int, i)
        move = abs(n - before[0])
        pos = abs(x - before[1]) + abs(y - before[2])
        if not (pos <= move and pos % 2 == move % 2):
            return "No"
        before = [n, x, y]
    return "Yes"

# output
print(check(li))


Measured memory_bytes: 27380