akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;
//using ll = long long;


const int MOD = 1000000007;
const int INF = 1e18;

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

const double pi = acos(-1);



template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


using Graph = vector<vector<int>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//*max_element(ALL(vector))
//count(ALL(vector),num) -> n




void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    int n; cin >> n;
    vector<int> A(n);
    vector<int> B(n-1);
    

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



signed main() {
    solve();
    return 0;
}



Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  string s;
  cin >> s;
  int n=s.size();
  
  int ze = 0;
  rep(i,n){
    if(s[i]=='0')ze++;
  }
  
  int ans=min(ze,n-ze);
  
  cout << 2*ans << endl;
  
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int count;

    rep(i, A + 1)
    {
        rep(j, B + 1)
        {
            rep(k, C + 1)
            {
                if (500 * i + 100 * j + 50 * k == X)
                {
                    count++;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}

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

using namespace std;

int main(void) {
	vector<int> num(3);
	for (int i = 0; i < 3; ++i) {
		cin >> num[i];
	}
	sort(num.begin(),num.end());
	cout << num[0]+num[1]+(10*num[2]) << endl;
	return 0;
}


Measured memory_bytes: 256
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(input())

    for i in range(1, 1000):
        x_min = 100 * i
        x_max = 105 * i

        if x_min <= x <= x_max:
            print(1)
            sys.exit()

    print(0)


if __name__ == '__main__':
    main()

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n;
    cin >> n;

    vector<int64_t> a(n);
    priority_queue<pair<int64_t, int64_t>> q;
    for (auto&& aa : a | indexed()) {
        cin >> aa.value();
        q.emplace(aa.value(), aa.index());
    }

    vector dp(n + 1, -1L);
    dp[0] = 0;
    int64_t r = 0;
    while (!q.empty()) {
        auto t = q.top();
        q.pop();

        vector next(n + 1, -1L);
        for (auto i : irange(0L, n)) {
            if (dp[i] < 0) {
                continue;
            }

            next[i + 1] = max(next[i + 1], dp[i] + t.first * abs(t.second - i));
            next[i] = max(next[i],
                          dp[i] + t.first * abs(t.second - (n - r + i - 1)));
        }

        ++r;
        dp = std::move(next);
    }

    cout << *max_element(dp.begin(), dp.end()) << endl;
}

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

int main()
{
    string S;
    cin >> S;
    int count1 = 0;
    int count2 = 0;
    for(int i = 0; i < (int)S.size(); i++){
        if(S[i] - '0' == i%2) count1++;
        if(S[i] - '0' == (i+1)%2) count2++;
    }
    cout << min(count1, count2) << endl;
    return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
# S=numpp.assaray(S)=="#"
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()



def main():
    N, A, B = list(map(int,input().split()))
    if N*A>B:
        print(B)
    else:
        print(A*N)
    
    
if __name__ == "__main__":
    main()

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


void gstr(char *str){
	int i;
	for(i = 0;(str[i] = getchar()) != '\n';i++);
	str[i] = '\0';
}

int main(void){
	int i, j, k, l, m, n, h, w, dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0}, ans = 0, f[500][500];
	char s[500][501], *c[4];
	scanf("%d%d%*c",&h,&w);
	for(i = 0;i < h;i++) gstr(s[i]);
	memset(f,0,sizeof(f));
	for(i = 0;i < h;i++){
		for(j = 0;j < w;j++){
			if(isupper(s[i][j])){
				for(k = 0;k < 4;k++){
					for(l = 1;i + dy[k] * l >=  0 && i + dy[k] * l < h && j + dx[k] * l >= 0 && j + dx[k] * l < w && !isupper(s[i + dy[k] * l][j + dx[k] * l]);l++)
						f[i + dy[k] * l][j + dx[k] * l]++;
				}
			}
		}
	}
	for(i = 0;i < h;i++){
		for(j = 0;j < w;j++){
			if(!isupper(s[i][j]) && f[i][j] >= 2){
				for(k = 0;k < 4;k++){
					for(l = 0;i + dy[k] * l >=  0 && i + dy[k] * l < h && j + dx[k] * l >= 0 && j + dx[k] * l < w && !isupper(s[i + dy[k] * l][j + dx[k] * l]);l++);
					if(i + dy[k] * l >= 0 && i + dy[k] * l < h && j + dx[k] * l >= 0 && j + dx[k] * l < w) c[k] = &s[i + dy[k] * l][j + dx[k] * l];
					else c[k] = NULL;
				}
				for(k = 0;k < 3;k++){
					for(l = k + 1;l < 4;l++)
						if(c[k] != NULL && c[l] != NULL && k != l && *c[k] == *c[l] && *c[k] != '.') *c[k] = '.',*c[l] = '.',i = -1, ans += 2;
				}
				if(i == -1){
					memset(f,0,sizeof(f));
					for(k = 0;k < h;k++){
						for(l = 0;l < w;l++){
							if(isupper(s[k][l])){
								for(m = 0;m < 4;m++){
									for(n = 1;k + dy[m] * n >= 0 && k + dy[m] * n < h && l + dx[m] * n >= 0 && l + dx[m] * n < w && !isdigit(s[k + dy[m] * n][l + dx[m] * n]);n++){
										f[k + dy[m] * n][l + dx[m] * n]++;
									}
								}
							}
						}
					}
				}
			}
			if(i == -1) break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2260
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    h, w = list(map(int, input().strip().split()))
    n = int(input().strip())
    a = list(map(int, input().strip().split()))
    c = [[0] * w for _ in range(h)]
    k = 1
    l = 0
    for i in range(h):
        for j in range(w):
            if i % 2 == 0:
                c[i][j] = k
            else:
                c[i][w-1-j] = k
            a[l] -= 1
            if a[l] == 0:
                k += 1
                l += 1
    for i in range(h):
        print(' '.join(map(str, c[i])))

if __name__ == '__main__':
    main()


Measured memory_bytes: 40048
#include <iostream> 
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long int


int main( ) {
  string s;
  int k;
  cin >> s >> k;

  int m = s.size();
  set<string> sub;
  for ( int i = 0; i < m; i++ ) {
    for ( int j = i; j < m && j < i + 5; j++ ) {
      sub.insert(s.substr( i, j - i + 1 ));
    } 
  }
  auto itr = sub.begin();
  for ( int i = 0; i < k - 1; i++ ) {
    ++itr;  
  }
  cout << *itr << endl;
  return 0;
}


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

using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    int c = (N - 1) * (N - 2) / 2;
    if (K > c) cout << "-1" << endl;
    else {
        int M = N - 1 + c - K;
        cout << M << endl;
        rep(i, N - 1) cout << 1 << " " << i + 2 << endl;
        int a = 0;
        bool f = false;
        if (c > K) {
        for (int i = 2; i < N; i++) {
            for (int j = i + 1; j <= N; j++) {
                cout << i << " " << j << endl;
                a++;
                if (a == c - K) {
                    f = true;
                    break;
                }
            }
            if (f) break;
        }
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
 
long long dp[20][1200][200];
 
long long f(int n,int s,int next){
    if(n==0 && s==0)return 1;
    if(n<0 || s<0)return 0;
    if(next>s)return 0;
    if(dp[n][s][next]!=-1){return dp[n][s][next];}
    long long res=0;
    loop(i,next,101){
        res+=f(n-1,s-i,i+1);
    }
    return dp[n][s][next]=res;
}
 
int main(){
    int n,k;
    while(cin>>n>>k,n||k){
        rep(i,20)rep(j,1200)rep(l,200)dp[i][j][l]=-1;
        cout<<f(n,k,0)<<endl;
    }
    return 0;
}

Measured memory_bytes: 38656
from functools import reduce
from math import ceil

n, m = map(int, input().split(' '))

alist = list(map(int,input().split(' ')))
# alist = [i // 2  for i in alist]


from fractions import gcd

def getLCM(a, b):
    return a * b // gcd(a, b)

def get_lcm_for(your_list):
    return reduce(lambda x, y: getLCM(x, y), your_list)

lcmr = get_lcm_for(alist)

for a in alist:
    if (lcmr//a)%2 == 0:
        if (lcmr != a):
            print(0)
            exit(0)

result = m//lcmr + 2*m//lcmr%2


print(result)


Measured memory_bytes: 14748
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,k,ans=0;
    int l[55];
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l, l+n, greater<int>());
    for(int j=0; j<k;j++){
        ans+=l[j];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    int A[N]; rep(i,N) cin >> A[i];
    int M; cin >> M;
    map<int,bool> m;
    vi b(M);
    rep(i,M){
        cin >> b[i];
    }
    for(int i=0;i<(1<<N);i++){
        int sum=0;
        rep(j,N){
            if(i&(1<<j)) sum+=A[j];
        }
        m[sum]=true;
    }
    rep(i,M){
        if(m[b[i]]) cout << "yes" << "\n";
        else cout << "no" << "\n";
    }
}


Measured memory_bytes: 3256
var
	n,m,ans,mo,p:int64;
	fac:array[0..131072]of int64;
	i:Longint;
function power(a,b:int64):int64;
var ret:int64;
begin
	if b=0 then power:=1
	else begin
		ret:=power(a*a mod 1000000007,b div 2);
		if b mod 2=1 then ret:=ret*a mod 1000000007;
		power:=ret;
	end;
end;
begin
	read(n,m);
	ans:=1;
	mo:=1000000007;
	fac[0]:=1;
	for i:=1 to 131071 do fac[i]:=fac[i-1]*i mod mo;
	i:=2;
	while i*i<=m do begin
		if m mod i=0 then begin
			p:=0;
			while m mod i=0 do begin
				m:=m div i;
				inc(p);
			end;
			ans:=ans*fac[n+p-1]mod mo*power(fac[n-1],mo-2)mod mo*power(fac[p],mo-2)mod mo;
		end;
		inc(i);
	end;
	if m>1 then ans:=ans*fac[n]mod mo*power(fac[n-1],mo-2)mod mo;
	writeln(ans);
end.


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

using namespace std;

int N,M;
vector<int> b,p;

int solve(int first) {
	int res=0;
	int t=0,tsum=0;
	vector<int> tmp(b);
	for(int i=0;i<N;++i) {
		int j=i;
		if(t&1)
			while(tmp[j]==first) ++j;
		else
			while(tmp[j]!=first) ++j;
		swap(tmp[i],tmp[j]);
		res+=j-i;
		++tsum;
		if(p[t]==tsum) tsum=0,++t;
	}
	return res;
}

int main() {
	cin >> N >> M;
	b.resize(N); p.resize(M);
	int num1=0,sume=0,sumo=0;
    for(int i=0;i<N;++i) {
		cin >> b[i];
		if(b[i]) ++num1;
	}
	for(int i=0;i<M;++i) {
		cin >> p[i];
		if(i&1) sumo+=p[i];
		else sume+=p[i];
	}
	int ans=1e9;
	if(sume>=sumo) ans=min(ans,solve(num1<=N-num1?0:1));
	if(sume<=sumo) ans=min(ans,solve(num1<=N-num1?1:0));
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3168
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeull(long long n){
		if(n<10)
			putchar(n+'0');
		else{
			writeull(n/10);
			putchar(n%10+'0');
		}
	}
	struct set_type{
		unsigned long long *data;
		int size;
		void clear(){
			memset(data, 0, sizeof(unsigned long long)*size);
		}
		void resize(int k){
			size=(k+63)/64;
			size=(size+3)/4*4;
			data=new unsigned long long [size];
			clear();
		}
		void operator|=(const set_type &b){
			assert(size%4==0);
			assert(size==b.size);
			for(int i=0; i<size; i+=4){
				data[i]|=b.data[i];
				data[i+1]|=b.data[i+1];
				data[i+2]|=b.data[i+2];
				data[i+3]|=b.data[i+3];
			}
		}
		int count(){
			assert(size%4==0);
			int result=0;
			for(int i=0; i<size; i+=4){
				result+=__builtin_popcountll(data[i]);
				result+=__builtin_popcountll(data[i+1]);
				result+=__builtin_popcountll(data[i+2]);
				result+=__builtin_popcountll(data[i+3]);
			}
			return result;
		}
		void set(unsigned index){
			assert(size%4==0);
			assert(index<size*64);
			data[index/64]|=(1ull<<(index%64));
		}
	};
	void run(){
		int n=readu();
		static char a[500][502];
		for(int i=0; i<n; ++i)
			gets(a[i]);
		static int cnt[10];
		static int index[500][500];
		for(int i=0; i<n; ++i)
			for(int j=0; j<n; ++j)
				if(a[i][j]!='#'){
					assert(isdigit(a[i][j]));
					index[i][j]=cnt[a[i][j]-'0']++;
				}
		static set_type data[500][10];
		for(int j=0; j<n; ++j)
			for(int k=0; k<10; ++k)
				data[j][k].resize(cnt[k]);
		long long result=0;
		cerr<<"clock(): "<<clock()/double(CLOCKS_PER_SEC)<<endl;
		for(int r=n-1; r>=0; --r)
			for(int c=n-1; c>=0; --c){
				if(isdigit(a[r][c])){
					for(int i=0; i<10; ++i){
						if(c<n-1)
							data[c][i]|=data[c+1][i];
						result+=(long long)data[c][i].count()*i*(a[r][c]-'0');
					}
					data[c][a[r][c]-'0'].set(index[r][c]);
				}
				else{
					for(int i=0; i<10; ++i)
						data[c][i].clear();
				}
			}
		cerr<<"clock(): "<<clock()/double(CLOCKS_PER_SEC)<<endl;
		writeull(result);
		putchar('\n');
	}
}
int main(){
	whatever::run();
}

Measured memory_bytes: 17152
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))

    ans = 0
    for i, b in enumerate(bb):
        a = aa[i]
        next_a = aa[i+1]

        if a < b:
            ans += a
            remain = b - a

            if remain <= next_a:
                ans += remain
                aa[i+1] -= remain
            else:
                ans += next_a
                aa[i+1] = 0
        elif a >= b:
            ans += b

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2
3 5 2
4 5"""
        output = """9"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3
5 6 3 8
5 100 8"""
        output = """22"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2
100 1 1
1 100"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 21968
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define maxn 610
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
ll f[maxn][maxn],g[maxn];
int id[maxn],sum[maxn];
int n,m;
int main()
{
	n=read(); m=read();
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		id[x]=y; id[y]=x;
	}
	for(int i=1;i<=2*n;i++)
		sum[i]=sum[i-1]+(!id[i]);
	g[0]=1;
	for(int i=2;i<=2*n;i+=2)
		g[i]=g[i-2]*(i-1)%mod;
	for(int i=2;i<=2*n;i+=2)
		for(int l=1,r=i;r<=2*n;l++,r++){
			int flag=0;
			for(int k=l;k<=r;k++)
				if(id[k]&&(id[k]<l||id[k]>r)){
					flag=1; break;
				}
			if(flag)continue;
			f[l][r]=g[sum[r]-sum[l-1]];
			for(int k=l;k<r;k++)
				f[l][r]=(f[l][r]-f[l][k]*g[sum[r]-sum[k]])%mod;
			f[l][r]=(f[l][r]%mod+mod)%mod;
		}
	ll ans=0;
	for(int l=1;l<=2*n;l++)
		for(int r=l;r<=2*n;r++)
			ans=(ans+f[l][r]*g[sum[2*n]-sum[r]+sum[l-1]])%mod;
	writeln(ans%mod);
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n)
    {
        cin >> w.at(i);
    }

    int w_sum = 0;
    rep(i, n)
    {
        w_sum += w.at(i);
    }

    int s1 = 0;
    int ans = INF;
    rep(i, n - 1)
    {
        s1 += w.at(i);
        int s2 = w_sum - s1;
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){
    ll n;cin>>n;
    ll b[n+1];rep(i,1,n)cin>>b[i];
    b[0]=inf;
    ll ans[n];
    rep(i,0,n-1){
        for(ll j=n;j>=1;j--){
            if(b[j]==j){
                //cout<<j<<endl;
                ans[n-1-i]=j;
                rep(k,j,n-1){
                    b[k]=b[k+1];
                }
                b[n]=0;
                break;
            }else if(j==1){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    rep(i,0,n-1){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}



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

int main() 
{
	int n,m;
	cin>>n>>m;
	long long a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int j=0;
	long long ans=INT_MAX;
	for(int i=m-1;i<n;i++)
	{
		ans=min(ans,(a[i]-a[j]) );
		j++;
		
		
	}
	cout<<ans;
		


}

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

int main() {
    int i, N, X, T, value;
    
    cin >> N >> X >> T;
    if (N % X == 0) {
        cout << N/X*T;
            } else {
                    value = (N/X+1)*T;
                    cout << value;
    }
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> P;

const Int INF = 100000;

int main(){ 
    Int H, W, num_of_bl = 0; cin >> H >> W;
    vector<vector<bool>> black(H, vector<bool>(W, false));
    vector<vector<Int>> howfar(H, vector<Int>(W, INF));

    rep(i,H) {
        string S;
        cin >> S;
        rep(j,W) {
            if (S[j] == '#') {
                black[i][j] = true;
                num_of_bl++;
            }
        }
    }


    queue<P> que;
    que.push(make_pair(0,0));
    howfar[0][0] = 0;

    while(!que.empty()) {
        P p = que.front();
        Int x, y, nowfar;
        x = p.first;
        y = p.second;
        nowfar = howfar[x][y];
        rep(i,4) {
            Int x1, y1;
            if (i / 2 == 0) {
                x1 = x;
                y1 = y - 1 + 2 * (i % 2);
            }
            else {
                y1 = y;
                x1 = x - 1 + 2 * (i % 2);
            }
            if (x1 < 0 || x1 >= H || y1 < 0 || y1 >= W) continue;
            if ((howfar[x1][y1]==INF)&&(!black[x1][y1])) {
                que.push(make_pair(x1,y1));
                howfar[x1][y1] = nowfar + 1;
            }
        }
        que.pop();
    }


    if (howfar[H-1][W-1] == INF) cout << -1 << endl;
    else cout << H * W - num_of_bl - howfar[H-1][W-1] - 1 << endl;
}

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

        using namespace std;

        int main(){
          int K,N,i,j;
          long long z=0;
          scanf("%d %d",&N,&K);
          long long lista[N];
          for(i=0;i<N;i++){
            scanf("%lld",lista+i);
          }
          sort(lista,lista+N);
          reverse(lista,lista+N);
          if(K>N)
          {
              printf("%d",0);
              return 0;
          }
          for(i=0;i<K;i++){
                lista[i]=0;
          }
          for(i=0;i<N;i++)
          {
              z+=lista[i];
          }
          printf("%lld",z);


        return 0;}


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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    
    vector<int> s(n, k-q);
    rep(i, q){
        int a;cin >> a;
        s[a-1]++;
    }

    rep(i, n){
        if(s[i]<=0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1024
from collections import deque

N = int(input())
tree = {i: [] for i in range(N+1)}
for i in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

black_distance = {i: float('inf') for i in range(N+1)}
black_distance[1] = 0
white_distance = {i: float('inf') for i in range(N+1)}
white_distance[N] = 0


def bfs(start, distance):
    visited = set()
    que = deque()
    que.append(start)
    cnt = 0
    while que:
        now = que.popleft()
        nodes = tree[now]
        for n in nodes:
            if n not in visited:
                visited.add(n)
                distance[n] = min(distance[now] + 1, distance[n])
                que.append(n)
    return distance


black = bfs(1, black_distance)
white = bfs(N, white_distance)

black_cnt = 0
white_cnt = 0
for i in range(1, N+1):
    if black[i] <= white[i]:
        black_cnt += 1
    else:
        white_cnt += 1

if black_cnt > white_cnt:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 64472
#include <iostream>
#include <set>

using namespace std;

int main(){

    int num, t;
    cin >> num >> t;

    if(t == 0){
        cout << num << endl;
        return 0;
    }

    set<int> forbid;
    
    for(int i = 0; i < t; i++){
        int k;
        cin >> k;
        forbid.insert(k);
    }

    int auxMA = num, auxME = --num;

    while(1){

        if(forbid.find(auxMA) == forbid.end()){
            cout << auxMA << endl;
            return 0;
        }

        if(forbid.find(auxME) == forbid.end()){
            cout << auxME << endl;
            return 0;
        }

        auxMA++;
        auxME--;
    }

    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    int ans = 0,sum = 0;
    priority_queue<int> left;
    priority_queue< int, vector<int>, greater<int> > right;
    rep(i,n){
        int p;
        cin >> p;
        if(p == 1){
            int a,b;
            cin >> a >> b;
            sum += b;
            left.push(a);
            right.push(a);
            int x = left.top();
            int y = right.top();
            if(x > y){
                left.pop();
                right.pop();
                left.push(y);
                right.push(x);
                ans += abs(x-y);
            }
        }else{
            cout << left.top() << " " << ans+sum << endl;
        }
    }

}


Measured memory_bytes: 4588
#include<iostream>
using namespace std;
int main()
{
	int n,d;
	cin>>n>>d;
	int s;
	s=2*d+1;
	int a;
	a=n/s;
	if(a*s<n) cout<<n/s +1<<endl;
	else cout<<n/s<<endl;
	return 0;
}

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

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  double n,m;
  cin >> n >> m;
  double x = (n-m) * 100;
  double cnt = 1;


  x =  (m * 1900 + 100 * (n-m))* (int)pow(2,m);

  //cout << x << endl;

  cout << x << endl;
  return 0;
}


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

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  cout << x - a - b*((x-a) / b) << "\n";
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

X=gets.to_i-400
puts 8-X/200

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int  h, n;
    cin >> h >> n;
    ivec a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    int ma = *max_element(a.begin(), a.end());
    int nh = h+ma;
    ivec dp(nh);
    dp[0] = 0;
    for (int i = 1; i < nh; i++){
        dp[i] = b[0]*(1+i/a[0] - !(i%a[0]));
        for (int j = 1; j < n; j++) dp[i] = fmin(dp[i], dp[fmax(0, i-a[j])] + b[j]);
    }
    cout << *min_element(dp.begin()+h, dp.end()) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

// 検索タグ
int main() {
	// 入力
	ll A,B;cin>>A>>B;
    
	// 解法
	ll ans = A*B/GCD(A,B);

	//出力
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char ch[100],s[300][130];
int n,cur[100],len[300],ans;
void solve(int k,int l,int r)
{
	if(l==r)
	{
		len[k]=cur[l];
		for(int i=1;i<=len[k];++i)s[k][i]=ch[l];
		return;
	}
	int mid=l+r>>1,t1=1,t2=1,t=1;
	solve(k<<1,l,mid);
	solve(k<<1|1,mid+1,r);
	len[k]=len[k<<1]+len[k<<1|1];
	while(t1<=len[k<<1]&&t2<=len[k<<1|1])
	{
		printf("? ");
		for(int i=1;i<t;++i)putchar(s[k][i]);
		putchar(s[k<<1][t1]);
		for(int i=t2;i<=len[k<<1|1];++i)putchar(s[k<<1|1][i]);
		putchar('\n');
		fflush(stdout);
		scanf("%d",&ans);
		if(ans==n-t1-len[k<<1|1])s[k][t++]=s[k<<1][t1++];
		else s[k][t++]=s[k<<1|1][t2++];
	}
	while(t1<=len[k<<1])s[k][t++]=s[k<<1][t1++];
	while(t2<=len[k<<1|1])s[k][t++]=s[k<<1|1][t2++];
}
int main()
{
	for(int i=1;i<=26;++i)ch[i]='a'+i-1;
	for(int i=27;i<=52;++i)ch[i]='A'+i-27;
	for(int i=53;i<=62;++i)ch[i]='0'+i-53;
	for(int i=1;i<=62;++i)
	{
		printf("? ");
		for(int j=1;j<=128;++j)putchar(ch[i]);
		putchar('\n');fflush(stdout);
		scanf("%d",&cur[i]);cur[i]=128-cur[i];
		n+=cur[i];
	}
	solve(1,1,62);
	printf("! ");
	for(int i=1;i<=len[1];++i)putchar(s[1][i]);putchar('\n');fflush(stdout);
	return 0;
}

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

int main(int argc, char* argv[]){
        char buf[128]={0};
        int s[3]={0};
        int ans = 0;

        memset(buf, 0, sizeof(buf));
        if(fgets(buf, sizeof(buf)-1, stdin)==NULL){
                return 1;
        }

        for(int i=0; i<3; i++){
                char c[2] = {0};
                c[0] = buf[i];
                ans += atoi(c);
        }

        printf("%d\n",ans);
        return 0;

}

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

int main() {
    int a, b; cin >> a >> b;
    if (a == 1) a += 13;
    if (b == 1) b+= 13;

    if (a > b) cout << "Alice" << endl;
    else if (a == b) cout << "Draw" << endl;
    else cout << "Bob" << endl;
    return 0;
}


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

int main() {
    for( ; ; ) {
        int h, w;
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        string s = "";
        for(int i=0; i<w; i++) s += '#';
        for(int i=0; i<h; i++) cout << s << endl;
        cout << endl;
    }
}


Measured memory_bytes: 3156
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char W[102];
int N;
int cnt[128];
int main(){
  int KL2GvlyY, Q5VJL1cS;
  N = rd(W);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<((N-1) + 1);Lj4PdHRW++){
      cnt[W[Lj4PdHRW]] ^= 1;
    }
  }
  if(128==0){
    Q5VJL1cS = 0;
  }
  else{
    int KL2GvlyY;
    Q5VJL1cS = cnt[0];
    for(KL2GvlyY=(1);KL2GvlyY<(128);KL2GvlyY++){
      Q5VJL1cS += cnt[KL2GvlyY];
    }
  }
  if(Q5VJL1cS){
    wt_L("No");
    wt_L('\n');
  }
  else{
    wt_L("Yes");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// char W[102];
// int N;
// int cnt[128];
// {
//   rd(W@N);
//   cnt[W[0..N-1]] ^= 1;
//   wt( if[sum(cnt(128)), "No", "Yes"] );
// }


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

int main(){

    int n, x; cin >> n >> x;
    vector<int> m(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> m[i];
        sum += m[i];
    }

    x -= sum;
    sort(m.begin(), m.end());
    cout << n + x / m[0] << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	if(n == 1){
		if(a != b)cout << 0 << endl;
		else cout << 1 << endl;
	}
	else if(a <= b){
		cout << max((ll)0,(n-2)*(b-a)+1) << endl;
	}
	else cout << 0 << endl;
}



Measured memory_bytes: 256
import math
N,M = map(int,input().split(' '))

ABn =[ list(map(int,input().split(' '))) for _ in range(N)]  
ABn.sort(key=lambda x:(x[0]))
amount_yen = 0
for i in range(N):
    if ABn[i][1] < M:
        M -= ABn[i][1]
        amount_yen += ABn[i][0] * ABn[i][1]
    else:
        amount_yen += ABn[i][0] * M
        break
print(amount_yen)


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int di2[] = {1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
const int dj2[] = {1, -1, 1, -1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main(){
  int n; cin >> n;
  vector<P> a(n);
  rep(i, n) {
    int x; cin >> x;
    a[i] = P(x, i+1);
  }
  sort(ALL(a));
  for(auto x : a) cout << x.second << " ";
  cout << endl;
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  int x[m], y[m];
  for (int i = 0; i < m; i++) {cin >> x[i] >> y[i]; x[i]--; y[i]--;}
  vector<int> num(n, 1);
  bool p[n] = {1};
  for (int i = 0; i < m; i++) {
    if (p[x[i]]) {
      p[y[i]] = 1;
      if (num[x[i]] == 1) {
        p[x[i]] = 0;
      }
    }
    num[x[i]]--;
    num[y[i]]++;
  }
  int res = 0;
  for (int i = 0; i < n; i++) res += p[i];
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <vector>

struct UnionFind
{
	std::vector<int> data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	bool unite(int x, int y)
	{
		x = find(x), y = find(y);
		if(x == y) return (false);
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return (true);
	}

	int find(int k)
	{
		if(data[k] < 0) return (k);
		return (data[k] = find(data[k]));
	}

	int size(int k)
	{
		return (-data[find(k)]);
	}
};

UnionFind uf(100000);
bool visit[100000];
std::vector<int> edges[100000];

void dfs(int v, int p)
{
	visit[v] = true;
	if (p != -1)
	{
		uf.unite(v, p);
	}
	for (int e : edges[v])
	{
		if (e != p && !visit[e])
		{
			dfs(e, v);
		}
	}
}

int ans[100000];

int main()
{
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		edges[a].emplace_back(b);
		edges[b].emplace_back(a);
	}

	for (int i = 0; i < n; ++i)
	{
		if (!visit[i]) dfs(i, -1);
	}
	for (int i = 0; i < n; ++i)
	{
		ans[i] = uf.size(i) - 1 - edges[i].size();
	}
	for (int i = 0; i < k; ++i)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		if (uf.find(a) == uf.find(b))
		{
			ans[a]--;
			ans[b]--;
		}
	}

	for (int i = 0; i < n; ++i)
	{
		printf(i == n - 1 ? "%d\n" : "%d ", ans[i]);
	}
}


Measured memory_bytes: 10112
#include<iostream>
#include<vector>
#include<map>
using namespace std;
long long n,a,b;
pair<int,int> p[100100];
vector<int> v[100100];
map<pair<int,int>,int> l;
void dfs(int x,int pre,int e)
{
	int h=1;
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i]!=pre)
		{
			if(h==e)
				h++;
			l[make_pair(x,v[x][i])]=h;
			l[make_pair(v[x][i],x)]=h;
			dfs(v[x][i],x,h);
			h++;	
		}	
	}
	return ; 
}
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>p[i].first>>p[i].second;
		v[p[i].first].push_back(p[i].second);
		v[p[i].second].push_back(p[i].first);
	}
	int r;
	for(int i=1;i<=n;i++)
		if(v[i].size()==1)
		{
			r=i;
			break;
		}
	dfs(r,-1,-1);
	long long m=0;
	for(int i=1;i<n;i++)	
	{
		long long k=l[p[i]];
		m=max(m,k);
	}
	cout<<m<<endl;	
	for(int i=1;i<n;i++)
		cout<<l[p[i]]<<endl;
}

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

int main(){
  int n;
  int s[110];
  cin >> n;
  int goukei = 0;
  for(int i = 0;i < n;i++){
    cin >> s[i];
    goukei += s[i];
  }
  int k = 200;
  if(goukei % 10 == 0){
    for(int i = 0;i < n;i++){
      if(s[i] % 10 != 0){
        k = min(k,s[i]);
      }
    }
    if(k != 200){
      cout << goukei - k << endl;
    }
    else{
      cout << 0 << endl;
    }
  }
  else{
    cout << goukei << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

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

        for(i = 1; i < 10; i++){
           for(j = 1; j < 10; j++){
              k = i * j;
                printf("%dx%d=%d\n", i, j, k);
           }
        }
        return 0;
}

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

int t[2];
long long a[2], b[2], x, y;

int main() {
	cin >> t[0] >> t[1] >> a[0] >> a[1] >> b[0] >> b[1];
	x = (a[0] - b[0]) * t[0];
	y = (a[1] - b[1]) * t[1];

	if (x + y == 0)
		cout << "infinity" << endl;
	else if ((x > 0) ^ (x + y > 0))
		cout << -x / (x + y) + (abs(y) - 1) / abs(x + y) << endl;
	else
		cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

map<string,int> key;
bool f = true;
string s;

int check(char c){
    if('0'<=c&&c<='9') return 0;
    else if('A'<=c&&c<='Z') return 1;
    else if('a'<=c&&c<='z') return 2;
    else return -1;
}

int dfs(int l,int r){
    int cnt = 0;
    int idx = -1;
    int ret = 0;
    int bf = 0;
    for (int i = l; i < r; i++) {
        if(s[i] == '('){
            if(cnt == 0){
                idx = i;
            }
            cnt++;
        }
        else if(s[i] == ')'){
            cnt--;
            if(cnt == 0){
                bf = dfs(idx+1,i);
                ret += bf;
            }
        }
        else{
            if(cnt) continue;
            int a = check(s[i]),b = -1;
            if(i+1 < r) b = check(s[i+1]);
            if(a == 1){
                if(b == 2){
                    string r = "";r += s[i];r += s[i+1];
                    if(key.find(r) == key.end()){
                        f = false;
                    }
                    else{
                        bf = key[r];
                        ret += bf;
                    }
                    i++;
                }
                else{
                    string r = "";
                    r += s[i];
                    if(key.find(r) == key.end()){
                        f = false;
                    }
                    else{
                        bf = key[r];
                        ret += bf;
                    }
                }
            }
            else if(a == 0){
                if(b == 0){
                    ret += bf * ((s[i] - '0') * 10 + (s[i+1] - '0') - 1);
                    i++;
                }
                else{
                    ret += bf * ((s[i] - '0') - 1);
                }
            }
        }
    }
    return ret;
}


int main(){
    string t;
    while(cin >> s){
        if(s == "END_OF_FIRST_PART") break;
        cin >> t;
        key[s] = stoi(t);
    }
    while(cin >> s){
        if(s == "0") break;
        f = true;
        auto r = dfs(0,s.length());
        if(f){
            cout << r << endl;
        }
        else{
            cout << "UNKNOWN\n";
        }
    }
    return 0;
}



Measured memory_bytes: 3176