akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

set<vector<int> > sv;
// vv[k] := 3個以上の合計が10になる饅頭の組合せ
vector<vector<int> > vv;
// v_sum[k] := vv[k]の合計
int v_sum[40] = {0};
// memo[k] := k 番目の組合せで饅頭が作れない
bool memo[40];

// v := 饅頭の集合, sum := v[0] + v[1] + ... + v[v.size()-1] (合計)
void f(vector<int> v, int sum = 0){
	if( sum == 10 ){
		if( 3 <= v.size() ){ 
			sort(v.begin(), v.end());
			sv.insert(v);
		}
	}else if( sum < 10 ){
		for(int i = 9; i >= 1 ; i-- ){
			v.push_back(i);
			f(v, sum + i);
			v.pop_back();
		}
	}
}

// 3個以上で10になる饅頭の組合せを事前に列挙しておく
void init(){
	vector<int> v;
	f(v);
	for(set<vector<int> >::iterator it = sv.begin() ; it != sv.end() ; ++it ){
		vv.push_back(*it);
	}
	for(int i = 0 ; i < vv.size() ; i++ ){
		int sum = 0;
		for(int j = 0 ; j < vv[i].size() ; j++ ){
			sum += vv[i][j];
		}
		v_sum[i] = sum;
	}
}

// v[k](k番目の合計が10になる組合せ)が使えるかどうかを返す
bool check(int k, vector<int> s){
	for(int i = 0 ; i < vv[k].size() ; i++ ){
		int e = vv[k][i];
		if( s[e] == 0 ){
			return false;
		}else{
			s[e]--;
		}
	}
	return true;
}

// v[k](k番目の合計が10になる組合せ)を使う
void used(int k, vector<int> &s){
	for(int i = 0 ; i < vv[k].size() ; i++ ){
		int e = vv[k][i];
		if( s[e] ) s[e]--;
	}
}

int foo;

set<vector<int> > mm;

// DFS
void dfs(int &res, int cnt, int sum, vector<int> &s){
	// 解の更新
	res = max(res, cnt);
	
	if( mm.count(s) ) return;
	
	if( foo < 100000 ){
		mm.insert(s);
	}
	
	foo++;
	if( 4000000 < foo ) return;
	
	if( sum < 10 ) return;
	// もう解が更新できない時点で探索打ち切る
	if( cnt + sum / 10 <= res ) return;
	
	for(int i = 0 ; i < vv.size() ; i++ ){
		if( memo[i] ) continue;
		
		if( check(i, s) ){
			vector<int> s_ = s;
			used(i, s_);
			dfs(res, cnt + 1, sum - v_sum[i], s_);
		}
	}
}

int solve(vector<int> &s){
	foo = 0;
	int sum = 0, res = 0;
	for(int i = 0 ; i < vv.size() ; i++ ){
		if( !check(i, s) ){
			memo[i] = true;
		}
	}
	
	mm.clear();
	for(int i = 1 ; i <= 9 ; i++ ) sum += i * s[i];
	dfs(res, 0, sum, s);
	return res;
}

int main(){
	// 3個以上で10になる饅頭の組合せを事前に列挙しておく
	init();
	
	int n;
	while( cin >> n, n ){
		
		// s[k] := 重さkの饅頭の個数
		vector<int> s(12, 0);
		fill(memo, memo + 40, false);
		
		for(int i=0 ; i < n ; i++ ){
			int e;
			cin >> e;
			s[e]++;
		}
		
		int ans = 0;
		// 2個で10になる組合せは貪欲に使う
		for(int i = 1 ; i <= 4 ; i++ ){
			int j = 10 - i;
			int k = min(s[i], s[j]);
			s[i] -= k;
			s[j] -= k;
			ans += k;
		}
		ans += s[5]/2;
		s[5] %= 2;
		// 3個以上で10になる組合せを探索する
		ans += solve(s);
		// 出力
		cout << ans << endl;
	}	
}

Measured memory_bytes: 1456
#include<stdio.h>
#include<math.h>
int main() {
	double x1, x2, y1, y2;
	double ans;

	scanf("%lf %lf %lf %lf", &x1, &x2, &y1, &y2);

	ans = (double)sqrt(pow(x1 - y1, 2.0) + pow(x2 - y2, 2.0));

	printf("%.15f", ans);

	return 0;
}

