akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long long n;

int main() {
  cin >> n;
  for(long long i = 0; i <= n; ++i) {
    long long x = i * 1.08;
    if(x == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

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

int main()
{
    int r,g,b,s,h;
    scanf("%d%d%d",&r,&g,&b);
    s=100*r+10*g+b;
    h=s%4;
    if(h==0)
        printf("YES");
    else
        printf("NO");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 

int data[300001];
int main(){
    int n;
    string s;
    cin >> n >> s;
    REP(i, 300001) data[i] = 0;
    if(s[0] == 'E') data[0] = 1;
    FOR(i, 1, s.size()){
    	if(s[i] == 'E') data[i] = data[i-1] + 1;
    	else data[i] = data[i-1];
    }
    int ans = 300001;
    ans = data[n-1] - data[0];	
    FOR(i,1,s.size()){
    	int cr = i - data[i-1];
    	int cl = (data[n-1] - data[i]);
    	ans = min(ans, cr + cl);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1796
import sys
readline = sys.stdin.readline

def root(x):
    if uf[x] == x:
        return x
    else:
        uf[x] = root(uf[x])
        return uf[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx == ry:
        return
    uf[rx] = ry

N, M = map(int,readline().split())
p = list(map(int,readline().split()))
p.insert(0, -1)
uf = [i for i in range(N+1)]
for i in range(M):
    a, b = (map(int,readline().split()))
    unite(a, b)
for i in range(1, N+1):
    root(i)

ans = 0
#N += 1
#match = [[] for i in range(N)]
#for i in range(1, N):
#    match[uf[i]].append(i)
#for i in range(1, N):
#    matchlen = len(match[i])
#    for j in range(matchlen):
#        if p[match[i][j]] in match[i]:
#            ans += 1

for i in range(1, N+1):
    if same(i, p[i]):
        ans += 1
print(str(ans))

Measured memory_bytes: 13876
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {

	int n, a, b;

	cin >> n >> a >> b;

	int ab = a + b;

	int abcount = 0;
	int bcount = 0;

	string s;

	cin >> s;



	for (int i = 0; i < n; i++)
	{


		if (s[i] == 'a') {
			if (abcount < ab) {
				abcount++;
				cout << "Yes" << endl;

			}
			else {
				cout << "No" << endl;

			}
		}
		if (s[i] == 'b') {

			if (abcount < ab && bcount < b) {
				abcount++;

				bcount++;
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;

			}

		}
		if (s[i] == 'c') {
			cout << "No" << endl;
		}
	}


}

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

int main(){
  int A,B,C,X;
  cin >>A>>B>>C>>X;
  int count=0;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      for(int k=0;k<C+1;k++){
        if(i*500+j*100+k*50==X){
          count++;
        }
      }
    }
  }
  cout <<count<<endl;

  return 0;
}


  

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

int main(){
  int n; cin>>n;
  int cnt=0;
  
  for (int i=1; i<=n; i++){
    int num=to_string(i).size();
    if (num%2==1) cnt+=1;
  }
  
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	e = [Int[] for i in 1:n]
	for i in 1:n-1
		x,y = readline() |> split |> parseMap
		push!(e[x],y)
		push!(e[y],x)
	end
	v = -ones(Int,n)
	t = -ones(Int,n)
	t[1] = 0
	v[1] = 0
	stack = Int[1]
	while !isempty(stack)
		now = shift!(stack)
		for i in e[now]
			if t[i] == -1
				t[i] = t[now]+1
				v[i] = now
				push!(stack,i)
			end
		end
	end
	m = maximum(t)
	z = Tuple{Int,Int}[(t[i],i) for i in 1:n]
	z = sort(z,by=x->x[1],rev=true)
	val = -ones(Int,n)
	for key in 1:n
		i = z[key][2]
		if i!=1&&length(e[i]) == 1
			val[i] = 0
		else
			if i!=1&&length(e[i])==2 || i==1&&length(e[i])==1
				for j in 1:length(e[i])
					if e[i][j] != v[i]
						val[i] = val[e[i][j]] + 1
					end
				end
			else
				val[i] = 0
				for j in 1:length(e[i])
					if e[i][j] != v[i]
						val[i] = (val[e[i][j]]+1)$val[i]
					end
				end
			end
		end
	end
	println(val[1]>0?"Alice":"Bob")
end

main()


Measured memory_bytes: 167208
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w==0 && h==0) break;
			
			int[][] map = new int[h][w];
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					map[i][j] = sc.nextInt();
				}
			}
			
			int[] c = new int[4];
			for(int i=0;i<4;i++){
				c[i] = sc.nextInt();
			}
			
			int[][][] cost = new int[4][h][w];
			for(int i=0;i<4;i++){
				for(int j=0;j<h;j++){
					for(int k=0;k<w;k++){
						cost[i][j][k] = Integer.MAX_VALUE;
					}
				}
			}
			cost[0][0][0] = 0;
			
			LinkedList<Integer> x = new LinkedList<Integer>();
			LinkedList<Integer> y = new LinkedList<Integer>();
			LinkedList<Integer> d = new LinkedList<Integer>();
			x.offer(0);
			y.offer(0);
			d.offer(0);
			int p, q, r, s;
			int[] e = new int[4];
			while(d.size()!=0){
				p = x.poll();
				q = y.poll();
				r = d.poll();
				s = cost[r][q][p];
				for(int i=0;i<4;i++){
					e[r] = c[i];
					if(map[q][p]==i) e[r] = 0;
					r++;
					if(r==4) r = 0;
				}
				
				if(p!=w-1 && cost[0][q][p+1]>s+e[0]){
					cost[0][q][p+1] = s+e[0];
					x.offer(p+1);
					y.offer(q);
					d.offer(0);
				}
				if(q!=h-1 && cost[1][q+1][p]>s+e[1]){
					cost[1][q+1][p] = s+e[1];
					x.offer(p);
					y.offer(q+1);
					d.offer(1);
				}
				if(p!=0 && cost[2][q][p-1]>s+e[2]){
					cost[2][q][p-1] = s+e[2];
					x.offer(p-1);
					y.offer(q);
					d.offer(2);
				}
				if(q!=0 && cost[3][q-1][p]>s+e[3]){
					cost[3][q-1][p] = s+e[3];
					x.offer(p);
					y.offer(q-1);
					d.offer(3);
				}
			}
			
			int ans = Math.min(cost[0][h-1][w-1], cost[1][h-1][w-1]);
			System.out.println(ans);
		}	
	}	
}

