akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int solve(int N, int M) {
    vector<vector<int>> problems(M);
    int d, v;
    for (int i = 0; i < N; i++) {
        cin >> d >> v;
        problems[d - 1].push_back(v);
    }
    int ret = 0;
    for (int i = 0; i < M; i++) {
        sort(problems[i].begin(), problems[i].end());
        ret += problems[i][problems[i].size() - 1];
    }
    return ret;
}

int main(void) {
    int N, M;
    vector<int> ans;
    while (1) {
        cin >> N >> M;
        if (!N && !M) break;
        ans.push_back(solve(N, M));
    }
    for (int a : ans) cout << a << endl;
}


Measured memory_bytes: 3080
n = int(input())
h = list(map(int, input().split()))

flag = True
for i in range(n-1):
    if h[-i-2] <= h[-i-1]:
        pass
    else:
        if h[-i-2] - h[-i-1] == 1:
            h[-i-2] -= 1
        else:
            flag = False

            
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef vector<int>Vl;
typedef vector<vector<int>>Vn;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=1e6+2;
const int inf=(int)(1e19+10LL);
const int mod=1e9+7;
void solve(){
	int num;
	sl(num);
	int one=num%10;
	if(one==3){
		cout<<"bon"<<endl;
		return;
	}
	if(one==2 || one==4 || one==5 || one==7 || one==9){
		cout<<"hon"<<endl;
		return;
	}
	cout<<"pon"<<endl;
 
	
	
}

signed main(){
  int test=1;
  //sl(test);
  int t=0;
 while(t++<test){
 //	cout<<"Case #"<<t<<": ";
 	solve();
 }
 
}

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

int main() {
 int k;
  string s;
  cin >> k >> s;
  for(int i=0; i<s.size(); i++){
  	if(i==k){
   	   cout << "...";	
      break;
    }
    cout << s.at(i);	
  }
}

Measured memory_bytes: 3596
import sys
input=sys.stdin.readline
n=int(input())
#print(n,end=' n')
data=[0]*(2*n)
def upd(i,x):
  i+=n
  data[i]=x
  while i>1:
    data[i>>1]=data[i]|data[i^1]
    i>>=1
def qry(l,r):
  l+=n
  r+=n
  res=0
  while l<r:
    if l&1:
      res|=data[l]
      l+=1
    if r&1:
      r-=1
      res|=data[r]
    l>>=1
    r>>=1
  return bin(res).count('1')

for i,c in enumerate(input()[:-1],n):
  data[i]=1<<(ord(c)-ord('a'))
for i in range(n-1,0,-1):
  data[i]=data[i<<1]|data[i<<1|1]
ans=[]
for _ in range(int(input())):
  q,a,b=input().split()
  if int(q)==1:
    upd(int(a)-1,1<<(ord(b)-ord('a')))
  else:
    ans.append(qry(int(a)-1,int(b)))
print('\n'.join(map(str,ans)))





Measured memory_bytes: 43536
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    b1 = [0] * 60
    for a in A:
        for i in range(60):
            if a & (1 << i): b1[i] += 1
    ans = Mint()
    for i in range(60):
        ans += Mint(1 << i) * b1[i] * (N - b1[i])
    print(ans)

MOD = 10**9 + 7
class Mint:
    __slots__ = ('value')

    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)


Measured memory_bytes: 123560
/*
 * B.cpp
 *
 *  Created on: 2020/06/27
 *      Author: 17k1028
 */





#include <iostream>
#include <string>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))


using namespace std;

int main(){
	string S,T;
	cin >> S >> T;
	long long count = 0;
	for (long long  i = 0; i < S.length(); i++){
		if(S[i] != T[i]){
			count++;
		}
	}
	cout << count <<endl;
}


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

using namespace std;

int n[10000]={},r[10000]={};
int p[10000][50] = {};
int c[10000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            s = 0;
            for(int t=c[i][j];t<p[i][j]+c[i][j]-1;t++){
                e[t] = e2[s];
                s++;
            }


        }
        
        cout << e[0] << endl;
    }

    return 0;
}


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

