akhauriyash/Code-Regression huggingface dataset:
//
// Created by tac on 2016/10/15.
//

#include <algorithm>
#include <cstdlib>
#include <string>
#include <iostream>
#include <sstream>

namespace  {

std::string string_to_upper(const std::string str) {
    std::string ret = str;

    std::transform(str.cbegin(), str.cend(), ret.begin(), ::toupper);

    return ret;
}

//int count_word(const std::string text, const std::string word) {
//    int count = 0;
//
//    auto pos = text.find(word);
//    while (pos != std::string::npos) {
//        ++count;
//        pos = text.find(word, pos + word.length());
//    }
//
//    return count;
//}

int count_word2(const std::string& text, const std::string& word) {
    std::stringstream ss;
    ss << text << std::endl;
    int count = 0;
    std::string s;
    while (true) {
        ss >> s;
        if (ss.eof()) {
            break;
        }
        if (s == word) {
            ++count;
        }
    }
    return count;
}


}


int main() {
    std::string word;
    std::string text;

    getline(std::cin, word);
    int count = 0;
    while (true) {
        getline(std::cin, text);
        if (text == "END_OF_TEXT") {
            break;
        }
        count += count_word2(string_to_upper(text), string_to_upper(word));
    }
    std::cout << count << std::endl;

    return EXIT_SUCCESS;
}

Measured memory_bytes: 3212
//150 C - Count Order 2020/01/10
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n; cin >> n;
    vector<int> v(n);
    vector<int> p(n);
    vector<int> q(n);
    rep(i, n) v[i] = i+1;
    rep(i ,n) cin >> p[i];
    rep(i ,n) cin >> q[i];
    int counter=0;
    int a; int b;
    do{
        if(v == p) a = counter;
        if(v == q) b = counter;
        ++counter;
    } while(next_permutation(v.begin(),v.end()));

        cout << abs( a - b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	string S;
	cin >> S;
	if (S.size() == 2) {
		cout << S;
	}
	else {
		cout << S[2] << S[1] << S[0] << endl;
	}
}

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

using namespace std;

bool is_prime(int n) {
    static int prime_max = 1;
    static vector<int> primes;
    if (n > prime_max) {
        for (int m=prime_max+1; m<=n; m++) {
            bool is_prime = true;
            for (vector<int>::iterator iter=primes.begin(); iter!=primes.end(); iter++) {
                if (m%(*iter) == 0) {
                    is_prime = false;
                    break;
                }
                if ((*iter)*(*iter) > m) {
                    break;
                }
            }
            if (is_prime) {
                primes.push_back(m);
            }
        }
        prime_max = n;
    }
    return binary_search(primes.begin(), primes.end(), n);
}

int main() {
    int a, d, n;
    while (true) {
        cin >> a >> d >> n;
        if (a == 0) {
            break;
        }
        int series = a;
        int count = 0;
        while (true) {
            if (is_prime(series)) {
                count++;
            }
            if (count == n) {
                break;
            }
            series += d;
        }
        cout << series << endl;
    }
    return 0;
}

Measured memory_bytes: 1728
N=int(input())
x = [list(map(int,input().split())) for _ in range(N)]
y = []
for i in range(N):
    y.append((x[i][0]-x[i][1], x[i][0]+x[i][1]))
y.sort(key = lambda x:x[1])
res = 0
t = -10**9
for i in range(N):
    if t <= y[i][0]:
        res += 1
        t = y[i][1]
print(res)


Measured memory_bytes: 71768
n = int(input())
X = []
x_wid = []
counter = 0
Min = 0
Max = 0

for i in range(n):
  X.append(list(map(int,input().split())))
  
X = sorted(X)

for i in range(n):
  if i == 0:
    Min = X[i][0] - X[i][1]
    Max = X[i][0] + X[i][1]
  else:
    if (X[i][0] - X[i][1]) < Max:
      counter += 1
      Max = min(Max, X[i][0] + X[i][1])
    else:
      Max = X[i][0] + X[i][1]
#  print("Max:", Max)

print(n - counter)

Measured memory_bytes: 28640
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<queue>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	VgetI(n);
	printf("ABC%d\n",n);
}


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