Measured memory_bytes: 656
#include <cstdio>
#include <iostream>
using namespace std;
int x, y;
int main()
{
	cin >> x >> y;
	while(x*y!=0)
	{
		if(x>y)
		{
			x=x%y;
		}
		else
		{
			y=y%x;
		}
	}
	cout << max(x, y) << endl;
	return 0;
}

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

int32_t main() {
    
   int n;
   cin >> n;
   int a[n];
   for(int i=0;i<n;i++)
   cin >>a[i];
   sort(a,a+n,greater<int>());
   
   int x=0,z=0;
   
   for(int i=0;i<n;i++) {
       if(i%2==0)
       x+=a[i];
       else
       z+=a[i];
   }
   
   cout << abs(x-z);
    
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  r, c, n = map(int, input().split())
  L = []
  def trans(x, y):
    z = None
    if x == 0:
      z = y
    if y == c:
      z = c + x
    if x == r:
      z = c + r + c - y
    if y == 0:
      z = 2*r + 2*c - x
    return z

  for _ in range(n):
    x1, y1, x2, y2 = map(int, input().split())
    z1 = trans(x1, y1)
    z2 = trans(x2, y2)
    if z1 is not None and z2 is not None:
      L.append((z1, z2))
      L.append((z2, z1))
  L.sort()
  cnt = 0
  D = dict()
  for z1, z2 in L:
    if z1 < z2:
      cnt += 1
      D[z1] = cnt
    else:
      if D[z2] != cnt:
        print("NO")
        exit()
      cnt -= 1
  print("YES")
if __name__ == "__main__":
  main()

Measured memory_bytes: 78428
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    //sort(all(a));
    dprint(a);
    ll ans=0;
    REP(i,n){
        if(i && a[i] && a[i-1]){
            ++ans;
            a[i]--;
        }
        ans+=a[i]/2;
        a[i]%=2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct edge_t {
	int fm;
	int to;
	int ct;
};
typedef struct edge_t Edge;

int main(void) {
	int n, i, k, fm, to, ct, upd, nedge = 0;
	int dis[10000];
	Edge *edges, *p;

	edges = malloc(sizeof(Edge)*500000);

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d", &fm, &k);

		while (k--) {
			scanf("%d %d", &to, &ct);

			p = &edges[nedge++];
			p->fm = fm;
			p->to = to;
			p->ct = ct;
		}
		dis[i] = INT_MAX;
	}
	dis[0] = 0;

	upd = 1;
	while (upd) {
		upd = 0;
		for (i = 0; i < nedge; i++) {
			fm = edges[i].fm;
			to = edges[i].to;
			ct = edges[i].ct;
			if (dis[fm] < INT_MAX && dis[to] > ct + dis[fm]) {
				dis[to] = ct + dis[fm];
				upd = 1;
			}
		}
	}
	for (i = 0; i < n; i++) {
		printf("%d %d\n", i, dis[i]);
	}

	
	return 0;
}



Measured memory_bytes: 7512
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

use std::collections::BinaryHeap;

fn main() {
    let mut b = read_vec::<u32>().into_iter().collect::<BinaryHeap<u32>>();
    let k = read::<u32>();

    for _ in 0..k {
        if let Some(i) = b.pop() {
            b.push(i * 2);
        }
    }
    println!("{}", b.iter().fold(0, |acc, x| acc + x));
}


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

/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}

/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*最大公約数*/
unsigned long long GCD(long long L,long long R){
    if(L>R){
        long long temp=R;
        R = L;
        L = temp;
    }
    unsigned long long pp=0,ppt=0;
    unsigned long long ans=0;
    if(R%L==0){
        ans = L;
    }else{
        while(true){
            ppt = pp;
            pp=R%L;
            if(pp == 0){
                ans = ppt;
                break;
            }
            R = L;
            L = pp;
        }
    }    
    return ans;    
}

/*最小公倍数*/
unsigned long long LCM(long long L,long long R){
    unsigned long long ans;
    unsigned long long gcd = GCD(L,R);
    ans = (L/gcd)*R;
    return ans;
}

