akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define slf(n) scanf("%lld",&n)
#define plf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,less<int> > q;
const int N=1e3+10;
const int mod=1e9+7;
int T,n,m,f[N],d[N];
string s,t;
void solve(){
	int count=0;
	rep(i,0,2)if(s[i]==t[i])count++;
	cout<<count<<endl;
	return ;
}
int main()
{
	cin>>s;
	cin>>t;
	solve();
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a)      cout<<a<<" "
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	cin>>n>>m>>k;
	if(n+m<k-1)re pr(m+(n+m+1)),0;
	pr(m+k);


	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    for i in range(H):
        for j in range(W):
            if (i + j)%2 == 0:
                print("#", end="")
            else :
                print(".", end="")
        print()
    if H == 0 and W == 0:
        break
    print()


Measured memory_bytes: 7008
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;



int main(){
	int n,m;
	cin>>n>>m;
	vector<int> a(n+m-1),b(n+m-1),par(n+1,0);
	vector<vector<int>>e=vector<vector<int>>(n+1,vector<int>(0));
	int v[101010]={};
	int h[101010]={};
	FOR(i,0,n+m-1){
		cin>>a[i]>>b[i];
		e[a[i]].PB(b[i]);
		h[b[i]]++;
	}
	queue<int> q;
	FORQ(i,1,n){
		if(h[i]==0){
			q.push(i);
			par[i]=0;
		}
	}

	while(q.size()){
		int now=q.front();
		q.pop();
		for(auto x:e[now]){
			par[x]=now;
			h[x]--;
			if(h[x]==0){
				q.push(x);
			}
		}
	}



	FORQ(i,1,n){
		cout<<par[i]<<endl;
	}
 return 0;
}


Measured memory_bytes: 7936
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	d := eGetInt(scanner)
	w := d*2 + 1
	fmt.Println((n - 1 + w) / w)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}

func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int a;
bool check(const string st,const int isa) {
	a = 0;
	if (isa) {
		if (st[a] != '>')return false;
		a++;
		if (st[a] != '\'')return false;
		a++;
		int num = 0;
		while (st[a] == '=') {
			num++;
			a++;
		}
		if (!num)return false;
		if (st[a] != '#')return false;
		a++;
		int num2 = 0;
		while (st[a] == '=') {
			num2++;
			a++;
		}
		if (num != num2)return false;
		if (st[a] != '~')return false;
		a++;
		if (st[a] != ' ')return false;
		return true;
	}
	else {
		if (st[a] != '>')return false;
		a++;
		if (st[a] != '^')return false;
		a++;
		int num = 0;
		while (1) {
			if (st[a] == 'Q') {
				num++;
				a++;
				if (st[a] != '=') {
					return false;
				}
				else {
					a++;
				}
			}
			else {
				break;
			}
		}
		if (!num)return false;
		
		
		if (st[a] != '~')return false;
		a++;
		if (st[a] != '~')return false;
		a++;
		if (st[a] != ' ')return false;
		return true;
	}
}