int main() {
  map<string, int> mp;
  string s,t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u; cin >> u;
  mp[s] = a, mp[t] = b;
  mp[u] --;
  cout << mp[s] << " " << mp[t] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
ll mod = pow(10, 9) + 7;
int main(){
    ll K[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin >> k;
    cout << K[k-1] << endl;
    return 0;
}


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

#define  ll   long long
#define  pb  push_back
#define  mp  make_pair
#define  MAX  500006
#define  MAX1  10000008
#define  mem(a,v)   memset(a,v,sizeof(a))

template <typename T>
T mymax (T a,T b){return (a>b)?a:b;}
template <typename T>
T mymin (T a,T b){return (a<b)?a:b;}
template <typename T>
T myabs (T a){return (a<0)?(-1*a):a;}
template <typename T>
T mysqrt (T x){if (x == 0 | x == 1)return x;int start = 1, End = x, ans;while (start <= End){int mid = (start + End) / 2;if (mid*mid == x)return mid;if (mid*mid < x){start = mid + 1;ans = mid;}else End = mid-1;}return ans;}

void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}

ll A[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

int main ()
{
    fastIO();
    ll a,b,c,n,m,k,p,q,r;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    float x,y,z;
    ll Max= 0,Max1=-1e18+1;
    ll Min = 1e18;
    string s,s1,s3,s4;

    cin>>n>>k;

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

    sort(A,A+n);
    for(int i=0;i<n-k;i++)sum+=A[i];

    cout<<sum<<endl;


    return 0;
}


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

int main(){
    string s; cin>>s;
    int n=s.size();
    int a=0;
    for(int i=0;i<n;i+=2){
        if(s[i]=='1')a++;
    }
    for(int i=1;i<n;i+=2){
        if(s[i]=='0')a++;
    }
    int b=0;
    for(int i=0;i<n;i+=2){
        if(s[i]=='0')b++;
    }
    for(int i=1;i<n;i+=2){
        if(s[i]=='1')b++;
    }
    cout<<min(a,b)<<endl;
}


Measured memory_bytes: 512
import bisect
s=list(input())
t=list(input())
s=s+s
u=[[] for i in range(26)]
x=0
count=0

for i in range(ord('a'),ord('z')+1):
    for j in range(len(s)):
        if i==ord(s[j]):
            u[i-97].append(j+1)

for i in range(len(t)):
    if len(u[ord(t[i])-97])==0:
        print(-1)
        exit()
    b=bisect.bisect_left(u[ord(t[i])-97],x+1)
    
    if u[ord(t[i])-97][b]>len(s)//2:
        count+=u[ord(t[i])-97][b]-x
        x=u[ord(t[i])-97][b]-len(s)//2
        
    else:
        count+=u[ord(t[i])-97][b]-x
        x=u[ord(t[i])-97][b]
        
        
print(count)  

     

    


Measured memory_bytes: 63236
import itertools
N,K=map(int,input().split())
D=set(list(map(str,input().split())))
U=list({'0','1','2','3','4','5','6','7','8','9'}^D)
U.sort()

PRD1 = list(itertools.product(U, repeat=len(str(N))))
PRD2 = list(itertools.product(U, repeat=len(str(N))+1))

import sys
for i in range(len(PRD1)):
    T=int(''.join(PRD1[i]))
    if T>=N:
        print(T)
        sys.exit()

for i in PRD2:
    T=int(''.join(i))
    if T>=N:
        print(T)
        sys.exit()

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

int h, w, k;
vector<vector<int>> s(10, vector<int>(1000));
int ans = 1000000000;

void dfs(int n, int now, vector<vector<int>> &v) {
	if (n == h) {
		for (int i = 0; i < v.size(); i++) {
			for (int j = 0; j < w; j++) {
				if (v[i][j] > k) return;
			}
		}
		vector<int> l(v.size());
		for (int j = 0; j < w-1; j++) {
			bool cut = false;
			for (int i = 0; i < v.size(); i++) {
				l[i] += v[i][j];
				if (l[i] + v[i][j+1] > k) cut = true;
			}
			if (cut) {
				now++;
				fill(l.begin(), l.end(), 0);
			}
		}
		ans = min(ans, now);
		return;
	}
	v.push_back(s[n]);
	dfs(n+1, now+1, v);
	v.pop_back();
	for (int j = 0; j < w; j++) {
		v.back()[j] += s[n][j];
	}
	dfs(n+1, now, v);
	for (int j = 0; j < w; j++) {
		v.back()[j] -= s[n][j];
	}
	return;
}

int main() {
	cin >> h >> w >> k;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char x;
			cin >> x;
			s[i][j] = x - '0';
		}
	}
	vector<vector<int>> v(1, vector<int>(w, 0));
	dfs(0, 0, v);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
// https://atcoder.jp/contests/abc132/tasks/abc132_a

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    size_t n1 = count(ALL(s), s[0]);
    size_t n2 = count(ALL(s), s[1]);
    size_t n3 = count(ALL(s), s[2]);
    size_t n4 = count(ALL(s), s[3]);
    if (n1 == 2 && n2 == 2 && n3 == 2 && n4 == 2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

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

int N, M, X;
vector<int> A;

int main(){
    scanf("%d%d%d", &N, &M, &X);
    for(int i=0; i<M; i++){
        int a = 0;
        scanf("%d", &a);
        A.push_back(a);
    }
    int ub = upper_bound(A.begin(), A.end(), X) - A.begin();
    int ans = min(ub, M-ub);
    printf("%d", ans);
    return 0;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef long long ll;

void solve() {
  ll N, ans = 0;
  cin >> N;
  if (N % 2 == 0) {
    ll tmp = 50;
    ll tmp_cnt = 0;
    while (tmp <= N) {
      tmp_cnt += N / tmp;
      tmp *= 5;
    }
    ans = tmp_cnt + (N / 10);
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
};

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
#a,b,c,k= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しに4 3sum変数使用はsum関数使用できないので注意
step = 0
for i in range(len(a)):
    if step:
        if a[i] == 'F':j(1)
    else:
        if a[i] == 'C':step+=1
j(0)

Measured memory_bytes: 13408
from collections import Counter

n,k,q=map(int,input().split())
l=[int(input()) for i in range(q)]

l_c=Counter(l)

for i in range(1,n+1):
  ok=l_c[i]
  num=k-q+ok
  if num>0:
    print("Yes")
  else:
    print("No")
  

Measured memory_bytes: 16916
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;

// A - Happy Birthday!
int main(){
    int A, B;
    cin >> A >> B;
    
    string ans;
    if(A>8 || B>8){
        ans = ":(";
    }else{
        ans = "Yay!";
    }
    cout << ans << endl;
    return 0;
}




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

class Amondai {
    static void Main()
    {
        var S = DateTime.Parse(Console.ReadLine());
        var now = new DateTime(2019,04,30);
        Console.WriteLine(now.CompareTo(S)<0?"TBD":"Heisei");
    }
}


Measured memory_bytes: 13660
#include<cstdio>

int main(){
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);
	int counter = 0;
	for (int i = 1; i <= N; ++i){
		int tenthousands = i / 10000;
		int thousands = i / 1000 % 10;
		int hundreds = i / 100 % 10;
		int tens = i / 10 % 10;
		int ones = i % 10;
		int sumofdigits = tenthousands + thousands + hundreds + tens + ones;
		if(sumofdigits >= A && sumofdigits <= B) counter += i;
	}
	printf("%d\n", counter);
}

Measured memory_bytes: 128
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

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

  int ans = N;
  
  for (int m=0; m<M && ans >= 0; ++m) {
    int a;
    cin >> a;
    ans -= a;
  }

  cout << (ans >= 0 ? ans : -1) << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int white[2001][2001];
int black[2001][2001];

int cntW(int k, int l, int i, int j){
    if(i < k || j < l){
        return 0;
    }
    return white[i][j] - white[k - 1][j] - white[i][l - 1] + white[k - 1][l - 1];
}

int cntB(int k, int l, int i, int j){
    if(i < k || j < l){
        return 0;
    }
    return black[i][j] - black[k - 1][j] - black[i][l - 1] + black[k - 1][l - 1];
}

int main(){

    memset(white, 0, sizeof(white));
    memset(black, 0, sizeof(black));

    int N, K;
    cin >> N >> K;
    int x, y;
    char c;
    int mod = 2 * K;
    for(int i = 0; i < N; i++){
        cin >> x >> y >> c;
        int modX = x % mod;
        int modY = y % mod;

        if(c == 'W'){
            white[modX + 1][modY + 1]++;
        }
        else{
            black[modX + 1][modY + 1]++;
        }
    }

    for(int i = 1; i <= 2 * K; i++){
        for(int j = 1; j <= 2 * K; j++){
            white[i][j] += (white[i - 1][j] + white[i][j - 1] - white[i - 1][j - 1]);
        }
    }

    for(int i = 1; i <= 2 * K; i++){
        for(int j = 1; j <= 2 * K; j++){
            black[i][j] += (black[i - 1][j] + black[i][j - 1] - black[i - 1][j - 1]);
        }
    }

    int ans = 0;
    for(int i = 1; i <= K + 1; i++){
        for(int j = 1; j <= K + 1; j++){
            int cnt = 0;
            cnt += cntB(1, 1, i - 1, j - 1);
            cnt += cntW(1, j, i - 1, j + K - 1);
            cnt += cntB(1, j + K, i - 1, 2 * K);
            cnt += cntW(i, 1, i + K - 1, j - 1);
            cnt += cntB(i, j, i + K - 1, j + K - 1);
            cnt += cntW(i, j + K, i + K - 1, 2 * K);
            cnt += cntB(i + K, 1, 2 * K, j - 1);
            cnt += cntW(i + K, j, 2 * K, j + K - 1);
            cnt += cntB(i + K, j + K, 2 * K, 2 * K);

            ans = max(ans, cnt);
        }
    }

    for(int i = 1; i <= K + 1; i++){
        for(int j = 1; j <= K + 1; j++){
            int cnt = 0;
            cnt += cntW(1, 1, i - 1, j - 1);
            cnt += cntB(1, j, i - 1, j + K - 1);
            cnt += cntW(1, j + K, i - 1, 2 * K);
            cnt += cntB(i, 1, i + K - 1, j - 1);
            cnt += cntW(i, j, i + K - 1, j + K - 1);
            cnt += cntB(i, j + K, i + K - 1, 2 * K);
            cnt += cntW(i + K, 1, 2 * K, j - 1);
            cnt += cntB(i + K, j, 2 * K, j + K - 1);
            cnt += cntW(i + K, j + K, 2 * K, 2 * K);

            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    int n,m;
    cin>>n>>m;
    vin p(m);
    vstr s(m);
    rep(i,m)cin>>p[i]>>s[i];
    vector<bool> sum(n);
    rep(i,n)sum[i]=true;
    vin wa(n);
    rep(i,n)wa[i]=0;
    int sumac=0;
    int sumwa=0;
    rep(i,m){
        if(sum[p[i]-1]){
            if(s[i]=="AC"){
                sumac++;
                sumwa+=wa[p[i]-1];
                sum[p[i]-1]=false;
            }
            else wa[p[i]-1]++;
        }
    }
    cout<<sumac<<" "<<sumwa<<endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>

using namespace std;

int n,m,ans=0;
int tri[5001][5001];


int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int x,y,size;
		scanf("%d%d%d",&y,&x,&size);
		tri[x][y]=size+1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			tri[j][i]=max(tri[j][i],max(tri[j-1][i-1],tri[j][i-1])-1);
			if(tri[j][i]>0)ans++;
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 65000
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int main()
{
  int W, A[100002];
  int close[100002] = {};
  
  scanf("%d", &W);
  for(int i = 1; i <= W; i++) {
    scanf("%d", &A[i]);
    if(A[i] == 0) close[i] = INF;
  }
  for(int i = 1; i <= W; i++) {
    close[i] = max(close[i], close[i - 1] - 1);
    if(A[i] < 0) close[i] = min(close[i], -A[i]);
  }
  for(int i = W; i >= 1; i--) {
    close[i] = max(close[i], close[i + 1] - 1);
    if(A[i] < 0) close[i] = min(close[i], -A[i]);
  }
  int ret = 0;
  for(int i = 1; i <= W; i++) {
    ret += max(0, min(close[i], A[i]));
  }
  printf("%d\n", ret);
}

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

int main(){
  int N, M;

  cin >> N;

  vector<int> T(N);
  for (int i = 0; i < N; i++)
  {
    cin >> T.at(i);
  }
  
  cin >> M;

  vector<pair<int, int>> PM(M);
  for (int i = 0; i < M; i++)
  {
    cin >> PM.at(i).first >> PM.at(i).second;
  }
  
  int sum;
  for (int i = 0; i < M; i++)
  {
    sum = 0;
    for (int j = 0; j < N; j++)
    {
      if (j + 1 == PM.at(i).first){
        sum += PM.at(i).second;
      }
      else
      {
        sum += T.at(j);
      }
      
    }
    cout << sum << endl;
  }
  
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion


int main() {
	//int road[51];
	//rep(i, 51) road[i] = 0;
	//int n, m;
	int a, b, c;
	put a >> b >> c;
	if (a <= c && c <= b) { putans("Yes"); }
	else { putans("No"); }
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();

		if (a<=b) {
			if (c<=b) {
				System.out.println(a+c);
			}else {
				System.out.println(a+b);
			}
		}else {
			if (c<=a) {
				System.out.println(b+c);
			}else {
				System.out.println(b+a);
			}
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--) 

const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;



int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   int r;
   cin >> r;
   cout << 3 * r * r << endl;
   return 0;
}

Measured memory_bytes: 256
N = int(input())
f = []
for _ in range(2):
    f.append(list(map(int, input().split())))

ans = 0

for i in range(N):
    h_ichi = 0
    w_ichi = 0
    flg = False
    ame = 0
    ame += f[0][0]
    for _ in range(N):
        if w_ichi == i and flg == False:
            h_ichi += 1
            flg = True
        else:
            w_ichi += 1
        ame += f[h_ichi][w_ichi]
    ans = max(ans, ame)
print(ans)

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define mp make_pair

#define NIL -1

#define list_itr list<ll>::iterator

#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define rep_cs(i, l, n) for (int i = (l); i <= (n); i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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 MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

bool binary_search(int a[], int n, int key)
{
    int l = 0;
    int r = n;
    int middle;
    while (l < r)
    {
        middle = (l + r) / 2;
        if (key == a[middle])
        {
            return true;
        }

        if (key > a[middle])
        {
            l = middle + 1;
        }
        else if (key < a[middle])
        {
            r = middle;
        }
    }
    return false;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long combination(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_C = 1000;
long long Com[MAX_C][MAX_C];

void combination_for_small()
{
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i)
    {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j)
        {
            Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]) % MOD;
        }
    }
}

bool isPalindrome(string s)
{
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    bool ans = true;
    string front = s.substr(0, n / 2);
    string sec = s.substr((n + 1) / 2);
    if (!isPalindrome(s))
    {
        ans = false;
    }

    if (!isPalindrome(front) || !isPalindrome(sec))
    {
        ans = false;
    }

    cout << (ans ? yes : no) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int maxn = 1e5 + 9;

vector<int> g[maxn];
int was[maxn];

signed main(){
   IOS;
   int n,m; cin >> n >> m;
   rep(i,0,m){
      int x,y; cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
   }
   queue<int> q;
   q.push(1);
   was[1] = 1;
   while(!q.empty()){
      int u = q.front();q.pop();
      for(auto v : g[u]){
         if(!was[v]){
            was[v] = u;
            q.push(v);
         }
      }
   }
   vector<int> ans;
   for(int i = 2;i<=n;i++){
      if(was[i]) ans.push_back(was[i]);
      else{
         cout << "No";
         return 0;
      }
   }
   cout << "Yes\n";
   for(auto x : ans) cout << x << "\n";
}

Measured memory_bytes: 14244
import java.io.*;
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();
		int c=sc.nextInt();
		System.out.println(a<=c&&c<=a+b?"YES":"NO");
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int64_t intl;


intl modpow(intl a, intl n, intl p){
  intl res = 1;
  while (n > 0){
    if (n&1){res = (res * a) % p;}
	a = (a * a) % p;
    n >>= 1;
  }
  return res;
}

intl modinv(intl a, intl p){
  if (a==0){
    cout << "/0 at modinv"<<endl;
    exit(0);
  }
  if (a < 0){
    cout << "/- at modinv" <<endl;
    exit(0);
  }
  if (a==1){return 1;}
  if (a > p){return modinv(a%p, p);}

  return p - ( modinv(p%a,p) * (p/a) ) % p;
}

intl modcomb(intl n, intl k, intl p){
  if (k > n || k < 0 || n < 0){
    cout << "error at modcomb"<<endl;
    exit(0);
  }
  if (2*k > n){ k = n-k;}
  if (k ==0){return 1;}
  intl c=1;
  for (intl i = 0; i < k; i++){
    c =( c * ( (n-i) % p ) % p ) * modinv(i+1,p) % p;
  }
  return c;
}

int main(){
  intl mod = 1000000007;
  int X,Y;
  cin >> X >> Y;
  if ( (X+Y)%3 != 0 ){
    cout << 0;
    exit(0);
  }
  
  if( (2*X) < Y || (2*Y) < X){
    cout << 0;
    exit(0);
  }
  
  int step = (X+Y)/3;
  int dof =( min(X,Y)*2 - max(Y,X) )/3;
  cout << modcomb(step, dof, mod);
}

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

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

const int MOD = 1e+9 + 7;

template <typename T>
T pow_mod(T n, T p, T m)
{
    if(p == 0) return 1;
    if(p%2 == 1) return pow_mod<T>(n, p-1, m) * n % m;
    else{
        T tmp = pow_mod<T>(n, p/2, m) % m;
        return tmp * tmp % m;
    }
}

int main()
{
    int N;
    cin >> N;
    vector<long long> C(N);
    REP(i, N) cin >> C[i];

    sort(C.begin(), C.end());  // コストの小さい順に変更していくのが最適

    long long ans = 0, before_cases = 1;
    REP(i, N){
        long long after_cases  = pow_mod<long long>(2, 2*N-2*i-2, MOD) * (N-i+1) % MOD;
        ans += before_cases * C[i] % MOD * after_cases % MOD;
        ans %= MOD;
        before_cases *= 4;
        before_cases %= MOD;
    }    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
const int maxn=105;
int d[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
char a[maxn][maxn];
int h,w;
int ans;
void dfs(int x,int y,char c)
{
	a[x][y]='!';
	for(int i=0;i<4;i++)
	{
		int nx=x+d[i][0],ny=y+d[i][1];
		if(nx>=0&&nx<h&&ny>=0&&ny<w&&a[nx][ny]==c)
			dfs(nx,ny,c);
	}
}

int main()
{
	while(scanf("%d%d",&h,&w)==2&h!=0)
	{
		for(int i=0;i<h;i++)
			scanf("%s",&a[i]);
		ans=0;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				if(a[i][j]!='!')
				{
					dfs(i,j,a[i][j]);
					ans++;
				}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 3152
n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)


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

int main() {
  int H,W;
  cin >> H >> W ;
  vector<char> A(W);

  for (int q=0;q<W+2;q++){
    cout << "#" ;
  }  
  cout << endl;
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      cin >> A.at(j);
    }
    cout << "#" ;
    for (int k=0;k<W;k++){
    cout << A.at(k);
    }
    cout << "#" << endl;
  }

  for (int l=0;l<(W+2);l++){
    cout << "#" ;
  }
  cout << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int h, w;
char a[9][9];

bool judge() 
{
	int fx = 0;
	int fy = 0;
	a[fy][fx] = '.';
	while (!(fx == w - 1 && fy == h - 1)) {//goal につくまで進める
		if (fx < w - 1 && fy < h - 1 && a[fy][fx + 1] == '#' && a[fy + 1][fx] == '.') {//右にあって下にない
			fx++;
			a[fy][fx] = '.';
		}
		else if (fx < w - 1 && fy < h - 1 && a[fy][fx + 1] == '.' && a[fy + 1][fx] == '#') {//下にあって右にない
			fy++;
			a[fy][fx] = '.';
		}
		else if (fx == w - 1 && a[fy + 1][fx] == '#') {
			fy++;
			a[fy][fx] = '.';
		}
		else if (fy == h - 1 && a[fy][fx + 1] == '#') {
			fx++;
			a[fy][fx] = '.';
		}
		else {
			//for (int i = 0; i < h; i++) {
				//for (int j = 0; j < w; j++) {
					//cout << a[i][j] << " ";
				//}
				//cout << endl;
			//}
			return false;
		}
	}//右下の経路は終わり
	a[h - 1][w - 1] = '.';
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#')return  false;
		}
	}

	//for (int i = 0; i < h; i++) {
		//for (int j = 0; j < w; j++) {
			//cout << a[i][j] << " ";
		//}
		//cout << endl;
	//}



	return true;

}




int main()
{
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	cout << (judge() ? "Possible" : "Impossible" )<< endl;

    return 0;
}



Measured memory_bytes: 256
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;
 
ll inv[MAX_N], fac[MAX_N];
 
template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }
 
typedef pair<int, pair<int, int>> edge;
 
class UnionFind {
private:
	vector<int> par;
public:
	vector<int> hen;
	UnionFind(int N) { par = vector<int>(N, -1LL); hen = vector<int>(N,0);}
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};

 
 
 
//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}
 
ll UnionFind::size(int x) {
	return -par[find(x)];
}
 
void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);
	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	if (x == y) hen[x]++;
	else hen[x] += hen[y]+1;
	if (x == y) return;
	par[x] += par[y];
	par[y] = x;
}
 
bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

signed main() {
	int a[3]; cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	if (a[0]+a[2] == a[1] || a[0] + a[1] == a[2]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! debug {
  ($($e:expr), *) => {println!(concat!($(stringify!($e), " = {:?}\n"), *), $($e), *)}
}

fn main() {
  let n = get::val::<usize>();
  let fss = get::lists::<usize>(n);
  let pss = get::lists::<isize>(n);
  
  let profit = |c| {
    let mut p = 0;
    for i in 0 .. n {
      let ref fs = fss[i];
      let ref ps = pss[i];
      let pc = popcount(c, to_decimal(&fs));
      p += ps[pc]
    }
    p
  };
  
  let ans = (1..1024).map(profit).max().unwrap();
  println!("{}", ans);
}

fn popcount(x: usize, y: usize) -> usize {
  let mut p = 0;
  let xy = x & y;
  for i in 0 .. 64 {
    if xy & (1<<i) == (1<<i) {p += 1}
  }
  p
}

fn to_decimal(bs: &[usize]) -> usize {
  let mut d = 0;
  for (i,b) in bs.iter().rev().enumerate() {
    d += b << i
  }
  d
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

ll o=0;
set<ll> op;
bool isPrime(ll n)
{
	// Corner case
	if(n==2){
		return true;
	}
	else if (n <= 1 || n%2==0)
		return false;

	for (ll i = 3; i <= sqrt(n); i+=2)
		if (n % i == 0)
			return false;

	return true;
}

void tbaben(ll i){
	//int j=floor(sqrt(i));
	if(isPrime(i)){
		if(!op.count(i)){
			o++;
		}
		return;
	}
	for (ll k=2;k<=i;k++){
		if (i%k==0 && !op.count(k)){
			if(isPrime(k)){
				o++;
				op.insert(k);
				tbaben(i/k);
				return;
			}
			else{
				for(ll d=2;d<=sqrt(k);d++){
					ll oi=d*d;
					while(oi<=k){
						if(oi==k&&isPrime(d)){
							o++;
							op.insert(k);
							tbaben(i/k);
							return;
						}
						oi*=d;
					}
				}
			}
		}

	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
	cin>>t;
	tbaben(t);
	cout<<o<<endl;
	return 0;
}


Measured memory_bytes: 3688
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  int n, x;
  cin >> n >> x;
  cout << 3 * (n - __gcd(n, x)) << '\n';
  rtn 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
//#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS() 
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 998244353;
const ll maxn=1e3+5;
ll pw(ll x, ll p){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=mod;
        }
        x*=x;
        x%=mod;
        p>>=1;
    }
    return ret;
}
ll inv(ll x){
    return pw(x, mod-2);
}
bool cmp(pii x, pii y) {
    return x.s<y.s;
}
signed main(){
    IOS();
    int n,m; cin>>n>>m;
    vector<int> graph[n+1], in(n+1), pointing[n+1];
    REP(i,m){
        int x,y; cin>>x>>y;
        graph[x].pb(y);
        pointing[y].pb(x);
        in[y]++;
    }
    vector<int> res;
    queue<int> qu;
    REP1(i,n){
        //cout<<in[i]<<' ';
        if (in[i]==0) qu.push(i);
    }
    //cout<<endl;
    while(qu.size()){
        int j=qu.front();
        res.pb(j);
        REP(i,graph[j].size()){
            in[graph[j][i]]--;
            if (in[graph[j][i]]==0){
                qu.push(graph[j][i]);
            }
        }
        qu.pop();
    }
    vector<int> dp(n+1);
    int ans=0;
    //cout<<res.size()<<endl;
    REP(i,n){
    	bug(i);
        int k=res[i];
        REP(j,pointing[k].size()){
        	//cout<<pointing[k][j]<<' ';
            dp[k]=max(dp[k], dp[pointing[k][j]]+1);
        }
        ans=max(ans, dp[k]);
        //cout<<endl;
        //cout<<ans<<endl;
    }
 
    cout<<ans<<endl;
 
 
}

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

const ll INF = 1LL << 60;

ll N, M;
struct Rerooting {
    /* TODO: start 問題ごとに書き換え */
    struct DP {  // DP の型
        ll dp;
        DP(ll dp_) : dp(dp_) {}
    };

    // 単位元はしっかり定義する(末端でもadd_rootされるので注意)
    const DP identity = DP(1);

    // d:辺eに対応する部分木のdpの値  cost:eのコスト
    function<DP(DP, DP, long long)> merge = [](DP dp_cum, DP d, long long cost) -> DP {
        ll v = dp_cum.dp * d.dp;
        v %= M;
        return DP(v);
    };

    // まとめたDPを用いて、新たな部分木のDPを計算する
    function<DP(DP)> add_root = [](DP d) -> DP {
        return DP(d.dp + 1);
    };
    /* TODO: end 問題ごとに書き換え */

    // グラフの定義
    struct Edge {
        int from;
        int to;
        long long cost;
    };
    using Graph = vector<vector<Edge>>;

    // dp[v][i]: vから出るi番目の有向辺に対応する部分木のDP
    vector<vector<DP>> dp;

    // ans[v]: 頂点vを根とする木の答え
    vector<DP> ans;
    Graph G;

    Rerooting(int N) : G(N) {
        dp.resize(N);
        ans.assign(N, identity);
    }

    void add_edge(int a, int b, long long c = 1) {
        G[a].push_back({a, b, c});
    }
    void build() {
        dfs(0);            // 普通に木DP
        bfs(0, identity);  // 残りの部分木に対応するDPを計算
    }

    DP dfs(int v, int p = -1) {  // 頂点v, 親p
        DP dp_cum = identity;
        int deg = G[v].size();
        dp[v] = vector<DP>(deg, identity);
        for (int i = 0; i < deg; i++) {
            int u = G[v][i].to;
            if (u == p) continue;
            dp[v][i] = dfs(u, v);
            dp_cum = merge(dp_cum, dp[v][i], G[v][i].cost);
        }
        return add_root(dp_cum);
    }
    void bfs(int v, const DP &dp_p, int p = -1) {
        int deg = G[v].size();
        for (int i = 0; i < deg; i++) {  // 前のbfsで計算した有向辺に対応する部分木のDPを保存
            if (G[v][i].to == p) dp[v][i] = dp_p;
        }

        vector<DP> dp_l(deg + 1, identity), dp_r(deg + 1, identity);  // 累積的なDP
        for (int i = 0; i < deg; i++) {
            dp_l[i + 1] = merge(dp_l[i], dp[v][i], G[v][i].cost);
        }
        for (int i = deg - 1; i >= 0; i--) {
            dp_r[i] = merge(dp_r[i + 1], dp[v][i], G[v][i].cost);
        }
        ans[v] = add_root(dp_l[deg]);
        for (int i = 0; i < deg; i++) {
            int u = G[v][i].to;
            if (u == p) continue;

            // 累積同士のmergeなので、edgeは適当に
            bfs(u, add_root(merge(dp_l[i], dp_r[i + 1], 0)), v);
        }
    }
};

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

    rep(i, N - 1) {
        ll x, y;
        cin >> x >> y;
        x--; y--;
        reroot.add_edge(x, y);
        reroot.add_edge(y, x);
    }
    reroot.build();

    rep(i, N) {
        cout << (reroot.ans[i].dp - 1) % M << endl;
    }
}

Measured memory_bytes: 37212
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		print();
	}

	private static void print() throws IOException {
		Scanner scn = new Scanner(System.in);
		int recX = scn.nextInt();
		int recY = scn.nextInt();
		int cirX = scn.nextInt();
		int cirY = scn.nextInt();
		int cirRad = scn.nextInt();
		circleInRectangle(recX, recY, cirX, cirY, cirRad);
	}

	private static void circleInRectangle(int recX, int recY, int cirX, int cirY, int cirRad) {
		if (cirX - cirRad < 0) {
			System.out.println("No");
		} else if (cirX + cirRad > recX) {
			System.out.println("No");
		} else if (cirY - cirRad < 0) {
			System.out.println("No");
		} else if (cirY + cirRad > recY) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

}

Measured memory_bytes: 26336
while True:
    h, w = list(map(int, input().split()))
    if h==0 and w==0:
        break
    for i in range(h):
        s = ''
        for j in range(w):
            if i%2 == 0 and j%2 == 0:
                s += '#'
            elif i%2 == 1 and j%2 == 1:
                s += '#'
            else:
                s += '.'
        print(s)
    print()


Measured memory_bytes: 5608
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  
  int min = a[0];
  int r = 1;
  for (int i = 1; i < n; i++) {
    if (min > a[i]) {
	    min = a[i];
      r++;
    }
    
  }
  cout << r << endl;
  
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    string a[n];
    int arr[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        int t;
        cin >> t;
        arr[i] = (i>0)?arr[i-1]+t:t;
    }
    string x;
    cin >> x;
    int id = find(a,a+n,x) - a;
    // cout << id << endl;
    cout << arr[n-1] - arr[id] << endl;


}


Measured memory_bytes: 256