akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_LEN 1001
 
int dataset;
char str_X[MAX_LEN];
char str_Y[MAX_LEN];
 
void LCSLength(char *X, char *Y){
  int m,n;
  int **c;
  int i,j;
 
  m = strlen(X);
  c = malloc(sizeof(int*) * (m+1));
  n = strlen(Y);
  for(i=0; i<=m; i++){
    c[i] = malloc(sizeof(int) * (n+1));
  }
  for(i=1; i<=m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<=n; j++){
    c[0][j] = 0;
  }
  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(X[i-1]==Y[j-1]){
        c[i][j] = c[i-1][j-1] + 1;
      }else if(c[i-1][j] >= c[i][j-1]){
        c[i][j] = c[i-1][j];
      }else{
        c[i][j] = c[i][j-1];
      }
    }
  }
  printf("%d\n",c[m][n]);
}
 
int main() {
  int i;
 
  scanf("%d",&dataset);
  for(i=0; i<dataset; i++){
    scanf("%s",str_X);
    scanf("%s",str_Y);
    LCSLength(str_X, str_Y);
  }
  return 0;
}



Measured memory_bytes: 80372
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var s = Console.ReadLine().Trim();
            if (s == "#") break;
            var ans = game(s, 'L');
            var ans2 = game(s, 'r');
            Console.WriteLine(Min(ans, ans2));
        }
    }
    static int game(string s, char start)
    {
        var sL = s.Length;
        var count = 0;
        int L, r;
        char nextLeg;
        if (start == 'r') { r = int.Parse(s[0].ToString()); L = 0; nextLeg = 'L'; }
        else { L = int.Parse(s[0].ToString()); r = 0; nextLeg = 'r'; }
        var p = 1;
        while (p < sL)
        {
            if (nextLeg == 'r')
            {
                r = int.Parse(s[p].ToString());
                if (!checkR(L, r)) { count++; L = r; nextLeg = 'r'; }
                else nextLeg = 'L';
            }
            else
            {
                L = int.Parse(s[p].ToString());
                if (!checkR(L, r)) { count++; r = L; nextLeg = 'L'; }
                else nextLeg = 'r';
            }
            p++;
        }
        return count;
    }
    static bool checkL(int L, int r)
    {
        if (r == 1 | r == 4 | r == 7)
            return (L == 1 | L == 4 | L == 7);
        if (r == 2 | r == 8)
            return (L == 2 | L == 8 | L == 1 | L == 4 | L == 7);
        return true;
    }
    static bool checkR(int L, int r)
    {
        if (L == 3 | L == 6 | L == 9)
            return (r == 3 | r == 6 | r == 9);
        if (L == 2 | L == 8)
            return (r == 2 | r == 8 | r == 3 | r == 6 | r == 9);
        return true;
    }
}



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

int fac(int n)
{
	int f = n;
	if (n <= 0)
		return(1);
	while(--n)
		f *=n;
	return f;
}
int conv(int x, int y)
{
	int c;
	c = fac(x)/fac(y);
	c = c/fac(x-y);

	return (c);

}

