akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pii             pair<int , int >
#define inf             1000000011
#define in(a)           scanf("%d", &a)
#define ins(a)          scanf("%s", a)
#define in2(a, b)       scanf("%d%d", &a, &b)
#define in3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pn              printf("\n")
#define pr(a)           printf("%d\n", a)
#define prs(a)          printf("%d ", a)
#define pr2(a, b)       printf("%d %d\n", a, b)
#define pr3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define pcs(a)          printf("Case %d: ", a)
#define mp              make_pair
#define vi              vector<int >
#define _ceil(n, a)     ((n)%(a)==0?((n)/(a)):((n)/(a)+1))
#define sz              size()
#define pb              push_back
#define mem(a, b)       memset((a), (b), sizeof(a))
#define all(X)          (X).begin(), (X).end ()
#define lg2(n)          (31-__builtin_clz(n))
#define ext(a)          {printf("%s\n", a); return 0;}
#define oka(x, y)       ((x)>=0&&(x)<row&&(y)>=0&&(y)<col)
#define x               first
#define y               second
#define lc              (2*i)
#define rc              (2*i+1)

typedef long long LL;
//int  dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int  dx[]={1,1,0,-1,-1,-1,0,1,0};int dy[]={0,1,1,1,0,-1,-1,-1,0};//8 direction
//int  dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//bool check(int n, int pos) {return (n & (1<<pos))>>pos;} //typecast 1 in case of int
//int  on(int n, int pos) {return n | (1<<pos);} //typecast 1 in case of int
//int  off(int n, int pos) {return n & ~(1<<pos);} //typecast 1 in case of int
//bool operator < (const data &d) const{return cost<d.cost;} //reverse in priority queue

const int M = 500010, mod = 1000000007;

int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("/home/lochness/Documents/in.txt", "r", stdin);
////    freopen("/home/lochness/Documents/in.txt", "w", stdout);
//#endif
//    ios_base::sync_with_stdio(false);

    LL n, A[1010];
    LL i, j, k;

    cin>>n;
    for (i = 0; i < n; i++) cin>>A[i];

    LL lcm = A[0];
    for (i = 1; i < n; i++)
    {
        LL gcd = __gcd(lcm, A[i]);
        lcm = lcm / gcd;
        lcm = lcm * A[i];
    }

    cout<<lcm<<endl;


    return 0;
}


Measured memory_bytes: 256
while True:
    interval,term_end, reexamination =map(int, input().split())
    if interval == -1 and term_end == -1 and reexamination == -1:
        break
    
    if interval == -1 or term_end == -1 or (interval + term_end < 30):
        print('F')
    elif 30 <= interval + term_end < 50:
        if reexamination >= 50:
            print('C')
        else:
            print('D')
    elif 50 <= interval + term_end < 65:
        print('C')
    elif 65 <= interval + term_end < 80:
        print('B')
    elif 80 <= interval + term_end:
        print('A')


Measured memory_bytes: 5596
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;
    if (a + b == 15) {
        std::cout << "+" << std::endl;
    } else if (a * b == 15) {
        std::cout << "*" << std::endl;
    } else {
        std::cout << "x" << std::endl;
    }
}

Measured memory_bytes: 888
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main(void){
    // Your code here!
    
  int N,K;
  int counter=0;
  cin >> N>>K;
  int height[N]; 
  
  REP(h,N) cin >> height[h];
 
  //B行の最後がnであった場合
  REP(k,N) if(height[k]>=K)counter++;
  //int f = arraySum(A, n);
  
  cout << counter;
    
}
    


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

int main(){
    int k;
    string s;
    while(cin>>k){
        cin >> s;
        if(k<s.size()){
            for (int i = 0; i < k;i++){
                cout << s[i];
            }
            cout << "..." << endl;
        }
        else
            cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main(){
  int n,a,b,A,B;
  while(1){
    cin>>n;
    if(n==0)break;
    A=B=0;
    for(int i=0;i<n;i++){
      cin>>a>>b;
      if(a>b){
	A+=a+b;
      }else if(a<b){
	B+=a+b;
      }else{
	A+=a;
	B+=b;
      }
    }
    cout<<A<<" "<<B<<endl;
  }
  return 0;
}

    

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long result;
		if ((B-A)%2==0) {
			System.out.println((B-A)/2);
		} else {
			long up,down,mid;
			up = A+(B-A)/2;
			down = N-B+1+(B-A)/2;
			if (B-A==1) {
				if(A>N-A) {
					System.out.println(N-A);
				} else {
					System.out.println(A);
				}
			} else {
				if (up>down) {
					System.out.println(down);
				} else {
					System.out.println(up);
				}
			}
		}
	}



}

