akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    map<string,int> mp;
    REP(i,n){
        string s; cin >> s; SORT(s);
        mp[s]++;
    }
    int ans = 0;
    for(auto x:mp) ans += x.second*(x.second-1)/2;
    out(ans);

    return 0;
}

Measured memory_bytes: 11264
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int A = sc.nextInt();
   int B = sc.nextInt();
   char[] c = sc.next().toCharArray();
   boolean flg = true;
   
   for(int i=0;i<A;i++)
   {
     if(c[i]=='-') flg = false; 
   }
   if(c[A]!='-') flg = false;
   for(int i=A+1;i<A+B+1;i++)
   {
     if(c[i]=='-') flg = false; 
   }
 
   if(flg) System.out.println("Yes");
   else System.out.println("No");
 }
}

Measured memory_bytes: 23764
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ll mod2 = 998244353;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define lwi(x) cout << " your " << #x << " is ---> " << x << " ";
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 1e6+5;
int32_t main(){
    FastIO;
    string s;
    cin >> s;
    string ans = ""; 
    for(int i=0; i<3; i++) {
        ans += s[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	std::string S;
	in >> S;

	std::string s1, s2;
	rep(i, S.length())
	{
		s1 += (i % 2 == 0 ? "0" : "1");
		s2 += (i % 2 == 1 ? "0" : "1");
	}

	LL ans1 = 0, ans2 = 0;
	rep(i, S.length())
	{
		if (S[i] != s1[i]) ++ans1;
		if (S[i] != s2[i]) ++ans2;
	}
	out << std::min(ans1, ans2) << std::endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define pii pair<int,int> 
int MOD = 1e9 + 7;

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


Measured memory_bytes: 256
def main():
    import re
    n = int(input())
    s = input()
    rindex = set()
    gindex = set()
    bindex = set()
    for i in range(n):
        if s[i] == "R":
            rindex.add(i)
        elif s[i] == "G":
            gindex.add(i)
        else:
            bindex.add(i)
    ans = len(rindex) * len(gindex) * len(bindex)

    for r in rindex:
        for g in gindex:
            if r > g:
                gap = r - g
                b1 = r + gap
                b2 = g - gap
                b3 = g + (gap/2)

            elif r < g:
                gap = g - r
                b1 = g + gap
                b2 = r - gap
                b3 = r + (gap/2)
            if b1 in bindex:
                ans -= 1
            if b2 in bindex:
                ans -= 1  
            if b3 in bindex:
                ans -= 1  
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 75788
def main():
    H, W = map( int, input().split())
    S = [ list( input()) for _ in range(H)]
    T = [[6,3,1,4], [2,0,2,0],[1,3,6,4],[5,0,5,0]]
    C = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                continue
            if T[i%4][j%4] == int(S[i][j]):
                C[i][j] = 1
    d = [(0,0)]
    P = [[False]*W for _ in range(H)]
    P[0][0] = True
    while d:
        x, y = d.pop()
        if x > 0:
            if C[x-1][y] == 1 and not P[x-1][y]:
                d.append((x-1,y))
                P[x-1][y] = True
        if x < H-1:
            if C[x+1][y] == 1 and not P[x+1][y]:
                d.append((x+1,y))
                P[x+1][y] = True
        if y > 0:
            if C[x][y-1] == 1 and not P[x][y-1]:
                d.append((x,y-1))
                P[x][y-1] = True
        if y < W-1:
            if C[x][y+1] == 1 and not P[x][y+1]:
                d.append((x,y+1))
                P[x][y+1] = True
    if P[H-1][W-1]:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()



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

int main()
{
    int k,s;
    cin >> k >> s;
    int x,y,z;
    int ans = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(s-i-j >= 0 && s-i-j <= k){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
    n, m = map(int, input().split())
    if -2 < (n - m) < 2:
        ans = 1
        for i in range(1, n+1):
            ans *= i
            ans %= 1000000007
        for i in range(1, m+1):
            ans *= i
            ans %= 1000000007
        if n != m:
            print(ans)
        else:
            print(((ans) * 2) % 1000000007)
    else:
        print(0)


if __name__=="__main__":
    solve()

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int i,k,a,b,c,sum;
    char s[4];
    while(~scanf("%s",s))
    {
        sum=0;
        b=0;
        a=0;

        for(i=0; i<4; i++)
        {
            if(s[i]=='+')
            {
                a++;
            }
            if(s[i]=='-')
            {
                b--;
            }

        }
        sum=a+b;
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a,b;

int main(){
	cin>>n;
	a=b=vi(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	if(n%2==1){
		cout<<"NA"<<endl;
		return 0;
	}
	bool B=1;
	for(int i=0;i<n/2;i++){
		int N=n/2;
		int x=a[i+1]-a[i],y=b[i+1]-b[i];
		int x_=a[(i+N+1)%n]-a[i+N],y_=b[(i+N+1)%n]-b[i+N];
		if(x!=x_||y!=y_) x*=-1,y*=-1;
		if(x!=x_||y!=y_) B=0;
	}
	if(B){
		double x=0,y=0;
		for(int i=0;i<n;i++) x+=a[i],y+=b[i];
		cout<<syosu(9)<<x/n<<' '<<y/n<<endl;
	}
	else cout<<"NA"<<endl;
}


Measured memory_bytes: 3296
n,a,b=map(int, input().split())
MOD=10**9+7

def comb(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % MOD
        q = q * (i+1) % MOD
    return p * pow(q, MOD-2, MOD) % MOD

ans=(pow(2,n,MOD)-1)%MOD
ans=(ans+MOD-comb(n,a))%MOD
ans=(ans+MOD-comb(n,b))%MOD

print(ans)


Measured memory_bytes: 39408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  ll n,a,b;
  cin >> n >> a >> b;
  if(a > b)cout << 0 << endl;
  else if(n == 1 && (a != b)) cout << 0 << endl;
  else if(n == 1)cout << 1 << endl;
  else cout << (n - 2) * (b - a) + 1 << endl; 
  return 0;
} 

Measured memory_bytes: 256
a = int(input())
b = 0

if len(str(a)) //2 *2 == len(str(a)):
    for i in range(len(str(a))//2):
        b += 10 **(2 *i) *9
    print(b)
else:
    for i in range(len(str(a))//2):
        b += 10 **(2 *i) *9
    b += a-10**(len(str(a))-1)+1
    print(b)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main () {
    int n, x;

    while (true) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;

        int cnt = 0;
        for (int i = 1; i <= n - 2; i++) {
            for (int j = i + 1; j <= n - 1; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) cnt++;
                }
            }
        }
        cout << cnt << endl;
        cnt = 0;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N,R,I;
    cin>>N;
    cin>>R;
    if(N<=10)
    { 
       I=R+(10-N)*100;
       cout<<I;
    }
    else
    {
       cout<<R;
    }
}

Measured memory_bytes: 256
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N = i_inpl()
    s = defaultdict(int)
    ans = 0
    for _ in range(N):
        si = tuple(sorted(input()))
        s[si] = s[si] +1

    for i in s.values():
        if i > 1:
            ans += 1/2 * (i-1)*i
    print(int(ans))
if __name__ == "__main__":
    main()


Measured memory_bytes: 33796
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll A, B, C;

int main()
{
  std::cin >> A >> B >> C;

  if( A > B )
    std::swap(A,B);

  puts( A <= C && C <= B ? "Yes" : "No" );

  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long ll;

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

int main() {
	int K, ans = 0;
	cin >> K;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3612
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Measured memory_bytes: 93416
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n; vector<string> s;
int main() {
	while (cin >> n, n) {
		s.resize(n);
		for (int i = 0; i < n; i++) cin >> s[i];
		vector<int> flag(n, 0); // bit / i -> j
		vector<vector<int> > cost(n, vector<int>(n)); // i -> j
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (s[i].find(s[j]) != string::npos) {
					flag[i] |= 1 << j;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k <= s[i].size(); k++) {
					string ret = s[i].substr(0, k) + s[j];
					if (ret.substr(0, s[i].size()) == s[i]) {
						cost[i][j] = ret.size() - s[i].size();
						break;
					}
				}
			}
		}
		vector<vector<string> > dp(1 << n, vector<string>(n, string(101, 'z')));
		dp[0][0] = "";
		for (int i = 1; i < 1 << n; i++) {
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				int p = i - (1 << j);
				for (int k = 0; k < n; k++) {
					string con = (p != 0 ? s[j].substr(s[j].size() - cost[k][j], cost[k][j]) : s[j]);
					if (dp[i][j].size() > dp[p][k].size() + con.size()) dp[i][j] = dp[p][k] + con;
					else if (dp[i][j].size() == dp[p][k].size() + con.size() && dp[i][j] > dp[p][k] + con) dp[i][j] = dp[p][k] + con;
				}
			}
		}
		string ret(101, 'z');
		for (int i = 1; i < 1 << n; i++) {
			int bit = i;
			for (int j = 0; j < n; j++) {
				if (i & (1 << j)) bit |= flag[j];
			}
			if (bit == (1 << n) - 1) {
				for (int j = 0; j < n; j++) {
					if (ret.size() > dp[i][j].size()) ret = dp[i][j];
					else if (ret.size() == dp[i][j].size() && ret > dp[i][j]) ret = dp[i][j];
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3584
from collections import deque
N = int(input())
X = [0]*N
L = [0]*N
lis = deque()
for i in range(N):
    X[i], L[i] = map(int, input().split())
    lis.append([i,X[i]-L[i], X[i]+L[i]])

lis = sorted(lis, key=lambda x:x[2])
lis = deque(lis)

end = lis[0][2]
start = lis[0][1]
lis.popleft()
cnt = 1
while lis:
    x, y, z = lis.popleft()
    if y < end:
        continue
    elif y >= end:
        start = y
        end = z
        cnt += 1

print(cnt)


Measured memory_bytes: 62808
n=int(input())
a=list(map(int,input().split()))

bit_l=[0 for _ in range(60)]

for x in a:
  for i in range(60):
    if ((x>>i)&1):
      bit_l[i]+=1
ans=0
mod=10**9+7
for y in range(len(bit_l)):
  r=2**y
  k=(n-bit_l[y])*bit_l[y]
  ans+=r*k%mod
  
print(ans%mod)

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

int main() {
  int N; cin >> N;
  vector<int> T(N), X(N), Y(N);
  for (int i = 0; i < N; i++) cin >> T.at(i) >> X.at(i) >> Y.at(i);
  int curt = 0, curx = 0, cury = 0;
  for (int i = 0; i < N; i++) {
    int dist = abs(X.at(i) - curx) + abs(Y.at(i) - cury);
    if (dist > T.at(i) - curt) { cout << "No" << endl; return 0; }
    if (dist % 2 != (T.at(i) - curt) % 2) { cout << "No" << endl; return 0; }
    curt = T.at(i);
    curx = X.at(i);
    cury = Y.at(i);
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
n, m = map(int, input().split())
ss = []
cc = []
num = []

for _ in range(m):
    s, c = map(int, input().split())
    ss.append(s)
    cc.append(c)

for i in range(1000):
    if len(str(i)) != n:
        continue
    cnt = 0
    for s, c in zip(ss, cc):
        if str(i)[s-1] == str(c):
            cnt += 1
    if cnt == len(ss):
        num.append(i)

if num:
    print(num[0])
else:
    print(-1)


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

signed main(){
  int n; cin >> n;
  int kosuu = 0;
  for(int i = 1; i <= n; ++i){
    int yaku = 0;
    if(i%2==1){
      for(int j = 1; j<=i; ++j){
        if(i%j==0) yaku++;
      }
    }
    if(yaku==8) kosuu++;
  }
  cout << kosuu << "\n";
}

Measured memory_bytes: 3588
#include<stdio.h>
long long a[100010];

int main(){
	int n;
    scanf("%d",&n);
    int i;
    for(i=0;i<n;i++)scanf("%lld",&a[i]);
    
    int zero=0;
    for(i=0;i<n;i++)if(a[i]==0)zero++;
    
    if(zero>0){
    	printf("0\n");
        return 0;
    }
    
    long long prod=1;
    for (i=0;i<n;i++){
    	if(a[i]<=1000000000000000000/prod){
        	prod*=a[i];
        }else{
        	printf("-1\n");
            return 0;
        }
    }
    printf("%lld\n",prod);

}

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

using namespace std;
typedef long long ll;



int main(){
  ll n,a[200000],s=0,ans=1e18;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i],s+=a[i];
  ll ss=0;
  for(int i=0;i<n-1;i++){
    ss+=a[i];
    ans=min(ans,abs(s-2*ss));
  }
  
  cout<<ans<<endl;
  
  return 0;
}






Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll mod = 1e9 + 7;
int P[maxn];

int Find(int x)
{
    if(P[x] < 0) return x;
    return P[x] = Find(P[x]);
}


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    // cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++)
    {
        int n,m;
        cin >> n >> m;
        int a[maxn], b[maxn];

        for(int i = 0; i < m; i++)
        {
            cin >> a[i] >> b[i];
        }

        ll sum = (ll) n * (n - 1) / 2;
        ll ans[maxn];
        ans[m] = sum;

        for(int i = 1; i <= n; i++) P[i] = -1;

        for(int i = m - 1; i > 0; i--)
        {
            int pa = Find(a[i]);
            int pb = Find(b[i]);

            if(pa != pb)
            {
                sum -= (ll) P[pa] * P[pb];
                if(P[pa] > P[pb]) swap(pa, pb);
                P[pa] += P[pb];
                P[pb] = pa;
            }
            ans[i] = sum;
        }
        for(int i = 1; i <= m; i++) cout << ans[i] << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
//typedef pair<int, int>pint;
//typedef vector<int>vint;
//typedef vector<pint>vpint;
//typedef pair<pint, int> P1;
//typedef pair<int, pint> P2;
//typedef pair<pint, pint> PP;



int main(void) {
	vector<vector<int>>mat(3, vector<int>(3));

	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			cin >> mat[i][j];

	bool flag2 = false;

	for (int i = 0; i <= mat[0][0]; i++) {
		int b[3] = { -1, -1, -1 };
		int a[3] = { i, -1, -1 };
		bool flag = false;

		for (int j = 0; j < 3; j++) {
			b[j] = mat[0][j] - i;
			if (b[j] < 0) {
				flag = true;
				break;
			}
		}

		if (flag == true)continue;

		if (mat[1][0] - b[0] >= 0 && mat[1][0] - b[0] == mat[1][1] - b[1] && mat[1][1] - b[1] == mat[1][2] - b[2]) {
			a[1] = mat[1][0] - b[0];
		}
		else continue;
		
		if (mat[2][0] - b[0] >= 0 && mat[2][0] - b[0] == mat[2][1] - b[1] && mat[2][1] - b[1] == mat[2][2] - b[2]) {
			a[2] = mat[2][0] - b[0];
		}
		else continue;

		flag2 = true;
		cout << "Yes" << endl;
		break;
	}

	if (flag2 == false)cout << "No" << endl;

	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,d;

signed main () {
    cin >> n >> d;
    cout << (n+d*2)/(d*2+1) << endl;
}


Measured memory_bytes: 256
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		while(true){
			int N = sc.nextInt();
			if(N == 0) break;
			System.out.println((int)Math.ceil(1.0*solve(N) / 3650));
		}
	}
	
	public static long solve(int N){
		long[] dp = new long[N+1];
		
		dp[0] = 1;
		
		for(int i = 0; i <= N; i++){
			if(i+1 <= N) dp[i+1] += dp[i];
			if(i+2 <= N) dp[i+2] += dp[i];
			if(i+3 <= N) dp[i+3] += dp[i];
		}
		
		return dp[N];
	}
}


class Queue{
	int n;
	int p, q, r;
	public Queue(int n, int p, int q, int r){
		this.n = n;
		this.p = p;
		this.q = q;
		this.r = r;
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}



Measured memory_bytes: 24272
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e16;
const ll mod=1000000007;
typedef pair<ll,ll> pi;

void solve()
{
string n;
cin>>n;
ll ans=0;
for(ll i=0;i<n.length();i++) ans+=(n[i]-'0');
if(ans%9==0)
    cout<<"Yes";
else cout<<"No";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t=1;
    for(ll i=1;i<=t;i++)
    {
        solve();
        cout<<endl;

    }
    return 0;
}


Measured memory_bytes: 3776
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt(), t = in.nextInt();
            long[] push = new long[n];
            for (int i = 0; i < n; i++) {
                push[i] = in.nextLong();
            }
            long last = 0, ans = 0;
            for (int i = 0; i < n; i++) {
                if (push[i] < last) {
                    ans = ans + t - (last - push[i]);
                } else {
                    ans += t;
                }
                last = push[i] + t;
            }
            out.println(ans);
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 47280
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        
        String[] NAB = line.split(" ");
        
        int N = Integer.parseInt(NAB[0]);
        int A = Integer.parseInt(NAB[1]);
        int B = Integer.parseInt(NAB[2]);
        
        // 最大値を求める
        int max = 0;
        
        if(A == B) {
            max = A;
        } else if(A > B) {
            max = B;
        } else if(B > A) {
            max = A;
        }
        
        // 最小値を求める
        int min = B - (N-A);
        
        if(min < 0) {
            min = 0;
        }
        
        System.out.println(max + " " + min);
    }
}


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

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  LL K;
  cin >> K;
  LL A[100010];
  rep(i,N) cin >> A[i];
  int num[40]={0};
  rep(bit,40){
    rep(j,N) if(A[j]&1LL<<bit) num[bit]++;
  }
  LL X=0, ans=0;
  for(int bit=39; bit>=0; bit--){
    if(X+(1LL<<bit)<=K&&num[bit]*2<N){
      X+=1LL<<bit;
      ans+=(1LL<<bit)*(N-num[bit]);
    }
    else ans+=(1LL<<bit)*num[bit];
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	const int M = 3;
	string str[M];
	for (int i = 0; i < M; i++)
	{
		cin >> str[i];
	}

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		char base = str[0][i];
		if(base == str[1][i] && base == str[2][i])
		{
		}
		else if (base == str[1][i] || base == str[2][i] || str[1][i] == str[2][i])
		{
			ans++;
			continue;
		}
		else
		{
			ans += 2;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main(){
    int n, num = 0;
    cin >> n;
    while(n){
        num += n%10;
        n /= 10;
    }

    if(num == 1)
        cout << 10 << endl;
    else
        cout << num << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  int a, b;
  cin >> a >> b;
  if(a > b){
    cout << 2 * a - 1 << endl;
  }else if (a < b){
    cout << 2 * b - 1 << endl;
  }else {
    cout << 2 * a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 + y1 - y2
y3 = y2 + x2 - x1
x4 = x1 + y1 - y2
y4 = y1 + x2 - x1
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
var
  a,b,d:integer;
  c,i:longint;
  s:array[0..100100] of boolean;
begin
  
  for i:=1 to 100100 do s[i]:=false;
  for i:=1 to trunc(sqrt(100100)) do
    s[i*i]:=true;
  readln(a,b);
  d:=b;c:=a;
  while b>0 do begin
    c:=c*10;
    b:=b div 10;
  end;
  c:=c+d;
  //writeln(c);
  if s[c] then writeln('Yes')
    else writeln('No');
  close(input);
  close(output);
end.


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			String s1 = scanner.next();
			String s2 = scanner.next();
			System.out.println(lcs(s1, s2));
		}
	}

	private int lcs(String x, String y) {
		int max = Math.max(x.length(), y.length());
		int[][] c = new int[max + 1][max + 1];
		int m = x.length();
		int n = y.length();
		int maxl = 0;
		x = ' ' + x;
		y = ' ' + y;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				if (x.charAt(i) == y.charAt(j)) {
					c[i][j] = c[i - 1][j - 1] + 1;
				} else {
					c[i][j] = Math.max(c[i - 1][j], c[i][j - 1]);
				}
				maxl = Math.max(maxl, c[i][j]);
			}
		}
		return maxl;
	}
}

Measured memory_bytes: 61508
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
inf=10**9
def magic(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs (c - C) - 30
        else:
            return inf
    
    ret0 = magic(cur+1, a, b, c)
    ret1 = magic(cur+1, a+l[cur], b, c) + 10
    ret2 = magic(cur+1, a, b+l[cur], c) + 10
    ret3 = magic(cur+1, a, b, c+l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(magic(0, 0, 0, 0))

Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
const ll DEP = (1LL << 50);
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
template<typename T>
T GCD(T x,T y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    int e[4]; cin >> e[0] >> e[1] >> e[2] >> e[3];
    sort(e,e+4);
    if(e[0] == e[1] && e[2] == e[3]){
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
}



Measured memory_bytes: 3164
use std::cmp;
use std::collections::VecDeque;
use std::fmt::Debug;
use std::str::FromStr;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn calc_size(table: &Vec<Vec<char>>, cur: (usize, usize), visited: &mut Vec<Vec<bool>>) -> usize {
    let mut queue: VecDeque<(usize, usize)> = VecDeque::new();
    let (mut whilte, mut black) = (0, 0);
    queue.push_back(cur);

    while let Some(cur) = queue.pop_front() {
        if visited[cur.0][cur.1] {
            continue;
        }
        visited[cur.0][cur.1] = true;
        if table[cur.0][cur.1] == '#' {
            whilte += 1;
        } else {
            black += 1;
        }

        if cur.0 > 0 {
            if table[cur.0 - 1][cur.1] != table[cur.0][cur.1] && !visited[cur.0 - 1][cur.1] {
                queue.push_back((cur.0 - 1, cur.1));
            }
        }

        if cur.0 < table.len() - 1 {
            if table[cur.0 + 1][cur.1] != table[cur.0][cur.1] && !visited[cur.0 + 1][cur.1] {
                queue.push_back((cur.0 + 1, cur.1));
            }
        }

        if cur.1 > 0 {
            if table[cur.0][cur.1 - 1] != table[cur.0][cur.1] && !visited[cur.0][cur.1 - 1] {
                queue.push_back((cur.0, cur.1 - 1));
            }
        }

        if cur.1 < table[0].len() - 1 {
            if table[cur.0][cur.1 + 1] != table[cur.0][cur.1] && !visited[cur.0][cur.1 + 1] {
                queue.push_back((cur.0, cur.1 + 1));
            }
        }
    }

    return whilte * black;
}

fn main() {
    let line = read_as_vec::<usize>();
    let (h, w) = (line[0], line[1]);
    let mut table: Vec<Vec<char>> = vec![];
    for _ in 0..h {
        table.push(read_as_string().chars().collect::<Vec<char>>());
    }
    let mut visited: Vec<Vec<bool>> = vec![vec![false; w]; h];
    let mut count: usize = 0;
    for i in 0..h {
        for j in 0..w {
            if !visited[i][j] {
                count += calc_size(&table, (i, j), &mut visited);
            }
        }
    }

    println!("{}", count);
}


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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
  string s;
  int64_t a = 0;

  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    a += (int)(s[i] - '0');
  }
  cout << (a % 9 == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3724
#include<iostream>
#include<algorithm>
#include<string>
#include<bitset>
#include<deque>
#include<iterator>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define pii pair<ll,ll>
#define mp make_pair 
#define M 1000000007
int main()
{
   ll k;
   ll a,b;
   ll i;
   ll f=0;
   cin>>k;
   cin>>a>>b;
   for(i=a;i<=b;i++)
   {
   	if(i%k==0)
   		f=1;
   } 
   if(f==1)
   	cout<<"OK";
  else
    cout<<"NG";
	return 0;
}

Measured memory_bytes: 3624
#-------------
N,D = map(int, input().split())
A = [input().split() for l in range(N)]
#-------------

dis = []

for i in range(N):
  Z = int(A[i][0])**2 + int(A[i][1])**2
  dis.append(Z)

cnt = 0
for i in range(N):
  if dis[i] <= D**2:
    cnt += 1
    
print(cnt)

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;
typedef long long ll;

const int nc = 26;
int D;
ll c[40], t[400];
ll s[400][40];

ll scoring(){
	vector<int> last(nc+10, -1);

	long long sat = 0;

	for(ll d = 0; d < D; d++){
		last[t[d]] = d;

		for(int i = 0; i < nc; i++){
			sat -= c[i] * (d - last[i]);
		}
		sat += s[d][t[d]];
		//cout << sat << endl;
	}

	return sat;
}

/*
ll calc_score(ll &score, int d, int q){
	int p = t[d]; // p -> q
	int prev_q = 0, prev_p = 0, next_q = D - 1 ,next_p = D - 1;

	if(p == q){
		return score;
	}

	for(int i = d-1; i >= 0; i--){
		if(prev_p == 0){
			if(t[i] == p){
				prev_p = i;
			}
		}
		if(prev_q == 0){
			if(t[i] == q){
				prev_q = i;
			}
		}
	}

	for(int i = d+1; i < D; i++){
		if(next_p == D-1){
			if(t[i] == p){
				next_p = i;
			}
		}
		if(next_q == D-1){
			if(t[i] == q){
				next_q = i;
			}
		}
	}

	//cout << "next_p:" << next_p << ", next_q:" << next_q << endl;
	//cout << "prev_p:" << prev_p << ", prev_q:" << prev_q << endl;

	score = score + s[d][q] - s[d][p];

	for(int i = d; i <= next_p; i++){
		//score += c[p] * (i-d);
		score -= c[p] * (i - prev_p);
	}

	for(int i = d; i <= next_q; i++){
		//score += c[q] * (i - prev_q);
		score -= c[q] * (i - d);
	}

	t[d] = q;
	return score;
}
*/

void ans_query(ll &score){
	int M;
	cin >> M;

	for(int i = 0; i < M; i++){
		int d, q, old;
		cin >> d >> q;
		d--; q--;
		old = t[d];
		t[d] = q;
		ll new_score = scoring();
		cout << new_score << endl;
		/*if(score > new_score){
			t[d] = old;
		}*/
	}
}


int main(){
	cin >> D;

	for(int i = 0; i < nc; i++){
		cin >> c[i];
	}

	for(int i = 0; i < D; i++){
		for(int j = 0; j < nc; j++){
			cin >> s[i][j];
		}
	}

		for(int i = 0; i < D; i++){
		cin >> t[i];
		t[i]--;
	}

	ll score = scoring();

	ans_query(score);

	return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    rep(i,3){
        ans += (s[i] == t[i]);
    }
    cout << ans << endl;
}

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

struct Edge{
    int to,id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v,int c=-1,int p=-1){
    int k=1;
    rep(i,g.at(v).size()){
        int u = g.at(v).at(i).to;
        int ei = g.at(v).at(i).id;
        if(u == p) continue;
        if(k == c)k++;
        ans.at(ei) = k;k++;
        dfs(u,ans[ei],v);
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n-1);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g.at(a).push_back(Edge{b,i});
        g.at(b).push_back(Edge{a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i,n) mx = max(mx,(int)g.at(i).size());
    cout << mx << endl;
    rep(i,n-1) cout << ans.at(i) << endl;
    return 0;
}

Measured memory_bytes: 11120
'use strict';

function Main(input) {
    const tmp = input.split("\n")[0].split(" ");
    const s = tmp[0].substr(0, 1) + tmp[1].substr(0, 1) + tmp[2].substr(0, 1);
    console.log(s.toUpperCase());
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 9420
#include<stdio.h>
int main()
{
    int i,h,len,j,n,k;
    scanf("%d",&h);
    i=0;
    if(h%2==0){
    for(j=1;j<h;j=j+2){
       i=i+j;
    }
    printf("%d\n",i);

    }
   else if(h%2!=0){
        for(j=2;j<h;j=j+2){
            i=i+j;
        }
        printf("%d\n",i);

    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c,i,j,n;
    string ans="";
    cin>>n;
    while(n>0)
    {
        n--;
        a=n%26;
        n/=26;
        ans+=(a+'a');
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <unordered_map>

using namespace std;

int sum = 0;
void dfs(const int& now, vector<int>& color, const vector<vector<int>>& adjlist);

int main(){
    int n,m;
    cin >> n >> m;

    vector<vector<int>> adjlist(n,vector<int>{});

    for(int i=0; i<m; i++){
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--;
        tmp2--;
        adjlist[tmp1].push_back(tmp2);
        adjlist[tmp2].push_back(tmp1);
    }

    vector<int> color(n,0);

    dfs(0,color,adjlist);

    cout << sum << endl;

    return 0;
}

void dfs(const int& now, vector<int>& color, const vector<vector<int>>& adjlist){

    color[now] = 1;

    if(find(color.begin(),color.end(),0) == color.end()){
        sum++;
        color[now] = 0;
        return;
    }

    for(auto i:adjlist[now]){
        if(color[i]==0){
            dfs(i,color,adjlist);
        }
        
    }

    color[now] = 0;
}

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

int main()
{
    int H, N;
    vector<int> A;
    int res;
    int t;

    cin >> H >> N;
    rep(i, N)
    {
        cin >> t;
        A.push_back(t);
    }

    res = accumulate(A.begin(), A.end(), 0);

    if (res >= H)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,m,n) for(int i=(m);i<(n);i++)
#define VSORT(v) sort(v.begin(),v.end());
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;
const int di[]={-1,0,1,0},dj[]={0,-1,0,1};
const int INF = 99999999;
const ll LINF = 9999999999999;

int main()
{
    int n;
    cin>>n;
    vector<ll> z(n),w(n);
    ll maxz=0,minz=LINF,maxw=0,minw=INF;
    REP(i,n)
    {
        ll x,y;
        cin>>x>>y;
        z[i]=x+y;
        w[i]=x-y;
    }
    sort(z.begin(),z.end());
    sort(w.begin(),w.end());

    cout<<max(z.back()-z[0],w.back()-w[0]);

}


Measured memory_bytes: 6420
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int>h(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  vector<int>res(n);
  res[0]=0;
  res[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;i++)
  {
    res[i]=min(res[i-1]+(abs(h[i]-h[i-1])),res[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<res[n-1];
}

Measured memory_bytes: 3944