int	main(void)
{
	int N, M;
	scanf("%d %d", &N, &M);
	int r_num = 0;
	if (N==1 && M==1)
	{
		printf("0\n");
		return 0;
	}
	
	printf("%d\n",(((N+M)*(N+M-1))/2)-(N*M));
	return (0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int x;
	cin >> x;
	if (x == 3 || x == 5 || x == 7 ){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;

	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
ll n;
ll a[100001];
ll k;
ll dp[100001];
ll getans(ll i)
{
if(i>=n-1)
{
	return 0;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	ll ans=mod;
	if(i+1<=n-1)
	{
		ans=min(ans,getans(i+1)+abs(a[i]-a[i+1]));
	}
	if(i+2<=n-1)
	{
		ans=min(ans,getans(i+2)+abs(a[i]-a[i+2]));
	}
return dp[i]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
cin>>n;
cin>>k;

for(ll i=0;i<n;i++)
{
	cin>>a[i];
}
memset(dp,0,sizeof(dp));
if(n==1)
{
	cout<<0<<endl;
	return 0;
}
dp[0]=0;
for(ll i=1;i<n;i++)
{
	dp[i]=1e10;
	for(ll j=1;j<=k;j++)
	{
if(i-j>=0)
{
	dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
}
	}
}
cout<<dp[n-1]<<endl;
}





Measured memory_bytes: 5164
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

S=list(input())
T=list(input())

print(sum([1 for x,y in zip(S,T) if x==y]))


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int r = array[0];
			int g = array[1];
			int b = array[2];

			int value = r * 100 + g * 10 + b;
			if (value % 4 == 0) {
				Console.WriteLine("YES");
			} else {
				Console.WriteLine("NO");
			}

			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    for(int i=1;i<=5;i++){
    	cin>>n;
    	if(n==0){
    		cout<<i;
    		break;
		}
	}
}


Measured memory_bytes: 3572
s = input()
a = int(s[:2])
b = int(s[2:])

if 1 <= a <= 12 and 1 <= b <= 12:
    print('AMBIGUOUS')
elif 1 <= a <= 12:
    print('MMYY')
elif 1 <= b <= 12:
    print('YYMM')
else:
    print('NA')


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

int main() {
    int a;
    cin >> a;
    int hur = 0;
    int min = 0;
    if ( a != 0) {
        hur = a / 3600;
        a = a - (hur * 3600);
        min = a / 60;
        a = a - (min * 60);
    }
    cout << hur << ":" << min << ":" << a << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a,b;cin>>a>>b;
    ll ans=0;
    if(a>b){ans+=a;a--;}
    else {ans+=b;b--;}
    ans+=max(a,b);
    cout<<ans<<endl;
}


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

a=input()
b=input()
c=input()

ans = 0

for i in range(N):
    if a[i]==b[i] and a[i]!=c[i]:
        ans = ans+1
    elif a[i]!=b[i] and a[i]==c[i]:
        ans = ans+1
    elif c[i]==b[i] and a[i]!=c[i]:
        ans = ans+1
    elif c[i]!=b[i] and a[i]!=c[i] and a[i]!=c[i]:
        ans = ans+2
    
print(ans)

Measured memory_bytes: 3064
# -*- coding:utf-8 -*-
"""
https://atcoder.jp/contests/abc122/tasks/abc122_b
"""

def solve():
    S = input()

    ans = 0
    cnt = 0
    for c in S:
        if c in ("A", "C", "G", "T"):
            cnt += 1
        else:
            ans = max(ans, cnt)
            cnt = 0
    ans = max(ans, cnt)

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long ans = 0;
    int min = 1000000000;
    int count = 0;
    for (int i = 0; i < N; i++) {
        int temp = abs(A[i]);
        ans += temp;
        if (min > temp) {
            min = temp;
        }
        if (A[i] < 0) {
            count++;
        }
    }
    if (count % 2 != 0) {
        ans -= 2 * min;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
import numpy as np
import itertools
import heapq
import bisect
import math
import queue
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque, defaultdict #要素ごとの出現回数、双方向アクセス可能データ型
from functools import reduce
mod = 1000000007
sys.setrecursionlimit(1000000)

input = sys.stdin.readline

def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res
 
def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
# template


def main():
    n, k = map(int, input().split())
    h = [int(i) for i in input().split()]

    dp = [0] * n

    for i, h_ele in enumerate(h):
        if i > 0:
            p = max(i-k, 0)
            dp[i] = min(j + abs(l - h_ele) for j, l in zip(dp[p:i], h[p:i]))

    print(dp[-1])

if __name__ == "__main__":
    main()



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

struct RollingHash {
  int Mod, Base;
  vector<int> pow;
  vector<vector<int>> hash;
  // mod : 1e9 + 9,base : 1007
  RollingHash(const int len = 3000000, const int mod = (int)(1e9 + 7),
              const int base = 1009) {
    Mod = mod;
    Base = base;
    pow.assign(len + 1, 0);
    pow[0] = 1;
    for (int i = 1; i <= len; ++i) pow[i] = (long long)pow[i - 1] * Base % Mod;
  }
  void add(const string &s) {
    int id = hash.size();
    hash.push_back(vector<int>((int)s.size() + 1, 0));
    sethash(id, s);
  }
  void changestr(const int &id, const string &s) {
    assert(id < (int)hash.size());
    sethash(id, s);
  }
  void sethash(const int &id, const string &s) {
    int len = s.size();
    for (int i = 0; i < len; ++i) {
      hash[id][i + 1] = (long long)hash[id][i] * Base % Mod;
      hash[id][i + 1] += s[i];
      if (hash[id][i + 1] >= Mod) hash[id][i + 1] -= Mod;
    }
  }
  // [l,r),0-indexed
  long long calchash(const int &id, const int &l, const int &r) const {
    assert(r >= l);
    long long res = hash[id][r];
    res -= (long long)hash[id][l] * pow[r - l] % Mod;
    if (res < 0) res += Mod;
    if (res >= Mod) res -= Mod;
    return res;
  }
  inline bool issame(const int &idl, const int &ll, const int &lr,
                     const int &idr, const int &rl, const int &rr) const {
    return calchash(idl, ll, lr) == calchash(idr, rl, rr);
  }
};

long long h, w;
vector<string> s;
RollingHash rh;

long long solve();
long long calc(int u, int d, int lef);

int main() {
  cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
    rh.add(s[i]);
  }
  for (int i = 0; i < h; ++i) {
    string t;
    for (int j = 0; j < w; ++j) t += ".#"[s[i][j] == '.'];
    rh.add(t);
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = max(h, w);
  for (int i = 0; i < w; ++i) {
    vector<long long> hist;
    for (int j = 1; j < h; ++j)
      hist.push_back(calc(j - 1, (s[j][i] != s[j - 1][i]) * h + j, i));
    stack<long long> len, id;
    hist.push_back(0);
    len.push(0);
    id.push(-1);
    for (int j = 0; j < h; ++j) {
      int nxtid = j;
      while (hist[j] < len.top()) {
        nxtid = id.top();
        res = max(res, len.top() * (j - id.top() + 1));
        len.pop();
        id.pop();
      }
      if (hist[j] > len.top()) {
        len.push(hist[j]);
        id.push(nxtid);
      }
    }
  }
  return res;
}

long long calc(int u, int d, int lef) {
  if (rh.calchash(u, lef, w) == rh.calchash(d, lef, w)) return w - lef;
  long long l = lef, r = w;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    if (rh.calchash(u, lef, mid) == rh.calchash(d, lef, mid))
      l = mid;
    else
      r = mid;
  }
  return l - lef;
}

Measured memory_bytes: 49536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    char c[2][3];
    rep(i, 2)
    {
        rep(j, 3)
        {
            cin >> c[i][j];
        }
    }
    rep(i, 2)
    {
        rep(j, 3)
        {
            if (c[i][j] != c[1 - i][2 - j])
            {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
#define MAXN 100000
#define LL long long
LL read(){
    LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}
struct ck{
	int u,v;
}p[MAXN+5];
int n,k,cnt,tot;
int fa[MAXN+5],siz[MAXN+5];
LL m,sum;
vector<int> G[MAXN+5];
int xfind(int x){
	return (fa[x]==x)?x:fa[x]=xfind(fa[x]);
}
int main()
{
	n=read(),m=read(),k=read();
	for(int i=1;i<=n;i++)fa[i]=i,siz[i]=1;
	for(int i=1;i<=k;i++){
		int u=read()+1,v=read()+1,opt=read();
		if(opt==0){
			int a=xfind(u),b=xfind(v);
			if(a!=b){
				fa[b]=a;siz[a]+=siz[b];
			}
		}else p[++cnt]=(ck){u,v};
	}
	for(int i=1;i<=cnt;i++)
	if(xfind(p[i].u)==xfind(p[i].v))
	{printf("No\n");return 0;}
	for(int i=1;i<=n;i++)
	if(xfind(i)==i)tot++;
	if(tot<=2&&cnt){printf("No\n");return 0;}
	if(n-1==m&&cnt){printf("No\n");return 0;}
	if(1LL*tot*(tot-1)/2+n-tot>=m){printf("Yes\n");return 0;}
	else {printf("No\n");return 0;}
}

Measured memory_bytes: 4096
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int a[4][13];
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {

			a[i][j] = 0;

		}
	}

	for (int k = 0; k < n;k++) {
		char c;
		int x;
		cin >> c >> x;

		int y;

		if (c == 'S') {
			y = 0;
		}

		if (c == 'H') {
			y = 1;
		}

		if (c == 'C') {
			y = 2;
		}

		if (c == 'D') {
			y = 3;
		}
		a[y][x-1] = 1;

	}


	for (int l = 0; l < 4; l++) {
		for (int m = 0; m < 13; m++) {

			if (a[l][m] == 0) {
				char c;

				if (l == 0) {
					c = 'S';
				}

				if (l == 1) {
					c = 'H';
				}

				if (l == 2) {
					c = 'C';
				}

				if (l == 3) {
					c = 'D';
				}

				cout << c << " " << m+1 << endl;
			}
		}

	}
	return 0;
}




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

int main() {
 int a, b, c, d;
 cin >> a >> b;
  vector<int> data;
  for(int i = 0;i < b;i++) {
    cin >> c;
    data.push_back(c);
  }
  for(int i = 0;i < b;i++) {
    d += data.at(i);
  }
  if(a - d < 0)
    cout << "-1" << endl;
  else
    cout << a - d << endl;
  }

Measured memory_bytes: 3652
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger sum = BigInteger.valueOf(0); 
		while(sc.hasNext()) {
			String str = sc.next();
			String [] a = str.split("[^0-9]");   //String [] a = str.split("[D]");だと上手くいかなかった 
			for(int i=0;i<a.length;i++) {
				if(a[i].length()>0) {
				       BigInteger b = new BigInteger(a[i]);  
                                       sum = sum.add(b);
				}
			}
		}
		System.out.println(sum.toString());
	}
}


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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    vector<int> A(N,0);
    int ans = 0;
    int minP = N + 1;
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
        if(A.at(i) <= minP) {
            ans++;
            minP = A.at(i);
        }
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 4048
n,m=map(int,input().split())
G=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

for g in G:
    island_1=False
    island_n=False
    for gg in g:
        if gg==0:
            island_1=True
        if gg==n-1:
            island_n=True
    if island_1==True and island_n==True: 
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')



Measured memory_bytes: 38320
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  auto f = [](string s) {
    int left = 0, right = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '(') right++;
      if (s[i] == ')') {
        if (right > 0)
          right--;
        else
          left++;
      }
    }
    return make_pair(left, right);
  };
  int N;
  cin >> N;
  pair<int, int> bra[N];
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    bra[i] = f(S);
  }
  auto comp = [](pair<int, int> l, pair<int, int> r) {
    if (l.first - l.second < 0 && r.first - r.second < 0)
      return l.first < r.first;
    if (l.first - l.second > 0 && r.first - r.second > 0)
      return l.second > r.second;
    return l.first - l.second < r.first - r.second;
  };
  sort(bra, bra + N, comp);
  debugArray(bra, N);
  int buf = 0;
  bool isok = true;
  for (int i = 0; i < N; i++) {
    debug(buf);
    debug(bra[i].first);
    if (buf < bra[i].first) {
      isok = false;
      break;
    }
    buf += bra[i].second - bra[i].first;
  }
  debug(buf);
  isok &= buf == 0;
  debug(buf);
  cout << (isok ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;


ull N, M;

ull H[100001];
ull Hclass[100001];

vector <vector <ull>> Hclassmap;

typedef struct {
	ull A;
	ull B;
} path;

// path hpath[10001];



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

	ull i, j;
	ull A, B;

	for (i = 0; i < N; i++) {
		cin >> H[i];
		Hclass[i] = 1;
	}

	for (i = 0; i < M; i++) {
		// cin >> hpath[i].A >> hpath[i].B;
		cin >> A >> B;
		if (H[A - 1] < H[B-1]) {
			Hclass[A - 1] = 0;
		}
		else if (H[A - 1] > H[B - 1]) {
			Hclass[B - 1] = 0;
		}
		else {
			Hclass[A - 1] = 0;
			Hclass[B - 1] = 0;

		}
	}

	//cout << "-----" << endl;
	ull n = 0;
	for (i = 0; i < N; i++) {
		//cout << i+1 << ": " << Hclass[i] << endl;
		n += Hclass[i];
	}
	cout << n << endl;

}


