akhauriyash/Code-Regression huggingface dataset:
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust";
    else cout<<"win";
}

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

using namespace std;

int main(){
	int n, ans = 0;
	double ave = 0, t;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		ave += a[i];
	}
	ave /= n;
	t = abs(ave - a[0]);
	for(int i = 1; i < n; i++){
		if(t > abs(ave - a[i])){
			t = abs(ave - a[i]);
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if (a<b){
		printf("a < b\n");
	}else if (a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	} 

	return 0;
}


Measured memory_bytes: 2056
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 c = sc.nextInt();
		int x = sc.nextInt();
		int sum = 0;
		int count = 0;
		
		for (int i = 0; i <= a; i++) {
			
			for (int j = 0; j <= b; j++) {
				
				for (int j2 = 0; j2 <= c; j2++) {
					sum = (500 * i) + (100 * j) + (50 * j2);
					
					if(x == sum) {
						count ++;
					}
					
				}
				
			}
			
		}
		
		System.out.println(count);
	}

}

Measured memory_bytes: 27048
import copy
n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)
cant = True
if a == a_sorted:
	print("YES")
	quit()
for i in range(n):
	for j in range(n):
		a_c = copy.copy(a)
		if i >= j:
			continue
		a_c[i],a_c[j] = a_c[j],a_c[i]
		if a_c == a_sorted:
			cant = False
if cant:
	print("NO")
else:
	print("YES")

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define int long long
const double eps = 1e-9;

int n,k,x,y;

int32_t main()
{
	cin >> n >> k >> x >> y;
	if(n <= k)
		cout << n*x << '\n';
	else
		cout << k*x + (n-k)*y << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
     int n; cin >> n;
     bool ans = false;
     for(int i = 0; i < n; i++){
          char a; cin >> a;
          if(a == 'Y') ans = true;
     }
     if(ans) cout << "Four" << endl;
     else cout << "Three" << endl;
}

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

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert 
#define mp make_pair
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define ft front() 
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define deb(x) cout<<#x<<" "<<x<<'\n';
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18; 
const ld pie = acos((ld)-1);

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



int main(){

	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    
	string s;
	cin>>s;
	int cnt=0;
	rep(i,0,3) if(s[i]=='R') cnt++;
	if(s[0]=='R'&&s[1]=='R'&&s[2]=='R'){
		cout<<3<<'\n';
	}else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R')){
		cout<<2<<'\n';
	}else if(cnt==0){
		cout<<0<<'\n';
	}else{
		cout<<1<<'\n';
	}


	return 0;

	/*STUFF TO LOOK:	
		1. Input ranges
		2. corner cases(n==0||n==1)
		3. Variables in loops
	*/
}


Measured memory_bytes: 3648
fun main(args: Array<String>){
    val (n, k, c) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!.toList()

    var si = 0
    val l = mutableListOf<Int>()
    while(l.size != k){
        if (s[si] == 'x'){
            si += 1
        }else{
            l.add(si)
            si += (c + 1)
        }
    }

    si = s.size - 1
    val r = mutableListOf<Int>()
    while(r.size != k){
        if (s[si] == 'x'){
            si -= 1
        }else{
            r.add(si)
            si -= (c + 1)
        }
    }
    r.reverse()

    for (i in 0 until l.size){
        if(l[i] == r[i]){
            println(l[i]+1)
        }
    }
}

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

int main(){
  
  int n,h,w,m;
  scanf("%d %d %d",&n,&h,&w);
  
  m=(n-h+1)*(n-w+1);
  
  printf("%d",m);
  
  
}

Measured memory_bytes: 128
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=0
for i in range(N-1):
    if a[i]+a[i+1]>x:
        if a[i]<=x:
            b+=a[i+1]-(x-a[i])
            a[i+1]=x-a[i]
        if a[i]>x:
            b+=a[i]-x+a[i+1]
            a[i]=x
            a[i+1]=0
