akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
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++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, n)
            cout
        << s[i] << t[i];

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
while True:
    x = A[N-1]/2
    if x < 0.5:
        break
    for i in range(N-1, -1, -1):
        if A[i] < x:
            break
        A[i] /= 2
        M -= 1
        if M == 0:
            break
    A.sort()
    if M == 0:
        break

sum = 0
for a in A:
    sum += a//1
print(int(sum))

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
ll f(vector<int> arr){
    int n = arr.size();
    ll ans = 0;
    ll sum = 0;
    for(int i = 0; i < n; ++i){
        ans += (ll)i*arr[i] - sum;
        sum += arr[i];
    }
    return ans % MOD;
}
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(n),y(m);
    for(int i = 0; i < n; ++i)
        scanf("%d",&x[i]);
    for(int i = 0; i < m; ++i)
        scanf("%d",&y[i]);
    ll area = f(x)*f(y)%MOD;
    cout << area << '\n';
}


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

using namespace std;
typedef long long LL;
const double pi = acos(-1.0);
const double eps = 1e-7;
const LL N = 100010;

LL T,n,m,i,j,k,a[N],t,ans=0,a1=0,a2=0,a3=0;

int main()
{
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(!(a[i]%4))a3++;
        else if(!(a[i]&1))a2++;
        else a1++;
    }
    if(a3>=a1 || (a3==a1-1 && a2==0))printf("Yes");
    else printf("No");
    //system("pause");
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <unordered_map>
typedef long long ll;
#define re register

#define gc getchar
#define pc putchar
#define sp pc(' ')
#define ln pc('\n')

template <class t>
inline void read(t&num) {
    register char c = gc();
    register bool flag = 0;
    while (c != '-' && (c < '0' || c > '9')) c = gc();
    if (c == '-') flag = 1, c = gc();
    num = 0;
    while (c >= '0' && c <= '9') num = (num << 1) + (num << 3) + (c ^ 48), c = gc();
    flag && (num = ~(num - 1));
}

template <class t>
inline void print(t num) {
    if (num < 0) pc('-'), num = ~(num - 1);
    if (num >= 10) print(num / 10);
    pc(num % 10 ^ 48);
}

int main() {
    int n;
    read(n);
    print(n * n * n), ln;
}


Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    N,M=map(int, input().split()) # 頂点の数、辺の数
    H=list(map(int,input().split()))
    edge = [[] for i in range(N)]
    for i in range(M):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        edge[x].append(y)
        edge[y].append(x) # 有向なら#つける
    cnt=0
    for i in range(N):
        val=H[i]
        if edge[i]==[]:
            cnt+=1
        else:
            num=0
            for j in edge[i]:
                if val>H[j]:
                    num+=1
            if num==len(edge[i]):
                cnt+=1
    print(cnt)
resolve()

Measured memory_bytes: 29336
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  string s; cin >> s;
  vector<int> cnt;
  {
    int i = 0;
    int flag = 1;
    while(i < n) {
      int tmp = i;
      while(i < n && s[i] == '0'+flag) i++;
      cnt.push_back(i-tmp);
      flag = 1-flag;
    }
  }
  int ans = 0;
  if(cnt.size() <= k*2+1) cout << n << endk;
  else {
    int tmp = accumulate(cnt.begin(), cnt.begin()+k*2+1, 0);
    REP(i, k*2+1, cnt.size()) {
      chmax(ans, tmp);
      tmp -= cnt[i-2*k-1]+cnt[i-2*k];
      tmp += cnt[i]+(i+1<cnt.size() ? cnt[i+1] : 0);
      i++;
    }
    chmax(ans, tmp);
    cout << ans << endk;
  }
  return 0;
}


Measured memory_bytes: 4044
#!/usr/bin/python3

import heapq
import os
import sys


def main():
    V, E, R = read_ints()
    G = [dict() for _ in range(V)]
    for _ in range(E):
        s, t, d = read_ints()
        G[s][t] = d
    print(*solve(V, E, R, G), sep='\n')


def solve(V, E, R, G):
    dists = [-1] * V
    q = []
    heapq.heappush(q, (0, R))
    while q:
        d, i = heapq.heappop(q)
        if dists[i] != -1:
            continue
        dists[i] = d
        for j, e in G[i].items():
            if dists[j] == -1:
                heapq.heappush(q, (d + e, j))
    return ['INF' if d == -1 else d for d in dists]


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 88928
#[allow(usused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      s: chars,
    }
    let ans: Vec<char> = "AKIHABARA".chars().collect();
    let mut idx = 0;
    for a in ans {
        if idx >= s.len() || a != s[idx] {
            if a == 'A' {
                continue;
            } else {
                return println!("{}", "NO");
            }
        }
        idx += 1;
    }
    if idx == s.len() {
        println!("{}", "YES");
    } else {
        println!("{}", "NO");
    }
}