Measured memory_bytes: 4748
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n, x = map(int, input().split())
l = list(map(int, input().split()))
# print(l)
ll = [0]
sum = 0
for i in range(n):
    sum += l[i]
    ll.append(sum)
# print(ll)

cnt = 0
for i in range(n+1):
    if ll[i] <= x:
        cnt += 1
print(cnt)


Measured memory_bytes: 3824
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    ret = 0
    C = [[0]*10 for _ in range(10)]

    for a in range(1, n+1):
        s = str(a)
        i, j = int(s[0]), int(s[-1])
        C[i][j] += 1

    for b in range(1, n+1):
        s = str(b)
        i, j = int(s[0]), int(s[-1])
        ret += C[j][i]

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
	int i=0;
        cin>>N;

	while(i<N){
          int A[10];
          for(int i=0;i<10;i++){
           cin>>A[i];
          }

          if(DFS(A)==true){
           cout<<"YES"<<endl;
          }
          else{
           cout<<"NO"<<endl;
          }

          i++;
        }
                
        return 0;
} 

Measured memory_bytes: 2980
import java.util.*;

public class Main{
  public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] num = new int[n];

        for(int i = 0; i < n; i++){
            num[i] = sc.nextInt();
        }

        int count = 0;

        while(true){
            if(checkOdd(n, num)){
                break;
            }

            for(int i = 0; i < n; i++){
                num[i] = num[i]/2;
            }
            count++;
        }

        System.out.println(count);
    }

    public static boolean checkOdd(int n, int[] a){
        boolean result = false;
        for(int i = 0; i < n; i++){
            if(a[i] % 2 != 0){
                result = true;
            }
        }
        return result;
    }
}

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