/*Combination set*/
#define mod 1000000007
#define maxcomb 3000/*大きいものを求めるときはここを変える*/
vector<long long> fc(maxcomb+1);
vector<long long> ifc(maxcomb+1);
long long modpow(long long x,long long n){
    long long ans = 1;
    while(n > 0){
        if(n & 1) {
            ans = ans*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}
void Conb(){
    fc[0]= 1;
    ifc[0]=1;
    for(long long i=0;i<maxcomb;i++){
        fc[i+1] = fc[i]*(i+1)%mod;//n!(mod)
        ifc[i+1] = ifc[i]*modpow(i+1,mod-2)%mod;//k!^{M-2} (mod)
    }
}
unsigned long long Combination(long long L,long long R){
    unsigned long long up=1,ans;
    Conb();
    if(L==0&&R==0){
        return 1;
    }else if(L<R||L<0){
        return 0;
    }else{
        long long t = ifc[L-R]*ifc[R]%mod;
        ans = t*fc[L]%mod;
    }
    return ans;
}
/*Combination set ここまで*/

/*ここから*/
int main() {
    int N,A,B;
    cin >> N >> A >> B;
    if(N*A>B){
        cout << B << endl;
    }else{
        cout << N*A << endl;
    }
}

Measured memory_bytes: 3684
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> prog = new ArrayList<>();

		int num = sc.nextInt();
		prog.add(num);
		int temp = num;

		for(int i = 1; i < n; i++) {
			num = sc.nextInt();
			if(num != temp) {
				prog.add(num);
			}
			temp = num;
		}

		for(int i = 0; i < prog.size(); i++) {
			if(i != 0) System.out.print(" ");
			System.out.print(prog.get(i));
		}
		System.out.println();
	}

}


Measured memory_bytes: 73952
#include<stdio.h>
 int main(void)
 {
     int A,B,C;

     scanf("%d%d%d",&A,&B,&C);

     if(A==B) { printf("%d\n",C); return 0; }
     if(A==C) { printf("%d\n",B); return 0; }
     if(B==C) { printf("%d\n",A); return 0; }

     return 0;
 }



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int parent[MAXN];
int counts[MAXN];
int friends[MAXN];
int blocked[MAXN];
int n, m, k;

int findSet(int i) {
	return (parent[i] == i)? i:parent[i] = findSet(parent[i]);
}

void unionSet(int i, int j) {
	int pi = findSet(i);
	int pj = findSet(j);
	if(pi != pj) {
		parent[pi] = pj;
		counts[pj] += counts[pi];
		counts[pi] = 0;
	}
}

bool isSameSet(int i, int j) {
	return findSet(i) == findSet(j);
}

int main() 
{
	cin >> n >> m >> k;
	for(int i = 0; i <= n; ++i) {
		parent[i] = i;
		counts[i] = 1;
		friends[i] = 1;
		blocked[i] = 0;
	}
	int u, v;
	for(int i = 0; i < m; ++i) {
		cin >> u >> v;
		unionSet(u,v);
		friends[u]++;
		friends[v]++;
	}
	for(int i = 0; i < k; ++i) {
		cin >> u >> v;
		if(isSameSet(u,v)) {
			blocked[u]++;
			blocked[v]++;
		}
	}
	for(int i = 1; i <= n; ++i) {
		int p = findSet(i);
		cout << counts[p] - friends[i] - blocked[i] << " ";
	}
	cout << endl;
	return 0;
}


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

using namespace std;
unsigned long long int dp[101][21];

void solve()
{
	int N;
	cin >> N;
	vector<int> nums(N);
	for(int i = 0; i < N; ++i)
	{
		cin >> nums[i];
	}
	int pos = 0;
	dp[1][nums[0]] = 1;
	for(int i = 1; i < N - 1; ++i)
	{
		for(int j = 0; j < 21; ++j)
		{
			if(0 <= j + nums[i] && j + nums[i] <= 20)
			{
				dp[i + 1][j + nums[i]] += dp[i][j];
			}
			if(0 <= j - nums[i] && j - nums[i] <= 20)
			{
				dp[i + 1][j - nums[i]] += dp[i][j];
			}
		}
	}
	cout << dp[N - 1][nums[N - 1]] << endl;
}

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

Measured memory_bytes: 1204
#include <stdio.h>

int main(void)
{
    int n, k;
    scanf("%d", &n);    scanf("%d", &k);
    int a[n];
    int i = 0;
    int c = 0;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (a[i] >= k)
            c++;
    }
    printf("%d", c);
    
    return 0;
}


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