Measured memory_bytes: 23764
n,m=map(int,input().split())

ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort(key=lambda x:x[0])

ans=0
now_b=0
for i in range(n):
    if(ab[i][1]+now_b<m):
        ans+=ab[i][0]*ab[i][1]
        now_b+=ab[i][1]
    else:
        ans+=ab[i][0]*(m-now_b)
        break
print(ans)

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

using namespace std;

int main()
{
	//
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s1, s2;
    cin>>s1>>s2;
    int l1=s1.size(), l2=s2.size();
    int dp[l1+1][l2+1];

    for(int i=0; i<=l1; i++){
    	for(int j=0; j<=l2; j++){
    		if(i==0 || j==0)
    			dp[i][j] = 0;
    		else{
    			if(s1[i-1] == s2[j-1])
    				dp[i][j] = dp[i-1][j-1] + 1;
    			else
    				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    		}
    	}
    }

    int len = dp[l1][l2];
    int i=l1, j=l2;

    string res = "";

    while(i>0 && j>0){
    	if(s1[i-1] == s2[j-1]){
    		res = s1[i-1] + res;
    		i--;
    		j--;
    		len--;
    	}
    	else if(dp[i-1][j]>dp[i][j-1])
    		i--;
    	else
    		j--;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 38864
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
DE = [0] * N
Q = [0]
while Q:
    i = Q.pop()
    for a in X[i][::-1]:
        if a != P[i]:
            P[a] = i
            DE[a] = DE[i] + 1
            X[a].remove(i)
            Q.append(a)

def lp(u, v):
    t = 0
    while u != v:
        if DE[u] > DE[v]:
            t += 1 << u-1
            u = P[u]
        elif DE[u] < DE[v]:
            t += 1 << v-1
            v = P[v]
        else:
            t += 1 << u-1
            t += 1 << v-1
            u = P[u]
            v = P[v]
    
    return t

Y = []
M = int(input())
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    Y.append(lp(a, b))

D = {1<<i: i for i in range(50)}
Z = [0] * (1<<M)
ans = 0
CC = [0] * N
BC = [0] * (1<<20)
for m in range(1, 1<<20):
    a = m & (-m)
    BC[m] = BC[m^a] + 1
for m in range(1<<M):
    a = m & (-m)
    if a == m:
        if a == 0:
            Z[m] = 0
        else:
            Z[m] = Y[D[a]]
    else:
        Z[m] = Z[m^a] | Y[D[a]]
    
    aa = Z[m]
    bc = BC[aa % (1<<10)]
    aa >>= 10
    bc += BC[aa % (1<<20)]
    aa >>= 20
    bc += BC[aa]
    CC[N - 1 - bc] += (1 if BC[m] % 2 == 0 else -1)

print(sum([2 ** i * CC[i] for i in range(N)]))

Measured memory_bytes: 56668
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    // 偶数からスタートすると3+4n番目に0にリセットされる様子
    // 奇数からスタートすると4n番目に元の数に戻る様子
    ll A, B;
    cin >> A >> B;
    ll p;
    ll ans;
    if (A % 2 == 0) {
        ans = 0;
        p = B - (B-A)%4;
    }else{
        ans = A;
        p = B - (B-A)%4 + 1;
    }
    for (ll i=p;i<=B;i++){
        ans = ans^i;
    }
    cout << ans << endl;
}



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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    double ans = 0;

    rep(i, 1, n + 1)
    {
        double cnt = 1.0 / n;
        int next = i;
        while (next < k)
        {
            next *= 2;
            cnt /= 2;
        }
        ans += cnt;
    }

    cout << Fixed(10) << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
import math
def angle(i1, j1, i2, j2, i3, j3) :
    a = math.sqrt((i1-i2)**2 + (j1-j2)**2)
    b = math.sqrt((i2-i3)**2 + (j2-j3)**2)
    c = math.sqrt((i3-i1)**2 + (j3-j1)**2)
    z = (a+b+c) / 2
    S = math.sqrt(z * (z-a) * (z-b) * (z-c))
    return S

ans = 0
x1, y1 = map(float, input().split(","))
x2, y2 = map(float, input().split(","))
while True :
    try :
        x3, y3 = map(float, input().split(","))
    except EOFError :
        break
    
    ans += angle(x1, y1, x2, y2, x3, y3)
    x2 = x3
    y2 = y3
    
print('{:.6f}'.format(ans))
    


Measured memory_bytes: 5660
#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 x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    rep(i,x)cin>>a[i];sort(a.rbegin(),a.rend());
    rep(i,y)cin>>b[i];sort(b.rbegin(),b.rend());
    rep(i,z)cin>>c[i];sort(c.rbegin(),c.rend());
    vector<ll> comb;
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y ; j++){
            comb.push_back(a[i]+b[j]);
        }
    }
    sort(comb.rbegin(),comb.rend());
    vector<ll> res;
    int yk = min(k,y);
    int comk = min(k,(int)comb.size());
    for(int i = 0; i < comk ; i++){
        for(int j = 0; j < yk ; j++){
            res.push_back(comb[i]+c[j]);
        }
    }
    sort(res.rbegin(),res.rend());
    rep(i,k){
        cout << res[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 43368
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        
        StringBuilder sb = new StringBuilder();
        sb.append(" ");
        //整数1～nのの値を確認
        for(int i=1; i<=n; i++){
            //iが3の倍数の場合(を3で割った余りが0)、または3を含む場合
            if(i%3 == 0 || Integer.toString(i).contains("3")){
                sb.append(i);
                sb.append(" ");
            }
        }
        //最後の空白削除
        sb.deleteCharAt(sb.lastIndexOf(" "));
        
        System.out.println(sb);
        

    }

}