print(b)

Measured memory_bytes: 14252
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        while(true){
            int h = scan.nextInt();
            int w = scan.nextInt();
            if(h == 0 && w == 0) break;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
        scan.close();
    }
}


Measured memory_bytes: 65624
N, M = map(int, input().split())
A_B = []
for _ in range(N):
    a, b = map(int, input().split())
    A_B.append([a, b])

A_B.sort(key=lambda x: x[0])
tmp = 0
ans = 0
for a, b in A_B:
    if tmp + b >= M:
        ans += a * (M - tmp)
        break
    ans += a * b
    tmp += b
print(ans)

Measured memory_bytes: 21208
#include<bits/stdc++.h>
using namespace std;
long long KnapSack(long long wt[], long long val[], long long w, long long n){
    long long table[n+1][w+1];
    for(long long i = 0; i<=n; i++)
        for(long long j = 0; j<=w; j++)
            if(i == 0 || j == 0)
                table[i][j] = 0;


    for(long long i = 1; i<=n; i++){
        for(long long j = 1; j<=w; j++){
            if(wt[i-1] <= j)
                table[i][j] = max(val[i-1] + table[i-1][j-wt[i-1]], table[i-1][j]);
            else 
                table[i][j] = table[i-1][j];
        }
    }
    return table[n][w];
}
int main(){
    long long n;
    long long w;
    cin>>n;
    cin>>w;
    long long wt[n];
    long long val[n];
    for(long long i = 0; i<n; i++){
        cin>>wt[i]>>val[i];
    }
    cout<<KnapSack(wt, val, w, n)<<"\n";    
}

Measured memory_bytes: 82464
fun main(args: Array<String>) {
    val (N, A, B) = readLine()!!.split(" ").map { it.toLong() }

    data class Point(var a: Long, var b: Long) {
        private var move = 0L
        fun isEvenDiff(): Boolean = (a - b) % 2 == 0L
        fun halfRange(): Long = move + Math.abs(a - b) / 2
        fun move() {
            if (a < b) {
                move = a
                a = 1
                b -= move
            } else {
                move = b
                b = 1
                a -= move
            }
        }
    }


    val list = arrayOf(Point(A, B), Point(1 + N - A, 1 + N - B))
    var ans = N

    list.forEach { p ->
        //        println(p)
        if (p.isEvenDiff()) {
            ans = Math.min(ans, p.halfRange())
        } else {
            p.move()
            //           println(p)
            ans = Math.min(ans, p.halfRange())
        }
    }
    println(ans)
}


Measured memory_bytes: 37560
(defun judge (k)
  (if (or
       (<= 1 k 9)
       (<= 100 k 999)
       (<= 10000 k 99999))
      t
      nil))
(defun range (n)
  (loop for i from 1 to n
        collect i))