const int MAXN = 200010;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
}
int f[MAXN], n;
void dfs(int u, int ga = 0, int va = 0, int gb = 0, int fa = 0) {
	if (u > ga) va = ga, ga = u, gb = 0, ++f[u];
	else {
		if (fa == ga) gb = u;
		if (u > va) va = 0;
		if (u <= va) ++f[ga]; else ++f[gb];
	}
	for (int i = head[u]; i; i = nxt[i]) if (to[i] != fa)
		dfs(to[i], ga, va, gb, u);
}
void dfs2(int u, int fa = 0) {
	f[u] += f[fa];
	for (int i = head[u]; i; i = nxt[i]) if (to[i] != fa) dfs2(to[i], u);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, addedge(t1, t2);
	dfs(1); dfs2(1);
	for (int i = 2; i <= n; ++i) std::cout << f[i] - 1 << ' ';
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 18816
#include <stdio.h>

int main (void){
	int a = 0,b = 0;
	scanf("%d %d",&a,&b);
	
	int x = 1000;
	if(b<10)x = 10;
	else if(b<100)x = 100;
	
	int n;
	n = a*x + b;
	
	int i = 1;
	while(1){
		if(i*i < n){
			i++;
			continue;
			}
		else if(i*i == n){
			printf("Yes");
			break;
			}
		else{
			printf("No");
			break;
			}
	}
	
	return 0;
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] num = Input.ScanIntArray();
          Array.Sort(num);
          Console.WriteLine(num[0]+num[1]);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	P := make([]int, N)
	for i := 0; i < N; i++ {
		var p int
		fmt.Scan(&p)
		P[i] = p
	}
	cnt := 0
	for idx, p := range P {
		if idx+1 != p {
			cnt++
		}
	}
	if cnt <= 2 {
		fmt.Println("YES")

	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
using namespace std;
int main()
{
	int c,n;
	string s;
	string ho="Hoshino";
	cin >> n;
	for (int r = 0; r <= n; r++){
		s.clear();
		while ((c = getchar()) != '\n'){
			s += c;
		}
		for (int i = 0; i < s.size(); i++){
			int flag = 0;
			if (s[i] == 'H'){
				for (int i2 = 0; i2 < ho.size(); i2++){
					if (s[i + i2] != ho[i2]){
						flag = 1;
						break;
					}
				}
				if (flag == 0){
					s[i + ho.size() - 1] = 'a';
				}
			}
		}
		if (r != 0){
		cout << s << endl;
		}
	}
}

Measured memory_bytes: 1208
N, T = [int(x) for x in input().split()]
ct = [[int(x) for x in input().split()] for _ in range(N)]
f = list(filter(lambda x: x[1] <= T, ct))
if not f:
    print("TLE")
else:
    print(min(f, key=lambda x: x[0])[0])


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

int rec(int a, int acc) {
    if (a == 0) throw "hoge";
    if (a % 2 == 1) {
        return acc;
    }
    else {
        return rec(a / 2, acc + 1);
    }
}

int count_by_divide2(int a) {
    return rec(a, 0);
}

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += count_by_divide2(A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = np.arange(n+1, dtype=int)
    a[3:n+1:3] = 0
    a[5:n+1:5] = 0
    print(np.sum(a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 34320
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >> S;
  int a=-1;
  int b=-1;
  int c=-1;
  int count=0;
  for(int i=1000;i<2000;i++){
    int j=i%10;
    int k=((i-j)/10)%10;
    int l=(i-1000)/100;
    int c[3];
    c[0]=l;c[1]=k;c[2]=j;
    int f=0;
    for(int m=0;m<N;m++){
      if(S[m]=='0'+c[f])f++;
      if(f==3) break;
    }
    if(f==3)count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define foreach(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
using namespace std;
const int mod=1e9+7;
int n,m,i,j,lk[605],dp[605][605],f[605],cnt[605],ans;
int dfs(int l,int r){
	if((cnt[r]-cnt[l-1])&1) return 0;
	int i;
	for(i=l;i<=r;i++) if(lk[i]&&(lk[i]<l||lk[i]>r)) return 0;
	if(dp[l][r]!=-1) return dp[l][r];
	dp[l][r]=f[cnt[r]-cnt[l-1]];
	for(i=l;i<r;i++){
		dp[l][r]=(dp[l][r]+1ll*(mod-f[cnt[r]-cnt[i]])*dfs(l,i))%mod;
	}
	return dp[l][r];
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	n*=2;
	rep(i,m){
		int x,y;
		cin>>x>>y;
		lk[x]=y;
		lk[y]=x;
	}
	f[0]=1;
	rep(i,n/2){
		f[i*2]=1ll*f[i*2-2]*(i*2-1)%mod;
	}
	rep(i,n){
		cnt[i]=cnt[i-1]+(!lk[i]);
	}
	rep(i,n){
		for(j=i;j<=n;j++){
			ans=(ans+1ll*dfs(i,j)*f[n-m-m-(cnt[j]-cnt[i-1])])%mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
using namespace std;
typedef long long int lli;

string charset[10][5] = {
	{},
	{".", ",", "!", "?", " "},
	{"a", "b", "c"},
	{"d", "e", "f"},
	{"g", "h", "i"},
	{"j", "k", "l"},
	{"m", "n", "o"},
	{"p", "q", "r", "s"},
	{"t", "u", "v"},
	{"w", "x", "y", "z"}
};
int loop[10] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};

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

	int N;
	cin >> N;
	for (int n = 0; n < N; n++){
		string s;
		cin >> s;

		int i = 0;
		int push = -1;
		string ans = "";
		while (i < s.length()){
			int num = stoi(s.substr(i, 1));
			if (num != 0){
				int thisnum = num;
				while (num != 0){
					push++;
					i++;
					num = stoi(s.substr(i, 1));
				}
				ans += charset[thisnum][push % loop[thisnum]];
				push = -1;
			}
			i++;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    ll n, r;
    cin >> n >> r;
    if(n>=10)
        cout << r;
    else
        cout << r + 100 * (10 - n);


    //system("pause");
    return 0;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a<b)
        cout << "a < b" <<endl;
    else if(a>b)
        cout << "a > b" <<endl;
    else
        cout << "a == b" <<endl;
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n,k;
    cin>>n>>k;
    int f[n],h[n];
    for(i=0;i<n;i++){
        cin>>h[i];
        f[i] = INT_MAX;
    }
    f[0] = 0;
    f[1] = abs(h[0]-h[1]);
    f[2] = f[1] + abs(h[1]-h[2]);
    if(k!=1)
        f[2] = min(abs(h[0]-h[2]),f[1]+abs(h[1]-h[2]));
    for(i=3;i<n;i++){
        for(j=i-1;j>=i-k && j>=0;j--){
            f[i] = min(f[i],f[j]+abs(h[i]-h[j]));
            //cout<<j<<" ";
        }
    }
    cout<<f[n-1];
    return 0;
}

Measured memory_bytes: 1024
a,b,k = map(int, input().split())

ret = []
for i in range(k):
    if 0<=a+i<=b:
        ret.append(a+i)
    if a<=b-k+1+i<=int(1e9):
        ret.append(b-k+1+i)
        
ret = list(set(ret)) # only unique
ret.sort()
for r in ret:
    print(r)

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

int main()
{
	char pass[4];
	cin >> pass;

	for (int i = 1; i < 4; i++) {
		if (pass[i - 1] == pass[i]) {
			printf("Bad");
			return 0;
		}
	}

	printf("Good");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
int main()
{	int k,a,b; cin>>k>>a>>b;
	if(b-a<=2||k<=a-1) return !printf("%d",1+k);
	int t=k-(a-1),ans=a; if(t&1) t--,ans++; t/=2;
	printf("%lld",ans+(ll)t*(b-a));
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    char S;
    ll count = 0;
    ll ans = 0;
    rep(i, 3){
        cin >> S;
        if(S == 'S'){
            count = 0;
        }else{
            count++;
            ans = max(ans, count);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
//HovalHaq!
#include <bits/stdc++.h>
typedef long long ll;

#define int ll

using namespace std;

int32_t main() {
	int n, k, s = 0; cin >> n >> k;
	vector<int> A(n);
	for(int i = 0; i < n; i++) cin >> A[i];
	sort(A.begin(), A.end(), greater<int>());
	for(int i = k; i < n; i++) s += A[i];
	cout << s;
}


Measured memory_bytes: 1792
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val ws = readLine.split(" ").map(_.toInt)
  val sums = ws.scanLeft(0)((z, w) => z + w)
  println(sums.map(s => Math.abs(sums.last - 2 * s)).min)
}

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

using namespace std;


//eps??????????????´???????????¨
inline double add(double a, double b){
    return abs(a+b)<(1e-10)*(abs(a)+abs(b)) ? 0.0 : a+b;
}

//double???2?¬????????????????
struct vec{
    long double x,y;
    vec operator-(vec b){
        return (vec){add(x,-b.x),add(y,-b.y)};
    }
    vec operator+(vec b){
        return (vec){add(x,b.x),add(y,b.y)};
    }
    vec operator*(long double d){
        return (vec){x*d,y*d};
    }
    bool operator==(vec b){
        return x==b.x&&y==b.y;
    }
    bool operator!=(vec b){
        return x!=b.x||y!=b.y;
    }
    bool operator<(const vec&r) const{
    return this->x==r.x?this->y<r.y:this->x<r.x;
    }
    long double dot(vec v){//??????
        return add(x*v.x,y*v.y);
    }
    long double cross(vec v){//??????
        return add(x*v.y,-y*v.x);
    }
    long double norm(){//?????????
        return sqrt(x*x+y*y);//???????????????????????¨??????hypot??§?????????????????????
    }
};

//????????¢??°CCW
int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = ab.cross(ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(ab.dot(ac)<0){
        return 2; //C-A-B
    }else{
        if(ab.dot(ab)<ac.dot(ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

//??????
vector<vec> convex_hull(vector<vec>& V){
    vector<vec> C;
    sort(V.begin(),V.end(),[](const vec& a, const vec& b){return a.y==b.y ? a.x < b.x : a.y< b.y;});
    //?????´
    for(int i=0; i<V.size(); i++){
        vec v = V[i];
        while(C.size()>=2&&ccw(C[C.size()-2],C.back(),v)==-1) C.pop_back();
        C.push_back(v);
    }
    //?????´
    for(int i=V.size()-2; i>=0; i--){
        vec v = V[i];
        while(C.size()>=2&&ccw(C[C.size()-2],C.back(),v)==-1) C.pop_back();
        C.push_back(v);
    }
    C.pop_back(); //????§???????????????£?????????????????§?¶????
    return C;
}

int main(){
    int n;
    cin >> n;
    vec v;
    vector<vec> V,C;
    while(n--){
        cin >> v.x >> v.y;
        V.push_back(v);
    }
    C=convex_hull(V);
    cout << C.size() << endl;
    for(auto& i : C) cout << i.x << " " << i.y << endl;
    return 0;
}

Measured memory_bytes: 11560
//#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
	int n;
	cin >> n;
	cout << (10000 - n) % 1000 << endl;
}

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

int main(){
  char a,b,c;
  int sum = 0;
  cin >> a >> b >> c;
  if(a == '1'){
    sum +=1;
  }
  if(b == '1'){
    sum +=1;
  }
  if(c == '1'){
    sum += 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
struct edge{
	int to,cost;
};

int main() {
	int n;
	cin>>n;
	ll a1;
	ll t=0;
	ll p=0;

	for(int i=0;i<n;++i){
		cin>>a1;
		if(a1>0){
			t+=(a1+p)/2;
			p=(a1+p)%2;
		}else{
			p=0;
		}
	}
	cout<<t<<endl;

	return 0;
}


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

int N;
int count[20];
int rinsetu[20][20];
int maxtime;

void tansaku(int prev,int now,int nowtime) {
	int i;
	if(nowtime>maxtime)maxtime=nowtime;
	for(i=0;i<N;i++) {
		if(i!=prev && rinsetu[now][i]>0)tansaku(now,i,nowtime+rinsetu[now][i]);
	}
}

int main(void) {
	int i,j;
	int timesum;
	while(scanf("%d",&N)==1 && N>0) {
		memset(rinsetu,0,sizeof(rinsetu));
		memset(count,0,sizeof(count));
		for(i=1;i<N;i++) {
			int a,b,t;
			scanf("%d%d%d",&a,&b,&t);
			a--;b--;
			rinsetu[a][b]=rinsetu[b][a]=t;
			count[a]++;count[b]++;
		}
		for(i=1;i<N;i++) {
			if(count[i]==1) {
				for(j=0;j<N;j++) {
					rinsetu[i][j]=rinsetu[j][i]=0;
				}
			}
		}
		timesum=0;
		for(i=0;i<N;i++) {
			for(j=i+1;j<N;j++)timesum+=rinsetu[i][j];
		}
		timesum*=2;
		maxtime=0;
		tansaku(-1,0,0);
		timesum-=maxtime;
		printf("%d\n",timesum);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		sc.close();

		List<TreeSet<Integer>> nexts = new ArrayList<>();
		for (int i = 0; i < 26; i++) {
			nexts.add(new TreeSet<>());
		}
		for (int i = 0; i < a.length; i++) {
			int c = a[i] - 'a';
			nexts.get(c).add(i);
		}

		List<Integer> list = new ArrayList<>();
		Set<Integer> set = new HashSet<>();
		for (int i = a.length - 1; i >= 0; i--) {
			int c = a[i] - 'a';
			set.add(c);
			if (set.size() == 26) {
				list.add(i);
				set = new HashSet<>();
			}
		}
		Collections.reverse(list);
		list.add(a.length);

		StringBuilder sb = new StringBuilder();
		int now = -1;
		for (int i = 0; i < list.size(); i++) {
			int idx = list.get(i);
			for (int j = 0; j < 26; j++) {
				if (i == list.size() - 1) {
					if (nexts.get(j).higher(now) == null) {
						sb.append((char) ('a' + j));
						break;
					}
				} else {
					int next = nexts.get(j).higher(now);
					if (next >= idx) {
						boolean flg = false;
						for (int k = 0; k < 26; k++) {
							Integer next2 = nexts.get(k).higher(next);
							if (next2 == null || next2 >= list.get(i + 1)) {
								flg = true;
								break;
							}
						}
						if (flg) {
							sb.append((char) ('a' + j));
							now = next;
							break;
						}
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
}


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

int main(){
  int N, M; cin >> N >> M;
  vector<pair<int64_t, int64_t>> drink(N);
  for(int i=0;i<N;i++){
    cin >> drink.at(i).first >> drink.at(i).second;
  }
  sort(drink.begin(), drink.end());
  int count=0;
  int sokomade=0;
  for(int i=0;i<N;i++){
    count+=drink.at(i).second;
    if(count>=M){
      sokomade=i;
      break;
    }
  }
  int64_t ans=0;
  for(int i=0;i<=sokomade;i++){
    ans+=drink.at(i).first*drink.at(i).second;
  }
  ans-=drink.at(sokomade).first*(count-M);
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int a[3000];
int sum = 0;
int check(int c,int b){
    int s = 0;
    for(int i = b + 1; i <= n - 1; i++){
        if(a[i] < a[c] + a[b]) {
            s += 1;
        }
    }
    return s;
}
int main(){
    
    scanf("%d",&n);
    for(int i = 0; i <= n - 1;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i = 0; i <= n - 3 ;i++){
        for(int j = i + 1; j <= n -2;j++) {
            sum += check(i,j);
            }
        }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
vector<int> color;
vector<vector<pair<int, int>>> link;

void paint(int node, int c){
	color[node] = c;
	for(auto & e : link[node]){
		if(color[e.first]) continue;
		if(e.second) paint(e.first, -c);
		else paint(e.first, c);
	}
}

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

	link.resize(N+1, {});
	color.resize(N+1, 0);

	for(int i=0; i<N-1; i++){
		int u,v,w;
		cin >> u >> v >> w;
		link[u].push_back({v, w & 1});
		link[v].push_back({u, w & 1});
//		cout << (w&1) << endl;
	}
	paint(1,1);
	for(int i=1; i<=N; i++){
		cout << ((color[i]+1)/2) << endl;
	}

	return 0;
}

Measured memory_bytes: 8192
#include<iostream>
using namespace std;
int main(){
	int a[5];
	bool b[5],c=0;
	for(int i=1;i<=4;i++){
		b[i]=0;
	}
	cin>>a[1]>>a[2]>>a[3]>>a[4];
	for(int i=1;i<=4;i++){
		if(a[i]==1&&b[1]==0)
			b[1]=1;
		if(a[i]==9&&b[2]==0)
			b[2]=1;
		if(a[i]==7&&b[3]==0)
			b[3]=1;
		if(a[i]==4&&b[4]==0)
			b[4]=1;
	}
	for(int i=1;i<=4;i++){
		if(b[i]==0)
			c=1;
	}
	if(c==1)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int block;
set<int> leaf;

void dfs(int from, vector<bool>& visited, vector< vector<int> >& edges, vector<int>& dist) {
    visited[from] = true;
    bool update = false;
    for(int next: edges[from]) {
        if(!visited[next] && next != block) {
            dist[next] = dist[from] + 1;
            dfs(next, visited, edges, dist);
            update = true;
        }
    }
    if(edges[from].size() == 1) leaf.insert(from);
}

int main() {
    int N, u, v;
    cin >> N >> u >> v;
    u--; v--;
    block = v;

    vector< vector<int> > edges(N, vector<int>());

    REP(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    vector<int> dist(N, 1e9), dist2(N, 1e9);
    vector<bool> visited(N), visited2(N);
    cerr << "dfs" << endl;
    dist[v] = 0;
    dfs(v, visited, edges, dist);

    dist2[u] = 0;
    dfs(u, visited2, edges, dist2);

    int max_dist = 0, dep;
    REP(i, N) {
        if(dist[i] > max_dist && dist[i] > dist2[i]) {
            max_dist = dist[i];
            dep = i;
        }
    }

    cout << max_dist - 1 << endl;

    return 0;
}

Measured memory_bytes: 13440
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int d[4];
	int e, f;
	int sum = 0;
	int MIN = 1000;
	for (int i = 0; i < 4; i++) {
		cin >> d[i];
		sum += d[i];
		MIN = min(MIN, d[i]);
	}
	cin >> e >> f;
	sum += max(e, f);
	cout << sum-MIN << endl;
	return 0;
}

Measured memory_bytes: 1160
class Node
  @@nodes = []
  @@queue = []
  def initialize(id)
    @id = id
    @discover = false
    @discover_time = nil
    @end_time = nil
    @edge = nil
    @@nodes[id - 1] = self
  end

  def set_dist(n)
    @discover_time ||= n
  end

  def <<(edges)
    @edge = edges
  end

  def search
    if !@discover
      @discover = true
      @edge.each{|item|
        @@nodes[item - 1].set_dist(@discover_time + 1)
        @@queue << @@nodes[item - 1]
      }
      while (node = @@queue.shift)
        node.search
      end
    end
  end

  def to_s
    return [@id, @discover_time].join(" ")
  end

  def discover?
    return @discover
  end
  
end

def main
  n = gets.to_i
  arr = Array.new(n){|i|Node.new(i + 1)}
  n.times do |i|
    arg =  gets.split(" ").map(&:to_i)
    arr[i] << arg[arg.length - arg[1]..-1]
  end
  arr[0].set_dist(0)
  arr[0].search
  arr.each do |item|
    item.set_dist(-1) if !item.discover?
    puts item
  end
end
main

Measured memory_bytes: 6136
<?php
// Your code here!

while(true) {
    fscanf(STDIN,"%d %d",$tate,$yoko);
    if ($tate == 0 && $yoko == 0) {
        exit;
    } else {
        
        for ($i = 0; $i < $tate; $i++) {
            for ($j = 0; $j < $yoko; $j++) {
                $dot = ($i % 2 == 0 && $j % 2 == 0) || ($i % 2 == 1 && $j % 2 == 1) ? "#" : ".";
                echo $dot;
            }
            echo PHP_EOL;
        }
        echo PHP_EOL;      
    }

}

?>



Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  vi accR(N+1,0);
  rep(i,N) {
    accR[i+1]=accR[i];
    if(s[i]=='R') {
      accR[i+1]++;
    }
  }
  auto getR = [&](int l,int r) {
    if(l>=r) return 0;
    return accR[r]-accR[l];
  };
  auto getB = [&](int l,int r) {
    if(l>=r) return 0;
    return r-l-(accR[r]-accR[l]);
  };
  int ans = INF;
  rep(i,N+1) {
    // 0 .. i-1 -> red
    // i .. N-1 -> black
    int b = getB(0,i);
    int r = getR(i,N);
    int res = min(b,r) + abs(b-r);
    chmin(ans,res);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4448
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 21:20:10 2020

@author: naoki
"""

N = int(input())
m = 10**N%(10**9+7) - ((9**N *2)%(10**9+7) - (8**N)%(10**9+7))
if N>=2:
    if m >= 0:
        print(m)
    else: 
        print(m+(10**9+7))
else: 
    print(0)

Measured memory_bytes: 10728
class UnionFind():
    def __init__(self, n):
        self.rank = [0] * n
        self.par = list(range(n))

    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx == ry:
            return
        if self.rank[rx] >= self.rank[ry]:
            self.par[ry] = rx
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1
        else:
            self.par[rx] = ry

    # find root
    def find(self, x):
        ch = []
        while self.par[x] != x:
            ch.append(x)
            x = self.par[x]
        for c in ch:
            self.par[c] = x
        return x

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

N, M = [int(x) for x in input().split()]
E = [[int(x) - 1 for x in input().split()] for _ in range(M)]

ans = 0
for (a, b) in E:
    uf = UnionFind(N)
    for (c, d) in E: # (a, b)以外の辺でunion findを作る
        if (c, d) != (a, b):
            uf.union(c, d)
    if not uf.same(a, b):
        ans += 1

print(ans)

Measured memory_bytes: 9188
#include<stdio.h>


int main(void){

  int i, j, k;
  int cons, max;
  int x[5];


  while(scanf("%d %d %d %d %d", &x[0], &x[1], &x[2], &x[3], &x[4])!=EOF){

    for(i=0; i<5; i++){
      max=x[i];
      k=i;
      for(j=i+1; j<5; j++){
	if(max<x[j]){
	  max=x[j];
	  k=j;
	}
      }
      cons = x[k];
      x[k]=x[i];
      x[i]=cons;
    }

    printf("%d %d %d %d %d\n", x[0], x[1], x[2], x[3], x[4]);

  }

  return(0);
}



Measured memory_bytes: 2128
#include <iostream>

using namespace std;

const int MAXN = 100005;
int h[MAXN], dp[MAXN];

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> h[i];
    for(int i = 2; i <= n; ++i)
        dp[i] = 1e9;
    for(int i = 2; i <= n; ++i){
        for(int j = 1; j <= k; ++j){
            if(i <= j)
                continue;
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
/*package whatever //do not write package name here */

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[m];
		int f = 0;
		for(int i = 0;i < n;i++)
		a[i] = sc.nextInt();
		for(int i = 0;i < m;i++)
		b[i] = sc.nextInt();
		Arrays.sort(a);
		Arrays.sort(b);
		for(int i = b[0];i > a[n - 1];i--)
		if(i > x && i <= y)
		{
		    System.out.print("No War");
		    f = 1;
		    break;
		}
		if(f != 1)
		System.out.print("War");
	}
}

Measured memory_bytes: 23764
a = input()
b = list(a)
num = 0
for i in range(len(b)):
  #print(b)
  if 1 <= i <= len(b)-1:
    if b[i-1] == "1" and b[i] == "1":
      b[i] = "0"
      num += 1
    elif b[i-1] == "0" and b[i] == "0":
      b[i] = "1"
      num += 1
    else:
      pass
  elif i == 0:
    pass
  elif i == 0 and len(b) == 1:
    pass
    
print(num)  

Measured memory_bytes: 3956
#include<bits/stdc++.h> 
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
typedef long long ll;
using namespace std;
const ll mod =1e9+7;

void solve()
{  string s;
   cin>>s;
   if(s[2]==s[3] && s[4]==s[5]) 
   cout<<"Yes";
   else cout<<"No";
}
int main()
{
// #ifndef ONLINE_JUDGE
 //  freopen("ques.txt","r",stdin);
  // freopen("ans.txt","w",stdout);
 //#endif 
  int t;
  //cin>>t;
  //while(t--)
  { solve();
    cout<<"\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	string s; cin >> s;
	int ans=0;
	if(s[0]=='1')ans=ans+1; //ifの{}は、後が1文なら省略可
	if(s[1]=='1')ans+=1;//+=は加算の記号(知らなくてもいい)
	if(s[2]=='1')++ans;//++は、次のを+1する記号(知らなくていい)
	cout <<ans<< endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
int main(){
int A,B;
cin >>A>>B;
cout << A - B + 1 << endl; }

Measured memory_bytes: 256
a,b,c,d = map(str, input())
op_list = ['+', '-']


for op1 in op_list:
    for op2 in op_list:
        for op3 in op_list:
            f = a+op1+b+op2+c+op3+d
            if eval(f) == 7:
                print(f+'=7')
                exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  string s;
  cin >> n >> m >> s;
  rep(i,n) {
    if(!isdigit(s[i])) {
      pr("No");
      return;
    }
  }
  if(s[n]!='-') {
    pr("No");
    return;
  }
  rep(i,m) {
    if(!isdigit(s[n+1+i])) {
      pr("No");
      return;
    }
  }
  pr("Yes");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
a = sorted(a)
sum_a = 1000000000000

for i in range(a[0], a[N-1]+1):
    ans = 0
    for j in range(N):
        ans += (a[j]-i)**2
    if(sum_a > ans):
        sum_a = ans
print(sum_a)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<unordered_map>

#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b)) cout<<"A"<<endl;
	else cout<<"B"<<endl;
}


Measured memory_bytes: 256
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii> 
using vec = vector<T>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 1e6;

struct DSU {
    vector<int> parent, set_size;
    set<int> roots;
    DSU(int n) {
        parent.resize(n);
        set_size.resize(n);
        iota(parent.begin(), parent.end(), 0);
        roots.insert(parent.begin(), parent.end());
        fill(set_size.begin(), set_size.end(), 1);
    }

    int root(int x) {
        vector<int> v;

        while (x != parent[x]) {
            v.emplace_back(x);
            x = parent[x];
        }

        for (int e : v)
            parent[e] = x;

        return x;
    }

    bool join(int a, int b) {
        a = root(a), b = root(b);
        if (a == b) return false;
        if (set_size[a] < set_size[b])
            swap(a, b);
        roots.erase(b);
        set_size[a] += set_size[b];
        parent[b] = a;
        return true;
    }

    bool check(int a, int b) {
        return root(a) == root(b);
    }
};

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);
    
    int n, m;
    cin >> n >> m;
    DSU d(n);

    while (m--) {
        int i, j, _;
        cin >> i >> j >> _;
        i--, j--;
        d.join(i, j);
    }
    cout << d.roots.size() << '\n';
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll s,t,d,w[100000],c=0,ans=1e11;
  cin>>s>>t>>d;
  for(ll i=0;i<d;i++)cin>>w[i],c-=w[i];
  s-=t;
  for(ll i=0;i<d;i++){
    s+=w[i];
    if(s<=0)ans=min(ans,i+1);
    else if(c>0)ans=min(ans,i+(s+c-1)/c*d+1);
  }
  if(ans==1e11)ans=-1;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3872
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by hikigineer on 2017/03/04.
 */
public class Main {
    static Scanner in;
    static PrintWriter out;
    static String INPUT = "";

    public static void main(String[] args) throws Exception
    {
        in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
        out = new PrintWriter(System.out);
        int a = ni();
        int b = ni();
        int c = ni();

        out.println((b - a) == (c - b) ? "YES" : "NO");
        out.flush();
    }

    static int ni() {
        return Integer.parseInt(in.next());
    }
}

Measured memory_bytes: 24020
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s = 0
for i in range(0, N):
    if A[i] >= B[i]:
        s = s+B[i]
    elif A[i] < B[i] <= A[i]+A[i+1]:
        s = s+B[i]
        A[i+1] = A[i+1]+A[i]-B[i]
    else:
        s = s+A[i]+A[i+1]
        A[i+1] = 0
print (s)

Measured memory_bytes: 18476
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

int n, k;
int forb[15];

void read_input()
{
    cin >> n >> k;
    for(int i = 0; i < k; ++i)
    {
        int x;
        cin >> x;
        forb[x] = 1;
    }
}

bool ok(int x)
{
    while(x > 0)
    {
        int d = x % 10;
        if(forb[d]) return false;
        x /= 10;
    }
    return true;
}

void solve()
{
    for(int i = n; ; ++i)
        if(ok(i))
        {
            cout << i << '\n';
            break;
        }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();
    static int N, M;
    static int[] a, b, c, d;

    public static void main(String[] args){
        N = in.i();
        M = in.i();
        int Q = in.i();
        a = new int[Q];
        b = new int[Q];
        c = new int[Q];
        d = new int[Q];
        for (int i = 0; i < Q; i++) {
            a[i] = in.i() - 1;
            b[i] = in.i() - 1;
            c[i] = in.i();
            d[i] = in.i();
        }
        int ans = dfs(1, 0, new int[N]);

        out.println(ans);
    }

    static int dfs(int i, int j, int[] A) {
        int ans = 0;
        if (j == N) {
            for (int k = 0; k < a.length; k++) {
                ans += A[b[k]] - A[a[k]] == c[k] ? d[k] : 0;
            }
        } else {
            for (; i <= M; i++) {
                A[j] = i;
                ans = Math.max(ans, dfs(i, j + 1, A));
            }
        }
        return ans;
    }

    static void printArray(int[] a) {
        for (int i = 0; i < a.length; i++) {
            out.print(a[i] + " ");
        }
        out.println();
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = read(cbuf, 0, cbuf.length);
            } catch (IOException e) {}
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                back();
                break;
            }
        }
    }

    char[] s(final int N) {
        skip();
        char[] s = new char[N];
        for (int i = 0; i < s.length; i++) {
            s[i] = next();
        }
        return s;
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


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


int main(){
    stack<int> s;
    string input;
    cin >> input;
    s.push(stoi(input));
    int temp;
    while (cin >> input) {
        if (input[0] == '+'){
            temp = s.top();
            s.pop();
            temp += s.top();
            s.pop();
            s.push(temp);
        }
        else if (input[0] == '-'){
            temp = -1 * s.top();
            s.pop();
            temp += s.top();
            s.pop();
            s.push(temp);
        }
        else if (input[0] == '*'){
            temp = s.top();
            s.pop();
            temp *= s.top();
            s.pop();
            s.push(temp);
        }
        else {
            s.push(stoi(input));
        }
    }
    cout << s.top() << endl;
}


Measured memory_bytes: 3168
function main(input) {
  const args = input.split('\n');
  const [N, X] = args[0].split(' ');
  const L = args[1].split(' ');
  const n = Number(N);
  let count = 0;
  for (let i = 0; i < n + 1; i++) {
    if (X < count) {
      console.log(i)
      return;
    } else {
      if (i == n) {
         console.log(i+1) 
         return;
      }
    }  
    count += Number(L[i]);
   }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29532