Measured memory_bytes: 27596
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll a,b;
    cin >> a >> b;
    ll p1,p2,i;
    // p1 = (100*a)/8;
    // p2 = (b*10);
    //cout << p1 << ' ' << p2 << "\n";
    ll ans = INT_MAX;
    
    //cout << x << ' ' << y << ' ' << z << ' ' << w << "\n";
    for(i=1;i<=12500;i++) {
    	ll x = (i*8)/100;
	    ll y=i/10;
	    //cout << x << ' ' << y << "\n";
	    if((x == a) && (y==b)) {
	    	ans = i;
	    	break;
	    }
    }
    
    //if((z == a) && (w == b)) ans = min(ans,p2);
    if(ans == INT_MAX) ans = -1;
    cout << ans;
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int cou = 0;
    for(int i=a; i<=b; i++) {
    		if(i/10000 == i%10) {
    			if(i/1000-i/10000*10 == (i%100)/10) {
    			cou++;
    		}
    }
    }
    System.out.println(cou);
    		}
}

Measured memory_bytes: 35612
#include<stdio.h>
#include<algorithm>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,k,x[110000],r,ans,te;
int main(){
	scanf("%d%d",&n,&k);
	ans=0x7fffffff;
	fo(i,1,n) scanf("%d",&x[i]);
	fo(l,1,n-k+1){
		r=l+k-1;
		if ((x[l]>=0)^(x[r]>=0)) te=-x[l]+x[r]+min(-x[l],x[r]);else te=max(abs(x[l]),abs(x[r]));
		if (te<ans) ans=te;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;

int main(){
  LL N,P;
  cin>> N>>P;
  for(LL i=pow(P,1.0/N)+1;i>=1;i--){
    if(P%LL(pow(i,N))==0){
      cout << i << endl;
      return 0;
    }
  }
  
  cout << 1<< endl;
  
  
  


}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[214514];
int main(){
	ll n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i>k){
			if(a[i]>a[i-k])cout<<"Yes\n";
			else cout<<"No\n";
		}
	}
	return 0;
}


Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
L n,y,m,d;

void solve(){
    L day=1,py;
    for(L i=y+1;i<1000;i++){
        if(i%3)day+=195;
        else day+=200;
    }
    if(y%3==0){
        L rm=(10-m),rd=20-d;
        day+=(rm*20)+rd;
    }
    else{
        if(m%2)day+=(20-d);
        else day+=(19-d);
        for(L j=m+1;j<=10;j++){
            if(j%2)day+=20;
            else day+=19;
        }
    }
    printf("%lld\n",day);
}
int main()
{
    scanf("%lld",&n);
    for(L i=0;i<n;i++){
        scanf("%lld%lld%lld",&y,&m,&d);
        solve();
    }

    return 0;
}