Measured memory_bytes: 112484
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(v) ;
#define eprintf(...) if(0) fprintf(stderr, "...")
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

const int maxQ = 100000 + 233;
const LL P = 1000003;
int n, x, d;
LL fac[P], ifac[P];

LL qpow(LL a, LL b) {
	LL r = 1;
	while(b) {
		if(b & 1) (r *= a) %= P;
		(a *= a) %= P; b >>= 1;
	}
	return r;
}

LL solve() {
	if(d == 0) {
		return qpow(x, n);
	}
	LL ind = qpow(d, P - 2);
	LL px = x * ind % P;
	if(px == 0 || px + n - 1 >= P) return 0;
	return fac[px + n - 1] * ifac[px - 1] % P * qpow(d, n) % P;
}

int main() {
	ios::sync_with_stdio(false);
	fac[0] = 1;
	for(int i = 1; i < P; ++i) fac[i] = fac[i - 1] * i % P;
	ifac[P - 1] = fac[P - 1]; assert(fac[P - 1] == P - 1);
	for(int i = P - 2; i >= 0; --i) ifac[i] = ifac[i + 1] * (i + 1) % P;
	int q; cin >> q;
	while(q--) {
		cin >> x >> d >> n;
		cout << solve() << '\n';
	}
	return 0;
}


Measured memory_bytes: 16512
#include <iostream>

using namespace std;

