akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define MAX 2000000001

typedef struct{
  int key;
  int p;
  int l;
  int r;
}Heap;

int main(){
  int i,h;
  Heap heap[251];
  
  scanf("%d",&h);

  for(i = 1;i <= h; i++){
    scanf("%d",&heap[i].key);
  }
  
  for(i = 1;i <= h; i++){
   if(i == 1){
      heap[i].p = MAX;
    }
    else heap[i].p = heap[i/2].key;
    if(2*i > h)heap[i].l = MAX;
    else  heap[i].l = heap[2*i].key;

    if(2*i+1 > h)heap[i].r = MAX;
    else  heap[i].r = heap[2*i+1].key;
  }
  for(i = 1;i <= h; i++){
   
   printf("node %d: key = %d, ",i,heap[i].key);
   if(heap[i].p != MAX)printf("parent key = %d, ",heap[i].p);
   if(heap[i].l != MAX)printf("left key = %d, ",heap[i].l);
   if(heap[i].r != MAX)printf("right key = %d, ",heap[i].r);
   printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MIN / 2 - 1;
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<ll>> dp(n + 1, vector<ll>(2, inf));
    dp[0][0] = 0;
    rep(i, n) {
        {
            chmax(dp[i + 1][0], dp[i][0] + a[i]);
            chmax(dp[i + 1][0], dp[i][1] - a[i]);
        }
        if (i < (n - 1)) {
            chmax(dp[i + 1][1], dp[i][0] - a[i]);
            chmax(dp[i + 1][1], dp[i][1] + a[i]);
        }
    }
    cout << dp[n][0] << endl;
    return 0;
}


Measured memory_bytes: 9532
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

const int MAX_N = 1<<20;

int n;
pii dat[2*MAX_N-1];
void init(int n_){
	n = 1;
	while(n < n_) n *= 2;
	for(int i = 0; i < 2 * n-1; i++){
		dat[i].fi = 0;
		dat[i].se = -(i-n+2);
	}
}

void update(int k, int add){
	k += n-1;
	dat[k].fi += add;
	while(k > 0) {
		k = (k - 1) / 2;
		dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

pii query(int a, int b, int k, int l, int r){
	if(r <= a || b <= l) return pii(0, 0);
	if(a <= l && r <= b) return dat[k];
	else{
		pii vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		pii vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}


int main(){
	int q;
	cin>>n>>q;
	init(n);
	int m, add;
	pii out;
	rep(i, q){
		cin>>m>>add;
		m--;
		update(m, add);
		out = query(0, n, 0, 0, n);
		println(-out.se <<" " <<out.fi);
		//cout<<dat[0].se * -1 << " "<<dat[0].fi<<endl;
		// for(int i = 0; i < n; i++){
		// 	cout<<" ("<<-dat[i+n-1].se<<", "<<dat[i+n-1].se<<")";
		// }
		// cout<<endl;
	}
}

Measured memory_bytes: 17548
n = int(input())
p = list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
  if p[i]>p[i-1] and p[i]>p[i+1]:
      continue
  elif p[i]<p[i-1] and p[i]<p[i+1]:
      continue
  else:
      cnt +=1
print(cnt)


Measured memory_bytes: 2940
import sys
from pprint import pprint

def solve(s):
    odd = ['R', 'U', 'D']
    even = ['L', 'U', 'D']
    for i, s_i in enumerate(s):
        if i % 2 == 0:
            if s_i not in odd:
                print("No")
                return
        if i % 2 == 1:
            if s_i not in even:
                print("No")
                return

    print("Yes")

if __name__ == '__main__':
  s = sys.stdin.readline().strip()
  solve(s)

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
 
void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

const int maxn = 110;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

#define pii pair<int,int >
#define fr first
#define sc second

#define vec vector<pii >
#define mp make_pair
#define pb push_back

#define iter vector <pii > :: iterator

vec t[maxn];
int n,m,q,f[maxn];

signed main() {
    t[1].pb(mp(1,2)),t[1].pb(mp(1,3)),t[1].pb(mp(1,4));
    f[0]=f[1]=1;for(int i=2;i<=100;i++) f[i]=f[i-1]+f[i-2];
    for(int i=1;i<=100;i++) 
        for(int j=0,l=t[i].size()-1;j<=l;j++) {
            int x=t[i][j].sc,y=t[i][j].fr+x;
            while(y<=f[i+3]+f[i]) t[i+1].pb(mp(x,y)),y+=x;
        }read(q);
    for(int i=1;i<=q;i++) {
        read(n),read(m);if(n>m) swap(n,m);
        int p=1,ans=0;
        while(f[p+1]<=n&&f[p+2]<=m) p++;
        printf("%lld ",p);
        if(p==1) {write(n%mod*m%mod);continue;}
        for(int j=0,l=t[p-1].size()-1;j<=l;j++) {
            int x=t[p-1][j].fr,y=t[p-1][j].sc;//printf("debug :: %d %d\n",x,y);
            if(y<=n) ans=(ans+(m-x)/y)%mod;
            if(y<=m) ans=(ans+(n-x)/y)%mod;
        }write(ans);
    }
    return 0;
}


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

citydic = {}
for i in range(n):
    s,p = map(str,input().split())
    if s not in citydic:
        citydic[s] = [[int(p),i+1]]
    else:
        citydic[s].append([int(p),i+1])
        citydic[s].sort(reverse=True)

citydic = sorted(citydic.items())

for k in citydic:
    for v in k[1:]:
        for n in v:
            print(n[1])

Measured memory_bytes: 9092
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 305

const int INF = 1e9 + 7;
const int MOD = 10000;

int main() {

	int n;
	cin >> n;
	string s;
	cin >> s;
	int r = 0, b = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'R')
		{
			r++;
		}
		else
		{
			b++;
		}
	}

	if (r > b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define q2(n) (n%2)==0
#define vp vector<pair <$$,$$> >
#define vctr vector<$$>
#define in(a) cin>>a;
#define out(a) cout<<a<<"\n";
#define nxt() cout<<"\n";
#define no() cout<<"No\n";
#define yes() cout<<"Yes\n";
#define bug1() cout<<"@ ";
#define bug2() cout<<"# ";
#define ff first
#define ss second
#define ip(n) $$ n; cin>>n;
#define ipar(ar,n) $$ ar[n]; loop(i,0,n) cin>>ar[i];
#define opar(ar,n) loop(i,0,n) cout<<ar[i]<<" ";
#define loop(i,m,p) for ($$ i = m; i < p; i++)
#define loopn(i,m,p) for ($$ i = p-1; i >=m; --i)

using namespace std;

int main()
{
   // ip(t)
   ip(n) ip(k)
    //     cout<<(n%k)<<endl;
    n=n%k;
   $$ t=100000,mn=n;
    while(t--)
    {
         n=(abs(n-k));
         mn=min(mn,n);

    }
    out(mn)







return 0;
}




Measured memory_bytes: 256
from collections import deque

N = int(input())

edges = [[] for _ in range(N + 1)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    edges[fr].append((to, i))
    edges[to].append((fr, i))

que = deque([(1, -1)])
ans = [-1] * (N - 1)
while que:
    now, parent = que.popleft()

    canUse = set(range(1, len(edges[now]) + 1))
    for to, i in edges[now]:
        if to == parent and ans[i] in canUse:
            canUse.remove(ans[i])

    canUse = list(canUse)
    for to, i in edges[now]:
        if to == parent:
            continue
        color = canUse.pop()
        if ans[i] == -1:
            ans[i] = color
        que.append((to, now))

print(max(ans))
print(*ans, sep='\n')


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

using namespace std;

#define ll long long

int main(void){
    ll a, b, k;
    cin >> a >> b >> k;

    if(k > a){
        k -= a;
        a = 0;

        if(k > b){
            b = 0;
        }else{
            b -= k;
        }
    }else{
        a -= k;
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
arr = list(map(int,input().split()))
csum = [0 for _ in range(N+1)]
csum[0] = arr[0]
for i in range(1,N):
    csum[i] = csum[i-1] + arr[i]
ncnt = {}
cnt = 0
for i in range(N):
    if csum[i] not in ncnt:
        ncnt[csum[i]] = 1
    else:
        ncnt[csum[i]] += 1
for i in ncnt:
    if i == 0:
        cnt += ncnt[i]
    if ncnt[i] > 1:
        cnt += ncnt[i]*(ncnt[i]-1)//2
print(cnt)

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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int x=0, x2=0;
    
    for(int i=0; i<n; i++){
        if(s[i]=='I')
            x++;
        else
            x--;
        if(x>x2)
            x2=x;
    }

    cout << x2;
}

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

#define MAX 10000001

static bool isprime[MAX];

void MakePrime()
{
  for(long long int i = 0; i < MAX; ++i){
    isprime[i] = true;
  }
  isprime[0]=isprime[1]=false;
  for(long long int i = 2; i < MAX; ++i){
    if( isprime[i] ){
      for(long long int j = 2; i * j < MAX; ++j){
	isprime[i*j] = false;
      }
    }
  }
}
int main()
{
  set<int> S;
  ///  vector<int> v;
  MakePrime();
  for(int i = 2; i < MAX-8; ++i){
    if( isprime[i] && isprime[i+2] && isprime[i+6] && isprime[i+8] ){
      S.insert(i+8);
    }
  }

  while(true){
    int n;
    int ans;
    cin >> n;
    if( n == 0 ) break;

    set<int>::iterator its = S.lower_bound(n);
    ans = *its;
    if( ans > n ){
      --its;
      ans = *its;
    }
    if( n > 9973219 ){
      ans = 9973219;
    }
    cout << ans << endl;
    /*

    int L = 0;
    int R = v.size();
    int preM = -1;
    while(true){
      int M = (L+R)/2;
      if( M == preM ) break;
      if( v[M] > n ){
	R = M;
      }else if( v[M] < n ){
	ans = max( ans, v[M] );
	L = M;
      }else{
	ans = n;
	break;
      }
      preM = M;
    }
    cout << ans << endl;
    */
  }
  return 0;
}

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

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

using namespace std;

int h,w,n;
map<int,int> ma;
map<int,pair<int,int> > p;
vector<vector<int> > v;

bool can(int i,int j,int ny,int nx)
{
	if(0 <= i && ny <= h && 0 <= j && nx <= w)
	{
		return true;
	}
	else return false;
}

bool canSet(int num,int y,int x,int y2,int x2)
{
	bool flag = true;

	REP(i,y,y2)
	{
		REP(j,x,x2)
		{
			if(v[i][j] != 0)
			{ 
				flag = false;
			}
		}
	}

	return flag;
}

void set(int num,int y,int x,int y2,int x2)
{
	REP(i,y,y2)
	{
		REP(j,x,x2)
		{
			v[i][j] = num;
		}
	}
}

int cnt = 0;
vector<vector<int> > v2;

void dfs(int num)
{
	if(num == 0)
	{
		if(cnt == 0)
		{
			bool flag = true;
			rep(i,h)
			{
				rep(j,w)
				{
					if(v[i][j] == 0) flag = false;
				}
			}

			if(flag)
			{
				v2.resize(h);
				rep(i,h) v2[i].resize(w);
				rep(i,h) rep(j,w) v2[i][j] = v[i][j];
			
				cnt++;
			}
		}
		else
		{
			bool flag = true;

			rep(i,h)
			{
				rep(j,w)
				{
					if(v[i][j] == 0) flag = false;
				}
			}

			if(flag)
			{
				cnt++;
			}
		}
	}
	else
	{
		REP(y,1,ma[num]+1)
		{
			if(ma[num]%y == 0)
			{
				int x = ma[num]/y;
				REP(i,p[num].first-y+1,p[num].first+1)
				{
					REP(j,p[num].second-x+1,p[num].second+1)
					{
						int ny = i+y;
						int nx = j+x;

						if(can(i,j,ny,nx))
						{
							v[p[num].first][p[num].second] = 0;
							if(canSet(num,i,j,ny,nx))
							{
								set(num,i,j,ny,nx);
								dfs(num-1);
								set(0,i,j,ny,nx);
							}
							v[p[num].first][p[num].second] = num;
						}
					}
				}
			}
		}
	}
}

int main()
{
	while(cin >> w >> h >> n)
	{
		if(h == 0 && w == 0 && n == 0) break;

		v.resize(h);
		rep(i,h) v[i].clear();

		ma.clear();
		p.clear();
		cnt = 0;

		rep(i,n)
		{
			int a,b;
			cin >> a >> b;
			ma[a] = b;
		}

		v.resize(n);
		rep(i,h)
		{
			rep(j,w)
			{
				int temp;
				cin >> temp;
				v[i].push_back(temp);

				if(1 <= temp && temp <= 15)
				{
					p[temp] = pair<int,int>(i,j);
				}
			}
		}

		dfs(n);

		if(cnt == 1)
		{
			rep(i,h)
			{
				rep(j,w)
				{
					cout << v2[i][j];
					if(j != w-1) cout << " ";
				}
				cout << endl;
			}
		}
		else
		{
			cout << "NA" << endl;
		}

	}
	return 0;
}

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

using namespace std;

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;

  string hands = "rsp";
  unordered_map<char, int> scores;
  scores['r'] = P;
  scores['s'] = R;
  scores['p'] = S;

  vector<vector<int64_t>> dp(K, vector<int64_t>(3, 0));
  for (int i = 0; i < N; i++) {
    char t = T[i];
    int j = hands.find(t);
    int k = i % K;
    vector<int64_t> next(3, 0);
    for (int current = 0; current < 3; current++) {
      int score = (current == j) ? scores[t] : 0;
      vector<int64_t> S;
      for (int prev = 0; prev < 3; prev++) {
        if (prev == current) continue;
        S.push_back(dp[k][prev] + score);
      }
      next[current] = *max_element(S.begin(), S.end());
    }
    dp[k] = next;
  }

  int64_t answer = 0;
  for (int k = 0; k < K; k++) {
    answer += *max_element(dp[k].begin(), dp[k].end());
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int n,m;
bool used[100005];
vector<int> g[100005];
deque<int> dq;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dq.push_back(1);
	used[1]=true;
	while(true){
		int u=dq.front();
		for(int i=0;i<g[u].size();i++){
			int v=g[u][i];
			if(!used[v]){
				dq.push_front(v);
				used[v]=true;
				break;
			}
		}
		if(u!=dq.front())continue;
		u=dq.back();
		for(int i=0;i<g[u].size();i++){
			int v=g[u][i];
			if(!used[v]){
				dq.push_back(v);
				used[v]=true;
				break;
			}
		}
		if(u!=dq.back())continue;
		break;
	}
	cout<<dq.size()<<endl;
	while(!dq.empty()){
		cout<<dq.front()<<' ';
		dq.pop_front();
	}
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	bool result = false;
	for( int i = 0; i <= N; i += 4 ) {
		for( int j = 0; i+j <= N; j += 7 ) {
			if( i+j == N ) {
				result = true;
				break;
			}
		}

		if( result ) { break; }
	}

	cout << (result ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
 
 
class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
 
    static Scanner cin;
    Random r;
 
    void calc()
    {
        string S = cin.next();
        if (S == "Sunny") Console.WriteLine("Cloudy");
        else if (S == "Cloudy") Console.WriteLine("Rainy");
        else Console.WriteLine("Sunny");
    }
 
}
 
 
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

template <class TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a)
{
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  ll n, i, j, w;
  cin >> n >> w;
  vector<ll> a(n), b(n);
  for(i = 0; i < n; i++)
  cin >> a[i] >> b[i];
  ll mx = 1e5 + 10;
  vector<ll> dp(mx, 2 * inf);
  dp[0] = 0;
  for(i = 0; i < n; i++)
  for(j = mx - 1; j >= b[i]; j--)
  dp[j] = min(dp[j - b[i]] + a[i], dp[j]);
  
  for(i = mx - 1; i >= 0; i--)
  if(dp[i] <= w) break;
  cout << i;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x-a) < abs(x-b)) cout << 'A' << endl;
  else cout << 'B' << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    long long a[200001], b[200001];
    a[0] = 0;
    for (int i = 1; i <= n; i++) { int x; cin >> x; a[i] = a[i-1] + x - k; }
    memcpy(b, a, sizeof a);
    sort(b, b+n+1);
    int r[200001];
    for (int i = 0; i <= n; i++) {
        if (a[i] == b[0]) r[i] = 1;
        else {
            int lb = 0, ub = n;
            while (ub - lb > 1) {
                int mid = (lb + ub) / 2;
                if (a[i] > b[mid]) lb = mid;
                else ub = mid;
            }
            r[i] = ub + 1;
        }
    }
    int bit[200002] = {};
    long long ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = r[i]; j > 0; j -= j&-j) ans += bit[j];
        for (int j = r[i]; j <= n+1; j += j&-j) bit[j]++;
    }
    cout << ans << endl;
}


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




Measured memory_bytes: 19244
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

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 / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

ll H, W;
vector<string> a;
vector<vll> t;
const ll mod = 1e9 + 7;

ll func(ll y, ll x) {
	if (y >= H || x >= W) {
		return  0;
	}

	ll ret = t[y][x];

	if (ret > -1) {
		return ret;
	}

	ret = 0;
	if (a[y][x] != '#') {
		ret += func(y, x + 1);
		ret += func(y + 1, x);
		ret %= mod;
	}
	t[y][x] = ret;
	return ret;
}


int main() {
	cin >> H >> W;
	a.resize(H);
	t.resize(H, vll(W,-1));
	rep(i, 0, H) {
		cin >> a[i];
	}

	t[H - 1][W - 1] = 1;
	cout << func(0, 0) << endl;


	return 0;

}


Measured memory_bytes: 13456
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef std::pair<int, int> Par;
typedef std::set<Par>::iterator iter;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005;
int tmp[maxn], tp;
int px[maxn], py[maxn];
struct Shit {
	std::set<Par> s;
	std::vector<Par> v;
};
Shit sx[maxn], sy[maxn];
/* std::set<Par> sx[maxn], sy[maxn]; */
/* std::vector<Par> vx[maxn], vy[maxn]; */

inline int sc(int x) {
	int res = int(std::lower_bound(tmp + 1, tmp + tp + 1, x) - tmp);
	return tmp[res] == x ? res : 0;
}

int main() {
	int n = read, a = read, b = read;

	for(int i = 1; i <= n; i ++) {
		int x = read, y = read;
		tmp[++ tp] = px[i] = x + y;
		tmp[++ tp] = py[i] = x - y;
	}

	int d = std::max(std::abs(px[a] - px[b]), std::abs(py[a] - py[b]));

	std::sort(tmp + 1, tmp + tp + 1);

	for(int i = 1; i <= n; i ++) {
		sx[sc(px[i])].s.insert(Par(py[i], i));
		sy[sc(py[i])].s.insert(Par(px[i], i));
		sx[sc(px[i])].v.push_back(Par(py[i], i));
		sy[sc(py[i])].v.push_back(Par(px[i], i));
	}

	for(int i = 1; i <= tp; i ++) {
		std::sort(sx[i].v.begin(), sx[i].v.end());
		std::sort(sy[i].v.begin(), sy[i].v.end());
	}

	ll ans = 0;
	std::queue<int> q;
	q.push(a);
	sx[sc(px[a])].s.erase(Par(py[a], a));
	sy[sc(py[a])].s.erase(Par(px[a], a));

	while(!q.empty()) {
		int u = q.front();
		q.pop();

		/* debug("bfs %d\n", u); */

		auto search = [&](Shit &s, int l, int r) {
			/* debug(" s\n"); */

			auto lit = std::lower_bound(s.v.begin(), s.v.end(), Par(l, 0));
			auto rit = std::lower_bound(s.v.begin(), s.v.end(), Par(r + 1, 0));
			ans += rit - lit;

			for(iter it = s.s.lower_bound(Par(l, 0));
					it != s.s.end() and it -> first <= r;) {

				/* debug("%d, %d\n", u, v); */
				int v = it -> second;
				q.push(v);
				++ it;

				sx[sc(px[v])].s.erase(Par(py[v], v));
				sy[sc(py[v])].s.erase(Par(px[v], v));
			}
		};


		int lx = px[u] - d, rx = px[u] + d;
		int ly = py[u] - d, ry = py[u] + d;

		search(sx[sc(lx)], ly, ry - 1);
		search(sx[sc(rx)], ly + 1, ry);
		search(sy[sc(ly)], lx + 1, rx);
		search(sy[sc(ry)], lx, rx - 1);
	}

	printf("%lld\n", ans >> 1);
}


Measured memory_bytes: 44928
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, M;
        cin >> N >> M;
        vector<ll> L(M), R(M);
        vector<ll> rui(N + 5);
        rep(i, 0, M) {
            cin >> L[i] >> R[i];
            rui[L[i]]++;
            rui[R[i] + 1]--;
        }
        for (int i = 0; i + 1 < rui.size(); ++i) {
            rui[i + 1] += rui[i];
        }

        int ans = 0;
        for (auto e : rui) {
            if (e == M) ans++;
        }
        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 2560
//abc121_b.cpp
//Sun Mar 17 23:07:08 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	int ans = 0;
	for (int i=0;i<n;i++){
		int a[m];
		int calc = c;
		for (int j=0;j<m;j++){
			cin >> a[j];
			calc += a[j]*b[j];
		}
//		cout << calc << endl;
		if (calc>0){
			ans++;
		}
	}
	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

int main() {
	int S; cin >> S;
	int Harshad = 0, s = S;
	while( S != 0 ){
		Harshad += S - (S/10)*10;
		S /= 10;
	}
	
	if( s % Harshad == 0 ) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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


void solve(long long N, std::vector<long long> l, std::vector<long long> r){
    long long ans = 0;
    for(long long i = 0; i < N; ++i){
        ans = ans + abs(r[i] - l[i] + 1);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> l(N);
    std::vector<long long> r(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
    }
    solve(N, std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int N;
    cin >> N;
    vector<int> c(N);
    ll res = 0;
    REP(i, N) cin >> c[i];

    REP(i, N){
        FOR(j, i + 1, N){
            if(i == j) continue;
            else{
                res += c[i] * c[j];
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
N,M = (int(i) for i in input().split())
H = [int(i) for i in input().split()]

Flags = [1] * N
for m in range(M):
  A,B = (int(i) for i in input().split())
  if H[A-1]>H[B-1]:
    Flags[B-1] = 0
  elif H[B-1]>H[A-1]:
    Flags[A-1] = 0
  else:
    Flags[A-1] = 0
    Flags[B-1] = 0

ans = sum(Flags)
print(ans)




Measured memory_bytes: 20120
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<bitset>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define Iter(c) __typeof__((c).begin())
#define foreach(i,c) for(Iter(c) i = (c).begin();i != (c).end();++i)
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[] = {+1,+0,-1,-2,-2,-2,+1,+0,-1,+2,+2,+2}; // frog
const int dy[] = {-2,-2,-2,+1,+0,-1,+2,+2,+2,+1,+0,-1}; // frog
const int ddx[] = {0,+0,-1,-1,-1,+0,+1,+1,+1};
const int ddy[] = {0,-1,-1,+0,+1,+1,+1,+0,-1};


//17:29
int main(){

  while(true)
    {
      int n;
      vector<P> points;
      P phoy;

      cin >> phoy.F >> phoy.S;
      if(!(phoy.F|phoy.S))break;

      map<P,bool> used;

      cin >> n;

      rep(i,n)
	{
	  int xx,yy;
	  cin >> xx >> yy;
	  points.pb(P(xx,yy));
	}

      deque<P> deq;
      deq.push_front(phoy);

      bool fin = true;

     
     
      /* 
      while(!deq.empty())
	{ 
	  Pi pi = deq.front(); deq.pop_front();

	  if(pi.S == 1023)
	    {
	      cout << "OK" << endl;
	      fin = true;
	      break;
	    } 

	  if(used[pi.F])
	    continue;

	  used[pi.F] = true;	  

	  for(int i=0;i<n;i++)
	    {
	      if((pi.S>>i & 1))
		continue;

	      map<P,bool> exist;
	      
	      for(int j=0;j<9;j++)
		{
		  int nx = points[i].F + ddx[j],ny = points[i].S + ddy[j];
		  exist[P(nx,ny)] = true;
		}

	      for(int j=0;j<12;j++)
		{
		  int nx = pi.F.F + dx[j],ny = pi.F.S + dy[j];
		  if(exist[P(nx,ny)])
		    {
		      deq.push_front(Pi(P(nx,ny),(pi.S | 1<<i)));
		    }
		}
	 
	    }
	  
	}
      */
          

      for(int i=0;i<=n;i++)
	{
	  int Size = deq.size();
	  map<P,bool> exist;

	  if(!Size)
	    {
	      cout << "NA" << endl;
	      fin = false;
	      break;
	    }

	  for(int j=0;j<9;j++)
	    {
	      int nx = points[i].F + ddx[j], ny = points[i].S + ddy[j];
	      exist[P(nx,ny)] = true;
	    }

	  //cout << "points[" << i << "] just now" << endl;
	 
	  used.clear();
	  
	  for(int j=0;j<Size;j++)
	    {
	      P p = deq.front(); deq.pop_front();
	      
	      //cout << "pop p = " << p.F << "," << p.S << endl;
	      
	    
		      
	      for(int k=0;k<12;k++)
		{
		  int nx = p.F + dx[k], ny = p.S + dy[k];
		  
		  if(exist[P(nx,ny)] && !used[P(nx,ny)])
		    {
		      used[P(nx,ny)] = true;
		      deq.push_back(P(nx,ny));
		    }

		}

	    }

	}



      if(fin)
	{
	  cout << "OK" << endl;
	}

    }
return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>

int	main(void)
{
int	A[256];
int	N, c = 0, tmp;
tmp = scanf("%d", &N);
if( tmp == EOF ) return -101;
if( N==0 || N>200 ) return 1;
for( int f= 0; f< N; ++f)	{
  tmp = scanf("%d", &A[ f ]);
  if( tmp == EOF ) return -102;
}

do	{
  int f= 0;
  for( f= 0; f< N; ++f)  {
    if( A[ f ] %2 != 0 ) break;
    A[ f ] /= 2;
  }
  if( f != N )  {
    printf("%d", c);
    return	0;
  } else {
	++c;
  }
} while(-1);  
return 0;
}


Measured memory_bytes: 128
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int a, b;
	cin >> a >> b;
	int c = a;
	if (b < a)c--;
	cout << c;
	return 0;
}





Measured memory_bytes: 256
import math
from itertools import permutations

N = int(input())
town_index = [i for i in range(N)]
town = []
sum_length = 0
for i in range(N):
    x, y = map(int, input().split())
    town.append([x, y])

all_routes = list(permutations(town_index))
for root in all_routes:
    length = 0
    for i in range(1, N):
        length += math.sqrt((town[root[i-1]][0] - town[root[i]][0]) ** 2 + (town[root[i-1]][1] - town[root[i]][1]) ** 2)
    sum_length += length

print(sum_length / len(all_routes))


Measured memory_bytes: 8052
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
  static final long INF = Long.MAX_VALUE / 2;
  static int n;
  static long[] t, a;

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

    n = sc.nextInt();
    t = new long[n]; a = new long[n];
    for(int i = 0; i < n; i++){
      t[i] = sc.nextInt();  a[i] = sc.nextInt();
    }

    long tc = t[0], ac = a[0];
    for(int i = 1; i < n; i++){
      long d = binarySearch(t[i], a[i], ac, tc);
      ac += d;
      if(ac % a[i] != 0){
        ac = ((long)(ac / a[i]) + 1) * a[i];
      }
      tc = t[i] * (ac / a[i]);
    }

    long sum = (tc + ac);
    System.out.println(sum);
  }

  private static long binarySearch(long T, long A, long ac, long tc){
    long low = -1L, high = INF;
    while(high - low > 1L){
      long mid = (high + low) / 2L;
      if(f(mid, T, A, ac, tc)){
        high = mid;
      }
      else{
        low = mid;
      }
    }
    return high;
  }

  private static boolean f(long d, long T, long A, long a, long t){
    BigInteger db = new BigInteger(Long.toString(d)),
      Tb = new BigInteger(Long.toString(T)),
      Ab = new BigInteger(Long.toString(A)),  ab = new BigInteger(Long.toString(a)),
      tb = new BigInteger(Long.toString(t));
    BigInteger val = Tb.multiply(ab.add(db)).subtract(Ab.multiply(tb));
    return val.compareTo(new BigInteger("0")) >= 0;
  }
}


Measured memory_bytes: 31128
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,t=0,u=0,st=0,su=0,ans;
  cin >> n;
  vi w(n);
  rep(i,0,n){
    cin >> w[i];
  }

  while(t+u < n){
    if(su <= st){
      su+= w[u];
      u++;
    }else{
      st+= w[n-1-t];
      t++;
    }
  }
  ans= max(st,su)- min(st,su);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 1000000
#define MOD 1000000007

int main(){
  int N,K;
  string S;
  cin>>N>>K>>S;
  int count=0;
  for(int i=0;i<N-1;i++){
    if(S.at(i)==S.at(i+1)){
      count++;
    }
  }
  cout<<min(count+2*K,N-1)<<endl;
}


Measured memory_bytes: 512
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.PriorityQueue

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, K = in.next().toInt
  val t = new Array[Int](N+1)
  val d = new Array[Long](N+1)
  for (i <- 1 to N) {
    t(i) = in.next().toInt
    d(i) = in.next().toLong
  }


  //
  val sushi = Array.fill[List[Int]](N+1)(Nil)
  for (i <- 1 to N) {
    sushi(t(i)) = i :: sushi(t(i))
  }

  var ans = 0L
  val kinds = new Array[Int](N+1)
  var kind = 0L
  var lst: List[(Long, Int)] = Nil // (score, index)
  for (i <- 1 to N) {
    if (!sushi(i).isEmpty) {
      val (v, k) = sushi(i).map(x => (d(x), x)).max
      sushi(i) = sushi(i).filter(_ != k)

      kinds(i) += 1
      kind += 1
      ans += v
      
      lst = (v, k) :: lst
    }
  }

  val pq = new PriorityQueue[(Long, Int)]
  for (i <- 1 to N) {
    if (!sushi(i).isEmpty) {
      for (e <- sushi(i)) {
        pq.enqueue((d(e), e))
      }
    }
  }


  if (lst.length > K) {
    lst = lst.sorted.reverse
    for ((v, k) <- lst.drop(K))
      kinds(t(k)) = 0

    lst = lst.take(K)
    ans = lst.map(_._1).sum
    kind = K
  }
  else if (lst.length < K) {
    for (_ <- 1 to K - lst.length) {
      val (v, k) = pq.dequeue()
      ans += v
      kinds(t(k)) += 1
      lst = (v, k) :: lst
    }
  }


  var ans2 = ans + kind * kind

  val pq2 = new PriorityQueue[(Long, Int)]
  for ((v, k) <- lst) {
    pq2.enqueue((-v, k))
  }

  while (!pq.isEmpty) {
    val (v1, k1) = pq.dequeue()
    val (_v2, k2) = pq2.dequeue()
    val v2 = -_v2

    if (v1 > v2) {
      pq2.enqueue((-v1, k1))

      kinds(t(k2)) -= 1
      if(kinds(t(k2)) == 0)
        kind -= 1

      if(kinds(t(k1)) == 0)
        kind += 1
      kinds(t(k1)) += 1

      ans += v1 - v2
      ans2 = Math.max(ans2, ans + kind * kind)
    }
    else {
      pq2.enqueue((-v2, k2))
    }

  }

  println(ans2)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 127708
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {
	K = 0 ; bool F = false ; char C = getchar() ; while( C < '0' or C > '9' ) { if( C == '-' ) F = true ; C = getchar() ; }
	while( C <= '9' and C >= '0' ) K = ( K << 1 ) + ( K << 3 ) + C - '0' , C = getchar() ; if( F ) K = -K ;
}
template < class R > inline void Checkmax( R &A , R B ) {
	if( A < B ) A = B ;
}
template < class R > inline void Checkmin( R &A , R B ) {
	if( A > B ) A = B ;
}
const int Mod = 1e9 + 7 ;
const int MaxN = 100000 + 10 ;
inline void Moding( int &A ) {
	if( A >= Mod ) A -= Mod ;
	if( A < 0 ) A += Mod ;
}
inline int Pow( int A , int B ) {
	register int Ans = 1 ;
	while( B ) {
		if( B & 1 ) Ans = 1ll * Ans * A % Mod ;
		A = 1ll * A * A % Mod ;
		B >>= 1 ;
	}
	return Ans ;
}
int Fac[MaxN] , Inv[MaxN] ;
inline void C_Init() {
	register int N = MaxN - 10 ;
	Fac[0] = Inv[0] = 1 ;
	for(register int i = 0 ; ++i <= N ; )
		Fac[i] = 1ll * Fac[i-1] * i % Mod ;
	Inv[N] = Pow( Fac[N] , Mod - 2 ) ;
	for(register int i = N ; --i ; )
		Inv[i] = 1ll * Inv[i+1] * (i+1) % Mod ;
}
inline int C( int N , int M ) {
	return 1ll * Fac[M] * Inv[N] % Mod * Inv[M-N] % Mod ;
}
int A , B ;
int main() {
	Readin( A ) ;
	Readin( B ) ;
	if( A <= 0 and B >= 0 ) return not printf( "Zero\n" ) ;
	if( A > 0 or ( ( B - A ) & 1 ) ) return not printf( "Positive\n" ) ;
	return not printf( "Negative\n" ) ;
}

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

bool is_prime[1000000];
int prime[1000000];

int main() {
	int n;
	rep(i, 1000000)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i < 1000000; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j < 1000000; j += i)is_prime[j] = false;
		}
	}
	while (cin >> n) {
		cout << upper_bound(prime, prime + p, n) - prime << endl;
	}
	return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll abs(ll a,ll b){
	if(a < b) swap(a,b);
	return (a - b);
}
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n){
	    cin >> v[i];
    }
    sort(v.rbegin(), v.rend());
    ll now = abs(2*v[1], v[0]);
    ll ans1 = v[0];
    ll ans2 = v[1];
    FOR(i,1,n){
        if(abs(2*v[i],v[0]) <= now){
            ans2 = v[i];
            now = abs(2*v[i],v[0]);
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 3728
#include <stdio.h>

int judge(int x);

int main(){

    int x;
    scanf("%d", &x);
    int happy = judge(x);
    printf("%d\n", happy);
    
    return 0;
}

int judge(int x){
    int h = 1000 *(x/500);
    int nokori = x%500;
    h += 5 *(nokori/5);
    return h;
}


Measured memory_bytes: 128
# 10^100のクソデカ数値がクソデカすぎるため、+0,+1..+Nが束になってもいたくも痒くもない
# なのでもはや無視していい
# 最初の例でいうと、2つ選ぶのは[0,1,2,3]からなので、和のバリエーションは最小値1~最大値5の5つ
# 3つ選ぶのは最小値3~最大値6の4つ
# 4つ選ぶのは1つ
# 毎回最大値と最小値を計算して差+1を加えてやるとできあがり
# 計算には数列の和を使う

n, k = map(int, input().split())
mod = 10**9 + 7

ans = 1
for i in range(k, n + 1):
    # 初項0,公差1,末項i-1までの和
    min_s = i * (i - 1) // 2
    # 初項n+1-i, 公差1, 末項i-1までの和
    max_s = i * (2 * (n + 1 - i) + (i - 1)) // 2
    ans += max_s - min_s + 1
    ans %= mod
print(ans)


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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc
const int N=1e5+5;
vector<int>ans[N];

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	int n;
	cin>>n;
	int k=1;
	while(k*(k-1)/2<n)++k;
	if(k*(k-1)/2!=n)
	{
		puts("No");
		exit(0);
	}
	int tot=0;
	rep(i,1,k)
	rep(j,i+1,k)
	{
		++tot;
		ans[i].push_back(tot);
		ans[j].push_back(tot);
	}
	puts("Yes");
	printf("%d\n",k);
	rep(i,1,k)
	{
		printf("%d ",int(ans[i].size()));
		for(auto x:ans[i])printf("%d ",x);
		puts("");
	}
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, T, c, t, ans=10000;
    cin >> n >> T;
    for (int i=0; i<n; i++){
        cin >> c >> t;
        if (t <= T){
            ans = min(c, ans);
        }
    }
    if (ans == 10000){
        cout << "TLE" << endl;
    } else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i =k;i<n;i++)
using namespace std;
int main()
{
  int n,m,M;
  cin >> n;
  vector<int>a(n);
  rep(i,0,n)
  {
    cin >> a[i];
  }
  m=*std::min_element(a.begin(),a.end());
  M=*std::max_element(a.begin(),a.end());
  
  if(M-m>1)
  {
    cout << "No" << endl;
  }
  else
  {
    int c=0;
    rep(i,0,n)
    {
      if(a[i]==m)
      {
        ++c;
      }
    }
   
    if(M==m)
    {
      if(m==n-1||m<=n/2)
      {
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    else
    {
      if(M>c&&(n-c)/2>=M-c)
      {
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }
    }
  }
  
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
typedef vector<vector<int > > vec2int;
typedef vector<vector<bool > > vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  char a;
  cin >> a;
  cout << (char)(a + 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include <iomanip>
using namespace std;
 
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  vector<int> e(N);
  long long M = 0;
  for (int i = 0; i < N; i++){
    cin >> p[i];
    e[i] = p[i]+1;
  }
  for (int i = 0; i < K; i++){
    M += e[i];
  }
  long long tmp1 = M;
  for (int i = K; i < N; i++){
    long long tmp2 = tmp1 + e[i] - e[i-K];
    if (tmp2 > M){
      M = tmp2;
    }
    tmp1 = tmp2;
  }
  double ans = (double) M/2.0;
  cout << fixed << setprecision(7) << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int res1 = 0 ,res2 = 0;
	int sum = 0;
	for(int i=0;i<n;i++){
		sum += a[i];
		if( i%2 == 0 && sum <= 0 ){
			res1 += 1 - sum;
			sum = 1;
		}
		if( i%2 == 1 && sum >= 0){
			res1 += 1 + sum;
			sum = -1;
		}
	}
	sum = 0;
	for(int i=0;i<n;i++){
		sum += a[i];
		if( i%2 == 1 && sum <= 0 ){
			res2 += 1 - sum;
			sum = 1;
		}
		if( i%2 == 0 && sum >= 0){
			res2 += 1 + sum;
			sum = -1;
		}
	}
	cout<<min(res1,res2)<<endl;
	return 0;
}

Measured memory_bytes: 1024
n, y = gets.chomp.split(" ").map(&:to_i)
x = y / 1000 - n

# a + b + c = n
# 10 * a + 5 * b + c = y / 1000
# 9 * a + 4 * b = y / 1000 - n

a = b = c = -1
a_max = x / 9
(0..a_max).each do |i|
  j = x - 9 * i
  break if j < 0
  k = j / 4
  if k * 4 == j && n - i - k >= 0
    a = i
    b = k
    break
  end
end

if a != -1
  c = n - a - b
end

puts "#{a} #{b} #{c}"



Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;


string s[55];

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

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int h, w; cin >> h >> w;
	rep(i, 0, h) cin >> s[i];


	rep(i, 0, h) rep(j, 0, w) {
		if (s[i][j] == '.') continue;
		bool ok = false;
		rep(k, 0, 4) {
			int nx = j + dx[k];
			int ny = i + dy[k];
			if (0 <= nx && nx < w && 0 <= ny && ny < h) {
				if (s[ny][nx] == '#') ok = true;
			}
		}
		if (!ok) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";

	return 0;
}

Measured memory_bytes: 3620