using namespace std;

#define MAX 1000000000

long long dp(int N, int K, int h[]) {
  long long c[N + 1];
  c[1] = 0;
  c[2] = c[1] + abs(h[2] - h[1]);
  for (int i = 3; i <= N; i++) {
    long long _min = MAX;
    for (int j = 1; j <=K; j++) {
      if (i - j >= 1) _min = min(_min, c[i - j] + abs(h[i] - h[i - j]));
      else break;
    }
    c[i] = _min;
  }
  return c[N];
}

int main()
{
  int N, K; cin >> N >> K;
  int h[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  cout << dp(N, K, h) << endl;

  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
typedef pair<ll, p> pp;
 
static const double eps = 1e-8;
static const double pi = 4.0 * atan(1.0);
static const ll inf = 1023456789;
 
#define rep(i,n)	for(int i=0;i<n;++i)
#define repr(i,n)	for(int i=n-1;i>=0;--i)
#define for(i,s,n)	for(int i=s;i<n;++i)
#define forr(i,s,n)	for(int i=n-1;i>=s;--i)
#define all(c)		(c).begin(),(c).end()
#define clear(v)	memset(v,0,sizeof(v))
#define mp(a,b)		make_pair((a),(b))
#define abs(a)		((a)>0?(a):-(a))
#define f			first
#define s			second
 
int main(int argc, char **argv) {
	int a, b;
	cin >> a >> b;
	cout << ((a + b + 1) / 2) << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char b;

    scanf("%c", &b);

    switch(b){
        case 'A':
            printf("T");
            break;
        case 'C':
            printf("G");
            break;
        case 'T':
            printf("A");
            break;
        case 'G':
            printf("C");
            break;
    }

    return 0;
}

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

const int A = 0;
const int X = 1;
const int Y = 2;
const int Z = 3;
const int W = 4;
const int B = 5;
const int D = 6;

void *map[7][2] = {{map[X], map[Y]},
                   {map[D], map[Z]},
                   {map[X], map[D]},
                   {map[W], map[B]},
                   {map[B], map[Y]},
                   {map[Y], map[X]},
                   {map[D], map[D]}};

int main(void) {
  string p;
  while (cin>>p, p[0]!='#') {
    void **city = map[A];
    for (int i=0, n=p.length(); i<n; i++) {
      city = (void **)city[p[i]-'0'];
    }
    cout << (city==map[B] ? "Yes" : "No") << endl;
  }

  return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
  FIO
  ll n;
  cin>>n;
  ll p=n/500;
  n-=p*500;
  ll q=n/5;
  cout<<p*1000+q*5;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	string str;
	cin >> str;
	stack <char> x;
	for (int i = 0; i < str.size(); i++) {
		if (str.at(i) == 'S') 
          x.push(str.at(i));
		else {
			if(x.empty()) 
              x.push(str.at(i));
			else if(x.top() == 'T') 
              x.push(str.at(i));
			else x.pop();
		}
	}
	cout <<x.size();
  return 0;
}


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

const int MAXN = 1e5+5;

int n, t[MAXN], v;
vector<int> g[MAXN];
int s[MAXN];

void dfs(int v, int f = -1) {
    s[v] = 1;
    int ct = 0;
    for (int u : g[v]) {
        if (u != f) {
            dfs(u, v);
            s[v] += s[u];
            ct += s[u]%2;
        }
    }
    ct += (n-s[v])%2;
    if (ct >= 2) {
        cout << "First\n";
        exit(0);
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs(0);

    cout << "Second\n";
    return 0;
}

Measured memory_bytes: 6144
# C
N = int(input())
A_list = [0]*N
for i in range(N):
    A_list[i] = int(input())
res = 0
A_list_s = sorted(A_list)

if N % 2 == 0:
    bar = A_list_s[N // 2]
    for i in range(N // 2):
        res += 2*(bar - A_list_s[i]) + 2*(A_list_s[N-1-i] - bar)
    res -= bar - A_list_s[N // 2 - 1]
else:
    bar = A_list_s[N // 2]
    for i in range(N // 2):
        res += 2*(bar - A_list_s[i]) + 2*(A_list_s[N-1-i] - bar)
    res -= min(bar - A_list_s[N // 2 - 1], A_list_s[N // 2 + 1] - bar)
print(res)

Measured memory_bytes: 8240
n = int(input())
a = list(map(int, input().split()))
k = max(a) + 1

b = [0 for i in range(n)]
c = [0 for i in range(k)]

for j in range(n):
    c[a[j]] += 1

for i in range(1, k):
    c[i] += c[i-1]

for j in range(n-1, -1, -1):
    b[c[a[j]] - 1] = a[j]
    c[a[j]] -= 1

print(*b)


Measured memory_bytes: 224388
#include<iostream>
#include<iomanip>
int main(){
  using namespace std;
  double a[10],b,c;
  while(cin>>b){
    c=0;
    a[0]=b;
    for(int i=1;i<10;i++)
      if(i%2==1)a[i]=a[i-1]*2;
      else a[i]=a[i-1]/3;
    for(int i=0;i<10;i++)
      c+=a[i];
    cout<<setprecision(8)<<c<<endl;
  }   
  return 0;
}

Measured memory_bytes: 1276
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    answer = 0
    for i in reversed(range(0,N)):
        answer += min(A[i+1],B[i])
        B[i] = max(0, B[i]-A[i+1])
        answer += min(A[i],B[i])
        A[i] = max(0, A[i]-B[i])
    print(answer)

Measured memory_bytes: 19156
import sys
s = str(input())
t = str(input())
ans = sys.maxsize 
for i in range(len(s) - len(t) + 1): 
        minRemovedChar = 0
        for j in range(len(t)): 
            if (t[j] != s[i + j]): 
                minRemovedChar += 1
        ans = min(minRemovedChar, ans) 
print(ans)

Measured memory_bytes: 9120
#include <stdio.h>
char serve[101];
int main() {
	int a, b, i;
	while(1) {
		scanf("%s", serve);
		if(serve[0] == '0') break;
		a = b = 0;
		for(i = 1; i < 101 && serve[i] != 0; ++ i) {
			if(serve[i] == 'A') a ++;
			else b ++;
		}
		if(a > b) a ++;
		else b ++;
		printf("%d %d\n", a, b);
	}
	return 0;
}

Measured memory_bytes: 536
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        Arrays.sort(l);

        int total = 0;
        for (int i = n - 1; i >= n - k; i--) {
            total += l[i];
        }

        System.out.println(total);
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#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 pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main()
{
    string s;
    cin>>s;
    for(int i=0;i<SZ(s)-1;){
        if(s[i]=='S'&&s[i+1]=='T'){
            s.erase(i,2);
            if(i) i--;
        }
        else i++;
    }
    cout<<SZ(s)<<endl;
    return 0;
}


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

long long u(long long a,long long b){
    if(a<b){
        long long temp = a;
        a = b;
        b = temp;
    }
    if(a % b == 0) return b;
    else return u(b, a-b*(a/b));
}

int main(){
    int N;
    cin >> N;
    long long T[N];
    for(int i=0;i<N;i++) cin >> T[i];
    for(int i=0;i<N-1;i++){
        long long uu = T[i]/u(T[i], T[i+1])*T[i+1];
        T[i+1] = uu;
        //cout << uu <<" "<< i << endl;
    }
    long ans = T[N-1];
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    
    var n = readLine()!!.toInt()
    var aka = (1..n).map{
        var (a,b) = readLine()!!.split(" ").map(String::toInt)
        Pair(a,b)
    }.sortedBy{it.first}
   var ao = (1..n).map{
        var (a,b) = readLine()!!.split(" ").map(String::toInt)
        Pair(a,b)
    }.sortedBy{it.first}

    var collect = mutableListOf<Pair<Int,Int>>()
    ao.map{blue->
        var leave = aka.filter{
                    var (a,b) = it
                    var (c,d) = blue
                    if(a<c && b<d && !collect.contains(it)) true
                    else false
                    }
        if(leave.size != 0){
            collect.add(leave.sortedBy{it.second}[leave.size-1])
        }
    }
    println(collect.size)
}

Measured memory_bytes: 37964
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N,A;cin>>N>>A;
    int x[N];REP(i,N)cin>>x[i];
    REP(i,N)x[i]-=A;
    int minus =0;
    int plus =0;
    vector<int> xm;
    vector<int> xp;
    REP(i,N){
        if(x[i]>0){
            plus++;xp.push_back(x[i]);
        }
        else if(x[i]<0){
            minus++;xm.push_back(-1*x[i]);
        }
    }

    LL minusdp[minus+1][2501];
    LL plusdp[plus+1][2501];
    fill(minusdp[0],minusdp[minus+1],0);
    fill(plusdp[0],plusdp[plus+1],0);
    minusdp[0][0]=1;
    plusdp[0][0]=1;

    REP(i,minus){
        REP(j,2501){
            minusdp[i+1][j]+=minusdp[i][j];
            if(j>=xm[i])minusdp[i+1][j]+=minusdp[i][j-xm[i]];
        }
    }
    REP(i,plus){
        REP(j,2501){
            plusdp[i+1][j]+=plusdp[i][j];
            if(j>=xp[i])plusdp[i+1][j]+=plusdp[i][j-xp[i]];
        }
    }

    LL ans=0;
    LL ans_=1;
    REP(i,N-(plus+minus))ans_*=2;ans_--;

    REP(i,2500){
        if(minusdp[minus][i+1]>0&&plusdp[plus][i+1]>0)ans+=minusdp[minus][i+1]*plusdp[plus][i+1];
    }
    REP(i,N-(plus+minus))ans*=2;
    ans+=ans_;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1280
H,W = map(int,input().split())
if H%3==0 or W%3==0:
    print(0)
    exit()
ans = min(H,W)
if H%2 == 0:
    for w in range(1,W):
        tmp = abs(w*H - (W-w)*H//2)
        ans = min(ans,tmp)
else:
    for w in range(1,W):
        a = w*H
        b = (W-w)*(H//2)
        c = (W-w)*(H//2+1)
        ans = min(ans, max(a,b,c) - min(a,b,c))
if W%2 == 0:
    for h in range(1,H):
        tmp = abs(h*W - (H-h)*W//2)
        ans = min(ans,tmp)
else:
    for h in range(1,H):
        a = h*W
        b = (H-h)*(W//2)
        c = (H-h)*(W//2+1)
        ans = min(ans, max(a,b,c) - min(a,b,c))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

signed main() {
  int N, K; 
  cin >> N >> K;

  vector<int> x(N), y(N);
  REP(i, N) cin >> x[i] >> y[i];
  
  vector<int> X = x, Y = y;
  sort(ALL(X)); sort(ALL(Y));

  auto f = [&](int x1, int y1, int x2, int y2){
    int cnt = 0;
    REP(i, N){
      if(IN(x1, x[i], x2+1) && IN(y1, y[i], y2+1)) cnt++;
    }
    if(cnt >= K) return (x2-x1)*(y2-y1);
    return 8*INF;
  };


  int ans = 8*INF;
  REP(a, N) FOR(b, a+1, N) REP(c, N) FOR(d, c+1, N){
    chmin(ans, f(X[a], Y[c], X[b], Y[d]));
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define Max 200000
int main ()
{
  int j,max,min,num,number[Max];
  
  scanf("%d",&num);
  
  
  for(j=0;j<num;j++)
    {
      scanf("%d",&number[j]);
    }
  
  

  for(j=1;j<=num-1;j++)
    {
	    
	      max=number[1]-number[0];
	      min=number[0];
	      
	      for(j=1;j<=num-1;j++)
		{
		 
		  if(max<number[j]-min)
		    {
		      max=number[j]-min;
		    }
		  
		  if(min>number[j])
		    {
		      min=number[j];
		    }

		}

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

Measured memory_bytes: 1376
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#define INF 2100000000
#define INVALID -1
using namespace std;
int absint(int a)
{
	return max(a , - a);
}
int main()
{
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        sb.append(sc.next());
        String str1 = sb.substring(0,2);
        String str2 = sb.substring(2,4);
        int i = Integer.parseInt(str1);
        int j = Integer.parseInt(str2);

        if(0 < i && i < 13){
          if(0 < j && j < 13){
            System.out.println("AMBIGUOUS");
          }else{
            System.out.println("MMYY");
          }
        }else{
          if(0 < j && j < 13){
            System.out.println("YYMM");
          }else{
            System.out.println("NA");
          }
        }
    }
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#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 ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }

  vector< int > ans;
  while(N != 0) {
    if (N & 1) {
      ans.emplace_back(1);
      N--;
    } else {
      ans.emplace_back(0);
    }
    N /= -2;
  }

  reverse(ALL(ans));
  EACH(ai, ans) {
    cout << ai;
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void){
    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(5);
    cout << sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) << endl;
}



Measured memory_bytes: 3284
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)

	H, W := getInt(), getInt()
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	dirc := true
	idx := 0
	cnt := 0
	for y := 0; y < H; y++ {
		b := make([]int, W)
		for x := 0; x < W; x++ {
			xx := x
			if !dirc {
				xx = W - 1 - x
			}
			b[xx] = idx + 1
			cnt++
			if a[idx] == cnt {
				cnt = 0
				idx++
			}
		}
		for x := 0; x < W; x++ {
			fmt.Print(b[x], " ")
		}
		out()
		if dirc {
			dirc = false
		} else {
			dirc = true
		}
	}

}


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

using namespace std;

int main () {
	long long q, h, s, d;
	cin >> q >> h >> s >> d;
	long long n;
	cin >> n;      
	h = min (h, q * 2);
	s = min (s, h * 2);
	d = min (d, s * 2);
	long long ans = (n / 2) * d + (n % 2) * s;
	cout << ans;
	return 0;
}

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

using namespace std;
#define ll long long int
int main() {
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    ll ans;
    while(A>0 && C>0){
        C=C-B;
        if(C<=0){
            ans=1;
            break;
        }
        A=A-D;
        if(A<=0){
            ans=2;
            break;
        }
    }
    if (ans==1){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}


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

bool marks[10];

int main() {
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= q; ++i) {
        int k; cin >> k;
        marks[k] = 1;
    }

    for (int j = n; j <= 10 * n; ++j) {
        string num = to_string(j);
        bool valid = true;
        for (auto el: num) if (marks[el - '0']) valid = false;
        if (valid) {
            cout << j << endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Practice
{
    class Program
    {

        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);
        }


        static void SolveA(string[] args)
        {
            string sz = (Console.ReadLine());
            int n = int.Parse(sz);
            int[] r = new int[n];

            for(int i=0;i<n;++i)
            {
                r[i] = int.Parse(Console.ReadLine());
            }
            long minv = r[0];
            long maxv = long.MinValue;
            for(int i=1;i < n;++i)
            {
                maxv = Math.Max(maxv, r[i] - minv);
                minv = Math.Min(minv, r[i]);
            }

            Console.WriteLine(maxv );
        }
        
    }

}



Measured memory_bytes: 10768
#include <stdio.h>
int main(void){
    char ch;
    while(1){
        scanf("%c",&ch);
        if(ch>='a'&&ch<='z')printf("%c",(ch-32));
        else if(ch>='A'&&ch<='Z')printf("%c",(ch+32));
        else if(ch=='\n')break;
        else printf("%c",ch);
    };
     putchar('\n');
    return 0;
}



Measured memory_bytes: 2044
i,j=map(int,input().split())
lst=[]
for n in range(i):
    lst.append(list(map(int,input().split())))
    lst[n].append(sum(lst[n]))
lst.append([])
for n in range(j+1):
    number=0
    for m in range(i):
        number+=lst[m][n]
    lst[i].append(number)
for n in range(i+1):
    print(' '.join(map(str,lst[n])))


Measured memory_bytes: 5704
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,k) = get!(usize,usize);
    let mut h = get!([usize]);
    if k >= n {
        println!("0");
        return;
    }
    h.sort();
    let res = h.iter().take(n-k).sum::<usize>();
    println!("{}", res);
}


Measured memory_bytes: 15608
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}
 
signed main(){
    /*
    int n,m;
    cin>>n>>m;
 
    h.assign(n,0);
    rep(i,0,n) cin>>h[i];
 
    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
 
    seen.assign(n,-1);
 
    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }
 
    int sum=accumulate(all(seen),0);
 
    cout<<sum<<endl;*/
 
    int n,m;
    cin>>n;
    int t[n];
    rep(i,0,n) cin>>t[i];
    cin>>m;
    int p[m],x[m];
    rep(i,0,m) cin>>p[i]>>x[i];

    int sum=accumulate(t,t+n,0);

    for(int i=0;i<m;i++){
        int si=sum;
        si-=t[p[i]-1]-x[i];
        cout<<si<<endl;
    }
}   

Measured memory_bytes: 256