int main() {
    int a, b;
    float t;
    int tmp = 1;
    int result;

    cin >> a >> b >> t;

    while(1) {

        if(tmp % a == 0) {
            result += b;
        }

        tmp ++;

        if(tmp > t+0.5) {
            break;
        }
    }

    cout << result << endl;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;
int check(char str);
int counter(int res,char *str);
int main(){
    char str[128]={0};
    while(~scanf("%s",str)){

        /*宣言*/
        int ans = 0,bef = 0;
        int cnt = 1;
        int len = strlen(str);
        int x;
        bool f = false;
        /*宣言終了*/

        reverse(str,str+len);
        rep(i,len){
            x = check(str[i]);
            if(!f){
                bef = x;
                f = true;
                continue;
                cnt++;
            }
            if(bef == x){
                cnt++;
            }
            else if(bef < x){
                ans += cnt*bef;
                cnt = 1;
                bef = x;
            }
            else{
                int coun = counter(i,str);
                ans += (bef*cnt) - (coun*x);
                cnt = 1;
                f = false;
                i += coun-1;
            }
        }
        if(x == bef)ans += cnt*bef;
        printf("%d\n",ans);
    }
	return 0;
}
int check(char str){
    if(str == 'I')return 1;
    if(str == 'V')return 5;
    if(str == 'X')return 10;
    if(str == 'L')return 50;
    if(str == 'C')return 100;
    if(str == 'D')return 500;
    if(str == 'M')return 1000;
}
int counter(int res , char *str){
    int cnt = 1;
    for(int i = res; str[i] != str[res] ; i++){
        cnt++;
    }
    return cnt;
}

Measured memory_bytes: 1136
n = int(input())
a = [int(input()) for _ in range(n)]
num = int(n/2)
a.sort(reverse = True)
x = []
y = []
if n%2 == 0:
    result = 0
    x = a[:num]
    y = a[num:]
    result += sum(x)*2 - x[-1]
    result -= sum(y)*2 - y[0]
    print(result)
else:
    x = a[:num]
    y = a[num+1:]
    mid = a[num]
    result_1 = int(sum(x)*2 + mid - x[-1] - sum(y)*2)
    result_2 = int(sum(x)*2 - sum(y)*2 -mid + y[0])
    print(max(result_1, result_2))

Measured memory_bytes: 7764
k, t = map(int,input().split())
A = list(map(int,input().split()))
max_A = max(A)

if t == 1:
    print(k-1)
else:
    if max_A -1 > sum(A) - max_A:
        print((max_A -1) - sum(A) + max_A)
    else:
        print(0)
    
        


Measured memory_bytes: 9164
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int H,A;
  cin>>H>>A;
 if(H!=0&&A!=0&&H<=10000&&A<=10000){
  if(H%A==0){
      cout<<H/A;
  }
  if(H%A!=0){
      cout<<(H/A)+1;
  }
 }
   return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
//static const ll MOD = 1;
static const ll MAX_L = (ll)1 << 62;

static const ll FACT_SIZE = 1000000;

ll x[100001] = {};
int main() {
	ll n, a, b; cin >> n >> a >> b;
	rep(i, 0, n)cin >> x[i];
	ll sum = 0;
	rep(i, 1, n) {
		ll d = x[i] - x[i - 1];
		sum += (d*a >= b) ? b : d * a;
	}
	cout << sum << endl;

	return 0;
}

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

bool check(int a,int b, int c){
        for(int i=a;i<(b+1)*a;i+=a){
                if(i%b==c){
                        return true;
                }
        }
        return false;
}

int main(){
        int a,b,c;
        cin >> a >> b >> c;

        if(check(a,b,c)){
                cout << "YES" << endl;
        }
        else{
                cout << "NO" << endl;
        }

        return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    string S; cin >> S;
    ll cnt = 0;
    rep(i, N - 2){
        if (S.substr(i, 3) == "ABC"){cnt += 1; i += 2;}
    }
    cout << cnt << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,a;
  cin >>n>>a;
  ll x[n];
  for(ll i=0;i<n;i++) cin >>x[i];
  ll ans=0;
    ll dp[n+1][n*a+1][n+1];
    //dp[i][j][k]=i-1までの中でk個選んだ時和がjになるもの
    memset(dp,0,sizeof(dp));
    for(ll i=0;i<=n;i++) dp[i][0][0]=1;
    for(ll i=0;i<n;i++){
      for(ll j=0;j<=n*a;j++){
         for(ll k=0;k<=n;k++){
          dp[i+1][j][k]=dp[i][j][k];
          if(k!=0&&j>=x[i]) dp[i+1][j][k]+=dp[i][j-x[i]][k-1];
          //i+1まででk個選び和がj=iまででk-1個選び和がj-x[i]+iまででk個選び和がj
        }
      }
    }
  for(ll i=1;i<=n;i++) ans+=dp[n][i*a][i];
  cout <<ans<<endl;
}


Measured memory_bytes: 51072
n = int(input())
A = list(map(int, input().split()))
ori = []
for i in range(len(A)):
    ori.append((A[i], i+1))

d = dict(ori)
d_sort = sorted(d.items())

ans =[]
for i in range(len(A)):
    ans.append(d_sort[i][1])

print(*ans)

Measured memory_bytes: 34140
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

bool solve(vector<int> v) {
    int zerocnt = count(v.begin(), v.end(), 0);
    if(zerocnt == 8) return true;
    rep(i,0,9) {
        if(v[i] >= 3) {
            v[i] -= 3;
            if(solve(v)) return true;
            v[i] += 3;
        }
    }
    rep(i,0,7) {
        if(v[i] >= 1 && v[i+1] >= 1 && v[i+2] >= 1) {
            v[i]--; v[i+1]--; v[i+2]--;
            if(solve(v)) return true;
            v[i]++; v[i+1]++; v[i+2]++;
        }
    }
    return false;
}

signed main() {
    string s;
    while(cin >> s) {
        vector<int> v(9, 0);
        bool invalid = false;
        rep(i,0,s.length()) {
            v[ s[i] - '1' ]++;
            if(v[ s[i] - '1' ] > 4) invalid = true;
        }
        if(invalid) cout << 0 << endl;
        else {
            vector<int> ans;
            rep(i,0,9) {
                if(v[i] == 4) continue;
                v[i]++;
                if(solve(v)) ans.pb(i+1);
                v[i]--;
            }

            bool find = false;
            if(ans.size()) {
                rep(i,0,ans.size()) {
                    if(find) printf(" %lld", ans[i]);
                    else printf("%lld", ans[i]);
                    find = true;
                }
                cout << endl;
            }
            else cout << 0 << endl;
        }
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  map<string, int> A;
  string s;
  A["AC"] = 0;
  A["WA"] = 0;
  A["TLE"] = 0;
  A["RE"] = 0;
  for (int i = 0; i < N; i++) {
    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: 3632
S = input()

i = 0
j = len(S)-1
ans = 'Yes'
while i <= j:
    if S[i] != S[j-i]:
        ans = 'No'
        break
    i +=1

i = 0
j = len(S)//2-1
while i <= j:
    if S[i] != S[j-i]:
        ans = 'No'
        break
    i +=1

i = len(S)//2+1
j = len(S)-1
while i <= j:
    if S[i] != S[j-i]:
        ans = 'No'
        break
    i +=1

print(ans)

Measured memory_bytes: 3064
// 参考: https://www.youtube.com/watch?v=ENSOy8u9K9I
// 基本方針:
//   (を+1, )を-1とした折れ線に見立てる
//   正しい括弧列であるには、
//     - 線が0で終わる
//     - 0未満にならない
//   必要がある
#include <bits/stdc++.h>
using namespace std;

bool can_join(vector<pair<int, int>> &brackets)
{
  int height = 0;
  for (pair<int, int> bracket : brackets)
  {
    int bottom = height + bracket.first;
    if (bottom < 0)
    {
      return false;
    }
    height += bracket.second;
  }
  return true;
}

int main()
{
  int bracket_num;
  cin >> bracket_num;
  // (左or右を始点とした最下点、最終的な高さ)のpair
  vector<pair<int, int>> l_brackets, r_brackets;
  int total_height = 0;
  // (を+, )を-として、+ならl、-ならrに格納する
  for (int i = 0; i < bracket_num; i++)
  {
    string s;
    cin >> s;
    int height = 0, bottom = 0;
    for (char c : s)
    {
      if (c == '(')
      {
        height++;
      }
      else
      {
        height--;
      }
      bottom = min(bottom, height);
    }
    if (height > 0)
    {
      l_brackets.emplace_back(bottom, height);
    }
    else
    {
      r_brackets.emplace_back(bottom - height, -height);
    }
    total_height += height;
  }
  sort(l_brackets.rbegin(), l_brackets.rend());
  sort(r_brackets.rbegin(), r_brackets.rend());
  if (can_join(l_brackets) && can_join(r_brackets) && total_height == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 11236
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int a[50];
		rep(i, n) a[i] = n - i;
		rep(j, r) {
			vector<int> v;
			int p, c;
			cin >> p >> c;
			REP(i, p - 1, p + c - 2) {
				v.push_back(a[i]);
			}
			rep(i, n) {
				if (p - 1 <= i && i <= p + c - 2) continue;
				v.push_back(a[i]);
			}
			//rep(i, n) {
			//	cout << v[i] << " ";
			//}
			//cout << endl;
			rep(i, n) a[i] = v[i];
		}
		cout << a[0] << endl;
	}

    return 0;
}



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

int main(){
  vector<char> s(10);
  for(int i=0;i<10;i++){
    cin >> s.at(i);
  }
  s.at(3)='8';
  for(int i=0;i<10;i++){
    cout << s.at(i) ;
  }
}

Measured memory_bytes: 256
n = int(input())

a=[0]*n
b=[1]*n

for i in range(n):
    a[i]=int(input())

now=1

for i in range(n):
    if now==2:
        print(i)
        break
    elif b[now-1]==1:
        b[now-1]=0
        now=a[now-1]
    else:
        print(-1)
        break

Measured memory_bytes: 8948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int sum(ll x)
{
    int ans=0;
    while(x)
        ans+=x%10,x/=10;
    return ans;
}
int main()
{
    int k;scanf("%d",&k);
    ll ans=1,add=1;
    while(k--)
    {
        printf("%lld\n",ans);
        ll s1=ans+add,s2=ans+2*add;
        if(s1*sum(s2)<=s2*sum(s1)) ans=s1;
        else add*=10,ans+=add,assert(ans*sum(ans+add)<=(ans+add)*sum(ans));
    }
    //for(int i=1;i<=1000;i++)
    //    if(1.0*i/sum(i)<1.0*(i+1)/sum(i+1))
    //    cout<<i<<' '<<1.0*i/sum(i)<<endl;
}
/*
9 1
19 1.9
29 2.63636
39 3.25
49 3.76923
59 4.21429
69 4.6
79 4.9375
89 5.23529
99 5.5
109 10.9

119 10.8182
129 10.75
139 10.6923
149 10.6429
159 10.6
169 10.5625
179 10.5294
189 10.5
199 10.4737

209 19
219 18.25
229 17.6154
239 17.0714
249 16.6
259 16.1875
269 15.8235
279 15.5
289 15.2105
299 14.95

309 25.75
319 24.5385
329 23.5
339 22.6
349 21.8125
359 21.1176
369 20.5
379 19.9474
389 19.45
399 19

409 31.4615
419 29.9286
429 28.6
439 27.4375
449 26.4118
459 25.5
469 24.6842
479 23.95
489 23.2857
499 22.6818
509 36.3571
519 34.6
529 33.0625
539 31.7059
549 30.5
559 29.4211
569 28.45
579 27.5714
589 26.7727
599 26.0435
609 40.6
619 38.6875
629 37
639 35.5
649 34.1579
659 32.95
669 31.8571
679 30.8636
689 29.9565
699 29.125
709 44.3125
719 42.2941
729 40.5
739 38.8947
749 37.45
759 36.1429
769 34.9545
779 33.8696
789 32.875
799 31.96
809 47.5882
819 45.5
829 43.6316
839 41.95
849 40.4286
859 39.0455
869 37.7826
879 36.625
889 35.56
899 34.5769
909 50.5
919 48.3684
929 46.45
939 44.7143
949 43.1364
959 41.6957
969 40.375
979 39.16
989 38.0385
999 37
*/


Measured memory_bytes: 256
N=int(input())
Mlen=Alen=Rlen=Clen=Hlen=0

for i in range(N):
	IN=list(input())
	if IN[0]=="M":
		Mlen+=1
	elif IN[0]=="A":
		Alen+=1
	elif IN[0]=="R":
		Rlen+=1
	elif IN[0]=="C":
		Clen+=1
	elif IN[0]=="H":
		Hlen+=1
	else:
		pass

name=[Mlen,Alen,Rlen,Clen,Hlen]
ans=0

for i in range(0,3):
	for j in range(i+1,4):
		for k in range(j+1,5):
			ans+=name[i]*name[j]*name[k]

print(ans)

Measured memory_bytes: 3064
# AOJ 0023 Circles Intersection
# Python3 2018.6.16 bal4u

n = int(input())
for i in range(n):
	xa, ya, ra, xb, yb, rb = list(map(float, input().split()))
	ans = 1
	d = (xa - xb)*(xa - xb) + (ya - yb)*(ya - yb);
	if d > (ra + rb)*(ra + rb): ans = 0
	elif d < (ra - rb)*(ra - rb):
		ans = 2 if ra > rb else -2
	print(ans)


Measured memory_bytes: 5604
#include<cstdio>
int main() {
	int n, i, a, b, asum, bsum;
	while (scanf("%d", &n) != EOF) {
		if (n == 0)break;
		asum = 0;
		bsum = 0;
		for (i = 0; i < n; i++) {
			scanf("%d%d", &a, &b);
			if (a < b) bsum += a + b;
			else if (a > b)asum += a + b;
			else {
				asum += a;
				bsum += b;
			}
		}
		printf("%d %d\n", asum, bsum);
	}
	return 0;
}


Measured memory_bytes: 2588
<?php
fscanf(STDIN, "%d", $num);
$min = 0;
$dif = 0;
for ($i = 0; $i < $num; $i++) {
    fscanf(STDIN, "%d", $r);
    if ($i === 0) {
        $min = $r;
    } elseif ($i === 1) {
        $dif = $r - $min;
    } else {
        $dif = max($dif, $r - $min);
    }
    $min = min($min, $r);
}
echo "$dif\n";


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

using namespace std;
int counter = 1;

int f(int n,int k)
{
    int how = k;
    for (int i = 0; i < counter; i++)
    {
        how = how*k;
    }
    if (n / how == 0)
    {
        return 0;
    }
    else
    {
        counter++;
        f(n, k);
    }
    
}

int main()
{
    int N,K;
    cin >> N;
    cin >> K;
    if (N < K)
    {
        cout << "1";
        goto end;
    }
    f(N,K);
    cout << counter + 1;
    end:
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
//#define getchar_unlocked()  getchar()
int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}
 
#define MAX_N 102
 
int a[MAX_N];
 
void dump(int n)
{
    int i;
 
    printf("%d", a[0]);
    for (i = 1; i < n; i++) printf(" %d", a[i]);
    putchar('\n');
}
 
void insertion_sort(int n)
{
    int i, j, key;
 
    dump(n);
    for (i = 1; i < n; i++) {
        key = a[i];
        j = i-1;
        while (j >= 0 && a[j] > key) a[j+1] = a[j], j--;
        a[j+1] = key;
        dump(n);
    }
}
 
int main()
{
    int N, i;
 
    N = in();
    for (i = 0; i < N; i++) a[i] = in();
    insertion_sort(N);
    return 0;
}


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

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=1e4,MAXR=1e2;

int M[MAXR][MAXR];
int R,C,N,A[MAXN];

int main() {
	rii(R,C); ri(N);
	FOR(i,0,N) ri(A[i]);
	int r=0,c=0,cnt=1;
	FOR(i,0,N) FOR(j,0,A[i]) {
		M[r][c] = i+1;
		c += cnt;
		if(c ==  C) c--, cnt=-1,r++;
		if(c == -1) c++, cnt=+1,r++;
	}
	FOR(r,0,R) FOR(c,0,C) printf("%d%c",M[r][c]," \n"[c==C-1]);
}


Measured memory_bytes: 384
n=int(input())

a= list(map(int,input().split()))
maxa=a[0]
dai=0
for i in range(1,n):
    if a[i]>maxa:
        maxa=a[i]
    if a[i]<maxa:
        dai+=maxa-a[i]
print(dai)
    
    

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))
#define INF 10000000000000

int main()
{
	ll n;
	cin >> n;
	VEC(ll,n,a,0);
	REP(i,n) cin >> a[i];

	VEC2( bool, 5, n + 1, p ,false );
	VEC2( ll, 5, n + 1, cnt, INF );

	p[0][0] = true;
	cnt[0][0] = 0;
	REP( i, n )
	{
		auto setC = [&p, &cnt, i]( ll type, ll from, ll value )
		{
			p[type][i+1] = true;
			cnt[type][i+1] = min( cnt[type][i+1], cnt[from][i] + value );
		};

		ll modi = a[i] % 2 == 0 && a[i] >= 2 ? 2 : a[i] % 2;
		ll modi1 = ( a[i] + 1 ) % 2;
		if( i == n - 1 )
		{
			if( p[0][i] ) // ↑なし
			{
				setC( 0, 0, 0 );
			}
			if( p[1][i] ) // ↓なし
			{
				setC( 1, 1, a[i] );
			}
			if( p[2][i] ) // 1
			{
				setC( 2, 2, 0 );
			}
			if( p[3][i] ) // 2閉じる
			{
				setC( 3, 3, a[i] % 2 );
			}
			if( p[4][i] ) // 2閉じない
			{
				setC( 4, 4, 0 );
			}
		}
		else
		{
			if( p[0][i] ) // ↑なし
			{
				setC( 0, 0, a[i] );
				setC( 2, 0, modi1 );
				setC( 4, 0, 2 - modi );
			}
			if( p[1][i] ) // ↓なし
			{
				setC( 1, 1, a[i] );
			}
			if( p[2][i] ) // 1
			{
				setC( 1, 2, a[i] );
				setC( 2, 2, modi1 );
				setC( 3, 2, 2 - modi );
			}
			if( p[3][i] ) // 2閉じる
			{
				setC( 1, 3, a[i] );
				setC( 3, 3, 2 - modi );
			}
			if( p[4][i] ) // 2閉じない
			{
				setC( 1, 4, a[i] );
				setC( 2, 4, modi1 );
				setC( 4, 4, 2 - modi );
			}
		}
	}

	ll min_ = INF;
	REP( j, 5 ) { min_ = min( min_, cnt[j][n] ); }
	cout << min_ << endl;

	return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

void trace(vector<int>& a) {
    for (int i = 0; i < a.size(); i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
}

void insertionSort(vector<int>& a) {
    int n = a.size();
    for (int i = 1; i < n; i++) {
        trace(a);
        int x = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > x) {
            a[j + 1] = a[j];
            j--; 
        }
        a[j + 1] = x;
    }
    trace(a);
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    insertionSort(a);
    return 0;
}

Measured memory_bytes: 3204
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 52;

int main(){
  int N,a[MAX_N];
  cin >> N;
  rep(i,N) cin >> a[i];
  if(N>=25){
    cout << "0" << endl;
    return 0;
  }
  int b[MAX_N];
  fill(b,b+13,0);
  if(N>=19&&N<=24){
    b[0]++;
    rep(i,N) b[a[i]]++;
    int _max = -INF;
    rep(i,13) _max = max(_max,b[i]);
    if(_max>=3||b[0]>=2) cout << "0" << endl;
    else cout << "1" << endl;
    return 0;
  }
  int ans = -INF;
  rep(i,1<<N){
    int ind = 0;
    b[ind++] = 0;
    rep(j,N){
      if(((1<<j)&i)!=0) b[ind++] = 24-a[j];
      else b[ind++] = a[j];
    }
    sort(b,b+N+1);
    int diff = 24 - b[N];
    rep(j,N) diff = min(diff,b[j+1]-b[j]);
    ans = max(ans,diff);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//aea ctmr
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//v.erase(unique(v.begin(),v.end()),v.end());
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846
 
typedef long double ld;
typedef long long ll;
const ll N = 200500;
const ll mod = 1e9 + 7;
using namespace std;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

ll pot[N];
vector <ll > xd;
ll yii(ll t){
    if(t == 0) return 1LL;
    ll dev = pot[t] + t * pot[t - 1];
    dev %= mod;
    return dev;
}

int main(){
    fastio;
    pot[0] = 1LL;
    for(ll i = 1; i < N; i++) pot[i] = (2 * pot[i - 1]) % mod;
    ll n;
    cin >> n;

    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        xd.push_back(a);
    }

    sort(xd.begin(), xd.end());
    ll ans = pot[n];    
    //trace(ans);
    ll wea = 0;
    for(ll i = 0; i < n; i++){
        ll uwu = xd[i];
        uwu *= pot[i];
        uwu %= mod;
        uwu *= yii(n - i - 1);
        uwu %= mod;
        //trace(uwu);

        wea += uwu;
        wea %= mod;
    }

    ans *= wea;
    ans %= mod;

    if(ans < 0) ans += mod;
    //trace(yii(0), yii(1), yii(2));
    cout << ans << endl;
    return 0;


}


Measured memory_bytes: 3956
#40桁
A,B=map(int, input().split())
#print(bin(A),bin(B))
if A==B:
  print(A)
  exit()
#１が奇数個なら１　偶数こなら０
#2**0 偶奇一致　（A-B）%2==0
#010101010101
#2**1 110011001100...
#2**2 11110000111100001111
ans=0
for i in range(40):
  now=0
  aone=False
  bone=False
  if A>>i&1==1:
    aone=True
  if B>>i&1==1:
    bone=True
  amod=(A)%(2**i)
  bmod=(B)%(2**i)
  #print("amod,bmod",amod, bmod)
  left=(A//(2**i))*(2**i)+amod+1
  right=(B//(2**i))*(2**i)+bmod+1
  base=right-left+1
  #print("left, right", left, right)
  if aone:
    now+=2**i-amod
    base-=2**i-amod
  if bone:
    now+=bmod+1
    base-=bmod+1
  if amod!=bmod:
    now+=(base//(2**i))*2
  now+=((base//(2**i))//2)*2**i
  if now%2==1:
    ans+=2**i
  #print(now)
  
print(ans)

    
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " ";cout << "\n"
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M,K;
    cin >> N >> M >> K;
    cout << M / K - (N - 1) / K << endl;
}

Measured memory_bytes: 3608
//Greatest Common divisor
//Least Common Multiple
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT unsigned long long

//Euclidの互除法
LINT gcd(LINT x, LINT y){
  LINT sm, la, work;
  if(x<y) {
    la = y;
    sm = x;
  }
  else{
    la = x;
    sm = y;
  }

  while(1){
    work= la%sm;
    if(work==0)break;
    la=sm;
    sm=work;
  }
  return sm;
}

int main(){
  int n;
  cin >> n;
  LINT num[n];
  REP(i, n) cin >> num[i];
  LINT x = num[0]; //最小公倍数

  REP(i, n-1) {
    x = x / gcd(x, num[i+1]) * num[i+1];
  }

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


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  string S, T; cin >> S >> T;
  cout << T << S << endl;

  return 0;
}



Measured memory_bytes: 3612
num = int(input())
if num == 2:
    print(2)
    exit()
flag = False
while True:
    for i in range(2, int(num**0.5)+1):
        if num % i ==0:
            flag = False
            break
        else:
            flag = True
    if flag:
        print(num)
        exit()
    else:
        num+=1

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

set<char> ACGT{'A', 'C', 'G', 'T'};

int main() {
  string S; cin >> S;
  int N = S.length();

  int ans{};
  int right{};
  for (int left{}; left < N;) {

    while (right < N
      // rightを1進めるための満たすべき条件
      && ACGT.find(S[right]) != ACGT.end()
        ) {
      // 条件更新となる処理
      ++right;
    }

    // 条件を満たすright取得時の処理
    ans = max(ans, right - left);

    left = ++right;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

struct Edge{
	int dist,cost;
	Edge(){}
	Edge(int dist,int cost):dist(dist),cost(cost){}
};
	bool operator<(const Edge& e1, const Edge& e2){
		return e1.cost > e2.cost;
	}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;cin>>n;
	vector<vector<Edge> > edge(n,vector<Edge>());
	REP(i,n){
		REP(j,n){
			int c;
			cin>>c;
			if(c == -1)continue;
			edge[i].push_back(Edge(j,c));
		}
	}
	priority_queue<Edge,vector<Edge>,less<Edge> > que;
	que.push(Edge(0,0));//from 0
	int ct = 0;
	int ans = 0;
	vector<bool> primed(n,false);
	while(ct < n){
		Edge e = que.top();
		que.pop();
		if(primed[e.dist])continue;
		primed[e.dist] = true;
		ct++;
		ans += e.cost;
		for(auto e2 : edge[e.dist]){
			que.push(e2);
		}
	}
	cout << ans << endl;
  return 0;
}

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

int main() {
  int n,sum = 0;
  cin >> n;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
    sum += data[i];
  }
  sort(data.begin(),data.end());
  sum -= data[n-1];
  if(sum > data[n-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;

	vector<ll> a(n);
	for(int i=0; i<n; i++){
		cin >> a.at(i);
	}

	if(n%2==0){
		for(int i=n-1; i>=0; i-=2){
			cout << a.at(i) << " ";
		}
		for(int i=0; i<=n-1; i+=2){
			cout << a.at(i) << " ";
		}
	}else{
		for(int i=n-1; i>=0; i-=2){
			cout << a.at(i)<< " ";
		}
		for(int i=1; i<=n-2; i+=2){
			cout << a.at(i) << " ";
		}
	}
	cout << endl;
	return 0;
}


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

int main(){
  using ll = long long ;
  ll n,y ;
  cin >> n >> y ;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      if(i*10000+j*5000+(n-i-j)*1000==y){
        cout << i << " " << j << " " << n-i-j << endl ;
        return 0 ;
      }
    }
  }
  cout << "-1 -1 -1" << endl ;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (int x) {  return x && (!(x&(x-1)));  }
void solve()
{
    ll x,k;  cin>>k>>x;
    set<ll> se;
    rep(i,0,k) 
    {
        se.insert(x-i);
        se.insert(x+i);
    }
    for(auto i: se) cout<<i<<" ";
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}

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

bool f(string a, string b) {
	auto it = a.begin();
	for (char c : b) {
		if (it != a.end() && *it == c) {
			it++;
		}
	}
	return it == a.end();
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	string s;
	cin >> s;
	if (f("KIHBR", s) && f(s, "AKIHABARA")) {
		cout << "YES" << '\n';
	} else {
		cout << "NO" << '\n';
	}
}


Measured memory_bytes: 3656
import sys
input = sys.stdin.readline
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors)
cnt = 0
for i in range(1, N+1, 2):
    if make_divisors(i) == 8:
        cnt += 1
print(cnt)


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a[(1<<n)];
	pair<long long,long long> dp[(1<<n)];
	for (int i = 0; i < (1<<n); ++i)
	{
		cin>>a[i];
		dp[i]={a[i],-1000000000000000LL};
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < (1<<n); ++j)
		{
			if (j&(1<<i))
			{
				if (dp[j].first<dp[j^(1<<i)].first)
				{
					long long tmp=dp[j].first;
					dp[j].first=dp[j^(1<<i)].first;
					dp[j].second=max(dp[j^(1<<i)].second,tmp);
				}
				else
				{
					dp[j].second=max(dp[j].second,dp[j^(1<<i)].first);
				}
			}
		}
	}
	long long ans=dp[0].first+dp[0].second;
	for (int i = 1; i < (1<<n); ++i)
	{
		ans=max(ans,dp[i].first+dp[i].second);
		cout<<ans<<endl;
	}
	return 0;
}


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a*b < c*d) cout << c*d << endl;
    else cout << a*b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, a, b, c, d, e, ans, minn;
	cin >> n >> a >> b >> c >> d >> e;
	minn = min(a, b);
	minn = min(minn, min(c, min(d, e)));

	ans = 4 + (n + minn - 1) / minn;
	cout << ans << "\n";

	return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
ll n;
ll A[1<<18];
dpi dp[1<<18];
void put(dpi &dp, pi x) {
	if(dp.f == x || dp.s == x) return;
	dp.s=max(dp.s,x);
	if(dp.s>dp.f) swap(dp.f,dp.s);
}
int main()
{
	FAST
	cin>>n;
	FOR(i,0,(1<<n)-1) cin>>A[i];
	FOR(i,0,(1<<n)-1) put(dp[i], pi(A[i], i));
	FOR(i,0,(1<<n)-1) {
		FOR(j,0,n-1) if(i&(1<<j)) {
			put(dp[i], dp[i^(1<<j)].f);
			put(dp[i], dp[i^(1<<j)].s);
		}
	}
	ll ans=0;
	FOR(i,1,(1<<n)-1) {
		ans=max(ans, dp[i].f.f+dp[i].s.f);
		cout<<ans<<'\n';
	}
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    ll a, b;
    cin >> a >> b;
    int m = min(a, b);
    ll cmax = 0;
    for (int i = 1; i <= m; i++) {
        if (a % i == 0 and b % i == 0) {
            cmax = i;
        }
    }
    cout << a * b / cmax << endl;
    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<int64_t> p(N);
  
for (int i=0;i<N;i++) {
  cin>>p.at(i);
}
  vector<int64_t>z(N);
  z.at(0)=0;
  z.at(1)=abs(p.at(0)-p.at(1));
  for(int i=2;i<N;i++){
    z.at(i)=min(z.at(i-1)+abs(p.at(i)-p.at(i-1)),z.at(i-2)+abs(p.at(i)-p.at(i-2)));
  }
  cout<<z.at(N-1)<<endl;
}




Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
    int x=0;char ch=getchar();
    while(ch<'0' || '9'<ch)ch=getchar();
    while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
    return x;
}

const int M=1e5+9;

int m;
int a[M],b[M],top;

int main()
{
    int n=read(),m=read();
    int odd1=-1,odd2=-1;
    for(int i=1;i<=m;i++)
    {
        a[i]=read();
        if(a[i]&1)
        {
            if(odd1==-1)
                odd1=i;
            else if(odd2==-1)
                odd2=i;
            else
            {
                puts("Impossible");
                return 0;
            }
        }
    }

    if(m==1)
    {
        if(a[1]==1)
            printf("1\n1\n1\n");
        else
            printf("%d\n2\n%d 1\n",a[1],a[1]-1);
        return 0;
    }

    if(odd1!=-1) swap(a[1],a[odd1]);
    if(odd2!=-1) swap(a[m],a[odd2]);

    for(int i=1;i<=m;i++)
        printf("%d%c",a[i]," \n"[i==m]);

    if(a[1]==1)
    {
        printf("%d\n",m-1);
        for(int i=2;i<m;++i)
            printf("%d ",a[i]);
        printf("%d ",a[m]+1);
        puts("");
        return 0;
    }

    b[1]=a[1]-1;
    for(int i=2;i<m;i++) b[i]=a[i];
    b[m]=a[m]+1;
    
    printf("%d\n",m);
    for(int i=1;i<=m;i++)
        printf("%d%c",b[i]," \n"[i==m]);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
int main(void){
  int c,f,st_s,st_l,i_s[100],i_l[100],n,s,l;
  while(1){
    c=getchar();
    if(c=='.')
      break;
    st_s=st_l=n=s=l=0;
    f=1;
    memset(i_s,0,sizeof(i_s));
    memset(i_l,0,sizeof(i_l));
    while(1){
      if(c=='.')
	break;
      n++;
      if(c=='('){
	st_s++;
	i_s[++s]=n;
      }
      else if(c=='['){
	st_l++;
	i_l[++l]=n;
      }
      else if(c==')'){
	if(st_s&&i_s[s]>i_l[l]){
	  st_s--;
	  s--;
	}
	else
	  f=0;
      }
      else if(c==']'){
	if(st_l&&i_l[l]>i_s[s]){
	  st_l--;
	  l--;
	}
	else
	  f=0;
      }
      c=getchar();
    }
    if(f==1&&st_s==0&&st_l==0)
      puts("yes");
    else
      puts("no");
    getchar(); 
  }
  return 0;
}

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int count = 0;
    for (int i=0; i<n; i++) {
        if (s[i] == 'R') {
            count++;
        }
    }

    if (count > (n/2)) {
        cout << "Yes" << endl;
    }

    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256