(defun solve (n)
  (princ (length
          (remove-if-not #'judge (range n)))))

(solve (read))

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    A += B;C += D;
    if(A == C) cout << "Balanced" << "\n";
    else if(A > C) cout << "Left" << "\n";
    else cout << "Right" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	if(n>=400 and n <= 599) cout<<8<<endl;
	if(n>=600 and n <= 799) cout<<7<<endl;
	if(n>=800 and n <= 999) cout<<6<<endl;
	if(n>=1000 and n <= 1199) cout<<5<<endl;
	if(n>=1200 and n <= 1399) cout<<4<<endl;
	if(n>=1400 and n <= 1599) cout<<3<<endl;
	if(n>=1600 and n <= 1799) cout<<2<<endl;
	if(n>=1800 and n <= 1999) cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 3676
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    N = I()
    S = SI()
    Q = I()
    K = LI()
    ans = []
    for k in K:
        D = 0; M = 0; C = 0
        now = 0
        for i in range(N):
            s = S[i]
            if s == "D":
                D += 1
            elif s == "M":
                M += 1
                now += D
            elif s == "C":
                C += now
            if i>=k-1:
                if S[i-k+1] == "D":
                    D -= 1
                    now -= M
                elif S[i-k+1] == "M":
                    M -= 1
#        print(D, M, C)
#        ans.append(C)
        print(C)
#    for v in ans:
#        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Measured memory_bytes: 86092
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>; //pop_back pop_front push_back push_front front back clear empty
using L = vector<long long>;
using M = map<int,long long>;  //erase  (でキーごと削除) 追加削除検索O(log(N))
using A = vector<vector<long long>>;
using P = priority_queue<long long>; //erase  (でキーごと削除)
using U = unordered_map<int,long long>; //map  (との違いはkeyの順番を保持していない)

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vdel(vector,a) vector.erase(vector.begin()+a)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define inf 1000000000000000000+10

template <typename T>
void print(T a){for (auto b:a){cout<<b<<" ";};cout<<endl;}
template <>
void print(unsigned long a){cout<<a<<endl;}
template <>
void print(char a){cout<<a<<endl;}
template <>
void print(bool a){cout<<a<<endl;}
template <>
void print(long long a){cout<<a<<endl;}
template <>
void print(A a){for (auto b:a){for (auto c:b){cout<<c<<" ";}cout<<endl;};cout<<endl;}
template <>
void print(string a){cout<<a<<endl;}


//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ
//printf("%.16f", ans); 誤差落ち対応君


int main(){
    long long n,m,tmp1,tmp2;
    unordered_map<long long ,L> u;
    cin>>n>>m;
    for(long long i=0  ;i<n  ;i++){
        cin>>tmp1>>tmp2;
        u[tmp1].push_back(tmp2);
    }
    
    priority_queue<long long> pq;
    
    long long ans=0;
    long long tmp;
    for(long long i=0  ;i<m+1  ;i++){
        if (u[i].size()){
            for(auto x:u[i]){
                pq.push(x);
            }
        }
        if (!pq.empty()){
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 8868
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


a,b,c = mi()
iti =  c - a -b
if iti <= 0:
    print("No")
    exit()
hidari = a*b*4
migi = (iti)**2
if (hidari < migi):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38480
(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  var N = Number(p.shift());
  var count = 0;
  while (count++ < N) {
    var n1 = p.shift();
    var n2 = p.shift();
    if (n1.length > 80 || n2.length > 80) {
      console.log('overflow');
      continue;
    }
    var n = sum(n1, n2);
    if (n.length > 80) {
      console.log('overflow');
      continue;
    }
    console.log('%s', n);
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function sum(n1, n2) {
  var a, b;
  if (n1.length > n2.length) {
    a = n1.split('').map(Number).reverse();
    b = n2.split('').map(Number).reverse();
  } else {
    b = n1.split('').map(Number).reverse();
    a = n2.split('').map(Number).reverse();
  }

  for (var i = 0; i < b.length; i++) {
    a[i] += b[i];
  }

  for (var i = 0; i < a.length - 1; i++) {
    if (a[i] >= 10) {
      var m = Math.floor(a[i] / 10);
      a[i] = a[i] % 10;
      a[i + 1] += m;
    }
  }

  return a.reverse().join('');
}

Measured memory_bytes: 7644
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 200010;
LL a[N],s1[N],b[N],s2[N];
int n,m,k;

int find(int x)
{
    int res = 0;
    int l = 0,r = m;
    while(l<r)
    {
        int mid = l + r + 1 >> 1;
        if(s2[mid] <= x) l = mid;
        else r = mid - 1;
    }
    return l;
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]),s1[i] = a[i] + s1[i-1];
    for(int i=1;i<=m;i++) scanf("%lld",&b[i]),s2[i] = b[i] + s2[i-1];
    
    int res = 0;
    for(int i=0;i<=n && s1[i] <= k;i++) res = max(res,i+find(k-s1[i]));
    cout << res << endl;
    return 0;
}

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

using namespace std;

using i64 = int64_t;

signed main(){
    i64 a, n, m;
    cin >> a >> n >> m;
    i64 ans = 0;
    for(i64 y = 1;; ++y){
        i64 val = 1;
        bool fl = true;
        for(i64 j = 0; j < n; ++j){
            val *= y + a;
            if(val > m){
                fl = false;
                break;
            }
        }
        if(!fl)
            break;

        i64 cnt = 0;
        while(val){
            cnt += val % 10;
            val /= 10;
        }
        if(cnt == y)
            ++ans;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3108
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long x = sc.nextLong();

		sc.close();

		long ans = (x / 11) * 2;
		if (x % 11 == 0) {

		} else if (x % 11 <= 6) {
			ans++;
		} else {
			ans += 2;
		}

		out.println(ans);

	}

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


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

ll mpp[1003][1003] ;
struct Tuple{
    ll fi,se,th;
    Tuple(){};
    Tuple(ll a,ll b,ll c):fi(a),se(b),th(c){};
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w;
    cin>>h>>w;
    string tmp;
    ll ans=0;
    ll left=0;
    memset(mpp,-1, sizeof(mpp));
    queue<Tuple> q;
    rep(i,h){
        cin>>tmp;
        rep(j,tmp.length()){
            if(tmp[j]=='#'){
                mpp[i+1][j+1] = 1;
                q.push(Tuple(i+1+1,j+1,0));
                q.push(Tuple(i+1-1,j+1,0));
                q.push(Tuple(i+1,j+1+1,0));
                q.push(Tuple(i+1,j+1-1,0));
            }else{
                mpp[i+1][j+1] = 0;
                left++;
            }
        }
    }
//    dbg(left);
//    dbgarr(4,4,mpp);
//    while(!q.empty()){
//        dbg(q.front().th);
//        q.pop();
//
//    }
    if(left>0){
        while(left&&!q.empty()){
            Tuple &now = q.front();
            if(mpp[now.fi][now.se]==0){
                mpp[now.fi][now.se]=now.th+1;
                left--;
                ans = max(ans,now.th+1);
                q.push(Tuple(now.fi+1,now.se,now.th+1));
                q.push(Tuple(now.fi-1,now.se,now.th+1));
                q.push(Tuple(now.fi,now.se+1,now.th+1));
                q.push(Tuple(now.fi,now.se-1,now.th+1));
            }
            q.pop();
        }
    }
    //dbgarr(7,7,mpp);
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 104872
import sys
input=sys.stdin.readline
s=input().rstrip()
n=len(s)
l=[0]
for i in range(n):
    x=int(s[n-1-i])
    y=l[-1]+x*pow(10,i,2019)
    l.append(y%2019)
c=[0]*2019
for i in l:
    c[i]+=1
ans=0
for i in c:
    ans+=i*(i-1)//2
print(ans)



Measured memory_bytes: 76036
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

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

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  string s;
  cin >> s;
  if(s.at(0) == s.at(1) and s.at(1) == s.at(2)) {
    cout << "Yes" << endl;
  } else if(s.at(2) == s.at(1) and s.at(3) == s.at(2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> h[i];
  }

  sort(h.begin(), h.end());
  ll ans = 1LL << 60;
  for(int i = 0; i <= n - k; ++i)
  {
    ans = min(ans, h[i + k - 1] - h[i]);
  }
  cout << ans;

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3924
import java.util.Scanner;

public class Main {
	static int N;
	static long A,B;
	static Long[] h;

	public static void main(String[] args){
		Scanner io = new Scanner(System.in);
		int N = io.nextInt();
		String S = io.next();
		int len = S.length();
		int stack = 0;
		for (int i = len-1; i>=0; i--) {
			if(S.charAt(i)==')') stack ++;
			else if(S.charAt(i)=='('){
				if(stack>0) stack --;
				else S = S + ")";
			}
		}
		for(int i=0;i<stack;i++){
			S = "(" + S;
		}
		System.out.println(S);
	}	
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=101, W=1e5+5;
ll dp[N][W],n,w,A[N][2];

ll f(int i, int j){
	if(i == n)return 0;
	ll &r=dp[i][j];
	if(r!=-1)return r;
	r=f(i+1,j);
	if(j>=A[i][0])r=max(r,f(i+1,j-A[i][0])+A[i][1]);
	return r;
}

int main(){FIN;mset(dp,-1);
	cin >> n >> w;
	fore(x,0,n)cin>>A[x][0]>>A[x][1];
	cout<<f(0,w)<<"\n";
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define nl "\n"
#define ump unordered_map<ll , ll>
const ll N=1e5+5;
ump freq;
void doit(){
	freq.clear();
	ll n,m,i,j,k,c,ans=0,x;
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> x;
		freq[x]++;
		ans+=x;
	}
	ll q;
	cin >> q;
	while(q--){
		ll c1,c2,c3;
		cin >> c1 >> c2;
		k = freq[c1];
		freq[c1] = 0;
		c1=k*c1;
		ans-=c1;
		ans+=c2*k;
		freq[c2]+=k;
		cout << ans << nl;
	}
	
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	// cin >> t;
	for(ll i = 1; i <= t; i++){
		doit();
	}
}


Measured memory_bytes: 7072
s = gets.to_i
dp = Array.new(1000_000 + 30)
dp[1] = s
used = { s => true }

ans = (2 .. 1_000_000).find do |i|
  v = dp[i] = dp[i - 1].odd? ? (dp[i - 1] * 3 + 1) : (dp[i - 1] / 2)
  found = used[v]
  
  used[v] = true if !found

  found
end
puts ans


Measured memory_bytes: 9596
S = input()
Q = int(input())
R = 1  # 1:False, -1:True
P = []
B = []
for _ in range(Q):
    Query = [i for i in input().split()]
    if Query[0] == '1':
        R *= -1
    else:
        if R == 1:
            if Query[1] == '1':
                P.append(Query[2])
            else:
                B.append(Query[2])
        else:
            if Query[1] == '1':
                B.append(Query[2][::-1])
            else:
                P.append(Query[2][::-1])

ans = ''.join(P[::-1])+S+''.join(B)
if R == -1:
    ans = ans[::-1]

print(ans)


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

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

using namespace std;

typedef long double ld;
typedef complex<ld> P;
typedef vector<P> VP;
const ld eps = 1e-8, pi = acos(-1.0);

vector<ld> sq_eq(ld a, ld b, ld c) {
  ld D = b*b - 4.0*a*c;
  if (D < eps) return vector<ld>();
  vector<ld> res;
  if (b > 0) {
    res.push_back((-b + sqrt(D)) / (2.0 * a));
    res.push_back((2.0 * c) / (b - sqrt(D)));
  } else {
    res.push_back(- (2.0 * c) / (b + sqrt(D)));
    res.push_back((-b - sqrt(D)) / (2.0 * a));
  }
  return res;
}

vector<ld> p2tan(ld x, ld y, ld v) {
  if (x == 0) return vector<ld>(1,-1);
  ld b = -v*v/(4.9*x);
  ld c = 1-b*y/x;
  return sq_eq(1.0,b,c);
}

vector<ld> l2tan(ld y, ld v) {
  ld a = -v*v/4.9;
  ld zsq = 1.0/(1.0/(a*a*4.0)+y/a);
  ld z1 = sqrt(zsq);
  ld z2 = -z1;
  vector<ld> res;
  res.push_back(-z1/(2.0*a));
  res.push_back(-z2/(2.0*a));
  return res;
}

int main() {
  int n,v;
  ld x,y;
  cin>>n>>v>>x>>y;
  vector<ld> tanl = p2tan(x,y,v);
  vector<tuple<ld,ld,ld>> lx;
  vector<tuple<ld,ld,ld>> ly;
  ld mn_oby_atx = 1000;
  REP(i,n){
    ld l,b,r,t;
    cin>>l>>b>>r>>t;
    if (l <= x && x <= r && b >= y)
      mn_oby_atx = min(mn_oby_atx, b);
    if (l >= x) continue;
    r=min(r,x);
    lx.emplace_back(t,l,r);
    lx.emplace_back(b,l,r);
    ly.emplace_back(l,b,t);
    ly.emplace_back(r,b,t);
    vector<vector<ld>> s(6);
    s[0] = p2tan(l,t,v);
    s[1] = p2tan(r,t,v);
    s[2] = p2tan(l,b,v);
    s[3] = p2tan(r,b,v);
    s[4] = l2tan(t,v);
    s[5] = l2tan(b,v);
    REP(j,6)
      tanl.insert(end(tanl),begin(s[j]),end(s[j]));
  }
  if (v == 0) {
    cout << "No" << endl;
    return 0;
  }
  auto itr = remove_if(begin(tanl),end(tanl),[](ld val){return val < 0.0;});
  tanl.erase(itr, end(tanl));
  bool ok = false;
  for (ld t : tanl) {
    ld a = (-4.9/(v*v))*(1+t*t);
    ld b = t;
    bool reachable = true;
    for (auto p : lx) {
      ld py, mnx, mxx;
      tie(py,mnx,mxx) = p;
      auto res = sq_eq(a,b,-py);
      for (ld ans:res) {
        if (mnx + eps< ans && ans + eps < mxx) {
          reachable = false;
          break;
        }
      }
    }
    for (auto p : ly) {
      ld px, mny, mxy;
      tie(px, mny, mxy) = p;
      ld cy = a*px*px+b*px;
      if (mny + eps < cy && cy + eps < mxy) {
        reachable = false;
        break;
      }
    }
    if (reachable) {
      ld cy = a*x*x+b*x;
      if (y < cy + eps && cy < mn_oby_atx + eps) {
        ok = true;
        break;
      }
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1312
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,M,V,P = MI()
A = [0] + LI()
A.sort()

from bisect import bisect_left


def f(n):  # 下からn番目のスコアの問題が、採用される可能性があるか
    v = V-n  # スコア下位n問には全員が投票したとしてよい
    if A[n] + M < A[-P]:  # 上位P人に入れない
        return False
    else:
        v -= P-1  # スコア上位P-1人には全員が投票したとしてよい
        if v <= 0:
            return True
        else:
            if sum(A[n]+M-A[i] for i in range(n+1,N-P+2)) >= M*v:
                return True
            else:
                return False


left = 0  # 採用される可能性なし
right = N  # 採用される可能性あり
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(N+1-right)


Measured memory_bytes: 86632
from sys import stdin

N = int(stdin.readline().rstrip())
v_lst = [int(v) for v in stdin.readline().rstrip().split()]
v_lst.sort()

while(len(v_lst) > 1):
  v0 = v_lst.pop(0)
  v1 = v_lst.pop(0)
  vn = (v0 + v1) / 2
  v_lst.append(vn)
  v_lst.sort()
  
print(v_lst[0])

Measured memory_bytes: 3060
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        mut a: [i64; 4],
    }
    a.sort();
    if &a == &[1, 4, 7, 9] {
        println!("YES");
    } else {
        println!("NO");
    }
    // println!("{}", );
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FS first
#define SC second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(auto i:c)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&a){return accumulate(ALL(a),T());}
template<typename T>T max(vector<T>&a){return *max_element(ALL(a));}
template<typename T>T min(vector<T>&a){return *max_element(ALL(a));}
template<typename T>T max_index(vector<T>&a){return distance((a).begin(),max_element(ALL(a)));}
template<typename T>T min_index(vector<T>&a){return distance((a).begin(),min_element(ALL(a)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int N; cin >> N;
   string S; cin >> S;

   int cnt = 0, MIN = 0;
   REP(i, N) {
      if (S[i] == '(') {
         cnt++;
      } else {
         cnt--;
      }
      chmin(MIN, cnt);
   }

   REP(i, abs(MIN)) {
      cout << "(";
   }
   cout << S;
   REP(i, cnt + abs(MIN)) {
      cout << ")";
   }
   cout << endl;

   return 0;
}


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

int main(){
  char a[10];
  char b[5];
  int num;
  int d;
  scanf("%s",a);
  scanf("%s",b);
  strcat(a,b);
  num = atoi(a);

  d = (int)sqrt((double)num);
  if(d*d == num){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N + 1];
        int[] B = new int[N + 1];
        int[] C = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 1; i <= N; i++) {
            B[i] = sc.nextInt();
        }
        for (int i = 1; i <= N - 1; i++) {
            C[i] = sc.nextInt();
        }

        int sum = 0;
        int prevIndex = 0;
        for (int i = 1; i <= N; i++) {
            int currentIndex = A[i];
            sum += B[currentIndex];
            if (currentIndex == (prevIndex + 1)) {
                sum += C[prevIndex];
            }
            prevIndex = currentIndex;
        }
        System.out.print(sum);
    }

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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> si;
typedef set<ll, ll> sll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int, int> mii;
typedef map<int, ll> mil;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;

#define FOR(i, a, b) for(int i = (a), loop_end_##i=(b); i < (loop_end_##i); i++)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort((c).begin(),(c).end())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define PB push_back

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int main(){
	while(true){
		int n = read<int>();
		if(!n) break;
		ll pipe = 0;
		REP(i, n) pipe+=read<int>();
		vector<ll> joint;
		REP(i, n-1) joint.PB(read<ll>());
		sort(joint.begin(), joint.end(), greater<ll>());
		ll ans = 0;
		REP(i, n){
			// cout << pipe << "\t" << n-i << endl;
			ans = max(ans, pipe*(n-i));
			if(i<n-1) pipe+=joint[i];
		}
		cout << ans << endl;
		// break;
	}
}

Measured memory_bytes: 2136
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll ret1=0,ret2=0;
	ll sum1=0,sum2=0;
	REP(i,n) {
		sum1+=a[i];
		if(i%2==0) {
			if(sum1<=0) {
				ret1+=1-sum1;
				sum1=1;
			}
		}
		if(i%2==1) {
			if(sum1>=0) {
				ret1+=1+sum1;
				sum1=-1;
			}
		}
	}
	REP(i,n) {
		sum2+=a[i];
		if(i%2==1) {
			if(sum2<=0) {
				ret2+=1-sum2;
				sum2=1;
			}
		}
		if(i%2==0) {
			if(sum2>=0) {
				ret2+=1+sum2;
				sum2=-1;
			}
		}
	}
	cout<<min(ret1,ret2)<<endl;
}


Measured memory_bytes: 1024
# input
S = input()

# check
ACGT = ["A", "C", "G", "T"]
S_len = len(S)
max_len = max(
    set(
        [
            len(S[i:j])
            for i in range(S_len)
            for j in range(S_len + 1, i, -1)
            if S[i:j].replace("A", "").replace("C", "").replace("G", "").replace("T", "") == ""
        ] + [0]
    )
)

print(max_len)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    T=list(map(int,input().split()))
    S=sum(T)
    M=int(input())
    for _ in range(M):
        p,x=map(int,input().split())
        p-=1
        print(S-T[p]+x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
let () = Scanf.scanf "%d\n" @@ fun n ->
  let ts = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun t -> t in
  let vs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun v -> v in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- acc.(i) + ts.(i)
  done;
  let dp = Array.make (1 + 2 * acc.(n)) max_int in
  for i = 0 to n - 1 do
    for j = 2 * acc.(i) to 2 * acc.(i + 1) do
      dp.(j) <- min dp.(j) (2 * vs.(i))
    done;
  done;
  dp.(0) <- 0;
  dp.(2 * acc.(n)) <- 0;
  for i = 1 to 2 * acc.(n) do
    dp.(i) <- min dp.(i) (dp.(i - 1) + 1)
  done;
  for i = 2 * acc.(n) - 1 downto 0 do
    dp.(i) <- min dp.(i) (dp.(i + 1) + 1)
  done;
  Printf.printf "%f\n" @@ ( *. ) 0.25 @@ float_of_int @@ Array.fold_left ( + ) 0 dp

Measured memory_bytes: 2560
#include <stdio.h>


int main(void) {
    int a,b,c,d;
    int n;
    int count;
    
    while(scanf("%d",&n) != EOF){
        count = 0;
        
        for(a = 0; a < 10; a++){
            for(b = 0; b < 10; b++){
                for(c = 0; c < 10; c++){
                    for(d = 0; d < 10; d++){
                        if((a+b+c+d) == n){
                            count++;
                        }
                    }
                }
            }
        }
        printf("%d\n",count);
    }
	return 0;
}

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        a: i32,
        b: i32,
    }

    if a > 9 {
        println!("{}", -1);
    } else if b > 9 {
        println!("{}", -1);
    } else {
        println!("{}", a * b);
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a) for (int i = (a); i > 0; --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N;
string S;

signed main() {
    cin >> N;
    cin >> S;

    int left = 0;
    int right = 0;
    REP(i, N) {
        char c = S[i];
        if (c == '(') {
            left++;
        } else {
            if (left == 0)
                right++;
            else
                --left;
        }
    }

    string ans = "";
    REP(i, right) { ans += "("; }
    ans += S;
    REP(i, left) { ans += ")"; }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int M,D;
	int d1,d10,count=0;
	cin>>M>>D;
	for(int i=1;i<=M;i++){
		for(int j=1;j<=D;j++){
			d1 = j%10;
			d10 = (j-j%10)/10;
			if(d1>=2 && d10>=2 && i==d1*d10)count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[60],b[60],c[60],d[60];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>c[i]>>d[i];
    }
    for(int i=1;i<=n;i++)
    {
        int ans=1000000000;
        int k;
        for(int j=1;j<=m;j++)
        {
            int t=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(t<ans){
                ans=t;
                k=j;
            }
        }
        cout<<k<<endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    ll n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
n,k = map(int,input().split())

count = [0]*(n+1)
count1 = 0

for i in range(k):
  d = int(input())
  A = list(map(int,input().split()))
  for i in A:
    count[i-1] += 1

for i in range(n):
  if count[i] == 0:
    count1 += 1

print(count1)
    

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(m); sll(k);
	VLL seq;
	LL max = (1ll<<m)-1; 
	if(k >= (1ll<<m))	puts("-1");
	else if(k == 0) {
		rep(i, 0, (1ll<<m))		pll(i);
		rep(i, (1ll<<m), 0ll)	pll(i);
		nl;
	}
	else if(m == 1 && k == 1)	puts("-1");
	else {
		rep(i, 0, (1ll<<m))	if(i != k)	pll(i);
		pll(k);
		rep(i, (1ll<<m), 0ll)	if(i != k)	pll(i);
		pll(k);
		nl;
	}
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int lcm(int c,int d){
  int e=gcd(c,d);
  return c/e*d;
}


signed main(){
  int a,b;
  while(cin>>a>>b){
    cout<<gcd(a,b)<<' '<<lcm(a,b)<<endl;
  }
  return 0;
}

Measured memory_bytes: 2932
#include<stdio.h>
#define N 100

int main(){
  int G[N][N];
  int n, u, k, v, i, j;

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ) G[i][j] = 0;
  }

  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d",&u,&k);
    u--;
    for( j = 0 ; j < k ; j++ ){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }

  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      if( j ) printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112