Measured memory_bytes: 3228
import math

A, B = map(int, input().split())

# 試し割り法(2以外の偶数は捨てる方法を追加)
def check_prime(n):
    flag = True

    # n:evenかつ2でないならば素数でない
    # n=1は素数でない,n=0も実装しやすいように入れておく
    if (n % 2 == 0 and n != 2) or n == 0 or n == 1:
        flag = False
        return(flag)

    # n:oddまたは2のときは考える
    else:
        # 2からrootnまでに約数は存在しうる
        for i in range(2, math.floor(math.sqrt(n))+1):
            if n % i == 0:
                flag = False
                break
        return(flag)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)
    # divisors.sort()
    return divisors

div = make_divisors(min(A, B))

div2 = []
for n in div:
    if check_prime(n):
        div2.append(n)

cnt = 1
for n in div2:
    if max(A, B) % n == 0:
        cnt += 1

print(cnt)



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

#define MAX 10000009
#define INF 99999999
#define MIN -99999999
#define in(a,b)  ( (b).find(a) != (b).end())
#define clr(a,b) memset((a), (b), sizeof((a)))
#define pb       push_back
#define all(a)   a.begin(), a.end()
#define mp       make_pair
#define ll	long long
#define FI	first
#define SE second


using namespace std;
string s;
int main() {
    
    cin >> s;
    int r=0;
    for(int i=0; i<s.length(); i++){
        r += s[i] - '0';
    }
    if( stoi(s) % r == 0 ) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
# r:"グー" p:"パー" s:"チョキ"
# p , s , r

pat = {"r":p, "p":s, "s":r, "":0}
hands = [""]*n
ans = 0
for i in range(n):
  if i < k or hands[i-k] != t[i]:
    hands[i] = t[i]
    ans += pat[t[i]]
    
print(ans)
    

Measured memory_bytes: 4792
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include<climits>
using namespace std;
int N, A, B;
string s;
int main()
{
	cin>>N>>A>>B>>s;
	int cnt = 0, bcnt = 0;
	for(int i = 0; i < N; i++) {
     if(s[i] == 'c') cout<<"No"<<endl;
     else if(s[i] == 'a') {
        if(cnt < A + B) {
            cnt++;
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
     }
     else {
        if(cnt < A + B && (bcnt == 0 || bcnt <= B - 1)) {
            cnt++;
            bcnt++;
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
     }
	}
	return 0;
}


Measured memory_bytes: 896
# https://atcoder.jp/contests/abc162/tasks/abc162_d

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    S = input()
    r = set()
    g = set()
    b = set()
    for i in range(n):
        if S[i] == "R":
            r.add(i)
        elif S[i] == "G":
            g.add(i)
        else:
            b.add(i)
    cnt = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            s1 = S[i]
            s2 = S[j]
            k = j + (j - i)
            if k > n - 1:
                break
            s3 = S[k]
            if s1 != s2 and s2 != s3 and s3 != s1:
                cnt += 1
    ans = (len(r) * len(g) * len(b)) - cnt
    print(ans)
    return


if __name__ == "__main__":
    main()


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

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

Measured memory_bytes: 256
N,K = map(int,input().split())
p = list(map(int,input().split()))
ans = 0
total = sum(p[:K])
anss = total
for i in range(N-K):
    total -= p[i]
    total += p[i+K]
    anss = max(anss,total)
print((anss+K)/2)

Measured memory_bytes: 71792
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <map>

#define MOD 1000000007

using namespace std;

long long int pow2(int k){
 long long int a = 1;
 while(k>0){
   a*=2;
   a%=MOD;
   k--;
 }
 return a;
}

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

  map<pair<long long int, long long int>, pair<int, int> > gcdMap;
  int z=0;
  for(int i=0;i<N;i++){
    long long int A,B;
    cin >> A >> B;
    if(A==0&&B==0){
      z++;
      continue;
    }else if(A==0){
      B = 1;
    }else if(B==0){
      A = 1;
    }else{
      auto d = __gcd(A,B);
      A/=d;
      B/=d;
      if(B<0){
      	A*=-1;
        B*=-1;
      }
    }
    if(A>0) {
      gcdMap[make_pair(A,B)].first++;
    }else{
      gcdMap[make_pair(B,-1*A)].second++;
    }
  }

  long long int answer=1;
  for(auto p : gcdMap){
  	auto p2=p.second;
    answer*=pow2(p2.first)+pow2(p2.second)-1;
    answer%=MOD;
  }
  cout << (answer+z-1+MOD)%MOD << endl;

}


Measured memory_bytes: 16056
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9;
const int MOD=1e9+7;
const int MAXN=2e3+7;

int ans=0;
int n,m,k,q,x,y;
vector<int> e[MAXN];
int visLvl=0;
int vis[MAXN];
int d[MAXN];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>x>>y;
    FORE(i,2,n){
        e[i].PB(i-1);
        e[i-1].PB(i);
    }
    e[x].PB(y);
    e[y].PB(x);
    FORE(i,1,n){
        queue<pii> Q;
        Q.push({i,0});
        ++visLvl;
        vis[i]=visLvl;
        while(!Q.empty()){
            pii v=Q.front();
            Q.pop();
            d[v.ND]++;
            for(int w:e[v.ST]){
                if(vis[w]<visLvl){
                    vis[w]=visLvl;
                    Q.push({w,v.ND+1});
                }
            }
        }
    }
    FOR(i,1,n){
        cout<<d[i]/2<<"\n";
    }
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    if (b-a == c-b) {
        YES;
    } else {
        NO;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

    string s; cin>>s;
    int n = s.size();
    deque<char> deq;
    for(int i=0; i<n; i++){
        deq.emplace_back(s[i]);
    }

    int q; cin>>q;
    bool rev = false;
    while(q--){
        int x; cin>>x;
        if(x == 1){
            if(!rev) rev = true;
            else rev = false;
        }
        else{
            int f; cin>>f;
            char c; cin>>c;
            if(f == 1){
                if(!rev) deq.emplace_front(c);
                else deq.emplace_back(c);
            }
            else{
                if(!rev) deq.emplace_back(c);
                else deq.emplace_front(c);
            }
        }
    }

    string ans = "";
    for(auto i : deq) ans += i;
    
    if(!rev){
        cout << ans << endl;
    }
    else{
        reverse(ans.begin(), ans.end());
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1368
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M=map(int,input().split())
     
UF=UnionFind(N)

for i in range(M):
  a,b=map(int,input().split())
  UF.union(a-1,b-1)

print(max([-i for i in UF.parents]))


Measured memory_bytes: 22540
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ios::sync_with_stdio(false);
  int r,c;
  cin >> r >> c;
  vii data(r,vi(c));
  int ans = 0;
  rep(i,r) {
      rep(j,c) {
          cin >> data[i][j];
          ans += data[i][j];
      }
  }
  rep(i,r) {
      int sum = 0;
      rep(j,c) {
          cout << data[i][j] << " ";
          sum += data[i][j];
      }
      cout << sum << "\n";
  }
  rep(i,c) {
      int sum = 0;
      rep(j,r) {
          sum += data[j][i];
      }
      cout << sum << " ";
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3184
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  if(n==0)cout<<1<<endl;
  else if(n==1)cout<<2<<endl;
  else if(n==2)cout<<1<<endl;
  else cout<<0<<endl;
  
}


Measured memory_bytes: 3164
use proconio::input;
 
fn main() {
    input! {
        n: i64
    }
  	let mut ac = 0;
  	let mut wa = 0;
  	let mut tle = 0;
  	let mut re = 0;
  
  	for _ in 0..n {
  		input! {
      		val: String
      	}
      	match val.as_str() {
      		"AC" => ac += 1,
          	"WA" => wa += 1,
          	"TLE" => tle += 1,
          	"RE" => re += 1,
          	_ => panic!("{} should not be come", val)
      	};
  	}
  	println!("AC x {}", ac);
  	println!("WA x {}", wa);
   	println!("TLE x {}", tle);
  	println!("RE x {}", re);
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int aa = a * 60 + b;
    int cc = c * 60 + d;
    int all = cc - aa - e;
    cout << all << endl;

    return 0;
}

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

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'

const int maxn=2e5+10;

int n;
pii a[maxn];
int r[maxn];
int mx[maxn][20];
int f[maxn];
int l0g[maxn];

int query(int x,int y) {
	int tmp=l0g[y-x+1];
	return max(mx[x][tmp],mx[y-(1<<tmp)+1][tmp]);
}

int main(){
	l0g[1]=0;
	for (int i=2;i<maxn;i++) l0g[i]=l0g[i/2]+1;
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d%d",&a[i].fi,&a[i].se);
	sort(a,a+n);
	f[n]=1;
	for (int i=n-1;i>=0;i--) {
		int x=lower_bound(a,a+n,MP(a[i].fi+a[i].se,0))-a-1;
		if (x>i) r[i]=query(i+1,x);
		else r[i]=i+1;
		mx[i][0]=r[i];
		for (int j=1;i+(1<<j)<=n;j++) mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
	}
	for (int i=n-1;i>=0;i--) {
		f[i]=(f[i+1]+f[r[i]])%mod;;
	}
	printf("%d",f[0]);
	return 0;
}


Measured memory_bytes: 19840
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

distance :: Int -> Int -> Int -> Int
distance k from to =
        if from > to then to + k - from
        else to - from

solve :: Int -> [Int] -> Int
solve n hs = let
    heightList = IM.fromList $ zip [1..] hs
    ansList = IM.fromList [(1, 0), (2, abs (heightList IM.! 2 - heightList IM.! 1))]
    getPoint to from m = m IM.! from + abs (heightList IM.! from - heightList IM.! to)
    getAns h m = min (getPoint h (h - 2) m) (getPoint h (h - 1) m)
    ansList' = foldl' (\b a -> IM.insert a (getAns a b) b) ansList [3..n]
    in
    ansList' IM.! n
    

main = do
    n <- readInt
    hs <- readInts
    print $ solve n hs





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

int main(){
  int N,M;
  cin >> N;
  vector<string> s(N);
  rep(i,N)
    cin >> s.at(i);
  cin >> M;
  vector<string> t(M);
  rep(i,M)
    cin >> t.at(i);
  vector<int> sum(N);
  
  rep(i,N){
    rep(j,N){
      if(s.at(i)==s.at(j))
        sum.at(i)++;
    } 
    rep(j,M){
      if(s.at(i)==t.at(j))
        sum.at(i)--;
    }
  }

  int result = sum.at(0);

  rep(i,N){
    if(result<sum.at(i))
      result = sum.at(i);
  }
  
  if(result<=0)
    cout << 0 << endl;
  else
    cout << result << endl;
    
  
  
  
  
  
    
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;

void solve() {
    set < ll > st;
    st.clear();
    ll n, k, i, j, l;
    cin>>n>>k;
    fo(i,k) {
        cin>>j;
        fo(l,j) {
            ll p;cin>>p;
            st.insert(p);
        }
    }
    cout<<n-(ll)st.size();
}   

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int n, a[50];

int solve(int i, int m) {
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res;
}
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int q, m[2000];
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> m[i];
        if (solve(0, m[i])) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int main(){
	boost;
	string a,b;
	cin>>a>>b;
	vv vec(26);
	for (int i = 0; i < sz(a); ++i)
		vec[a[i]-'a'].pb(i);
	for (int i = 0; i < sz(b); ++i)
		if(vec[b[i]-'a'].empty()){cout<<-1;return 0;}
	int idx=0,c=0;
	for (int i = 0; i < sz(b); ++i)
	{
		int s=lower_bound(all(vec[b[i]-'a']),idx)-vec[b[i]-'a'].begin();
		if(s==sz(vec[b[i]-'a']))c++,idx=vec[b[i]-'a'][0]+1;
		else{ 
			idx=vec[b[i]-'a'][s]+1;
			if(s==sz(a))s=0,c++;
		}
	}
	cout<<c*sz(a)+idx;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 1228
open System
open System.Collections.Generic
open System.Linq
open System

let Puts = Console.WriteLine : 'a -> unit
let Reads () = Console.ReadLine().Split()
let ReadDouble () = Reads() |> (fun x -> x.[0], x.[1])
let ReadTriple () = Reads() |> (fun x -> x.[0], x.[1], x.[2])
let ReadQuadruple () = Reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])

let FuncDouble f1 f2 (t1, t2) = (f1 t1, f2 t2)
let FuncTriple f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let FuncQuadruple f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)

let ReadIntDouble () = ReadDouble () |> FuncDouble int int

let ensmallen l = l % 1000000007L

let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)


let (n, m) = ReadIntDouble ()

// main code

let students = seq { for _ in 1..n -> ReadIntDouble () } |> List.ofSeq
let checkPoint = seq { for _ in 1..m -> ReadIntDouble () } |> List.ofSeq

for student in students do
    checkPoint
        |> Seq.mapi (fun i v -> i + 1, manhattan v student)
        |> Seq.minBy snd
        |> fst
        |> Console.WriteLine


Measured memory_bytes: 13524
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 3e3+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
char str1[maxn],str2[maxn];
int dp[maxn][maxn];
pii pre[maxn][maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    scanf("%s%s",str1+1,str2+1);
    int len1=strlen(str1+1);
    int len2=strlen(str2+1);
    for(int i=1;i<=len1;i++)
    {
        for(int j=1;j<=len2;j++)
        {
            if(str1[i]==str2[j])
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                pre[i][j]=pii(i-1,j-1);
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                if(dp[i-1][j]>dp[i][j-1]) pre[i][j]=pii(i-1,j);
                else pre[i][j]=pii(i,j-1);
            }
        }
    }
    string ans="";
    pii tmp=pii(len1,len2);
    while(ans.length()<dp[len1][len2])
    {
        if(str1[tmp.Fi]==str2[tmp.Se]) ans=ans+str1[tmp.Fi];
        tmp=pre[tmp.Fi][tmp.Se];
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 105984
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val d = sc.nextInt()
    println(problem083a(a, b, c, d))
}

fun problem083a(a: Int, b: Int, c: Int, d: Int): String {
    return when {
        a + b > c + d -> "Left"
        a + b < c + d -> "Right"
        else -> "Balanced"
    }
}

Measured memory_bytes: 29472
#include <bits/stdc++.h>
using namespace std;
int N,cnt;
pair<int,int> A[111111];
set<pair<int,int>>B;
// in: n, m, graph
// out: match, matched
// vertex cover: (reached[0][left_node] == 0) || (reached[1][right_node] == 1)
// O(E*sqrt(V))
struct BipartiteMatching {
    int n, m;
    vector<vector<int>> graph;
    vector<int> matched, match, edgeview, level;
    vector<int> reached[2];
    BipartiteMatching(int n, int m) : n(n), m(m), graph(n), matched(m, -1), match(n, -1) {}

    bool assignLevel() {
        bool reachable = false;
        level.assign(n, -1);
        reached[0].assign(n, 0);
        reached[1].assign(m, 0);
        queue<int> q;
        for (int i = 0; i < n; i++) {
            if (match[i] == -1) {
                level[i] = 0;
                reached[0][i] = 1;
                q.push(i);
            }
        }
        while (!q.empty()) {
            auto cur = q.front(); q.pop();
            for (auto adj : graph[cur]) {
                reached[1][adj] = 1;
                auto next = matched[adj];
                if (next == -1) {
                    reachable = true;
                }
                else if (level[next] == -1) {
                    level[next] = level[cur] + 1;
                    reached[0][next] = 1;
                    q.push(next);
                }
            }
        }
        return reachable;
    }

    int findpath(int nod) {
        for (int &i = edgeview[nod]; i < graph[nod].size(); i++) {
            int adj = graph[nod][i];
            int next = matched[adj];
            if (next >= 0 && level[next] != level[nod] + 1) continue;
            if (next == -1 || findpath(next)) {
                match[nod] = adj;
                matched[adj] = nod;
                return 1;
            }
        }
        return 0;
    }

    int solve() {
        int ans = 0;
        while (assignLevel()) {
            edgeview.assign(n, 0);
            for (int i = 0; i < n; i++)
                if (match[i] == -1)
                    ans += findpath(i);
        }
        return ans;
    }
};
int main(){
    cin>>N;
    BipartiteMatching bm(N,N);
    for(int i=0;i<N;i++)cin>>A[i].first>>A[i].second;
    for(int i=0;i<N;i++){
        int x,y;
        cin>>x>>y;
        for(int j=0;j<N;j++){
            if(x>A[j].first && y>A[j].second){
                bm.graph[i].push_back(j);
            }
        }
    }
    cout<<bm.solve()<<'\n';
}


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

int main(){
        int N;
        int t[110];
        int M;
        int sum = 0;
        int p[110],x[110];
        cin >> N;
        rep(i,N){
                cin >> t[i];
                sum += t[i];
        }
        cin >> M;
        rep(i,M) cin >> p[i] >> x[i];
        rep(i,M) cout << sum - (t[p[i]-1] - x[i]) << endl;
        return 0;
}


Measured memory_bytes: 256
program sample
    implicit none
    
    integer(8) :: i,j,m,n,a,b,c,d,dis,p,q,ma
    integer(8),allocatable :: x(:),y(:),indy(:),ans(:)
  
    read(*,*) n,m
    if(n*100<m)then
        write(*,*)'0'
        stop
    end if
    a=m/2
    allocate(x(n),y(0:a),indy(0:a),ans(n))
    read(*,*)x
    call msort(x)
    ans(:)=x(:)
    y(:)=0
    q=0  !キューの要素数-1

    y(0)=x(n)
    indy(0)=n
    do i=1,m
        ma=0
        do j=0,q !キューでの最大値とその場所
            if(y(j)>ma)then
                ma=y(j)
                b=j
            end if
        end do
        a=indy(b)
        ans(a)=x(a)/2**(b+1)
        if(y(b+1)==0)then
            y(b+1)=ans(a)
        end if
        if(a>1)then
            indy(b)=a-1
            y(b)=x(a-1)/2**b
        else
            indy(b)=0
            y(b)=0
        end if
        if(b>1)then
            if(indy(b)==indy(b-1))then
                y(b)=0
            end if
        end if
        if(b==q)then
            q=q+1
            y(q)=x(n)/2**q
            indy(q)=n
        end if
    end do
    write(*,*)sum(ans)
   


    
    stop
    contains
    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program sample
  



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

int n;
int a[100005];

int main(){
	cin >> n;
	int ans = 0;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		a[tmp] += 1;
		a[tmp - 1] += 1;
		a[tmp + 1] += 1;
		ans = max(ans, a[tmp]);
		ans = max(ans, a[tmp+1]);
		ans = max(ans, a[tmp-1]);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"4
2 3 7 9"# => r#"7"#,

r#"8
3 1 4 1 5 9 2 6"# => r#"8"#,

r#"1
3"# => r#"0"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        mut a: [usize; n],
    }
    a.sort();
    a.dedup();

    (a[a.len() - 1] - a[0]).to_string()
}

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

using namespace std;

const int maxn=1e5+5;

typedef long long ll;



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>m>>n;
	for(int i=n-m+1;i<n;i++){
		cout<<i<<' ';
	}
	for(int i=n;i<n+m;i++){
		cout<<i<<' ';
	}
	return 0;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount
bool S, E, N, W;

int main () {
	string s;
	cin >> s;
	for (int i = 0; i < (int) s.length(); i ++) {
		if (s[i] == 'S') S = 1;
		if (s[i] == 'E') E = 1;
		if (s[i] == 'N') N = 1;
		if (s[i] == 'W') W = 1;
	}
	if ((S^N) || (E^W)) puts ("No");
	else puts ("Yes");
	return 0;
}

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

int main()
{
    string cmd;
    int key;
    priority_queue<int> PQ;

    while (cin >> cmd)
    {
        if (cmd == "insert")
        {
            cin >> key;
            PQ.push(key);
        }
        else if(cmd == "extract")
        {
            key = PQ.top();
            PQ.pop();
            cout << key << endl;
        }
        else
        {
            break;
        }
    }
    return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> h(n);
	for(int i=0; i<n; i++){
		cin >> h[i];
	}
	vector<bool> ans(n, true);
	for(int i=0; i<m; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		if(h[a] <= h[b]){
			ans[a] = false;
		}
		if(h[b] <= h[a]){
			ans[b] = false;
		}
	}
	int cnt = 0;
	for(int i=0; i<n; i++){
		if(ans[i]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3784
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);  


    int K,X;
    cin>>K>>X;

    int h = X+K;
    int l = X-K;

    for(ll i = l+1;i<h;i++)
        cout<<i<<" ";

    return 0;
}

Measured memory_bytes: 256