Measured memory_bytes: 4352
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    d = [na() for _ in range(n)]

    d.reverse()

    ans = 0
    for a, b in d:
        if (a + ans) % b > 0:
            ans += b - (a + ans) % b
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, sum = 1;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    if (sum >= K) {
      sum += K;
    }
    else {
      sum *= 2;
    }
  }
  cout << sum << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N+1];
  for (int i = 0; i <= N; i++) {
    cin >> A[i];
  }
  if (N == 0) {
    if (A[0] == 1) {
      cout << 1 << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (A[0] != 0) {
    cout << -1 << endl;
    return 0;
  }
  if (A[N] == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll R[N+1];
  R[N] = A[N];
  for (int i = N-1; i >= 0; i--) {
    R[i] = R[i+1] + A[i];
  }
  ll DP[N+1];
  DP[0] = 1;
  ll ans = 1;
  for (ll i = 1; i <= N; i++) {
    if (i == N) {
      if (((DP[i-1] - A[i-1]) * 2) < A[i]) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      if (((DP[i-1] - A[i-1]) * 2) - 1 < A[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
      DP[i] = min((DP[i-1] - A[i-1]) * 2,R[i]);
    ans += DP[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n + 1);
  rep(i, n) cin >> h[i + 1];

  vector<bool> good(n + 1, true);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (h[a] == h[b]) {
      good[a] = false;
      good[b] = false;
    } else if (h[a] > h[b]) {
      good[b] = false;
    } else {
      good[a] = false;
    }
  }

  int ans = -1;
  rep(i, n + 1) {
    if (good[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}

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

int main(void)
{
  bool ok[3][3]; rep(i, 3) rep(j, 3) ok[i][j] = false;
  bool flag;
  int a[3][3]; rep(i, 3) rep(j, 3) cin >> a[i][j];
  int n; cin >> n;

  rep(i, n)
  {
  	int x;
	cin >> x;
	rep (i, 3) rep (j, 3)
      if (x == a[i][j])
        ok[i][j] = true;
  }
  flag = true;
  rep(i, 3) if (!ok[i][i]) flag = false;
  if (flag)
  {
	  cout << "Yes" << endl;
	  return 0;
  }
  flag = true;
  rep(i, 3) if (!ok[i][2 - i]) flag = false;
  if (flag)
  {
	  cout << "Yes" << endl;
	  return 0;
  }
  rep(i, 3)
  {
  	flag = true;
	rep(j, 3) if (!ok[i][j]) flag = false;
  	if (flag)
  	{
	  cout << "Yes" << endl;
		 return 0;
  	}
  	flag = true;
  	rep(j, 3) if (!ok[j][i]) flag = false;
	if (flag)
	{
		cout << "Yes" << endl;
		return 0;
	}
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main() {
	int N, C, K;
	cin >> N >> C >> K;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	sort(T.begin(), T.end());
	int ans = 0;
	int i = 0;
	while (i < N) {
		int j = i;
		while (i - j < C && i < N && T[i] <= T[j] + K) {
			i++;
		}
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 764
#include<cstdio>
#include<cstring>

double map[200][200];
// turn, index

int next(int x, int y, int n) {
    if(x+y<n)
        return x+y;
    else
        return 2*n-(x+y);
}

int main(void) {
    while(true) {
        int N,T,L,B,l[200]={},b[200]={};
        for(int i=0; i<200; i++)
            for(int j=0; j<200; j++)
                map[i][j] = 0.0;

        scanf("%d%d%d%d",&N,&T,&L,&B);
        if(!N) break;

        for(int i=0; i<L; i++) {
            int lt;
            scanf("%d",&lt);
            l[lt] = 1;
        }
        for(int i=0; i<B; i++) {
            int bt;
            scanf("%d",&bt);
            b[bt] = 1;
        }
        map[0][0] = 1.0;
        for(int t=1; t<=T; t++) {
            for(int i=0; i<N; i++) {
                for(int k=1; k<=6; k++) {
                    int nt = next(i,k,N);
                    if(b[nt])
                        map[t][0] += map[t-1][i]/6.0;
                    else if(l[nt])
                        map[t+1][nt] += map[t-1][i]/6.0;
                    else
                        map[t][nt] += map[t-1][i]/6.0;
                }
            }
            map[t][N] += map[t-1][N];
        }
        printf("%lf\n", map[T][N]);
    }

    return 0;
}

Measured memory_bytes: 1376
N=int(input())

minarg_A=0
min_B=float("inf")
for _ in range(N):
  A,B=map(int,input().split())
  if B<min_B:
    min_B=B
    minarg_A=A
#print(minarg_A,min_B)

print(minarg_A+min_B)

Measured memory_bytes: 8992
a, b, c, d = map(int, input().split())
m = c // b
if c%b == 0:
    m += 0
else:
    m += 1
n = a // d
if a%d == 0:
    n += 0
else:
    n += 1
if m <= n:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9180
package main

import (
	"fmt"
)

func main() {
	var n int
	var s, t string
	fmt.Scan(&n, &s, &t)

	for i := 0; i < n; i++ {
		if s[i:] == t[:n-i] {
			fmt.Println(n + i)
			return
		}
	}
	fmt.Println(2 * n)
}


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

int main(){
int a,b,sum=0;
cin >> a >> b;
vector<int> v(999);
for(int i =1; i <= 999;i++){
sum += i;
v[i] = sum;
}

cout << v[b-a] - b <<endl;

return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 998244353L;
template<class T> inline void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }

void cinv(lls& llVec, ll n, bool to_0_origin = false) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		if (to_0_origin) val--;
		llVec.push_back(val);
	}
}


int main()
{
	ll N, K;
	cin >> N >> K;
	lls h;
	cinv(h, N);

	lls tbl(N, INF);
	tbl[0] = 0;

	for (ll i = 0; i < N - 1; i++) {

		for (ll k = 1; k <= K; k++) {
			if (i + k >= N) break;

			chmin(tbl[i + k], tbl[i] + std::abs(h[i] - h[i + k]));
		}
	}

	cout << tbl[N - 1] << '\n';

	return 0;
}


Measured memory_bytes: 1792
import numpy as np
#A = list(map(int,input().split()))
S = list(input())
K = int(input())

S1 = S + ['0']
S2 = S + S + ['0']

cur=S1[0]
cnt=0
Sl1 = list()
for s in S1:
    if cur==s:
        cnt+=1
    else:
        Sl1 += [cnt]
        cur = s
        cnt = 1

cur=S2[0]
cnt=0
Sl2 = list()
for s in S2:
    if cur==s:
        cnt+=1
    else:
        Sl2 += [cnt]
        cur = s
        cnt = 1

Sl1 = np.array(Sl1,dtype='int64')
Sl2 = np.array(Sl2,dtype='int64')

if 2*len(Sl1)==len(Sl2):
    N = int(K*np.sum(Sl1[::]//2))
else:
    if len(Sl1)>1 :
        N = int(Sl1[0]//2 + Sl1[-1]//2 + K*np.sum(Sl1[1:-1]//2) + (K-1)*((Sl1[0]+Sl1[-1])//2))
    else:
        N = int((K*Sl1[0])//2)


print(N)


Measured memory_bytes: 12508
#include <iostream>
#define MAX 2000
#define Q 200
#define N 20

using namespace std;

void solve(int *A, int n, int M[MAX][2], int max){
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= max; j++){
			if( A[i] == j ) M[j][1] = 1;
			if( j-A[i] >= 0 && M[j-A[i]][0] == 1 ) M[j][1] = 1;
		}
		for(int j = 0; j <= max; j++){
			M[j][0] = M[j][1];
		}
	}
}

main(){
	int n,q,max = 0;
	int A[N],que[Q],M[MAX][2];
	for(int i = 0; i < MAX; i++){ M[i][0] = 0; M[i][1] = 0; }
	cin >> n;
	for(int i = 0; i < n; i++) cin >> A[i];
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> que[i];
		if( max < que[i] ) max = que[i];
	}
	solve(A,n,M,max);
	for(int i = 0; i < q; i++){
		if( M[que[i]][1] == 1 ) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
}


Measured memory_bytes: 3132
#include <cstdio>
#include <algorithm>
using namespace std;


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

const int N  = 100;
int a[N];

int main() {
    int sum = 0;
    int n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1, x; i <= n; i++) {x = read(), a[i] -= x; if (a[i] > 0) sum += a[i]; }
    printf("%d\n", sum);
    return 0;  
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int a, b;
  int result;
  string s;
  cin >> a >> b;
  result = (a * b) % 2;
  if (result == 1){
    s = "Odd";
  } else{
    s = "Even";
  }
  cout << s << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#define MAX 2000001
int n;
int a[MAX];
int parent(int i) { return i/2;}
int left(int i) { return 2*i;}
int right(int i) { return 2*i+1;}

void maxHeapify(int i) 
{
  int l,r,largest,tmp;
  l = left(i); 
  r = right(i);
  if(l<=n && a[l]>a[i])   largest = l;
  else largest = i;
  if(r<=n && a[r]>a[largest]) largest = r;
  
  if(largest != i){
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxHeapify(largest);
  }
}

int extractMax() 
{
  int max = a[1];
  a[1] = a[n];
  n--;
  maxHeapify(1);
  return max;
}


void increaseKey(int key) 
{
  int i=n;
  int tmp;
  a[i] = key;
  while(i>1 && a[parent(i)] < a[i]) {
    tmp = a[i];
    a[i] = a[parent(i)];
    a[parent(i)] = tmp;
    i = parent(i);
  }
}
  
void insert(int key) 
{
  n += 1;
  a[n] = 0;
  increaseKey(key);
}

int main() 
{
  int i,key;
  char c[10];

  while(1) {
    scanf("%s",c);
    if(!strcmp(c,"insert")) {
      scanf("%d",&key);
      insert(key);
    }
    else if(!strcmp(c,"extract")) printf("%d\n",extractMax());
    else if(!strcmp(c,"end")) break;
  }
  return 0;
}

Measured memory_bytes: 4696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s[500];
    int k,l;
    cin>>k>>l;
    getchar();
    for(int i = 1; i <= k; i++)
    {
        cin>>s[i];

    }
    for(int i = 0; i <= k+1; i++)
    {
        if(i==0 || i==k+1)
        {
            for(int j = 0; j <= l+1;j++)
            {
                cout<<"#";
            }
        }
        else
        {
            cout<<"#"<<s[i]<<"#";
        }
        cout<<endl;
    }

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = long.Parse(ReadLine());
        var d = SortedYakusuu(N);
        if (d.Length == 2)
        {
            WriteLine(N-1);
            return;
        }
        if (d.Length % 2 == 1)
        {
            WriteLine((d[d.Length / 2] - 1) * 2);
        }
        else
        {

            WriteLine(d[d.Length / 2] + d[d.Length / 2 - 1] - 2);
        }

    }


    public static long[] SortedYakusuu(long n)//O(sqrt(N) + d(N)) 
    {
        if (n < 1) return new long[0];//Assert
        var r = new List<long>();
        for (long i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                r.Add(i);
                if (i * i != n) r.Add(n / i);
            }
        }
        var k = r.ToArray();
        Array.Sort(k);//自前ソートd(N)のほうが速いか･･･？
        return k;
    }
}



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

int main(void) {
  int x, y, z;
  cin >> x >> y >> z;

  int n = x / (y + z);
  if (x % (y + z) >= z) {
    cout << n << endl;
  } else {
    cout << n - 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
BC_list = [list(map(int, input().split())) for i in range(Q)]

count_dict = dict(Counter(A_list))
_sum = 0
for i, a in count_dict.items():
    _sum += i * a

for b, c in BC_list:
    if b in count_dict:
        count_b = count_dict[b]
        if c in count_dict:
            count_dict[c] += count_dict[b]
        else:
            count_dict[c] = count_dict[b]
        count_dict.pop(b)
        _sum -= b * count_b
        _sum += c * count_b
    print(_sum)

Measured memory_bytes: 113876
#include<stdio.h>
#include<string.h>
int main()
{
  char n[100],m[100];
  scanf("%s",n);
  int l;
  l=strlen(n);
  int i;
  int flag=0;
  for(i=0;i<l;i++){
    if(n[i]!=n[l-i-1]){
      flag=1;
      break;
    }
  }
  for(i=0;i<l/2;i++){
    if(n[i]!=n[l/2-i-1]){
      flag=1;
      break;
    }
  }
  for(i=l/2+1;i<l;i++){
    if(n[i]!=n[l-i-1]){
      flag=1;
      break;
    }
  }
  if(flag==0){
  	printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    u32 N;
    cin >> N;
    Vec<i32> X(N);
    for (u32 i = 0; i < N; i++) cin >> X[i];
    i32 min_X = *min_element(ALL(X));
    i32 max_X = *max_element(ALL(X));
    i64 min_sum = INF;
    for (u32 i = min_X; i <= max_X; i++) {
        i64 sum = 0;
        for (u32 j = 0; j < N; j++) sum += (X[j] - i) * (X[j] - i);
        if (min_sum > sum) min_sum = sum;
    }
    cout << min_sum << endl;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self,size):
        self.parent=range(size)
        self.tree_num=size
        self.tree_w=[1]*size
        self.rank=[0]*size

    def findset(self,x):
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.findset(self.parent[x])
            return self.parent[x]

    def unite(self,x,y):
        x=self.findset(x)
        y=self.findset(y)
        if x==y:
            return
        if self.rank[x]<self.rank[y]:
            self.parent[x]=y
            self.tree_num-=1
            self.tree_w[y]+=self.tree_w[x]
        else:
            self.parent[y]=x
            self.tree_num-=1
            self.tree_w[x]+=self.tree_w[y]
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def same(self,x,y):
        if self.findset(x)==self.findset(y):
            return True
        else:
            return False

    def tree_number(self):
        return self.tree_num

    def tree_weight(self,x):
        return self.tree_w[self.findset(x)]
n=int(raw_input())
xy=[]
yx=[]
for i in xrange(n):
    x, y = map(int,raw_input().split())
    xy.append([x,y,i])
    yx.append([y,x,i])
xy.sort()
yx.sort()
dist=[]
for i in xrange(n-1):
    a,b,idx1=xy[i]
    c,d,idx2=xy[i+1]
    dist.append([min(abs(a-c),abs(b-d)),idx1,idx2])
for i in xrange(n-1):
    a,b,idx1=yx[i]
    c,d,idx2=yx[i+1]
    dist.append([min(abs(a-c),abs(b-d)),idx1,idx2])
dist.sort()
uf=UnionFind(n)
ans=0
for i in xrange(2*(n-1)):
    d,idx1,idx2=dist[i]
    if uf.same(idx1,idx2):continue
    uf.unite(idx1,idx2)
    ans+=d
print ans


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

int main(){
  char c,cc;
  while(scanf("%c",&c)!=-1){
    if(c=='@'){
      cin>>c>>cc;
      for(int i=0;i<c-'0';i++){
	cout<<cc;
      }
	
    }else cout<<c;
  }
  return 0;
}

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

int main()
{
    long long a,b,k;
    cin >> a >> b >> k;
    long long a1,a2;

    a1 = max(a - k,0LL);
    a2 = max(b-max(k-a,0LL),0LL);
    cout << a1 << " " << a2 << endl;
}

Measured memory_bytes: 256
n = int(input())
t = [0,0,0,0]#AC,WA,TLE,RE
for i in range(n):
    s = input()
    if(s == 'AC'):
        t[0] += 1
    elif(s == 'WA'):
        t[1] += 1
    elif(s == 'TLE'):
        t[2] += 1
    else:
        t[3] += 1
print('AC x '+ str(t[0]))
print('WA x '+ str(t[1]))
print('TLE x '+ str(t[2]))
print('RE x '+ str(t[3]))

Measured memory_bytes: 69976
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define sec second
int angle=0;
int edge[6][6][4]={0};
vector<int> ans;
P now;
P nextpoint(P t,int angl)
{
	P f;
	f.fi=t.fi;
	f.sec=t.sec;
	if(angl==0)
	{
		f.sec++;
	}
	if(angl==1)
	{
		f.fi++;
	}
	if(angl==2)
	{
		f.sec--;
	}
	if(angl==3)
	{
		f.fi--;
	}
	return f;
}
void output(int n)
{
	if(n==0)
	{
		cout << 'R';
	}
	else if(n==1)
	{
		cout << 'D';
	}
	else if(n==2)
	{
		cout << 'L';
	}
	else
	{
		cout << 'U';
	}
	return ;
}
void step()
{
	int tmp;
	int ans;
	tmp=(angle+4-1)%4;
	while(1)
	{
		if(edge[now.fi][now.sec][tmp])break;
		tmp=(tmp+1)%4;
	}
	angle=tmp;
	P r;
	r.fi=nextpoint(now,angle).fi;
	r.sec=nextpoint(now,angle).sec;
	now.fi=r.fi;
	now.sec=r.sec;
	return ;
}
int main()
{
	now.fi=1;now.sec=1;
	for(int i=1;i<=9;i++)
	{
		if(i%2==1)
		{
			string s;
			cin >> s;
			for(int j=0;j<4;j++)
			{
				edge[(i+1)/2][j+1][0]=s[j]-'0';
				edge[(i+1)/2][j+2][2]=s[j]-'0';
			}
		}
		else
		{
			string s;
			cin >> s;
			for(int j=0;j<5;j++)
			{
				edge[i/2][j+1][1]=s[j]-'0';
				edge[i/2+1][j+1][3]=s[j]-'0';
			}
		}
	}
	while(1)
	{
		step();
		ans.pb(angle);
		if(now.fi==1&&now.sec==1)
		{
			break;
		}
	}
	for(int i=0;i<ans.size();i++)
	{
		output(ans[i]);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1204
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      String str = sc.nextLine();
      String list = "aiueo";
      if(list.indexOf(str)>=0){
        System.out.println("vowel");
      }else{
        System.out.println("consonant");
      }  
	}
}


Measured memory_bytes: 21972
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int t[n + 1], x[n + 1], y[n + 1];
    t[0] = x[0] = y[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }

    for (int i = 1; i <= n; i++)
    {
        int sum = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        int tm = t[i] - t[i - 1];
        if (!(tm - sum >= 0 && (tm - sum) % 2 == 0))
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>

#ifdef GONGKUNPENG
#include <cassert>
#endif

#define GG 1
#define GIO 1
#define uint unsigned
#define max(a, b) std::max((a), (b))
#define min(a, b) std::min((a), (b))
#define sort(...) std::sort(__VA_ARGS__)
#define ms(a, v) memset(a, v, sizeof(a))
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)

#if __cplusplus >= 201103L
using ll = long long;
using ull = unsigned long long;
#else
typedef long long ll;
typedef unsigned long long ull;
#endif

#if GIO
class GLIB
{
#define BUFSIZE 1 << 20
#define uns(x) (x == ' ' || x == '\t' || x == '\n' || x == '\r')
	char ruf[BUFSIZE], wuf[BUFSIZE], *p, *q, *r, rcha;
	bool rneg;

public:
#if GG
#else
	GLIB() : p(ruf), q(ruf), r(wuf), rcha(' ')
	{
	}

	~GLIB()
	{
		fwrite(wuf, 1, r - wuf, stdout);
	}
#endif
	inline void flush()
	{
		fwrite(wuf, 1, r - wuf, stdout), r = wuf;
	}

	inline int readc()
	{
#if GG
		return getchar();
#else
		return (p == q && (q = (p = ruf) + fread(ruf, 1, BUFSIZE, stdin), p == q) ? -1 : *p++);
#endif
	}

	template <typename T, typename... Args>
	void read(T &x, Args &... args)
	{
		read(x), read(args...);
	}

	inline void read() {}

	inline void read(char *s)
	{
		while (uns(rcha))
			rcha = readc();
		while (!uns(rcha) && rcha > 0)
			*s++ = rcha, rcha = readc();
		*s = '\0';
	}

	inline void readl(char *s)
	{
		while (uns(rcha))
			rcha = readc();
		while (rcha != '\n' && rcha > 0)
			*s++ = rcha, rcha = readc();
		*s = '\0';
	}

	template <typename T>
	inline void read(T &x)
	{
#ifdef GONGKUNPENG
		static_assert(std::is_integral<T>::value);
#endif
		x = rcha = rneg = 0;
		while (!isdigit(rcha) && rcha != '-')
			rcha = readc();
		rcha == '-' && (rneg = true, rcha = readc());
		while (isdigit(rcha))
			x = (x << 3) + (x << 1) - 48 + rcha,
			rcha = readc();
		rneg && (x = -x);
	}

	inline void writec(const char &c)
	{
#if GG
		putchar(c);
#else
		(r - ruf == BUFSIZE) && (fwrite(wuf, 1, BUFSIZE, stdout), r = wuf);
		*r++ = c;
#endif
	}

	template <typename T, typename... Args>
	void write(const T &x, const Args &... args)
	{
		write(x), write(args...);
	}

	inline void write() {}

	template <typename T>
	void write(T x)
	{
#ifdef GONGKUNPENG
		static_assert(std::is_integral<T>::value);
#endif
		if (x < 0)
		{
			writec('-');
			write(-ll(x));
			return;
		}
		if (x > 9)
			write(x / 10);
		writec(x % 10 ^ 48);
	}

	inline void write(const char *s)
	{
		while (*s)
			writec(*s++);
	}
#undef BUFSIZE
} io;
#endif

const ll INF = 0x3f3f3f3f;
const uint MAXN =
#ifdef GONGKUNPENG
	15
#else
	1000005
#endif
	;

int main()
{
	int n, b, r = 1, t = 1;
	io.read(n, b);
	while (t * b <= n)
	{
		t *= b;
		++r;
	}

	io.write(r, "\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


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

	int h, w, n;
	cin >> h >> w >> n;
	vector<P> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	sort(all(p));
	int b = -1;
	rep(i, n) {
		if (p[i].first - p[i].second > b + 1) {
			cout << p[i].first - 1 << endl;
			return 0;
		}
		else chmax(b, p[i].first - p[i].second);
	}
	cout << h << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=2010,Mo=1000000007;
int v[N],f[N];
inline int Pow(int x,int y) {
    int ret=1;
    while(y) {
	if(y&1) ret=1LL*ret*x%Mo;
	x=1LL*x*x%Mo,y>>=1;
    }
    return ret;
}
int main() {
    int n,k,tp=0,ans=0;
    cin>>n>>k;
    for(int i=1;i*i<=n;i++)
	if(n%i==0) {
	    v[++tp]=i;
	    if(i*i!=n) v[++tp]=n/i;
	}
    sort(v+1,v+1+tp);
    for(int i=1;i<=tp;i++) {
	int x=v[i];
	f[i]=Pow(k,(x+1)/2);
	for(int j=1;j<i;j++)
	    if(v[i]%v[j]==0) f[i]=(f[i]-f[j])%Mo;
	if(x&1) ans=(ans+1LL*x*f[i])%Mo;
	else ans=(ans+1LL*x*Pow(2,Mo-2)%Mo*f[i])%Mo;
    }
    cout<<(ans+Mo)%Mo;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int t,n,s,f,i,a;
	while(1){
		scanf("%d",&t);
		if(t==0){
			break;
		}
		scanf("%d",&n);
		a=0;
		for(i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			a+=f-s;
		}
		if(a>=t){
			printf("OK\n");
		}
		else{
			printf("%d\n",t-a);
		}
	}
	return 0;
}



Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

typedef unsigned long long ull;

ull mod_pow(ull x,ull n){
  ull res=1;
  while(n){
    if(n%2) res=res*x;
    x=x*x;
    n/=2;
  }
  return res;
}



signed main(){
  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;

  vector<int> ans;
  
  ull B = 1777771;
  ull hash1=0,hash2=0;

  for(int i=0;i<n;i++){
    hash1 += mod_pow(B,A[i]);
    hash2 += mod_pow(B,A[n-i-1]);
    if(hash1 == hash2) ans.push_back(i+1);
  }

  cout<<ans<<endl;  

  return 0;
}



Measured memory_bytes: 4472
# -*- coding: utf-8 -*-
import sys

def io_generator():
	while True:
		yield raw_input()

#+++++++++++++++++++

def next(pre):
	return pre/2 if pre %2==0 else 3*pre + 1

def main(io):
	s=int(io.next())
	i=1
	opened=[]
	while True:
		opened.append(s)
		s=next(s)
		i+=1
		if s in opened:
			return i
	return -1

#++++++++++++++++++++

if __name__ == "__main__":
	io=io_generator()
	print main(io)


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

#define N 501

int asc(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main(void)
{
	int n, k, a[N], s[N];

	scanf("%d %d", &n, &k);

	int i, j, sum = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}

	for (i = sum; i > 0; i--)
	{
		if (sum % i == 0)
		{
			for (j = 0; j < n; j++)
				s[j] = a[j] % i;
			qsort(s, n, sizeof(int), asc);
			for (j = 1; j < n; j++)
				s[j] += s[j - 1];
			for (j = 0; j < n; j++)
				if ((n - j - 1) * i == s[n - 1])
					break;
			if (s[j] <= k)
				break;
		}
	}
exit:
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 252
import sys
sys.setrecursionlimit(1000000000)
n,m=map(int,input().split())
es=[[[] for j in range(n)] for i in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    for j in range(m):
        if i!=j:
            es[j][a].append(b)
            es[j][b].append(a)
sw = [[True for i in range(n)] for i in range(m)]# 頂点0とのパスが存在すればFalse, 存在しないならTrue と定義する
def dfs(v,k):
    sw[k][v] = False
    for i in es[k][v]:
        if sw[k][i]:
            dfs(i,k)
for i in range(m):
    dfs(0,i)
ans=0
for j in range(m):
    for i in range(n):
        if sw[j][i]:
            ans+=1
            break
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include <queue>

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef queue<int> QI;

const LL mod=1000000007;
LL powmod(LL a,LL b) {LL res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

LL a[2010],g[2010];
LL f[2333][2333];
int main(){
    LL ans=0,n,x;cin>>n>>x;rep(i,0,n){cin>>a[i];g[i]=a[i];ans+=a[i];}
    /*rep(i,0,n){
        rep(j,0,i){
            if(a[j]+x*(i-j) <g[i]){g[i]=a[j];f[i]=(i-j);}
        }
        rep(j,i+1,n){
            if(a[j]+x*(i+n-j)<g[i]){g[i]=a[j];f[i]=i+n-j;}
        }
    }*/
    rep(i,0,n){
        f[i][0]=a[i];
        rep(j,1,n){
            int now=i-j;if(now<0)now+=n;
            f[i][j]=min(f[i][j-1],a[now]);
        }
    }

    rep(i,0,n){
        LL now=x*i;
        rep(j,0,n){
            now+=f[j][i];
        }
        ans=min(ans,now);
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 36736
#include<stdio.h>
int main(void){
   int A, B, C, D, E, F, S;
   scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);
   S = A + B + C;
   if ( S < B + C + D ) S = B + C + D;
   if ( S < C + D + A ) S = C + D + A;
   if ( S < D + A + B ) S = D + A + B;
   if ( E > F ) printf("%d\n", S + E);
   else printf("%d\n", S + F);
   return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector<int> v;
for(int i=0,j=2;i<n;i++,j+=2)v.push_back(j);

for(int i=0,j=1;i<m;i++,j+=2)v.push_back(j);
int cnt=0;
int l = v.size();
for(int i=0;i<l-1;i++){
   for(int j=i+1;j<l;j++){

        if( (v[i]+v[j]) % 2 == 0)cnt++;

	}



}

cout<<cnt<<endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if(k <= a){
        cout << k << endl;
        return 0;
    }

    k -= a;

    if(k <= b){
        cout << a << endl;
        return 0;
    }

    k -= b;

    cout << a - k << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{   long long N,A,B,C,D;
       cin>>N>>A>>B>>C>>D;
       long long l=0;
       long long r=0;
       for(int i=0;i<=N-1;i++)
       {
           l=-1*D*i+C*(N-1-i);
           r=-1*C*i+D*(N-1-i);
           if(B-A<=r&&B-A>=l)
            {cout<<"YES";
              return 0;}
       }
       cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
import math
dimension = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(3):
    d_xy = 0
    b = 0
    for j in range(dimension):
        a = math.fabs(x[j]-y[j]) ** (i+1)
        b += a
    d_xy = b ** (1/(i+1))
    print(d_xy)
distance = []
for k in range(dimension):
    distance.append(math.fabs(x[k]-y[k]))
print(max(distance))


Measured memory_bytes: 5720
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = np.array(list(map(int, input().split())), dtype='i8')
    ans = np.zeros(N, dtype='i8')
    A = A * 2
    s = np.sum(A) // 2

    na1 = 0
    for i in range(1, N, 2):
        na1 += A[i]

    ans[0] = s - na1
    for i in range(N - 1):
        ans[i + 1] = A[i] - ans[i]

    print(' '.join(map(str, ans.tolist())))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 24676
from fractions import gcd

N=int(input())
a=list(map(int,input().split()))

lcm=a[0]
for i in range(N):
    g=gcd(lcm,a[i])
    lcm=(lcm*a[i])//g
    
lcm-=1

ans=0
for i in range(N):
    aa=lcm%a[i]
    ans+=aa
    
print(ans)




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

int main() {
  int n, K;
  cin >> n >> K;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];

  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for (int i = 2; i < n; i++) {
    int mn = INT_MAX;
    for (int k = 1; k <= K; k++) {
      if (i - k < 0) break;
      int ret = dp[i - k] + abs(h[i - k] - h[i]);
      mn      = min(mn, ret);
    }
    if (mn == INT_MAX) continue;
    dp[i] = mn;
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
use std::cmp;
use std::collections::VecDeque;

fn main(){
  loop {
    let n: usize = read();

    if n == 0 { break; }

    let mut wll: Vec<Vec<usize>> = Vec::new();

    wll.push(read_vec());
    wll.push(read_vec());
    
    let mut jmp: Vec<Vec<usize>> = vec![vec![10000;n];2];
    jmp[0][0] = 0;
    jmp[1][0] = 0;

    let mut que: VecDeque<(usize, usize)> = VecDeque::new();

    que.push_back((0, 0));
    que.push_back((1, 0));

    loop {
      match que.pop_front() {
        Some((p, i)) => {
          if i < n - 1 && wll[p][i] == 1 && wll[p][i+1] == 1 {
            if jmp[p][i] < jmp[p][i+1] {
              jmp[p][i+1] = jmp[p][i];
              que.push_back((p, i+1));
            }
          } else if wll[p][i] == 2 {
            if jmp[p][i] < jmp[p][i-1] {
              jmp[p][i-1] = jmp[p][i];
              que.push_back((p, i-1));
            }
          } else {
            if jmp[p][i] + 1 < jmp[1-p][i] {
              jmp[1-p][i] = jmp[p][i] + 1;
              que.push_back((1-p, i));
            }
            if i+1 < n && jmp[p][i] + 1 < jmp[1-p][i+1] {
              jmp[1-p][i+1] = jmp[p][i] + 1;
              que.push_back((1-p, i+1));
            }
            if i+2 < n && jmp[p][i] + 1 < jmp[1-p][i+2] {
              jmp[1-p][i+2] = jmp[p][i] + 1;
              que.push_back((1-p, i+2));
            }
          }
        },
        None => {
          if wll[0][n-1] == 2 && wll[1][n-1] == 2 ||
             wll[0][n-1] == 2 && jmp[1][n-1] == 10000 ||
             jmp[0][n-1] == 10000 && wll[1][n-1] == 2 ||
             jmp[0][n-1] == 10000 && jmp[1][n-1] == 10000 {
               println!("NA");
             } else {
               println!("{}", cmp::min(jmp[0][n-1], jmp[1][n-1]));
             }
          break;
        },
      }
    }
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



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

typedef long long ll;
#define MAX 200005

int main(int, char**)
{
    int n;
    cin >> n;
    
    vector<string> a;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        a.push_back(s);
    }
    sort(a.begin(), a.end());

    s = "";
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != s) count++;
        s = a[i];
    }
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 11664
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for(int i = 1; i < n; i++){
		if(s[i] != s[i-1]) ans++;
	}
	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define INF -1
using namespace std;

int main()
{
	int n, x, l;
	vector<pair<int, int>> s;
	pair<int, int> tmp;
	int area = 0, ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x >> l;
		tmp = make_pair(x + l, l);
		s.emplace_back(tmp);
	}

	sort(s.begin(), s.end());

	for (int i = 0; i < n; i++) {
		if (i==0 || area <= s[i].first - 2 * s[i].second) {
			ans++;
			area = s[i].first;
		}
	}

	printf("%d", ans);

	return 0;
}

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

int qsort_compare_int(const void *a, const void *b)
{
    return *(int *) a - *(int *) b;
}

int main(int argc, char *argv[])
{
    int n; // input
    int a[100000], b[100000];
    int c[100000];
    int i; // loop counter
    int p_plus;
    long long sum_minus, sum_plus;
    int ans;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &b[i]);
    }

    for (i = 0; i < n; i++) {
        c[i] = a[i] - b[i];
    }

    qsort(c, n, sizeof(int), qsort_compare_int);

    sum_minus = 0;
    sum_plus = 0;

    for (i = 0; i < n; i++) {
        if (c[i] < 0) {
            sum_minus += -c[i];
        } else {
            break;
        }
    }
    p_plus = i;

    i = n;
    while(sum_plus < sum_minus) {
        if (i > p_plus) {
            i--;
            sum_plus += c[i];
        } else {
            break;
        }
    }

    if (sum_plus >= sum_minus) {
        ans = n - i + p_plus;
    } else {
        ans = -1;
    }

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

    return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf = 1e7;
const int maxN = 2e5 + 4;

void solve() {    
    int n ; 
    cin >> n ; 
    vector<pair<int,int>> a(n) ; 
    for(int i=0;i<n;i++){
        cin >> a[i].first >> a[i].second ; 
    }
    int ans = 0 ;
    for(int tt= 0 ; tt < 2 ;tt++ ){
        if(tt) {
            for(int i=0;i<n;i++) {
                a[i].second *= -1 ;
            }
        }
        set<pair<int,int>> st; 
        sort(a.begin() , a.end()) ; 
        for(int i=0;i<n;i++){
            int sum = a[i].first + a[i].second ; 
            st.insert({sum , i}) ; 
        }
        for(int i=0;i<n-1;i++){
            st.erase(st.lower_bound(make_pair(a[i].first + a[i].second , -1 ))) ;
            auto itr = st.rbegin() ;
            int best = (*itr).first ; 
            ans = max(ans , best - a[i].first - a[i].second ) ; 
        }
        
    }
    cout << ans <<endl; 
}

int main() {
    //  freopen("in.txt", "r", stdin);
    //  freopen("out.txt", "w", stdout);
    int q = 1;
    //  cin >> q;
    while (q--) {
        solve();
    }
}

Measured memory_bytes: 14348