akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(1000000)
#def input():
#    return sys.stdin.readline()[:-1]

'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True))  # 降順にソート
a.sort()  # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
2 3
0 1 1
1 0 1
1 4 0
1 2
3 3
'''

test_data2 = '''\
4 3
0 12 71
81 0 53
14 92 0
1 1 2 1
2 1 1 2
2 2 1 3
1 1 2 2
'''

test_data3 = '''\

'''
td_num=2

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3

if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        # Start Input code ---------------------------------------
        N,C=map(int,f.readline().split())
        c=[[0 for j in range(C)] for i in range(3)]
        D=[[0 for i in range(C)] for j in range(C)]
        for i in range(C):
            D[i]=[int(x) for x in f.readline().split()]
        for x in range(N):
            y=0
            for j in f.readline().split():
                c[(x+y)%3][int(j)-1]+=1
                y+=1
        # End Input code ---------------------------------------
else:
    if 0==0:
        # Start Input code ---------------------------------------
        N,C=map(int,input().split())
        c=[[0 for j in range(C)] for i in range(3)]
        D=[[0 for i in range(C)] for j in range(C)]
        for i in range(C):
            D[i]=[int(x) for x in input().split()]
        for x in range(N):
            y=0
            for j in input().split():
                c[(x+y)%3][int(j)-1]+=1
                y+=1
        # End Input code ---------------------------------------

St=[[0 for i in range(3)] for j in range(C)]
ans=10**20
for c1 in range(C):
    for c2 in range(C):
        for c3 in range(C):
            cc=0
            dd=0
            for i in range(C):
                cc+=c[0][i]*D[i][c1]
                cc+=c[1][i]*D[i][c2]
                cc+=c[2][i]*D[i][c3]
                
                dd+=c[0][i]*D[c1][i]
                dd+=c[1][i]*D[c2][i]
                dd+=c[2][i]*D[c3][i]
            if len(set([c1,c2,c3]))==3:
                ans=min(ans,cc)
            #print(ans,c,D)
#print('N,C=',N,C,'D=',D,'c=',c,'St=',St)
print(ans)


Measured memory_bytes: 47836
N, W ,D = map(int, input().split())
inf = float("inf")
dp = [0]*(N*W)
s = [inf]*N*W

d = [list(map(int, input().split())) for i in range(N)]
T = int(input())
m = [list(map(int, input().split())) for i in range(T)]
ans = 0
 
for i in range(N):
    for j in range(W):
        s[d[i][j]-1] = [i,j]
k=0
#print(s)

for n in range(D,N*W):
    #print(n)
    dp[n] = dp[n-D]+abs(s[n][0]-s[n-D][0])+abs(s[n][1]-s[n-D][1])
    k+=1
for x,y in m:
    if x == y:print(0)
    else:print(dp[y-1]-dp[x-1])



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

void InputSet(std::vector<int> & a) {
	int n;
	cin >> n;
	a.resize(n,0);
	for(int i=0;i<n;++i) {
		cin >> a.at(i);
		a.at(i)--;
	}
}
int main(){
	//u k v1 v2 ... vk
	int n;
	cin >> n;
	vector<vector<int> > Ad;
	Ad.resize(n);
	for(int k=0;k<n;++k) {
		int u;
		cin >> u;
		--u;
		InputSet(Ad[u]);
	}
	for(int i=0;i<n;++i){
		string a(n,'0');
		for(int j=0;j<(int)Ad[i].size();++j){
			a.at(Ad[i][j]) = '1';
		}
		for(int j=0;j<n;++j){
			if(j==0){
				cout << a[j];
			} else  {
				cout << " " << a[j];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) cout << "a > b" << endl;
	if (a < b) cout << "a < b" << endl;
	if(a==b)  cout << "a == b" << endl;
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    string s;
    cin >> s;
    FOR(i, (ll)s.size()) s[i] = 'x';
    cout << s << '\n';
}



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

struct P
{
    int x,y;

    /*bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }*/

};

vector<int> v;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[1];
int l[1];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[3];
stack<int> s;
//set<int> s[222][22];
//priority_queue<int> q;
//queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

string r;
//char r[222253];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;
}



int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        scanf("%d",&n);
        k+=n;
        m=max(m,n);
    }
    printf("%d",k-m/2);
}






Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll n;
    cin >> n;
    ves s(n);
    rep(i, n) {
        cin >> s[i];
    }
    ll cnt = 0;
    sort(s.begin(), s.end());
    rep(i, n - 1) {
        if(s[i] != s[i + 1]) {
            cnt++;
        }
    }
    cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 9656
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append(cnt)
  if temp!=1:
    arr.append(1)
  if n==1:
    arr.append(0)
  return arr
def kak(n):
  return ((1+8*n)**(1/2)-1)//2
  
A=factorization(int(input()))
print(int(sum([kak(i) for i in A])))

Measured memory_bytes: 63324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
inline int lowbit(int x) { return (x & (-x));}
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
ll powMod(ll a, ll k)
{
	ll ret = 1;
	while(k)
	{
		if(k & 1) ret = ret * a % mod;
		a = a * a % mod; k >>= 1;
	}
	return ret;
}
ll inv(ll a) { return powMod(a, mod - 2);}
ll C(int n, int m) 
{
	ll a = 1, b = 1;
	for(int i = 1; i <= m; ++i) 
	{
		a = a * i % mod;
		b = b * (n - i + 1) % mod;
	}
	return b * inv(a) % mod;
}
int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	ll ans = powMod(2, n) - C(n, a) - C(n, b) - 1;
	while(ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7;
bool x[N];
int main() {
	int n;
	scanf("%d", &n);
	int las = -1, ans = 1, cur = 0, cnt = 0;
	for (int i = 1; i <= n; ++ i) {
		int a;
		scanf("%d", &a);
		int old = las;
		//printf("%d\n", i - cnt);
		ans = 1LL * ans * (i - cnt) % MOD;
		if (a == las + 1) {
			cnt ++;
		}
		else {
			las += 2;
		}
	}
	cout << ans << endl;
}



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

int main(){
    int a,b,n,ans;
    cin >> a >> b;
    if(a>0) ans = 1;
    else if(b >= 0) ans = 0;
    else{
        if((b-a)%2) ans = 1;
        else ans = -1;
    }
    switch(ans){
        case -1:
            cout << "Negative" << endl;
            break;
        case 0:
            cout << "Zero" << endl;
            break;
        case 1:
            cout << "Positive" << endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>

using namespace std;

#define cn cout << '\n'
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll arr[200005];
ll nu_b[200005];

int main() {
    cio;
    int n, a = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size() - 2; ++i) {
        if (s[i] == 'A' &&
          s[i+1] == 'B' &&
          s[i+2] == 'C') {
            a++;
        }
    }
    cout << a;
    cn;
}


Measured memory_bytes: 3208
N, M = gets.split.map(&:to_i)
CAKES = readlines.map{|l| l.split.map(&:to_i)}

def score(cake, signs)
  cake[0] * signs[0] +
  cake[1] * signs[1] +
  cake[2] * signs[2]
end

SIGNS = [1, -1].repeated_permutation(3)
p SIGNS.map{|signs|
  #cs = CAKES.map.with_index(1){|c, i| [score(c, signs), c, i]}.sort_by(&:first).last(M)
  #cs.map(&:first).inject(:+)
  CAKES.map{|c| score(c, signs)}.sort.last(M).inject(0, :+)
}.max

Measured memory_bytes: 2040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int num = Integer.parseInt(br.readLine());
//		???????????????????????°???????????????
		ArrayList<Integer> Scd = new ArrayList<Integer>();
		ArrayList<Integer> Hcd = new ArrayList<Integer>();
		ArrayList<Integer> Ccd = new ArrayList<Integer>();
		ArrayList<Integer> Dcd = new ArrayList<Integer>();
//		S,H,C,D????????????????????¨???

		String[] buf = new String[2];
		int tmp = 0;
		for(int i=0; i<num; i++)
		{
			buf = br.readLine().split(" ");
			tmp = Integer.parseInt(buf[1]);
//			????????\?????????????????????????????????????´?
			switch(buf[0])
			{
			case "S":
				Scd.add(tmp);
				break;
			case "H":
				Hcd.add(tmp);
				break;
			case "C":
				Ccd.add(tmp);
				break;
			case "D":
				Dcd.add(tmp);
				break;
			}
		}

		for(int i=1; i<=13; i++)
		{
			if(Scd.indexOf(i)==-1)
			{
				System.out.println("S " + i);
			}
		}
//		???????????????????????????????????????????????§?????°???????´¢????????????
//		?????¨??????????????°???????????°??¨????????????
		for(int i=1; i<=13; i++)
		{
			if(Hcd.indexOf(i)==-1)
			{
				System.out.println("H " + i);
			}
		}
		for(int i=1; i<=13; i++)
		{
			if(Ccd.indexOf(i)==-1)
			{
				System.out.println("C " + i);
			}
		}
		for(int i=1; i<=13; i++)
		{
			if(Dcd.indexOf(i)==-1)
			{
				System.out.println("D " + i);
			}
		}
	}
}

Measured memory_bytes: 24240
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int h, w, b[55][55] = {};
string s[55];

void bfs(int x, int y, int d) {
	if (x < w - 1 && s[y][x + 1] == '.' && b[y][x + 1] - 1 > d) {
		b[y][x + 1] = d + 1;
		bfs(x + 1, y, d + 1);
	}
	if (x > 0 && s[y][x - 1] == '.' && b[y][x - 1] - 1 > d) {
		b[y][x - 1] = d + 1;
		bfs(x - 1, y, d + 1);
	}
	if (y < h - 1 && s[y + 1][x] == '.' && b[y + 1][x] - 1 > d) {
		b[y + 1][x] = d + 1;
		bfs(x, y + 1, d + 1);
	}
	if (y > 0 && s[y - 1][x] == '.' && b[y - 1][x] - 1 > d) {
		b[y - 1][x] = d + 1;
		bfs(x, y - 1, d + 1);
	}
}

int main()
{
	cin >> h >> w;
	REP(i, h) {
		cin >> s[i];
	}

	int white = 0;
	REP(i, h) {
		REP(j, w) {
			b[i][j] = INF;

			if (s[i][j] == '.')white++;
		}
	}
	b[0][0] = 1;

	bfs(0, 0, 1);

	if (b[h - 1][w - 1] != INF) {
		cout << white - b[h - 1][w - 1];
	}
	else {
		cout << -1 << endl;
	}
}

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

int a, b, k;

int solve();

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

  cout << solve() << endl;
  return 0;
}

int solve() {
  vector<int> v;
  for(int i = 1; i <= max(a, b); ++i)
    if(a % i == 0 && b % i == 0) v.push_back(i);
  sort(v.begin(), v.end(), greater<int>());
  return v[k - 1];
}

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

int main(){
	long long A, B, K;
	cin >> A >> B >> K;

	bool flag = false;

	if( (A + B) <= K) {
		cout << 0 << " " << 0 << endl;
		flag = true;
	} else {
		if(A <= K) {
			K = K - A;
			A = 0;
		} else {
			A = A - K;
			K = 0;
		}
		
		if(K != 0) {
			B = B - K;
			K = 0;
		}
	}

	if(flag == false) {
		cout << A << " " << B << endl;
	}
}


Measured memory_bytes: 256
/*
                  友利奈緒の力でACしてくれ！！！！！！！！！！！！
                  Charlotteまだ見てない人は見ような！！！！！！！

                  ／　 /:／　　　　　　　　　　　 　 ＼:ヽ　＼
  　　　　　　　 /　　／　　　　　　 　 　 　 　 　 　 　 ＼　　ヽ
  　　　　　＼__L 彡　　　　　　　　　　　　　　　　　　　 ヽ　　',
  　　　　　　　ﾌ /　　　/　　/　 /　　　,　　 　 　 　 ヽ　　', 　ｊ
  　　　　　　　ﾚ　　　 /　　/ 　/　 　 　 　 　 　 　 　 ', 　ヽ　j
  　　　 　 　 // 　 　 !　/_l＿/__ノ 　　{ ＼}　　　　 　 ',　　',/
  　　　　　　i ﾊ 　 　 {　从j　ﾊ　i　　　 ',　 ト-､}　 i i　 }　　jj
  　　　　　　( ﾊ　　　(　 川　ハ ﾊ　 !　 '　ﾊ　 ﾊ　j j　,' 　 八
  　　　 ＜＿,ｨ∧　　　斗芹ﾃミxハ ﾊ　 ﾚ　} /__ﾚﾚ　/ 　 ∧ ＼　ﾉ
  　　　 　 　 ∨　＼ 　ゝ　辷:ソ　　 　)　芹ﾚ心ヾレ′　/ ト--　´
  　　　＼ｰ‐'　ﾉ　　 ＼ゝ　　　　　　 　 　 ゞ:_ソ "/ 　／ 　ヽ
  　　　　 　 フ　　　　i八 " "　　　,　　　　　　　ム彡　　　　＼
  　　　　 　/　　/　　j　 ト　　　　　　 　 　 " "イト＜　 　 　 ＼＼
  　　　　 /　　/　　　j　/／ヽ､ 　 ∩　　 　 イ　{ {　　￣ フフへ ＼＼
  　　　　(　／　　　 ,/ / 　　i　＞――＜ニニニﾆ┐　 〃／: : ヽ　ヽヽ
  　　　　／　　ィT´/ /┌―　￣￣ /::: , ,)　 　 　 〃／／: : : : : :}　ヽヽ)
  　　　/ /　 ∧ヾi┌― { {￣　　　 ﾉ:::トﾟ<　 　 　 ∥//: : : : : : : : i　 ﾉ ﾉ
  . 　　( 人　 {:ヽヾi∨　∧V　　　 /:::/　､ヽ　　　 ∥/: : : : : : : : : :}　/
  　　　V　( ∧: :＼'∨　∧V　　 ﾉ:::/　 ∧ 〉＿__∥: : : : : :／: : : :ﾚ
  　　 　 　 /∧: : : : ∨　∧V┬ｲ:::ﾉ　 〈 TT　|　|{{: : : : ／: : : : : ∧　　 ﾉ
  　　　 　 (　ハ: : : : :∨'T∧Vi　i (　 　 V　!　!　{{: : ／ : : : : : : /　ｰ　ノ
  　　　　　V　ハ: : : : :∨ﾍ∧V　i ゝゝ　 i／⌒＼{／ : : : : : : : /ｰ― ´
  　　　　　 ∨　ヽ: : : : :∨ﾍ∧∨i　〉 〉 /　/二　 ): : : : : : : : :/

          (https://seesaawiki.jp/asciiart/d/Charlotteより)
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) REP(i,n+1)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RREP(i,n+1)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define PERM(c) sort(ALL(c)); for(bool cp = true;cp;cp = next_permutation(ALL(c)))
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1E9+7;
int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1};
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a(3*n);
  cin >> a;
  sort(RALL(a));
  ll ans = 0;
  REP(i,n){
    ans += a[i*2+1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream&o,const pair<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
mt19937 rnd(random_device{}());

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
V<ll>fac,rfac; void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}

ll randInt(ll l,ll r){return uniform_int_distribution<ll>(l,r)(rnd);}
double randDouble(double l,double r){return uniform_real_distribution<double>(l,r)(rnd);}
void dout(double d){printf("%.12f\n",d);}

const double PI = acos(-1);
const double EPS = 1e-10;
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;

ll k, x, y, px, py;
V<pll> ans;
pll _f(ll a, ll b){
  ll d = a+b;
  if(d==k) return mp(a, b);
  if(d>=k*2 || d%2) return mp(min(a, k), k-min(a, k));
  return mp(d/2, -k+d/2);
}
pll f(ll a, ll b){
  bool x, y, z;
  if(x=a<0) a *= -1;
  if(y=b<0) b *= -1;
  if(z=a<b) swap(a, b);
  auto p = _f(a, b);
  if(z) swap(p.fi, p.se);
  if(y) p.se *= -1;
  if(x) p.fi *= -1;
  return p;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> k >> x >> y;
  if((x+y)%2 && k%2==0){
    cout << -1 << endl;
    return 0;
  }
  while(x!=px || y!=py){
    auto p = f(x-px, y-py);
    px += p.fi;
    py += p.se;
    ans.pb({px, py});
  }
  cout << sz(ans) << endl;
  for(auto p:ans) cout << p.fi << " " << p.se << endl;
}

Measured memory_bytes: 6124
#include<iostream>

using namespace std;

int main()
{
    int t;
    int ac=0,wa=0,tle=0,re=0;
    string s;
    cin>>t;
    while(t--)
    {
        cin>>s;
        if(s == "AC") ac++;
        else if(s == "WA") wa++;
        else if(s == "TLE") tle++;
        else if(s == "RE") re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;

    return 0;
}


Measured memory_bytes: 3588
//from PKU1125
main(){
	int a,b,c,t,k,n,i,j,time[101][101],cost[101][101];
	for(;scanf("%d%d",&k,&n),n;){
		/*initialize*/
		memset(time,11,sizeof(time));
		memset(cost,11,sizeof(cost));
		for(i=1;i<=n;i++)time[i][i]=cost[i][i]=0;
		for(;k;k--){
			scanf("%d%d%d%d",&a,&b,&c,&t);
			time[a][b]=time[b][a]=t;
			cost[a][b]=cost[b][a]=c;
		}
		
		{/*warshall-floyd*/
			int k,i,j;
			for(k=1;k<=n;k++)
				for(i=1;i<=n;i++)
					for(j=1;j<=n;j++){
						if(time[i][j]>time[i][k]+time[k][j])
							time[i][j]=time[i][k]+time[k][j];
						if(cost[i][j]>cost[i][k]+cost[k][j])
							cost[i][j]=cost[i][k]+cost[k][j];
					}
		}
		
		{/*query*/
			for(scanf("%d",&k);k;k--){
				scanf("%d%d%d",&a,&b,&t);
				printf("%d\n",t?time[a][b]:cost[a][b]);
			}
		}
	}exit(0);
}

Measured memory_bytes: 688
import java.util.Scanner;
class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int box[][] = {{1,2,3,4,5,6,7,8,9,10,11,12,13},
        	{1,2,3,4,5,6,7,8,9,10,11,12,13},
        	{1,2,3,4,5,6,7,8,9,10,11,12,13},
        	{1,2,3,4,5,6,7,8,9,10,11,12,13}};

        for(int i = 0; i < n; i++) {
            String m = sc.next();
            int b = sc.nextInt();

            if(m.equals("S")) {
                box[0][b-1] = 0;
            }
            if(m.equals("H")) {
            	box[1][b-1] = 0;
            }
            if(m.equals("C")) {
            	box[2][b-1] = 0;
            }
            if(m.equals("D")) {
            	box[3][b-1] = 0;
            }
        }
        for(int i = 0 ; i< 4; i++) {
            for(int j = 0; j < 13; j++) {

            	if(box[i][j]!=0) {
            		if (i == 0)
                        System.out.println("S " + (j + 1));
                    else if (i == 1)
                        System.out.println("H " + (j + 1));
                    else if (i == 2)
                        System.out.println("C " + (j + 1));
                    else
                        System.out.println("D " + (j + 1));
            	}
            }
        }
    }
}


Measured memory_bytes: 26308
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Abc162D
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            long r = 0;
            long g = 0;
            long b = 0;
            long m = 0;
            for (int i = 0; i < n; i++)
            {
                switch (s[i])
                {
                    case 'R':
                        r++;
                        break;
                    case 'G':
                        g++;
                        break;
                    case 'B':
                    default:
                        b++;
                        break;
                }

                for (int j = 1; j <= n / 2; j++)
                {
                    if (i + 2 * j > n - 1)
                        break;
                    if (s[i] == s[i + j] || s[i + j] == s[i + 2 * j] || s[i] == s[i + 2 * j])
                        continue;
                    m++;
                }
            }
            Console.WriteLine(r * g * b - m);
        }
    }
}


Measured memory_bytes: 17700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    //IOS;
    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        cin>>n;
        for(i=1;i<n;i++)
        {
            if(n%i==0)
                sum+=(n/i-1);
            else sum+=(n/i);
        }
        cout<<sum<<endl;



    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	char x;
	cin>>x;
	if(x>='A' && x<='Z') cout<<"A"<<endl;
	else if(x>='a'&& x<='z') cout<<"a" <<endl;
	return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    unordered_map<string,int> a;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        a[s]++;
    }
    cout<<"AC x "<<a["AC"]<<endl;
    cout<<"WA x "<<a["WA"]<<endl;
    cout<<"TLE x "<<a["TLE"]<<endl;
    cout<<"RE x "<<a["RE"]<<endl;
}

Measured memory_bytes: 3616
while(1):
    n=int(raw_input())
    if n==0:
        break
    m=int(raw_input())
    distlist=[[] for x in range(n)]
    for i in range(m):
        [a,b,d]=[int(x) for x in raw_input().split(',')]
        distlist[a].append((b,d))
        distlist[b].append((a,d))
        
    visited=[0]
    notyet={}
    for i in range(1,n):
        notyet[i]=float('inf')
    toro=0
    for pk in distlist[0]:
        dest=pk[0]
        dd=pk[1]
        notyet[dest]=dd
        
    while len(notyet)!=0:
        #search for smallest dist
        smallest=float('inf')
        K=0
        for k in notyet:
            if notyet[k]<smallest:
                smallest=notyet[k]
                K=k
        #print smallest,K,notyet
        toro=toro+smallest/100-1
        for pk in distlist[K]:
            dest=pk[0]
            dd=pk[1]
            if dest in notyet:
                notyet[dest]=min(notyet[dest],dd)
        del notyet[K]
    print toro

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

ll func(ll a,ll b,ll x) {
    return floor(a*x/b)-a*floor(x/b);
}

int main() {
    ll a,b,n;
    cin>>a>>b>>n;
    ll left=0;
    ll right=n+1;
    ll mid;
    ll maxi=func(a,b,n);
    while(right-left>1) {
        mid=(left+right)/2;
        if (func(a,b,mid)>maxi) {
            left=mid;
            maxi=func(a,b,mid);
        }
        else right=mid;
    }
    cout<<maxi<<endl;
}   


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

int main() {
	int n,k;
  	cin>>n>>k;
  
  	vector <int> h(n);
  	rep(i,n)cin>>h[i];
  
  sort(h.begin(),h.end());
  reverse(h.begin(),h.end());
  
  ll ans=0;
  
  for(int i=0+k;i<n;i++){
  	while(h[i]>0){
    	ans++;
      	h[i]--;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 4032
_dividers = function(n) {
  var arr = []
  for (var i = 1; i*i <= n; i++) {
     if (n % i === 0) {
       arr.push(i)
       if ( i != n / i) {
         arr.push(n / i)
       }
     }
  }
  return arr.sort((a, b) => a - b)
}

inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
N = inp.shift() * 1
cnt = 0
for (i=1; i<=N; i+=2) {
    if (_dividers(i).length == 8) {
        cnt++
    }
}
console.log(cnt)

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int a, b, c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> c;
  cout << (a + b + c >= 22 ? "bust" : "win") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb                 push_back
#define bug(x)             cerr<<#x<<" "<<x<<endl;
#define T int time;        scanf("%d", &time); while(time--)

   int main(){
               

               char a;
               cin>>a;
               a++;
               cout<<a<<endl;
            }
   

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    string s;
    cin >> s;

    for (char& c : s) {
        if (c == '?') c = 'D';
    }

    cout << s << newl;

    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll m; cin >> m;
    if (n==m){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    char a[10];
    while(scanf("%s",&a)!=EOF){
        int b[10],i,j;
        for(i=0;i<10;i++)b[i]=a[i]-'0';
        for(i=8;i>=0;i--){
            for(j=0;j<=i;j++){
                b[j]=(b[j]+b[j+1])%10;
            }
        }
        printf("%d\n",b[0]);
    }
    return 0;
}

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

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

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

    for (int i=0;i<N;i++){
        cout << S[i] << T[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b,c;
	scanf ("%d",&a);
	scanf ("%d",&b);
	if (a==1 && b==2  || b==1 && a==2){
		printf ("3\n");
    }
    else if (a==2 && b==3 || b==2 && a==3){
    	printf ("1\n");
	}
	else if (a==1 && b==3 || b==1 && a==3){
		printf ("2\n");
	}
	else {
		printf ("error");
	}
	return 0;
}

Measured memory_bytes: 2052
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int F[45] = {};

int fib(int n) {
	if (n == 0 || n == 1)
		return F[n] = 1;
	else
		return F[n] ? F[n] : F[n] = fib(n - 1) + fib(n - 2);
}

int main() {
	int n;	cin >> n;
	cout << fib(n) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}




int main(){
    string S;
    cin >> S;
    int ans = 0;
    bool flag = false;
    int tmp = 0;
    rep(i, S.length()){
        if(flag == true && (S[i] == 'A' || S[i] == 'C' ||S[i] == 'G' || S[i] == 'T')){
            tmp++;
        }else if(flag == true && (S[i] != 'A' || S[i] != 'C' ||S[i] != 'G' || S[i] != 'T')){
            ans = max(ans, tmp);
            tmp = 0;
            flag = false;
        }else if(flag == false && (S[i] == 'A' || S[i] == 'C' ||S[i] == 'G' || S[i] == 'T')){
            flag = true;
            tmp = 1;
        }
    }
    ans = max(ans, tmp);
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
//#include <math.h>
#define MAX 100
#define INFINITY 100000000

int n, M[MAX][MAX], d[MAX], Q[MAX];
int head = 0;
int tail = 0;

void enqueue(int x){
  Q[tail] = x;
  tail = (tail + 1) % MAX;
}
int dequeue(){
  int x = Q[head];
  head = (head + 1) % MAX;
  return x;
}
int isEmpty(void){
  if(head == tail) return 1;
  else return 0;
}
void dfs(int s){
  int i, u, v;
  
  enqueue(s);
  for(i = 0; i < n; i++) d[i] = INFINITY;
  d[s] = 0;
  while( !isEmpty() ){
    u = dequeue();
    for(v = 0; v < n; v++){
      if(M[u][v] == 0) continue;
      if(d[v] != INFINITY) continue;
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }
  for(i = 0; i < n; i++){
    printf("%d %d\n", i + 1, (d[i] == INFINITY ? (-1) : d[i]));
  }
}

int main(){
  int i, j, k, u, v;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++)
      M[i][j] = 0;
  }

  for(i = 0; i < n; i++){
    scanf("%d %d", &u, &k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  
  dfs(0);
  
  return 0;
}



Measured memory_bytes: 2100
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] W = new int[N];
		for (int i = 0; i < N; i++) {
			W[i] = sc.nextInt();
		}
		int dif = 1023;
		for (int T = 1; T < N; T++) {
			int sum1 = 0;
			int sum2 = 0;
			for (int i = 0; i < T; i++) {
				sum1 += W[i];
			}
			for (int j = T; j < N; j++) {
				sum2 += W[j];
			}
			int abs = Math.abs(sum1 - sum2);
			if (abs < dif) {
				dif = abs;
			}
		}
		System.out.println(dif);
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23252
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;

int dsort(const void *A,const void *B){return *(ll*)A<*(ll*)B?1:0;}

int main(void){
    ll n,sum=0,ans=0;
    scanf("%lld",&n);
    ll a[n],b[n],k[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    for (int i=0; i<n; i++){
        scanf("%lld",&b[i]);
    }
    for (int i=0; i<n; i++){
        k[i]=a[i]-b[i];
        if (k[i]<0){
            sum+=k[i];
            ans++;
        }
    }
    qsort (k,n,sizeof(ll),dsort);
    for (int i=0; i<n; i++){
        if (sum<0){
            sum+=k[i];
            ans++;
        } else {
            break ;
        }
    }
    if (sum>=0){
        printf("%lld\n",ans);
    } else {
        printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 3324
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

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

	auto ans = make_v<int>(55);

	fill_v(ans, 0);

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		ans[a]++;
		ans[b]++;
	}

	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}


}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	int sum=0;
	for(int i=0;i<n;i++) cin>>arr[i],sum+=arr[i];
	sum=sum/n;
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=(arr[i]-sum)*(arr[i]-sum);
	}
	int ans2=0;
	for(int i=0;i<n;i++){
		ans2+=(arr[i]-sum-1)*(arr[i]-sum-1);
	}
	cout<<min(ans,ans2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll a, b, c; cin >> a >> b >> c;
    if(a%2 == 1 || b%2 == 1 || c%2 == 1){
        cout << 0 << endl;
    }
    else if(a == b && b == c && c == a){
        cout << -1 << endl;
    }
    else{
        ll cnt = 0;
        while(a%2 == 0 && b%2 == 0 && c%2 == 0){
            cnt++;
            ll ta = (b+c)/2;
            ll tb = (a+c)/2;
            ll tc = (a+b)/2;
            a = ta, b = tb, c = tc;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3636
N=int(input())
H=list(map(int,input().split()))
dp=[float('inf') for i in range(N+1)]
dp[0]=0
dp[1]=0
dp[2]=abs(H[1]-H[0])
for i in range(3,N+1):
  dp[i]=min(dp[i-1]+abs(H[i-1]-H[i-2]),dp[i-2]+abs(H[i-1]-H[i-3]))
print(dp[N])

Measured memory_bytes: 13928
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int h, w;
	string temp;
	cin >> h >> w;
	vector<string> a(h+2);
	for (int i = 0; i < w + 2; i++) {
		a[0] = a[0] + "#";
		a[h + 1] = a[0];
	}

	for (int i = 1; i <= h; i++) {
		cin >> temp;
		a[i] = "#" + temp + "#";
	}

	for (int i = 0; i < h + 2; i++) {
		cout << a[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

const LL MOD = 1e9 + 7;

int N;
VI A;

vector<LL> fact;
vector<LL> rfact;

LL fastpow(LL base, LL p, LL mod) {
    LL ans = 1;
    while (p > 0) {
        if (p % 2 == 1) {
            ans = (ans * base) % mod;
        }
        base = (base * base) % mod;
        p /= 2;
    }
    return ans;
}

LL ncr(LL n, LL r, LL mod) {
    if (r > n || n < 0 || r < 0) {
        return 0;
    }
    LL ans = (fact[n] * rfact[r]) % mod;
    ans = (ans * rfact[n - r]) % mod;
    return ans;
}


int main(int argc, char const* argv[])
{
    cin >> N;
    int l, r;
    map<int, int> d;
    REP(i, N + 1) {
        int a; cin >> a; A.PB(a);
        if (d.find(a) != d.end()) {
            l = d[a];
            r = i + 1;
        } else {
            d[a] = i + 1;
        }
    }

    fact = vector<LL>(N + 10, 1);
    rfact = vector<LL>(N + 10, 1);
    FOR(i, 1, N + 10) {
        fact[i] = (fact[i - 1] * i) % MOD;
        rfact[i] = fastpow(fact[i], MOD - 2, MOD);
    }

    for (int i = 0; i < N; i++) {
        // cout << N + 1 << " " << i + 1 << " " << ncr(N + 1, i + 1, MOD) << endl;
        LL ans = ncr(N + 1, i + 1, MOD) + MOD;
        ans -= ncr(l - 1 + N + 1 - r, i, MOD);
        cout << ans % MOD << endl;
    }
    cout << 1 << endl;
    return 0;
}


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

int main() {
  int D,G;
  cin >> D >> G;
  vector<int> p(12),c(12);
  for(int i=0;i<D;i++)cin >> p[i] >> c[i];
  int ans=200000;
  for(int bit=0;bit<(1<<D);bit++){
    int sum=0; int cnt=0;
    for(int i=0;i<D;i++){
      if(bit&(1<<i)){sum+=c[i]+p[i]*(100*(i+1)); cnt+=p[i];}
    }
    if(sum<G){
      for(int i=D-1;i>=0;i--){
        if(!(bit&(1<<i))){
          if(sum+(p[i]-1)*(100*(i+1))<G){cnt+=2000000; break;}
          else{
            int a=G-sum;
            cnt+=(a+(100*(i+1))-1)/(100*(i+1)); break;
          }
        }
      }
    }
    ans=min(ans,cnt);
  }
  cout << ans << endl;
}  

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

int main(){
	string S;
	cin >> S;
	for (int i = 0;i < (1<<(3));i++){
		ll sm = S[0] - '0';
		vector<char> op{'-','-','-'};
		for (int j = 0;j < 3;j++){
			if (i & (1<<j)){
				sm += S[j+1] - '0';
				op.at(j) = '+';
			} else {
				sm -= S[j+1] - '0';
			}
		}
		if (sm == 7){
			cout << S[0] << op.at(0) << S[1] << op.at(1) << S[2] << op.at(2) << S[3] << "=7" << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]

from collections import defaultdict, deque
g = defaultdict(list)
for u, v, w in uvw:
    g[u-1].append((v - 1, w))
    g[v-1].append((u - 1, w))

ans = [-1] * n
ans[0] = 0
q = deque([0])

while q:
    cur = q.popleft()
    for target, w in g[cur]:
        if ans[target] == -1:
            if w % 2 == 0:
                ans[target] = ans[cur]
            else:
                ans[target] = 1 - ans[cur]
            q.append(target)

for a in ans:
    print(a)


Measured memory_bytes: 97112