int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;

	if ( 0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H ){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <stdio.h>

int main(void)	
{
	char str[21];
	
	int i, j;
	
	
	scanf("%s", str);
	
	for(i = 0; i < 21; i++)
	{
		if(str[i] == '\0')
		{
			for(j = i - 1; j >= 0; j--)
			{
				printf("%c", str[j]);
			}
			putchar ('\n');
			break ;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  vector<ll> acc(n + 1);
  rep(i, n) acc[i + 1] = acc[i] + a[i];
  // cout << acc << endl;
  map<ll, int> mp;
  for (ll ai : acc) mp[ai]++;

  ll ans = 0;
  for (auto e : mp) ans += 1LL * e.S * (e.S - 1) / 2;
  cout << ans << endl;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  string x = "keyence";

  REP (i, x.size()) {
    string pre = s.substr(0, i);
    string suf = s.substr(s.size() - x.size() + i, x.size() - i);
    if (pre + suf == x) {
      cout << "YES" << endl;
      exit(0);
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, K = map(int, readline().split())
A = list(map(lambda x: x - 1, map(int, readline().split())))
visited = [False for i in range(N)]

cur = 0
cycle = []
start = 0
while True:
    if visited[cur]:
        start = cur + 1
        break

    visited[cur] = True
    cycle.append(cur + 1)
    cur = A[cur]

# print(cycle)
cycle_start_idx = 0
for i in range(len(cycle)):
    if cycle[i] == start:
        cycle_start_idx = i
        break

if K <= cycle_start_idx:
    print(cycle[K])
    exit()


cycle_len = len(cycle) - cycle_start_idx
idx = (K - cycle_start_idx) % cycle_len
print(cycle[idx + cycle_start_idx])

Measured memory_bytes: 46316
N = int(input())
sgs = {"3", "5", "7"}
ans = {""}
for i in range(len(str(N))):
  res = set()
  for x in ans:
    for i in sgs:
      if int(i+x) <= N:
        res.add(i+x)
  ans |= res
print(len([x for x in ans if set(list(x)) == sgs]))

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;
typedef pair<ll,int> P;
struct edge{int to; ll cost;};

const ll INF = 1234567890123456LL;

vector<edge> G[100000];
ll dist[100000];
ll cost[100000];

int main()
{
    int n,m,k,s;
    ll p,q;
    cin >>n >>m >>k >>s;
    cin >>p >>q;

    vector<int> c(k);
    vector<pi> ed(m);
    rep(i,k)
    {
        scanf(" %d", &c[i]);
        --c[i];
    }
    rep(i,m)
    {
        int a,b;
        scanf(" %d %d",&a,&b);
        --a;
        --b;

        ed[i]=pi(a,b);

        G[a].pb(edge{b,1});
        G[b].pb(edge{a,1});
    }

    priority_queue<P,vector<P>,greater<P>> que;

    //????????????????????????????????????????????¢????±???????
    fill(dist,dist+n,INF);
    rep(i,k)
    {
        dist[c[i]]=0;
        que.push(P(0,c[i]));
    }
    while(!que.empty())
    {
        P now=que.top();
        que.pop();
        int v=now.se;
        if(dist[v]<now.fi) continue;
        rep(i,G[v].size())
        {
            edge e=G[v][i];
            if(dist[e.to] > dist[v]+e.cost)
            {
                dist[e.to]=dist[v]+e.cost;
                que.push(pi(dist[e.to],e.to));
            }
        }
    }

    //rep(i,n) printf("%d : %lld\n", i+1,dist[i]);

    //?????????????????´???
    rep(i,n) G[i].clear();
    rep(i,m)
    {
        int a=ed[i].fi, b=ed[i].se;

        //??????????????????????????§????????????????????????
        if(dist[a]==0 || dist[b]==0) continue;

        //??´???????????????????????????????????????0
        if(a==n-1 || b==n-1)
        {
            G[a].pb(edge{b,0});
            G[b].pb(edge{a,0});
        }
        else
        {
            //a?????±?????????a?????\?????????????????????q
            if(dist[a]<=s) G[b].pb(edge{a,q});
            else G[b].pb(edge{a,p});
            //b???????§?
            if(dist[b]<=s) G[a].pb(edge{b,q});
            else G[a].pb(edge{b,p});
        }
    }

    fill(cost,cost+n,INF);
    cost[0]=0;
    que.push(P(0,0));
    while(!que.empty())
    {
        P now=que.top();
        que.pop();
        int v=now.se;
        if(cost[v]<now.fi) continue;
        rep(i,G[v].size())
        {
            edge e=G[v][i];
            if(cost[e.to] > cost[v]+e.cost)
            {
                cost[e.to]=cost[v]+e.cost;
                que.push(P(cost[e.to],e.to));
            }
        }
    }

    cout << cost[n-1] << endl;
    return 0;
}

Measured memory_bytes: 19524
#include <iostream>
#include <algorithm>

using namespace std;

int func(int a[101][2], int n, int s, int t, bool vis[101][2], int c)
{
  if(t >= n && a[t][s] != 2){
    return c;
  }
  if(!vis[t][s]){
    return -1;
  }

  vis[t][s] = false;
  if(a[t][s] == 1 && a[t+1][s] == 1){
    return func(a, n, s, t+1, vis, c);
  } else if(a[t][s] == 2){
    return func(a, n, s, t-1, vis, c);
  } else {
    return func(a, n, ((s == 0)? 1 : 0), t+2, vis, c+1);
  }
}


int main()
{
  int n, a[101][2], m;
  bool vis[101][2];

  while(1){
    cin >> n;
    if(n == 0){
      break;
    }
    for(int j = 0; j < 2; j++){
      for(int i = 0; i < n; i++){
	cin >> a[i][j];
      }
    }

    fill(&vis[0][0], &vis[n][1], true);
    m = func(a, n-1, 0, 0, vis, 0);
    fill(&vis[0][0], &vis[n][1], true);
    n = func(a, n-1, 1, 0, vis, 0);
    if(m == -1 && n == -1){
      cout << "NA" << endl;
    } else {
      if(m == -1){
	cout << n << endl;
      } else if(n == -1){
	cout << m << endl;
      } else {
	m = min(m, n);
	cout << m << endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


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

	if (A % 2 == 0 && A == B && B == C)cout << -1 << endl;
	else {
		int ans = 0;
		while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
			int a = A, b = B;
			A = (B + C) / 2;
			B = (a + C) / 2;
			C = (a + b) / 2;
			ans++;
		}
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	mod int = 1e9 + 7
)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	N := getInt()
	players := make([]int, N)

	K := getInt()
	Q := getInt()

	for i := 0; i < Q; i++ {
		number := getInt()
		players[number - 1]++
	}

	for _, player := range players {
		if K - (Q - player) > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
using namespace std;

int main(){
  int N;
  cin >>N;
  tuple<string, int, int> in;
  string city;
  int point;
  vector<tuple<string, int, int>> v_tuple;
  for(int i=0; i<N; i++){
    cin >> city >> point;
    in = make_tuple(city, point*-1, i+1);
    v_tuple.push_back(in);
  }
  sort(v_tuple.begin(), v_tuple.end());
  for(int i=0; i<N; i++){
    int num;
    tie(ignore, ignore, num) = v_tuple.at(i);
    cout << num << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h = 0, w = 0, m = 0, x = 0, y = 0, z = 0, res = 0;
	cin >> h >> w >> m;
	vector<int> row(m);
	vector<int> col(m);
	vector<int> rct(h + 1, 0);
	vector<int> cct(w + 1, 0);
	for (int i = 0; i < m; ++i)
	{
		cin >> row[i] >> col[i];
		++rct[row[i]]; ++cct[col[i]];
	}
	int mr = *max_element(rct.begin(), rct.end());
	int mc = *max_element(cct.begin(), cct.end());
	for (int i = 0; i <= h; ++i)
		if (rct[i] == mr)
			++x;
	for (int i = 0; i <= w; ++i)
		if (cct[i] == mc)
			++y;
	for (int i = 0; i < m; ++i)
		if (rct[row[i]] == mr && cct[col[i]] == mc)
			++z;
	res = mr + mc;
	if (x * y == z)
		--res;
	cout << res << endl;
}

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

int x;

int main() {
  cin >> x;
  x -= 400;
  x /= 200;
  x = 8 - x;
  cout << x << endl;
  return 0;
}


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

int main(){
    string s; cin>>s;
    map<char, int>mp;
    rep(i, s.size()){
        mp[s[i]]++;
    }
    bool jud = true;
    for (auto p : mp){
        if (p.second%2 != 0) jud = false;
    }
    if (jud) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut map = std::collections::HashMap::new();
    let mut ans = 0;
    for i in 0..n {
        let j = i as i64 - a[i];
        let p = map.entry(j).or_insert(0);
        *p += 1i64;
    }
    for i in 0..n {
        let j = i as i64 + a[i];
        let p = map.entry(j).or_insert(0);
        ans += *p;
    }
    println!("{}", ans);
}


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

int main(){
    int m,n;
    cin >> n >> m;
    vector<int> a(n);
    int cnt=0, mcnt=0;
    rep(i, n){
        cin >> a.at(i);
        cnt += a.at(i);
    }
    int vote = ceil((double)cnt/(4*m));
    // cout << cnt << ' ' << vote << ' ' << ceil((double)cnt/(4*m)) << endl;
    rep(i,n){
        if(a.at(i)>= vote) mcnt+=1;
    }
    // cout << mcnt << endl;

    if(mcnt>=m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    readLine()!!.toInt()
    val array = readLine()!!.split(' ').map(String::toInt).toIntArray()
    repeat(readLine()!!.toInt()){
        val (b, e) = readLine()!!.split(' ').map(String::toInt)
        for (i in 0 until (e - b) / 2){
            swap(array, b + i, e - 1 - i)
        }
    }
    println(array.joinToString(" "))
}

fun swap(array:IntArray, a:Int, b:Int):Unit {
    val (f, t) = Pair(array[a], array[b])
    array[a] = t
    array[b] = f
}


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

using namespace std;

int main(){
int N,M;
cin >> N >> M;
int A[N+1]={};
int a,b;
for(int i=1;i<=M;i++){
    cin >> a >> b;
    A[a]++;
    A[b]++;
}

for(int i=1;i<=N;i++){
    
    cout << A[i]<<endl;
}
    

 return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int a[3][3];
int jdg[3][3];
int n;

int main() {
    for (int i = 0; i < 3; i++) scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int b;
        scanf("%d", &b);
        for (int i = 0; i < 9; i++) {
            if (a[i / 3][i % 3] == b) jdg[i / 3][i % 3] = true;
        }
    }
    bool ans = false;
    for (int i = 0; i < 3; i++) {
        if (jdg[i][0] && jdg[i][1] && jdg[i][2]) ans = true;
    }
    for (int i = 0; i < 3; i++) {
        if (jdg[0][i] && jdg[1][i] && jdg[2][i]) ans = true;
    }
    if ((jdg[0][0] && jdg[1][1] && jdg[2][2]) || 
        (jdg[0][2] && jdg[1][1] && jdg[0][2])) ans = true;
    printf("%s\n", ans ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m) == 0) break;
			int[] ys = new int[n];
			int[] cs = new int[m];
			for(int i=0;i<m;i++) cs[i] = sc.nextInt();
			for(int i=0;i<n;i++) ys[i] = sc.nextInt();
			int[][] dp = new int[n+1][256];
			for(int[] a: dp) fill(a, INF);
			dp[0][128] = 0;
			for(int i=0;i<n;i++) for(int j=0;j<m;j++) for(int y=0;y<256;y++) {
				int tmp = max(0, min(255, y+cs[j]));
				dp[i+1][tmp] 
				  = min(dp[i+1][tmp], dp[i][y] + (tmp - ys[i]) * (tmp - ys[i]) );
//				if(y==255) debug(dp[i+1]);
			}
			int ans = INF;
			for(int i=0;i<256;i++) ans = min(ans, dp[n][i]);
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 39000
n = gets.to_i
num = 0
a = []
n.times do |i|
  s,t = gets.split
  a << [s, t.to_i]
end
x = gets.chomp
flag_cnt = false
a.each do |b|
  if flag_cnt
    num += b[1]
  else
    flag_cnt = true if b[0] == x
  end
end
puts num

Measured memory_bytes: 14356
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

void print1d(const vector<int>& vec) {
    for (auto val : vec) {
        cout << val << " ";
    }
    cout << endl;
}

void print2d(const vector<vector<int>>& vec) {
    for (auto row : vec) {
        for (auto val : row) {
            cout << val << " ";
        }
        cout << endl;
    }
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
#endif
    crap;

    string str;
    cin >> str;

    if (str == "ABC")
        cout << "ARC" << endl;
    else {
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int a, b;
   cin >> a >> b;
   if ((a + b) % 2 == 0)
   {
      cout << (a + b) / 2 << endl;
   }
   else
   {
      cout << (a + b) / 2 + 1 << endl;
   }
   return 0;
}


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

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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



int main() {

	ll W, a, b;
	cin >> W >> a >> b;
	ll ans;

	if (a + W < b) { ans = b - W - a; }
	else if (b + W < a) { ans = a - W - b; }
	else { ans = 0; }
	cout << ans;
	system("PAUSE");
}


Measured memory_bytes: 504
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	int n = 0;
	int s = 0;
	int e = 0;
	int w = 0;

	for( int i = 0; i < S.size(); ++i ) {
		if( S[i] == 'N' ) { n = 1; }
		if( S[i] == 'S' ) { s = 1; }
		if( S[i] == 'E' ) { e = 1; }
		if( S[i] == 'W' ) { w = 1; }
	}

	cout << (n == s && e == w ? "Yes" : "No") << endl;

	return 0;
}


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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  int n=in();
  int t[n];
  rep(i,n) cin>>t[i];
  int sum=accumulate(t,t+n,0);
  int m=in();
  rep(i,m)
  {
    int p,x; cin>>p>>x;
    print(sum+x-t[p-1]);
  }

  return 0;
}

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

//def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    ll n, k;
    cin >> n >> k;
    if (k == 0) {
        out(n * n);
        return 0;
    }

    ll ans = 0;
    repeat(b, k + 1, n + 1) {
        ll cnt = b - k;
        // debug(b);
        // debug(cnt);

        ans += cnt * floor(n / b);
        ll lb = floor(n / b) * b + k;
        // ll ub = (floor(n / b) + 1) * b - k;
        ans += max(0LL, n - lb + 1);
    }
    out(ans);

    return 0;
}


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

int main()
{
  while(1){
    int D, E;
    cin >> D >> E;
    if(D == 0 && E == 0) break;
    double ans = 100;
    for(int i = 0; i <= D; i++){
      double x = i;
      double y = D-x;
      double z = fabs(sqrt(pow(x,2)+pow(y,2))-(double)E);
      ans = (ans > z) ? z : ans;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main() {
  int N, M, P, X;
  int *T;

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

  cin >> M;
  for (int m = 0; m < M; m++) {
    int sum = 0;
    cin >> P >> X;
    P--;
    for (int n = 0; n < N; n++) {
      if (n == P) sum += X;
      else sum += T[n];
    }
    cout << sum << endl;
  }

  return 0;
}


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


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,K;
  cin>>N>>K;
  if(N%K==0)cout<<0;
  else cout<<1;


  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int A, B, AB, wa, sa;
	scanf("%d", &A); scanf("%d", &B);
	AB = B % A;
	wa = A + B;
	sa = B - A;

	if (AB == 0)
		printf("%d", wa);
	else
		printf("%d", sa);

	return 0;


}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int H, W; std::cin >> H >> W;
  std::vector<std::vector<char>> ans(H+2, std::vector<char>(W+2));

  for(int i=0; i<H+2; i++) for(int j=0; j<W+2; j++) {
    if ( i == 0 || i == H+1 || j == 0 || j == W+1 ) ans[i][j] = '#';
    else {
      char c; std::cin >> c;
      ans[i][j] = c;
    }
  }

  for(int i=0; i<H+2; i++) {
    for(int j=0; j<W+2; j++) std::cout << ans[i][j];
    std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
 int A,B;
 cin>>A>>B;
 int tap = A;
 int i = 0;
 if(B == 1)cout<<i;
 else{
 while(tap < B){
     i++;
     tap += A-1;
 }
 cout<<i+1;
}
}

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

int main(){
    ll n, t;
    cin >> n >> t;
    vector<ll> osu(n);
    for(int i = 0; i < n; i++){
        cin >> osu[i];
    }
    ll ans = t;
    for(int i = 1; i < n; i++){
        ll x = 0;
        if(osu[i] - osu[i - 1] < t) x = t - (osu[i] - osu[i - 1]);
        ans += t - x;
    }
    cout << ans << endl;
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a,b,c,d;
		int count = 0;
		while (sc.hasNext()){
		int sum = sc.nextInt();
		for(a = 0; a < 10 ; a++){
			for(b = 0 ; b < 10 ; b++){
				for(c = 0 ; c < 10 ; c++){
					for(d = 0 ; d < 10 ; d++){
						if(sum == a+b+c+d){
							count++;
						}
					}
				}
			}
		}
		
		System.out.println(count);
		count = 0;
		}
		
		
		sc.close();
	}

}

Measured memory_bytes: 19348
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int n, t, a, ans;
    cin >> n >> t >> a;
    double close = INT_MAX;
    REP(i,n){
        long long h;
        double kion;
        cin >> h;
        kion = t - h * 0.006;
        double tmp = abs(a - kion);
        if(tmp < close){
            close = tmp;
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}



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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




int main() {

	string s;
	cin >> s;

	VVLL v(100005, VLL(13, 0));

	if (s[0] == '?') {
		REP(i, 10)v[0][i] = 1;
	}
	else {
		int a = s[0] - '0';
		v[0][a] = 1;
	}



	int n = s.size();
	FOR(i, 1, n) {
		if (s[i] == '?') {
			REP(j, 10) {
				REP(k, 13) {
					v[i][((10 * k) + j) % 13] += v[i - 1][k];
					v[i][((10 * k) + j) % 13] %= mod;
				}
			}
		}
		else {
			int a = s[i] - '0';
			REP(k, 13) {
				v[i][(10 * k + a) % 13] += v[i - 1][k];
				v[i][(10 * k + a) % 13] %= mod;
			}
		}
		
	}

	

	cout << v[n - 1][5] << endl;
	

}


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

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

	using ll = long long;

	int n, cnt = 0;
	cin >> n;

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

	sort(a.begin(), a.end());
	ll ans = (cnt % 2 == 1) ? -a[0] : 0;
	for (int i = (cnt % 2 == 1) ? 1 : 0 ; i < n; i++) {
		ans += a[i];
	}

	cout << ans << "\n";
}

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

using namespace std;

int main()
{long x;
cin>>x;
long long l[100000];
for(int i=0;i<x;i++)
    cin>>l[i];
sort(l,l+x);
reverse(l,l+x);
bool aa=true,kk=true;
long a=0,b=0;
for(int i=0;i<x-1;i++)
{
    if(l[i]==l[i+1]&&aa==true)
    {a=l[i];l[i+1]=-1;aa=false;}

   if(l[i]==l[i+1]&&aa==false&&kk==true)
    {b=l[i];kk=false;}


}cout<<a*b<<endl;
}


Measured memory_bytes: 1024
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
tmp=[]
sum_tmp=0
if sum(a)<sum(b):
    print(-1)
    sys.exit()
for i in range(n):
    if a[i]>=b[i]:
        tmp.append(a[i]-b[i])
    else:
        cnt+=1
        sum_tmp+=abs(a[i]-b[i])
tmp.sort(reverse=True)
for i in range(len(tmp)):
    if sum_tmp<=0:
        break
    sum_tmp-=tmp[i]
    cnt+=1

print(cnt)


Measured memory_bytes: 19060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define alpha_size 26

const int N = 14;

struct node{
  int cost;
  vector<int> cur;
};

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  
  int n, m, x;
  cin >> n >> m >> x;
  
  vector<node> v(n + 1);
  for (int i = 0; i < n; i++){
    cin >> v[i].cost;
    for (int j = 0; j < m; j++){
      int x;
      cin >> x;
      v[i].cur.push_back(x);
    }
  }
  int ans = 1e18;
  bool ok = false;
  vector<int> ret;
  for (int msk = 0; msk < 1 << n; msk++){
    vector<int> sum(m, 0);
    int cost = 0;
    for (int i = 0; i < n; i++){
      if (msk & (1 << i)){
        auto a = v[i].cur;
        for (int j = 0; j < a.size(); j++){
          sum[j] += a[j];
        }
        cost += v[i].cost;
      }
    }
      
    bool flag = true;
    for (int i = 0; i < sum.size(); i++){
      if (sum[i] < x){
        flag = false;
      }
    }
    if (flag){
      ans = min(ans, cost);
      ok = true;
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    string s; cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }else{
        cout<<"Sunny"<<endl;
    }
    
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
long long A[100000];
long long bins[100000];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  bins[0] = - A[0];
  int bin_no = 1;
  for(int i = 1; i < N; i++){
    auto it = upper_bound(bins, bins + bin_no, - A[i]);
    *it = - A[i];
    if(it == bins + bin_no){
      bin_no ++;
    }
  }
  cout << bin_no << endl;
  return 0;
}


Measured memory_bytes: 1792
from functools import lru_cache

N = input()
K = int(input())

@lru_cache(maxsize=None)
def search(d, cnt, isEq):
    if d == len(N):
        return 1 if cnt == K else 0

    n = int(N[d])

    if isEq and n == 0:
        return search(d + 1, cnt, isEq)

    if isEq:
        ret = 0
        ret += search(d + 1, cnt, False)
        for _ in range(1, n):
            ret += search(d + 1, cnt + 1, False)
        ret += search(d + 1, cnt + 1, True)
        return ret

    return search(d + 1, cnt, False) + search(d + 1, cnt + 1, False) * 9

print(search(0, 0, True))


Measured memory_bytes: 4828