int main() {
	int N; cin >> N;
	while (N--) {
		string st; cin >> st;
		for (int i = 0; i < 100; ++i) {

			st.push_back(' ');
		}
		if (check(st, true)) {
			cout << "A" << endl;
		}
		else if (check(st, false)) {
			cout << "B" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2976
/* ITP1_7_8_C:Spreadsheet */
/* 20181123 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	int r, c, i, j;
	int A[101][101] = {0};

	scanf("%d %d", &r, &c);
	for(i = 0; i < r; i++) {
		for(j = 0; j < c; j++) {
			scanf("%d", &A[i][j]);
			A[i][c] += A[i][j];
			A[r][j] += A[i][j];
		}
		A[r][c] += A[i][c];
	}

	for(i = 0; i <= r; i++) {
		for(j = 0; j < c; j++) {
			printf("%d ", A[i][j]);
		}
		printf("%d\n", A[i][j]);
	}

	return 0;
}


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

typedef unsigned long long ll;
ll tmp = 1e9+7;
vector<int> insuu(1001,0);

void sosuu(int number)
{
    int i;
    for(i = 2;i <= number;++i){
        while(number%i == 0){
            ++insuu.at(i);
            number /= i;
        }
    }
    return;
}

int main()
{
    int n;
    int i,j,k;
    cin >> n;
    ll ans = 1;
    for(i = 2;i <= n;++i){
        sosuu(i);
    }
    for(i = 1;i <= 1000;++i){
        ans *= (insuu.at(i)+1);
        ans %= tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pi 3.1415926535897932384626
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string x;
    cin>>x;
    if((x[0]-'0')+(x[1]-'0')+(x[2]-'0')+(x[3]-'0')==7)printf("%c+%c+%c+%c=7\n",x[0],x[1],x[2],x[3]);
    else if((x[0]-'0')+(x[1]-'0')+(x[2]-'0')-(x[3]-'0')==7)printf("%c+%c+%c-%c=7\n",x[0],x[1],x[2],x[3]);
    else if((x[0]-'0')+(x[1]-'0')-(x[2]-'0')+(x[3]-'0')==7)printf("%c+%c-%c+%c=7\n",x[0],x[1],x[2],x[3]);
    else if((x[0]-'0')+(x[1]-'0')-(x[2]-'0')-(x[3]-'0')==7)printf("%c+%c-%c-%c=7\n",x[0],x[1],x[2],x[3]);
    else if((x[0]-'0')-(x[1]-'0')+(x[2]-'0')+(x[3]-'0')==7)printf("%c-%c+%c+%c=7\n",x[0],x[1],x[2],x[3]);
    else if((x[0]-'0')-(x[1]-'0')+(x[2]-'0')-(x[3]-'0')==7)printf("%c-%c+%c-%c=7\n",x[0],x[1],x[2],x[3]);
    else if((x[0]-'0')-(x[1]-'0')-(x[2]-'0')+(x[3]-'0')==7)printf("%c-%c-%c+%c=7\n",x[0],x[1],x[2],x[3]);
    else if((x[0]-'0')-(x[1]-'0')-(x[2]-'0')-(x[3]-'0')==7)printf("%c-%c-%c-1%c=7\n",x[0],x[1],x[2],x[3]);
    return 0;
}


Measured memory_bytes: 256
import collections
import queue
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, M = map(int, input().split())
X, Y = [0] * M, [0] * M
g = [[] for _ in range(N)]

for i in range(M):
    X[i], Y[i] = map(int, input().split())

    X[i] -= 1
    Y[i] -= 1
    g[X[i]].append(Y[i])
    g[Y[i]].append(X[i])


def bfs(x, y):
    visited = [False] * N
    q = queue.Queue()
    for nx in g[x]:
        if nx == y:
            continue
        q.put(nx)
        visited[nx] = True

    visited[x] = True

    while not q.empty():
        cur = q.get()
        if cur == y:
            return True

        for nx in g[cur]:
            if visited[nx]:
                continue
            q.put(nx)
            visited[nx] = True

    return False


cnt = 0
for i in range(M):
    if not bfs(X[i], Y[i]):
        cnt += 1

print(cnt)

Measured memory_bytes: 4208
import math
s=int(input())
t=[list(map(int,input().split())) for i in range(s)]
list=[]
for i in range(s):
  for j in range(s):
    a=math.sqrt((t[i][0]-t[j][0])**2+(t[i][1]-t[j][1])**2)
    list.append(a)
c=1
for l in range(s):
  c*=(l+1)
e=c
c=c//s
d=0
for p in range(len(list)):
  d+=list[p]
d=d*c
d=d/e
print(d)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			
			String input;
			for (;;) {
				input = reader.readLine();
				if (input.equals("0")) break;
				char ch;
				int sum = 0;
				for (int i = 0; i < input.length(); i++) {
					ch = input.charAt(i);
					sum += Character.getNumericValue(ch);
				}
				System.out.println(sum);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

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

int main() {
  int X, Y , Z, K;
  cin >> X >> Y >> Z >> K;
  vector<long> A, B, C;
  long tmp;
  for(int i = 0; i < X; ++i) {
    cin >> tmp;
    A.push_back(tmp);
  }
  for(int i = 0; i < Y; ++i) {
    cin >> tmp;
    B.push_back(tmp);
  }
  for(int i = 0; i < Z; ++i) {
    cin >> tmp;
    C.push_back(tmp);
  }  

  vector<long> buf;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      buf.push_back(A[i] + B[j]);
    }
  }
  sort(buf.begin(),buf.end(),greater<long>());
  

  vector<long> vec;
  for(int i = 0; i < min(K,X*Y); ++i) {
    for(int j = 0; j < Z; ++j) {
       vec.push_back(buf[i] + C[j]);
    }
  }
  sort(vec.begin(),vec.end(),greater<long>());

  for(int i = 0; i < K; ++i) {
    cout << vec[i] << endl;
  }
    
  return 0;
  
}


Measured memory_bytes: 43256
N = int(input())
a = [list(map(str, input().split())) for i in range(N)]
a = list(map(list, zip(*a)))
ans = 0
for i, v in enumerate(a[1]):
    if v == "JPY":
        ans += int(a[0][i])
    else:
        ans += float(a[0][i]) * 380000

print(ans)


Measured memory_bytes: 3060
k,s=gets.split.map(&:to_i)
count=0
result=[]
for x in 0..k
    for y in 0..k
      z=s-(x+y)
      if z<=k && z>=0
      count+=1
      #result<<[x,y,z]
      end
      
    end
end
#p result
p count

Measured memory_bytes: 14396
#include <cstdio>
#include <iostream>
using namespace std;
int N, K;
long long result;

int main()
{
    scanf("%d %d", &N, &K);
    for(int i = 1; i <= N; i++)
    {
        if(i - K >= 0)
        {
            int temp;
            result += (N / i) * (i - K);
            temp = N % i + 1 - K;
            if(temp > 0)
            {
                result += temp;
            }
        }
    }
    if(K == 0)
    {
        result -= N;
    }
    printf("%lld", result);
}

Measured memory_bytes: 256
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    if N % 2 == 0:
        print(N)
    else:
        print(N * 2)


if __name__ == '__main__':
    main()


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

using namespace std;
#define ll long long
#define ull unsigned ll
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const int N = 1e5 + 10;

int main() {
    string s;
    cin >> s;
    if (s.back() == 's')
        cout << s << "es" << endl;
    else cout << s << "s" << endl;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n ;
	VI a(n);
	rep(i, n) cin >>a[i];

	auto fc=[&](int p){
		ll sm = 0, ans =0;
		rep(i, n){
			sm += a[i];
			if(sm >= 0 && (p+i)%2 ){
				ans += abs(-1 -sm); sm = -1;
			}else if(sm <= 0 && (p+i+1)%2){
				ans += abs( 1 -sm); sm =  1;
			}
		}
		return ans;
	};
	cout << min(fc(0), fc(1)) <<"\n";
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n;
vll a;

void input() { 
  cin >> n;
  a.resize(n);
  rep(i,n){
    cin >> a[i];
  }
}

void solve() {
  sort(a.begin(),a.end(),greater<ll>());
  ll ans=a[0];
  ll t=(ll)floor(n/2.0)-1;
  rep(i,t){
    ans+=a[i+1]*2;
  }
  if (n%2==1){ans+=a[t+1];}
  cout << ans << endl;
}

int main() {
  input();
  solve();
  return 0;
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int ab = a + b;
	int bc = b + c;
	int ca = c + a;

	if (ab < bc && ab < ca) {
		cout << ab << endl;
	}
	else if (bc < ab && bc < ca) {
		cout << bc << endl;
	}
	else {
		cout << ca << endl;
	}


	return 0;
}

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

int main(){
    ll A,V,B,W,T;
    cin>>A>>V>>B>>W>>T;
    cout<<(abs(A-B)<=(V-W)*T?"YES":"NO")<<endl;
}


Measured memory_bytes: 3596
import sys

stdin = sys.stdin

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

n = ni()
l = nl()
print(min(sum((x-y)**2 for x in l) for y in range(101)))


Measured memory_bytes: 3060
n = int(input())

a = [int(n) for n in input().split()]

sum_a = sum(a)

#i = 0の場合
left = a[0]
right = sum_a - left
delta_min = abs(left - right)
left_ = left

# i >= 1の場合
for i in range(1, n-1):
    left = left_ + a[i]
    right = sum_a - left

    delta = abs(left - right)

    delta_min = min(delta_min, delta)
 
    left_ = left

print(delta_min)


Measured memory_bytes: 24812
class Solution:
    def solve(self, A, N: int, b) -> str:

        s = {}
        for i in range(3):
            for j in range(3):
                s[A[i][j]] = (i, j)

        isOpen = [[False] * 3 for _ in range(3)]

        for bi in b:
            if bi in s:
                isOpen[s[bi][0]][s[bi][1]] = True

        # check
        for i in range(3):
            check = True
            for j in range(3):
                if not isOpen[i][j]:
                    check = False
                    break

            if check:
                return "Yes"

        for j in range(3):
            check = True
            for i in range(3):
                if not isOpen[i][j]:
                    check = False
                    break

            if check:
                return "Yes"

        check = True
        for i in range(3):
            if not isOpen[i][i]:
                check = False
                break

        if check:
            return "Yes"

        check = True
        for i in range(3):
            if not isOpen[2-i][i]:
                check = False
                break

        if check:
            return "Yes"

        return "No"


if __name__ == '__main__':

    # standard input
    A = []
    for i in range(3):
        A.append(list(map(int, input().split())))

    N = int(input())
    b = []
    for n in range(N):
        b.append(int(input()))

    # solve
    solution = Solution()
    print(solution.solve(A, N, b))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,cnt,k;ll a[200005],sum[200005],ans;
map<ll,int> m;
struct segtree{
    int dat[525000],n;
    void build(int nn)
    {
        n=1;
        while(n<=nn) n<<=1;
    }
    void update(int k,int a){
        k+=n-1;
        dat[k]+=a;
        while(k>0){
            k=(k-1)/2;
            dat[k] = dat[(k<<1)+1]+dat[(k<<1)+2];
        }
    }
    int query(int l,int r){
        return query(l,r+1,0,0,n);
    }
    int query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return 0;
        if(a<=l&&r<=b) return dat[k];
        return query(a,b,(k<<1)+1,l,(l+r)>>1)+query(a,b,(k<<1)+2,(l+r)>>1,r);
    }
}seg;
int main()
{
    fastio;
    cin>>n>>k;
    seg.build(n);
    rep(i,1,n) cin>>a[i];
    rep(i,1,n) sum[i] = sum[i-1] + a[i] - k, m[sum[i]] = 0;
    m[0] = 0;
    for(map<ll,int>::iterator it = m.begin();it != m.end();it++) it->se = ++cnt;
    rep(i,1,n) sum[i] = m[sum[i]];
    seg.update(m[0],1);
    rep(i,1,n) {
        ans += seg.query(1,sum[i]);
        seg.update(sum[i],1);
    }
    cout<<ans<<'\n';
    return 0;
}

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

int main() {
  int n;
  vector<int> c, v;
  int best;
  cin >> n;
  while (n--) {
    cin >> best;
    v.push_back(best); 
  }
  while (cin >> best) c.push_back(best);
  best = 0;
  for (int i = 0; i < c.size(); i++)
    if (v[i] > c[i]) best += v[i] - c[i];
  printf("%d\n", best);

  return 0;}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int x,a,a1,b,b1,c;
    scanf("%d",&x);
    a=x/500;
    a1=a*1000;
    b=(x%500)/5;
    b1=b*5;
    c=a1+b1;
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

ll N, A, B;
ll h[100010];

bool C(ll T) {
    ll cnt = 0;
    rep(i, 0, N) {
        ll tmp = h[i] - B * T;
        if(tmp > 0) {
            cnt += (tmp / (A - B));
            if(tmp % (A - B)) cnt++;
        }
    }
    return cnt <= T;
}

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

    cin >> N >> A >> B;
    rep(i, 0, N) cin >> h[i];

    int left = 0, right = 1e9;
    while(right - left > 1) {
        ll mid = (left + right) / 2;
        if(C(mid)) right = mid;
        else left = mid;
    }

    cout << right << endl;

}


Measured memory_bytes: 1024
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <time.h>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9

const double eps = 1e-10;


int main()
{
    int n;
    cin >> n;
    int base = 1;
    while(base *2 <= n) base *= 2;
    cout <<base<<endl;
    return 0;
}



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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;
const int maxN = 1e5 + 5;
int fact[maxN];

signed main() {
  fact[1] = 1;
  for (int i = 2; i <= maxN; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  int n, m;
  std::cin >> n >> m;
  if (abs(n - m) == 1)
    print((fact[n] * fact[m]) % mod);
  else if (n == m)
    print((fact[n] * fact[m] * 2) % mod);
  else
    print(0);
}


Measured memory_bytes: 1024
import sys

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

input = sys.stdin.readline
n = int(input())

yaku_list = make_divisors(n)
index = int(len(yaku_list)/2)


if len(yaku_list) % 2 == 0:
    result = yaku_list[index-1] - 1 + yaku_list[index] - 1 
else:
    result = yaku_list[index] - 1 + yaku_list[index] - 1 

print(result)


Measured memory_bytes: 9232
import bisect

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    num_list.sort()

    ans = 0

    for i in range(n-2):
        for j in range(i+1,n-1):
            tmp = bisect.bisect_left(num_list, num_list[i]+num_list[j])
            ans += tmp - j - 1

    print(ans)

if __name__ == '__main__':
    main()

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

int n,T,x,y,ans,d[61],fa[61],col[61],Col[61],dd[61],nw;
vector<int> v[61],V[61];

void addedge(int x,int y) {v[x].push_back(y),v[y].push_back(x);}
void Addedge(int x,int y) {V[x].push_back(y),V[y].push_back(x);}

bool work()
{
	for (int i=1; i<nw; i++)
	{
		int p=0;
		for (int j=1; j<=n; j++) if (col[j]==1&&Col[j]==1) {p=j; break;}
		if (!p)
		{
			memset(col,0,sizeof(col));
			memset(Col,0,sizeof(Col));
			return 0;
		}
		col[p]=Col[p]=2;
		for (int j=0,sz=v[p].size(); j<sz; j++)
			if ((--dd[v[p][j]])==1) if (!col[v[p][j]]) col[v[p][j]]=1;
		for (int j=0,sz=V[p].size(); j<sz; j++)
			if (V[p][j]!=fa[p]) Col[V[p][j]]=1;
	}
	memset(col,0,sizeof(col));
	memset(Col,0,sizeof(Col));
	return 1;
}

void getfa(int x)
{
	for (int i=0,sz=V[x].size(); i<sz; i++)
		if (V[x][i]!=fa[x]) fa[V[x][i]]=x,getfa(V[x][i]);
}

void dfs(int x)
{
	col[x]=Col[x]=2,nw--;
	for (int i=0,sz=V[x].size(); i<sz; i++)
		if (V[x][i]!=fa[x])
		{
			bool bo=0;
			for (int k=0,siz=v[x].size(); k<siz; k++)
				if (v[x][k]==V[x][i]) {bo=1; break;}
			if (bo) dfs(V[x][i]); else Col[V[x][i]]=1;
		}
}

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n),ans=n+1;
		for (int i=1; i<=n; i++) v[i].clear(),V[i].clear(),d[i]=0;
		for (int i=1; i<n; i++) scanf("%d%d",&x,&y),addedge(x,y),d[x]++,d[y]++;
		for (int i=1; i<n; i++) scanf("%d%d",&x,&y),Addedge(x,y);
		if (n<=2) {puts("0"); continue;}
		for (int i=1; i<=n; i++)
		{
			Col[i]=1,fa[i]=0,getfa(i),nw=n;
			for (int j=1; j<=n; j++) if ((dd[j]=d[j])==1) col[j]=1;
			if (work()) {ans=n; break;}
		}
		for (int i=1; i<=n; i++)
		{
			nw=n,fa[i]=0,getfa(i),dfs(i);
			for (int j=1; j<=n; j++) if ((dd[j]=d[j])==1) if (!col[j]) col[j]=1;
			if (work()) ans=min(ans,nw);
		}
		if (ans==n+1) puts("-1"); else printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct bian
{
	int nxt,to;
}bi[200020];
int n,m,head[100010],num,d[100010],st[100010],tp,l[100010],r[100010];
bool used[100010],ok[100010];
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;++d[to];}
void dfs(int v)
{
	for(int &i=head[v],u;i;i=bi[i].nxt)
		if(!used[(i+1)/2])
		{
			u=bi[i].to;used[(i+1)/2]=1;
			dfs(u);
		}
	st[++tp]=v;
}
int main()
{
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=1;i<=m;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i=1;i<=n;++i)if(d[i]&1)return printf("No"),0;
	for(int i=1;i<=n;++i)if(d[i]>=6)return printf("Yes"),0;
	int cnt=0;
	for(int i=1;i<=n;++i)cnt+=d[i]==4;
	if(cnt>=3)return printf("Yes"),0;
	dfs(1);
//	for(int i=1;i<=tp;++i)printf("%d ",st[i]);printf("\n");
	int minr=0x3f3f3f3f;
	for(int i=tp-1;i;--i)
	{
		ok[i]=ok[i+1];
		if(!l[st[i]])l[st[i]]=r[st[i]]=i;
		else
		{
			if(r[st[i]]>minr)return printf("Yes"),0;
			if(ok[l[st[i]]])return printf("Yes"),0;
			minr=min(minr,l[st[i]]);
			l[st[i]]=i;
			ok[i]=1;
		}		
	}
	printf("No");
	return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,s,i;
  while(cin>>n,n>-1){
    for(s=0,i=11;i<=n;i++){
      if(i<21)s+=125;
      else if(i>20&&i<31)s+=140;
      else s+=160;
    }
    cout<<3130-s<<endl;
  }
}

Measured memory_bytes: 2988
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


void solve(){

	ll n;
	cin >> n;
	ll cp = n;
	// find all the prime factors of n
	vector<pair<int,int > > pd;
	for(ll i =2;i*i <= n;i++){
		if(cp%i==0){
			int p = i;
			int c= 0;
			while(cp%i==0){
				c++;
				cp/=i;
			}
			pd.pb(mp(p,c));
		}
	}
	if(cp>1)
		pd.pb(mp(cp,1));
	ll ans = 0;
	for(auto e:pd){
		int go = e.second;
		int i =1;
		while(go>0){
			go-=i;
			if(go>=0)
				ans++;
			i++;
		}
	}
	cout << ans << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
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; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int a;
    cin >> a;
    string s;
    cin >> s;
    if(a >= 3200) cout << s;
    else cout << "red";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF=(1LL<<60);

int main(void){
    int N,M; cin >> N >> M;
    vector<int> v[N+1], p(M), y(M);
    for(int i=0; i<M; i++){
        cin >> p[i] >> y[i];    
        v[p[i]].push_back(y[i]);
    }

    for(int i=1; i<=N; i++){
        sort(v[i].begin(), v[i].end());
    }

    for(int i=0; i<M; i++){
        auto itr=lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]);
        int rank=itr-v[p[i]].begin()+1;
        printf("%06d%06d\n", p[i], rank);
    }
}

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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i > (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

string s;

string solve() {
  irep(i, 1, s.length()) {
    if (s[i] == s[i-1]) return "Bad";
  }
  return "Good";
}

int main() {
  cin >> s;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

X, Y = LI()

for i in range(X):
    if 2 * i + 4 * (X - i) == Y:
        print("Yes")
        sys.exit()
    elif 4 * i + 2 * (X - i) == Y:
        print("Yes")
        sys.exit()


print("No")   

Measured memory_bytes: 9308
N = int(input().replace(" ", ""))

n = N
pf = dict()
for i in range(2, N + 1):
	while not n % i:
		if i in pf:
			pf[i] += 1
		else:
			pf[i] = 1
		n //= i
#print(pf)
for pfv in pf.values():
	if pfv % 2:
		print("No")
		break
else:
	print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;


int main(){
    int A, B, C;
    cin >> A >> B >> C;
    string ans;
    if ((A==B || B==C || A==C) && !(A==B && B==C)) {
        ans = "Yes";
    }
    else { ans = "No"; }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int n;
   cin>>n;
   vector<int> a(n);
   rep(i, n) cin>>a[i];

   int nxt=1, cnt=0;
   rep(i, n){
      if(a[i]==nxt) nxt++;
      else cnt++;
   }

   if(cnt==n) cout<<(-1)<<endl;
   else cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
long long MOD = 1e9+7;
long long INF = 1e15;
typedef pair<long long, long long> P;

int main(){
    int N, M;
    cin >> N >> M;
    long long S[N+1], T[M+1];
    rep2(i, 1, N+1){
        cin >> S[i];
    }
    rep2(i, 1, M+1){
        cin >> T[i];
    }
    long long dp[N+1][M+1];
    rep(i, N+1){
        dp[i][0] = 1;
    }
    rep(i, M+1){
        dp[0][i] = 1;
    }
    rep2(i, 1, N+1){
        rep2(j, 1, M+1){
            dp[i][j] = dp[i-1][j] + dp[i][j-1];
            if(S[i] != T[j]){
                dp[i][j] += MOD-dp[i-1][j-1];
            }
            dp[i][j] %= MOD;
        }
    }
    cout << dp[N][M] << endl;
}

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

int main()
{
    unsigned long long int A, B, C, ans;

    cin >> A >> B >> C;
    
    if(A+B+1 >= C){
        ans = B+C;
    }else{
        ans = A+B+1+B;
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

	vector<int> p(n);
	for (int i = 0; i < n; i++)
	{
		cin >> p.at(i);
	}

	int res = 0;
	for (int i = 1; i < n - 1; i++)
	{
		if ((p.at(i) > p.at(i-1) && p.at(i) < p.at(i+1)) || (p.at(i) < p.at(i-1) && p.at(i) > p.at(i+1)))
		{
			res += 1;
		}
	}

	cout << res << endl;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int N(109);

int n, m, k, ans;
int a[N];
int f[100005][2];

int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for (int i=0;i<=k;i++)
	{
		for (int j=0;j<2;j++)
		{
			for (int l=1;l<=n;l++)
			{
				if (i >= a[l] && !f[i - a[l]][!j])
				{
					f[i][j] = 1;
				}

			}
		}
	}
	if (f[k][0]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

  public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     while(in.hasNext()){

         int n = in.nextInt();
         int m = in.nextInt();
         int ans = (n-1)*(m-1);

         System.out.println(ans);
     }
     in.close();
  }
}

Measured memory_bytes: 22996
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll           long long
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;

void solve()
{
    int n , ans=0;
    cin >> n;
    int k = n/1000;
    if(n%1000>0)
    ans = (k+1)*1000 - n;
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long h = sc.nextLong();
		long c=1;
		long sum = 1;

		while(h > 1) {
			h /= 2;
			c *= 2;
			sum += c;
		}

		System.out.println(sum);

		return;

	}

}



Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,sum=0,count=0,f=1,a , b, c;
    cin>>n>>a>>b>>c;
    ll var[3] = {0};
    var[0] = a;
    var[1] = b;
    var[2] = c;
    vector<string> s;
    string temp;
    for(i=0;i<n;i++){
        cin>>temp;
        s.pb(temp);
    }
    vector<char> ans;
    for(i=0;i<n;i++){
        x = s[i][0] - 'A';
        y = s[i][1] - 'A';
        if(var[x] == 0 && var[y] == 0){
            cout<<"No";
            return 0;
        }else if(var[x] == 0){
            ans.pb(s[i][0]);
            var[x]++;
            var[y]--;
        }else if(var[y] == 0){
            ans.pb(s[i][1]);
            var[x]--;
            var[y]++;
        }else if(i < n -1 && (var[x] == 1 || var[y] == 1)){
            if(var[x] == 1 && (((s[i+1][0] - 'A') == x) || ((s[i+1][1] - 'A') == x))){
                ans.pb(s[i][0]);
                var[x]++;
                var[y]--;
            }else{
                ans.pb(s[i][1]);
                var[x]--;
                var[y]++;
            }            
        }else{
            ans.pb(s[i][0]);
            var[x]++;
            var[y]--;
        }
    }
    cout<<"Yes\n";
    for(i=0;i<n;i++){
        cout<<ans[i]<<"\n";
    }
}    
    


Measured memory_bytes: 7432
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
        b: [usize; n],
        c: [usize; n-1]
    }
    let mut ans: usize = 0;
    let mut bef: usize = 1000;
    for i in 0..n {
        ans += b[a[i]-1];
        if bef + 2 == a[i] {
            ans += c[bef];
        }
        bef = a[i]-1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		String[] str = new String[H];
		String[][] S = new String[H][W];
		
		for(int i = 0; i < H; i++) {
			str[i] = sc.next();
		}
		
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				String[] s = str[i].split("");
				S[i][j] = s[j];
			}
		}
		
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(S[i][j].equals("#")) {
					System.out.print("#");
				} else {
					System.out.print(bom(i, j, S));
				}
			}
			System.out.println();
		}
	}
	
	public static int bom(int a, int b, String[][] S) {
		int count = 0;
		for(int i = a - 1; i <= a + 1; i++) {
			if(i < 0 || i >= S.length) {
				continue;
			}
			for(int j = b - 1; j <= b + 1; j++) {
				if(j < 0 || j >= S[0].length) {
					continue;
				}
				if(S[i][j].equals("#")) {
					count++;
				}
			}
		}
		return count;
	}
}


Measured memory_bytes: 35052
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;

const int maxn=2e5+5;

map<long long,int>mp;
long long a[maxn],b[maxn],c[maxn],d[maxn],n,m,K,ans=0;

int lowbit(int x)
{
    return x&(-x);
}
int getsum(int x)
{
    int sum=0;
    while(x)
    {
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}

void add(int x)
{
    while(x<maxn)
    {
        c[x]++;
        x+=lowbit(x);
    }
}

int main()
{
    cin>>n>>K;
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]=a[i]+a[i-1];
        b[i]=a[i]-K*i;
        d[i]=b[i];
    }
    sort(b+1,b+n+1);
    m=unique(b+1,b+n+1)-b;
    for(long long i=1;i<m;i++)
    {
        mp[b[i]]=i;
    }
    for(long long i=1;i<=n;i++)
    {
        if(d[i]>=0)ans++;
        ans=ans+getsum(mp[d[i]]);
        add(mp[d[i]]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main() {
  int N; cin >> N;
  vi W(N); rep(i,N) cin >> W.at(i);

  int S = accumulate(all(W),0);
  int ans = 10000;
  rep(T,N-1) {
    int S1 = accumulate(W.begin(),W.begin()+T+1,0);
    int S2 = S-S1;
    ans = min(ans,abs(S1-S2));
  }
  cout << ans << endl;
}

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

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( stdin.hasNextLine() ) {

	    final String input = stdin.nextLine();
	    int[] n = new int[10];
	    for ( int i = 0; i < 10; i++ ) {
		n[i] = input.charAt( i ) - '0';
	    }

	    for ( int t = 9; t > 0; t-- ) {
		for ( int i = 0; i < t; i++ ) {
		    n[i] = ( n[i] + n[i + 1] ) % 10;
		}
	    }
	    System.out.println( n[0] );
	}
    }    
}

Measured memory_bytes: 17128
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

int main()
{
    vector<int> v(3);
    rep(i, 3)cin >> v[i];
    swap(v[0], v[1]);
    swap(v[0], v[2]);
    output(v);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    int s,t,u,z=max(x,y);
    s=a*x+b*y;
    t=((x>y)? c*2*y+a*(x-y):c*2*x+b*(y-x));
    u=c*2*z;

    cout<<min(min(s,t),u)<<endl;

	return 0; 
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
S = isl()

if 'Y' in S:
    print('Four')
else:
    print('Three')

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
  int X;
  scanf("%d", &X);

  if(X>=400 && X<=599) printf("8\n");
  else if(X>=600 && X<=799) printf("7\n");
  else if(X>=800 && X<=999) printf("6\n");
  else if(X>=1000 && X<=1199) printf("5\n");
  else if(X>=1200 && X<=1399) printf("4\n");
  else if(X>=1400 && X<=1599) printf("3\n");
  else if(X>=1600 && X<=1799) printf("2\n");
  else if(X>=1800 && X<=1999) printf("1\n");

  return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<algorithm>
#include<vector>
 
using namespace std;
 
vector<int> a;
 
int main() {
	int n, x; scanf("%d", &n);
	while(n--) {
		scanf("%d", &x);
		auto it = upper_bound(a.begin(),a.end(),x,greater<int>());
		if (it == a.end()) a.push_back(x);
		else *it = x;
	}
    cout << a.size();
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
using namespace std;
int main(){
  string n, m;
  cin >> n >> m;
  string one = "", two = "";
  for(int i = 0; i < stoi(n); i++) one += m;
  for(int i = 0; i < stoi(m); i++) two += n;
  if(one <= two) cout << one << endl;
  else cout << two << endl;
}

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

using namespace std;

int
main()
{
	int a, b;
	cin >> a >> b;

	for (int i = 1; i <= 3; i++) {
		if (a*b*i % 2 == 1) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  char str[3];
  scanf("%s",str);

  if(str[0] == 'S'){
   if(str[1] == 'A'){
     printf("1");
   }
   else if(str[1] == 'U'){
       printf("7");
   }
  }
  else if(str[0] == 'M'){
    printf("6");
  }
  else if(str[0] == 'T'){
    if(str[1] == 'U'){
      printf("5");
    }
    else if(str[1] == 'H'){
      printf("3");
    }
  }
  else if(str[0] == 'W'){
    printf("4");
  }
  else if(str[0] == 'F'){
    printf("2");
  }

  return 0;
}

Measured memory_bytes: 128