akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
a = int(input())
c = [int(input()) for i in range(a)]

#最大値のindexを探し、最大値が複数あるか確認
all_max = max(c)
first_max_id = c.index(all_max)

c_dash = sorted(c,reverse=True)
second_max_value = c_dash[1]
for i,v in enumerate(c):
    if i != first_max_id:
        pr_val = all_max
    else:
        if all_max == second_max_value:
            pr_val = all_max
        else:
            pr_val = second_max_value
    print(pr_val)

Measured memory_bytes: 14176
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	int n, a, q;
	cin >> n;
	map<int, int> m;
	LL sum = 0, b, c;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		m[a] += 1;
		sum += a;
	}
	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> b >> c;
		LL d = m[b];
		m[b] = 0;
		sum -= b * d;
		m[c] += d;
		sum += c * d;
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 8080
#include<bits/stdc++.h>
#define int ll
#define all(v) v.begin(),v.end()
#define ll long long 
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define hell 1000000007
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;


ll fastExp(ll a,ll b,ll m=1000000007) //log(n) computes a raised power b
{
   ll res = 1;
    while(b>0){
        if(b&1){
            res = (res*a)%m;
        }
        a = (a*a)%m;
        b = b>>1;
    }
    return res;
}




// Extended Euclidean for Calculating of Inverse Modulo i.e. given gcd(a,M)=1 then only inverse of a will exist under modulo M;
void extEuclid(ll A,ll B,ll& x, ll& y, ll& gc)  //Here gc stores the gcd(A,B) i.e. For modulo inverse gc must be 1;
{
    if(B==0)        // for the last base case A*1+B*0=A and so is the result ....
    {
        gc=A;
        x=1;
        y=0;
    }
    else 
    {
        extEuclid(B, A%B,x,y,gc);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}



ll modInverse(ll A, ll M) // for any value of M i.e. mod value
{
    ll x,y,g;
    extEuclid(A,M,x,y,g);
    if(g==1)  // base condition for Inverse to exist ..... i.e. gcd must be 1...
    return (x%M+M)%M;
    else return -1;
}

ll modInverseFermat(ll A,ll M)  //if M is prime
{
    return fastExp(A,M-2);
}


void cook_ur_dish(){
	// inputs and Solution goes here
    int k,a,b;
    cin>>k>>a>>b;
    if(a%k==0 or b%k==0)
   {cout<<"OK"<<endl;return;}
    if(a/k == b/k)
    cout<<"NG"<<endl;
    else cout<<"OK"<<endl;
	
	
	
	
}

signed main(){
	fastIO;
	int t=1;
	// cin>>t;
	while(t--){
		cook_ur_dish();		
	}	
	return 0;
}


Measured memory_bytes: 3644
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10;
const ll mx = 1e18;

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = ((k % 2) ? b - a : a - b);
	if (ans > mx or ans < -mx) {
		cout << "Unfair\n";
	} else {
		cout << ans << endl;
	}
}

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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

constexpr int C = 20000;
bitset<C * 2> dp[80][80];

int main() { initio();
  int H, W; cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W)); rep(i, H) rep(j, W) cin >> A[i][j];
  vector<vector<int>> B(H, vector<int>(W)); rep(i, H) rep(j, W) cin >> B[i][j];
  dp[0][0][C + A[0][0] - B[0][0]] = true;
  dp[0][0][C - A[0][0] + B[0][0]] = true;
  rep(i, H) rep(j, W) rep(k, C * 2) if (dp[i][j][k]) {
    if (i + 1 < H) {
      dp[i + 1][j][k + A[i + 1][j] - B[i + 1][j]] = true;
      dp[i + 1][j][k - A[i + 1][j] + B[i + 1][j]] = true;
    }
    if (j + 1 < W) {
      dp[i][j + 1][k + A[i][j + 1] - B[i][j + 1]] = true;
      dp[i][j + 1][k - A[i][j + 1] + B[i][j + 1]] = true;
    }
  }
  int ans = 1e9;
  rep(k, C * 2) if (dp[H - 1][W - 1][k]) {
    ans = min(ans, abs(C - k));
  }
  cout << ans << endl;
}


Measured memory_bytes: 31488
import bisect

n = int(input())
l = sorted(list(map(int, input().split())))

total = 0
for i in range(n-1):
    for j in range(i+1, n):
        l2 = l[j+1:]
        total += bisect.bisect_left(l2, l[j]+l[i])
print(total)

Measured memory_bytes: 58496
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

struct UnionFind{
	vector<int> par,rank;
	UnionFind(int N){
		par.assign(N,0);
		rank.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]) swap(x,y);

		//x becomes root
		par[y]=x;
		if(rank[x]==rank[y]) rank[x]++;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,M;
	cin >> N >> M;
	UnionFind UF(N);
	rep(i,M){
		int x,y,z;
		cin >> x >> y >> z;
		x--,y--;
		UF.unite(x,y);
	}
	int ans = 0;
	rep(i,N) if(UF.find(i) == i) ans++;
	cout << ans << endl;
}


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

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;


int main(void){
	int n,m;
	cin >> n >> m;
	vector<int> x;
	for(int i=0;i<m;i++){
		int a;
		cin >> a ;
		x.push_back(a); 
	}
	if(n>=m) {
		cout << 0 << endl;
		return 0;
	}
	sort(x.begin(),x.end());
	vector<int> d;
	rep(i,m-1){
		d.push_back( x[i+1]-x[i] );
	}
//	rep(i,m-1)cout << "d[" << i <<"]=" << d[i] << endl;
	sort(d.rbegin(),d.rend());
//	rep(i,m-1)cout << "d[" << i <<"]=" << d[i] << endl;
	int full_length = x[m-1]-x[0];
	for(int i=0;i<n-1;i++){
		full_length -= d[i];
	}
	cout << full_length << endl;
	return 0;
}



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

int main() {
  int N, a, b, c, d;
  cin >> N;
  
  a = N / 1000;
  b = N % 1000 / 100;
  c = N % 100 / 10;
  d = N % 10;
  
  if (a == b && b == c || b ==c && c == d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
    int l, r, d;
    int ang, a = 0;
    scanf("%d %d %d", &l, &r, &d);

    for(int i = 1; i < 101; i++){
        ang = i * d;
        if( ang >= l && ang <= r){
            a++;
        }
    }
    printf("%d", a);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int flag = 0;

  for (int i=0; i<N; i++) {
    cin >> A.at(i);
    // cout << A.at(i) << endl;
  }


  for (int i=0; i<N; i++) {
    if (A.at(i)%2 == 0) { // even number
      if (!(A.at(i)%3 == 0 || A.at(i)%5 == 0)) {
        flag = 1;
        break;
      }
    }
  }

  if (flag) cout << "DENIED" << endl;
  else cout << "APPROVED" << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max1 100005
#define siz 1000005
#define mod 998244353
#define inf 1e18
#define ll long long int
#define debug(x) cout<<#x<<" "<<x<<endl
#define jam(x) cout<<"Case #"<<x<<": "
#define hackercup(x) cout<<"Case #"<<x<<": "
ll tt;
#define run_time cout << "\nTIME = " << clock() - tt << endl; tt = clock();
typedef pair<ll,ll> pr;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  tt = clock();
  #endif*/
  ll x;
  cin >> x;
  if(x >= 30)
  {
    cout << "Yes\n";
  }
  else
  {
    cout << "No\n";
  }
} 

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

using namespace std;

const long long INF = 1e18;
const int MOD = 1e9 + 7;

int n,i,j,lx,ly;
long long a,b,lval,s[100005];

struct dat{
	long long sum;
	bool tag;
}dpa[400005],dpb[400005];

struct com{
	bool a, type;
	long long x,val;
};

void zero(dat* t){
	t[1].tag = 1;
	t[1].sum = 0;
}

void push(int id, dat* t){
	if(t[id].tag){
		t[id].tag = 0;
		t[id * 2].tag = 1;
		t[id * 2 + 1].tag = 1;
		t[id * 2].sum = 0;
		t[id * 2 + 1].sum = 0;
	}
}

void add(int l, int r, int ind, dat* t){
	if(l == r){
		t[ind].sum = (t[ind].sum + lval) % MOD;
		return;
	}
	
	push(ind, t);
	
	int mid = (l + r) / 2;
	
	if(lx <= mid)
	add(l, mid, ind * 2, t);
	else
	add(mid + 1, r, ind * 2 + 1, t);
	
	t[ind].sum = (t[ind * 2].sum + t[ind * 2 + 1].sum) % MOD;
}

void query(int l, int r, int ind, dat* t){
	if(lx <= l && r <= ly){
		lval = (lval + t[ind].sum) % MOD;
		return;
	}
	
	push(ind, t);
	
	int mid = (l + r) / 2;
	
	if(lx <= mid)
	query(l, mid, ind * 2, t);
	if(ly > mid)
	query(mid + 1, r, ind * 2 + 1, t);
	
	t[ind].sum = (t[ind * 2].sum + t[ind * 2 + 1].sum) % MOD;
}

int main(){
	scanf("%d%lld%lld", &n, &a, &b);
	for(i = 1; i <= n; i++)
	scanf("%lld", &s[i]);
	
	s[0] = -INF;
	
	lx = 1;
	lval = 1;
	add(1, n, 1, dpa);
	add(1, n, 1, dpb);
	
	int p = 0;
	int p1 = 0;
	
	for(i = 2; i <= n; i++){
		vector <com> q;
		
		while(s[i] - s[p] >= a)
		p++;
		while(s[i] - s[p1] >= b)
		p1++;
		
		if(s[i] - s[i - 1] < a)
		q.push_back({0, 0, 0, 0});
		if(s[i] - s[i - 1] < b)
		q.push_back({1, 0, 0, 0});
		
		//from 1 to p
		lx = 1;
		ly = p;
		lval = 0;
		
		query(1, n, 1, dpb);
		
		q.push_back({0, 1, i, lval}); 
		
		lx = 1;
		ly = p1;
		lval = 0;
		
		query(1, n, 1, dpa);
		
		q.push_back({1, 1, i, lval});
		
		for(j = 0; j < q.size(); j++){
			if(q[j].type == 0){
				if(q[j].a == 0)
				zero(dpa);
				else
				zero(dpb);
			}
			else{
				lx = q[j].x;
				lval = q[j].val;
				if(q[j].a == 0)
				add(1, n, 1, dpa);
				else
				add(1, n, 1, dpb);
			}
		}
	}
	
	lx = 1;
	ly = n;
	lval = 0;
	
	query(1, n, 1, dpa);
	query(1, n, 1, dpb);
	
	printf("%lld\n", lval % MOD);
}


Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define MAX 30
#define INF 10000000.0
struct S{
	int e,s,b;
};

struct S2{
	int d,c,to;
};

int main(){

	int n,m;
	int s,g;
	int x,y,d,c;
	int min;
	double cost[MAX+1][MAX+1][MAX+1];
	S point,tmp;
	S2 nod;
	vector<S2> ed[MAX+1];
	queue<S> no;

	while(1){

		cin>>n>>m;
		if(n==0&&m==0) break;

		for(int i=1;i<=n;i++){
			if(!ed[i].empty()) ed[i].clear();
		}

		for(int i=0;i<=30;i++){
			for(int j=0;j<=30;j++){
				for(int k=0;k<=30;k++){
					cost[i][j][k]=INF;
				}
			}
		}

		cin>>s>>g;
		point.e=s,point.s=0,point.b=0;
		cost[0][s][0]=0;

		for(int i=0;i<m;i++){
			cin>>x>>y>>d>>c;
			nod.c=c,nod.d=d,nod.to=y;;
			ed[x].push_back(nod);
			nod.to=x;
			ed[y].push_back(nod);
		}

		no.push(point);
		while(!no.empty()){
			point=no.front();
			no.pop();
			for(int i=0;i<ed[point.e].size();i++){
				if(point.b!=ed[point.e][i].to){
					for(int j=-1;j<=1;j++){
						if(point.s+j>0&&point.s+j<=30){
							//if(point.s+j==1&&ed[point.e][i].to==g) cout<<cost[point.s][point.e]+((double)ed[point.e][i].d/(point.s+j))<<endl;
							if(ed[point.e][i].c>=point.s+j){
								//cout<<point.e<<","<<point.b<<","<<point.s<<","<<ed[point.e][i].to<<","<<cost[point.s][point.e]<<"^^"<<cost[point.s][point.e]+(double)ed[point.e][i].d/(point.s+j)<<endl;
								if(cost[point.s+j][ed[point.e][i].to][point.e]>cost[point.s][point.e][point.b]+((double)ed[point.e][i].d/(point.s+j))){
									cost[point.s+j][ed[point.e][i].to][point.e]=cost[point.s][point.e][point.b]+((double)ed[point.e][i].d/(point.s+j));
									tmp.e=ed[point.e][i].to;
									tmp.s=point.s+j;
									tmp.b=point.e;
									no.push(tmp);
								}
							}
						}
					}
				}
			}
		}
		min=0;
		for(int i=1;i<=30;i++){
			if(cost[1][g][i]<cost[1][g][min]) min=i;
		}
		if(min==0) printf("unreachable\n");
		else printf("%.5f\n",cost[1][g][min]);
	}

}

Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

int N;
const int field_size = 100000;
int P[210000];
pair<long long, int> points_cnt[210000];

int root(int x);

void unite(int x, int y){
    P[root(x)] = root(y);
}

int root(int x){
    if(P[x] == x){
        return x;
    }
    return P[x] = root(P[x]);
}

int main(){
    cin >> N;
    for(int i = 1; i <= 2 * field_size; i++){
        P[i] = i;
    }

    for(int i = 0; i < N; i++){
        int x, y;
        cin >> x >> y;
        unite(x, y + field_size);
    }

    for(int i = 1; i <= 2 * field_size; i++){
        root(i);
    }
    
    for(int i = 1; i <= 2 * field_size; i++){
        if(i <= field_size){
            points_cnt[root(i)].first++;
        }else{
            points_cnt[root(i)].second++;
        }
    }

    long long ans = -N;
    for(int i = 1; i <= 2 * field_size; i++){
        if(root(i) == i){
            ans += points_cnt[root(i)].first * points_cnt[root(i)].second;
        }
    }
    cout << ans << endl;

    
}


    


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	hl := make([]int, n)

	for i := 0; i < n; i++ {
		hl[i] = nextInt()
	}
	sort.Ints(hl)

	dh := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		dh[i] = hl[i+1] - hl[i]
	}
	minrun := 1000000000

	for i := 0; i < n-k+1; i++ {
		runsum := 0
		for j := 0; j < k-1; j++ {
			runsum += dh[i+j]
			//fmt.Println("i,j=", i, j, "runsum += dh[i+j] (", dh[i+j], ")", " new runsum=", runsum)
		}
		//fmt.Println(i, runsum, minrun)
		minrun = min(minrun, runsum)
	}

	fmt.Println(minrun)
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 5228
N, D = [int(elem) for elem in input().split()]
coords = [[int(elem) for elem in input().split()] for _ in range(N)]
assert len(coords[0]) == D

def is_squared(num):
    i = 1
    while i * i <= num:
        if i * i == num:
            return True
        i += 1
    return False


num_pairs = 0
for i in range(N):
    c1 = coords[i]
    for j in range(i + 1, N):
        c2 = coords[j]
        sqaured_dist = sum((p1 - p2) ** 2 for p1, p2 in zip(c1, c2))
        if is_squared(sqaured_dist):
            num_pairs += 1
print(num_pairs)


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

int main()
{
    string s;
    cin>>s;
    int l=s.size()-1;
    if(s[l]=='2' || s[l]=='4' || s[l]=='5' || s[l]=='7' || s[l]=='9') cout<<"hon";
    else if(s[l]=='3') cout<<"bon";
    else cout<<"pon";
}


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

int n,sum[200101],pre[200101];
vector<int> vc[200101],road;

void dfs(int x,int f)
{
    sum[x]=1;
	pre[x]=f;
    for(int i=0;i<vc[x].size();i++)
    if(vc[x][i]!=f)
    {
        dfs(vc[x][i],x);
        sum[x]+=sum[vc[x][i]];
    }
    return ;
}
int main()
{
    scanf("%d",&n);
    for(int i=1,x,y;i<n;i++)
    {
    	scanf("%d%d",&x,&y);
		vc[x].push_back(y);
		vc[y].push_back(x);
	}
    dfs(1,0);
    for(int i=n;i;i=pre[i])
        road.push_back(i);
    reverse(road.begin(),road.end());
    int tb,ta;
    tb=sum[road[(road.size()+1)/2]];
    ta=n-tb;
    if(ta>tb)
		puts("Fennec");
    else
    	puts("Snuke");
    return 0;
}

Measured memory_bytes: 16380
import numpy as np
import sys
# '#'からの距離を測る

buf = sys.stdin.buffer
H,W = map(int,buf.readline().split())
black = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'#').reshape(H,W+1)

INF = 10 ** 9
dist = np.zeros((H,W),dtype=np.int32)
dist[~black[:,:-1]] = INF

for n in range(1,H):
  np.minimum(dist[n-1]+1,dist[n],out=dist[n])
for n in range(H-2,-1,-1):
  np.minimum(dist[n+1]+1,dist[n],out=dist[n])

for n in range(1,W):
  np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n])
for n in range(W-2,-1,-1):
  np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n])

answer = dist.max()
print(answer)


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



signed main() {
	int n,  m;
	vector<int>list(100005, 0);
	vector<bool>flag(100005, false);
	int cnt = 0, cnt2=0;

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int num;
		string s;
		cin >> num >> s;

		if (s == "WA" && flag[num]==false) {
			list[num]++;
			//cnt++;
		}
		else if (s == "AC"&& flag[num] == false) {
			flag[num] = true;
			cnt2++;
		}
	}

	for (int i = 0; i < flag.size(); i++) {
		if (flag[i] == true) {
			cnt += list[i];
		}
	}

	cout << cnt2 << " " << cnt << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
signed main(){
  priority_queue<int,vector<int>,greater<int> > q;
  int a,b,c[1000000]={};
  int d,e;
  int f;
  vector<pair<int,int> > p;
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>c[i];
    q.push(c[i]);
  }
  sort(c,c+a);
  for(int i=0;i<b;i++){
    cin>>d>>e;
    p.push_back(make_pair(e,d));
  }
  sort(p.begin(),p.end(),greater<pair<int,int> >());
  for(int i=0;i<b;i++){
    f=q.top();
    if(f<p[i].fi){
      for(int j=0;j<p[i].se;j++){
        //cout<<f<<" "<<e<<"\n";
        f=q.top();
        if(f<p[i].fi){
          q.pop();
          q.push(p[i].fi);
        }
        //else break;
      }      
    }
    //else break;
  }
  f=0;
  for(int i=0;i<a;i++){
    f+=q.top();
    q.pop();
  }
  cout<<f<<"\n";
}

Measured memory_bytes: 10996
h, w = gets.split(" ").map(&:to_i)
s = []
h.times do |i|
  s_raw = gets.split("").map{|x| x == "."}
  s << s_raw
end

# p s

dp = []
f = lambda do |i, j|
  if i < 0 || j < 0 then
    return [i == 0 || j == 0 ? 0 : Float::INFINITY, false]
  else
    return dp[i][j]
  end
end

h.times do |i|
  w.times do |j|
    up_a, up_c = f.yield(i-1, j)
    left_a, left_c = f.yield(i, j-1)
    up = up_c ? [up_a, !s[i][j]] : (s[i][j] ? [up_a, false] : [up_a + 1, true])
    left = left_c ? [left_a, !s[i][j]] : (s[i][j] ? [left_a, false] : [left_a + 1, true])
    # puts "#{i}, #{j}"
    # puts "debug #{up_c}, #{s[i][j]}"
    # puts "up: #{up}, left: #{left}"
    dp[i] ||= []
    dp[i][j] ||= []
    if up[0] <= left[0] then
      dp[i][j] = up
    else
      dp[i][j] = left
    end
  end
end

# p dp
puts dp[h-1][w-1][0]

Measured memory_bytes: 2812
//tanzim bin nasir
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int gcd(int a,int b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
int main()
{
     int n;
     string s;
     cin>>n>>s;
     int i=0,j=n-1,ans=0;
     while(i<j)
     {
         if(s[i]=='W')
         {
             while(j>i)
             {
                 if(s[j]=='R')
                 {
                     swap(s[i],s[j]);
                     ++ans;
                     break;
                 }
                 --j;
             }
         }
         ++i;
     }
     cout<<ans<<endl;
}


Measured memory_bytes: 3768
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = str(I())
ans = 0
space_num = len(n) - 1
for i in range(2 ** space_num):
    ret = n[0]
    for j in range(space_num):
        if i & 1 << j:
            ret += '+'
        ret += n[j + 1]
    ans += eval(ret)


print(ans)


Measured memory_bytes: 39792
import sys
from string import ascii_lowercase

input = sys.stdin.readline


class Solution:
    def main(self):
        C = input().rstrip()

        for i, _char in enumerate(ascii_lowercase):
            if _char == C:
                print(ascii_lowercase[i + 1])
                exit()


# Run main
if __name__ == '__main__':
    Solution().main()


Measured memory_bytes: 38640
S = input()
S_sub = []
for i in range(len(S)-2):
    S_sub.append(int(S[i: i +3]))
S_sub_mi = [0]*len(S_sub)
for i in range(len(S_sub)):
    S_sub_mi[i] = abs(753 - S_sub[i])
print(min(S_sub_mi))

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

int main(void) {
  int yyyy, mm, dd;
  scanf("%d/%d/%d", &yyyy, &mm, &dd);
  puts(mm <= 4 ? "Heisei" : "TBD");
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
    B.append(A[i] - i - 1)
B.sort()
cen = B[N//2]
sum = 0
for i in range(N):
    sum += abs(B[i]-cen)
print(sum)

Measured memory_bytes: 26020
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long
int a[10003];

signed main() {
  int n;
  cin >> n;
  FOR(i,1,100) {
    FOR(j,1,100) {
      FOR(k,1,100) {
        int tmp = i*i+j*j+k*k+i*j+j*k+k*i;
        if(tmp<=n) a[tmp]++;
      }
    }
  }
  
  FOR(i,1,n+1) cout << a[i] << endl;


  return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n,m,p;
    cin >> n >> m;
    string s;
    auto AC = vector<int>(n+1,0);
    auto WA = vector<int>(n+1,0);
    
    int ACsum = 0;
    int WAsum = 0;
    

    for(int i=0;i<m;i++){
        cin >> p >> s;
        if(AC[p]==1) continue;
        if(s=="AC"){
           ACsum++;
           WAsum+=WA[p];
           AC[p]=1;
        }else if(s=="WA"){
            WA[p]++;
        }
    }

    cout << ACsum << " " << WAsum;
    

    return 0;
}

Measured memory_bytes: 1024
while true do
  n, w = gets.split.map(&:to_i)
  break if n | w == 0
  histogram = Array.new
  n.times do
    v = gets.to_i
    histogram[v / w] = 0.0 if !histogram[v / w]
    histogram[v / w] += 1.0
  end
  histogram = histogram.collect{|e| e ? e : 0.0}
  largest = histogram.max
  size = histogram.size - 1
  answer = 0.01
  size.times do |i|
    answer += histogram[i] / largest * (size - i).to_f / size.to_f
  end
  p answer
end

Measured memory_bytes: 6136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { min(v, o.v) };
        }
        int v;
    };

    SegmentTree(int n) : e({ 1 << 30 }), n(n) {
        for (m = 2; m < n; m *= 2); // m >= n
        t = vector<Node>(m + n + n % 2, e);
    }
    Node *data() {
        return &t[m];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    const Node& root() const {
        return t[1];
    }
    void update(int i, const Node& o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) const {
        Node o[2] = { e, e };
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o[1] = t[--r] * o[1];
            if (l & 1) o[0] = o[0] * t[l++];
        }
        return o[0] * o[1];
    }
    void print() {
        for (int j = 1; j <= m; j *= 2) {
            int k = min(j * 2, m + n);
            for (int i = j; i < k; i++) {
                cout << t[i].v << " \n"[i == k - 1];
            }
        }
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

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

    int n;
    cin >> n;

    vector<int> r(n), p(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        p[r[i]] = i;
    }

    SegmentTree st[2] = { n / 2, n / 2 };
    for (int i = 0; i < n; i++) {
        st[i % 2].data()[i / 2].v = r[i];
    }
    for (int j = 0; j < 2; j++) {
        st[j].build();
    }

    using A = array<int, 3>;
    priority_queue<A, vector<A>, greater<>> q;
    q.push({ st[0].root().v, 0, n });

    for (int i = 0; i < n; i += 2) {
        auto a = q.top(); q.pop();
        r[i] = a[0];
        int p0 = p[r[i]];
        int j = p0 % 2;
        st[j].update(p0 / 2, st[j].e);

        r[i + 1] = st[j ^ 1].query((p0 + 1) / 2, (a[2] + 1) / 2).v;
        int p1 = p[r[i + 1]];
        st[j ^ 1].update(p1 / 2, st[j ^ 1].e);

        auto f = [&](int l, int r) {
            if (l == r) return;
            q.push({ st[l % 2].query(l / 2, r / 2).v, l, r });
        };
        f(a[1], p0);
        f(p0 + 1, p1);
        f(p1 + 1, a[2]);
    }

    for (int i = 0; i < n; i++) {
        cout << r[i] << " \n"[i == n - 1];
    }

    return 0;
}

Measured memory_bytes: 5500
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int a, b, cnt = 0;
	string s;
	cin >> a >> b >> s;
	for (int i = 0; i < a + b + 1; i++) {
		if (s[i] == '-') {
			cnt++;
		}
	}
	if (cnt == 1 && s[a] == '-') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
bingo = [ input().split() for j in range(3)]
N = int(input())
b = []
for n in range(N):
	b.append(input())
for x in range(N):
	for i in range(3):
		for j in range(3):
			if bingo[i][j] == b[x]:
				bingo[i][j] = 'OK'
if bingo[0][0] == 'OK' and bingo[0][1] == 'OK' and bingo[0][2] == 'OK':
	print('Yes')
elif bingo[1][0] == 'OK' and bingo[1][1] == 'OK' and bingo[1][2] == 'OK':
	print('Yes')
elif bingo[2][0] == 'OK' and bingo[2][1] == 'OK' and bingo[2][2] == 'OK':
	print('Yes')
elif bingo[0][1] == 'OK' and bingo[1][1] == 'OK' and bingo[2][1] == 'OK':
	print('Yes')
elif bingo[0][0] == 'OK' and bingo[1][0] == 'OK' and bingo[2][0] == 'OK':
	print('Yes')
elif bingo[0][2] == 'OK' and bingo[1][2] == 'OK' and bingo[2][2] == 'OK':
	print('Yes')
elif bingo[0][0] == 'OK' and bingo[1][1] == 'OK' and bingo[2][2] == 'OK':
	print('Yes')
elif bingo[0][2] == 'OK' and bingo[1][1] == 'OK' and bingo[2][0] == 'OK':
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3188
from copy import copy

def solve_negative():
    def count_less_x(x):
        ret = 0
        i = 0
        j = 0
        while i < len(negative_a):
            while j < len(positive_a) and positive_a[j] * negative_a[i] > x:
                j += 1
            ret += len(positive_a) - j
            i += 1

        return ret

    upper = -1
    lower = -1000000001*1000000001
    while upper - lower > 1:
        middle = (upper + lower) // 2
        if count_less_x(middle) >= k:
            upper = middle
        else:
            lower = middle
    return upper


def solve_positive():
    def count_less_x(x):
        ret = 0
        i = 0
        j = len(positive_a) - 1
        while i < len(positive_a):
            while j > i and positive_a[i] * positive_a[j] > x:
                j -= 1
            ret += j - i
            i += 1
            if i >= j:
                break
        i = 0
        j = len(r_negative_a) - 1
        while i < len(r_negative_a):
            while j > i and r_negative_a[i] * r_negative_a[j] > x:
                j -= 1
            ret += j - i
            i += 1
            if i >= j:
                break
        return ret
    lower = 0
    upper = 1000000001*1000000001
    while upper - lower > 1:
        middle = (upper + lower) // 2
        if count_less_x(middle) + num_mul_n + num_mul_z >= k:
            upper = middle
        else:
            lower = middle
    return upper


def solve_zero():
    return 0


def create_sign_split_a(a):
    negative = []
    positive = []
    zero = []
    for x in a:
        if x < 0:
            negative.append(x)
        elif x > 0:
            positive.append(x)
        else:
            zero.append(x)
    return negative, zero, positive


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

num_n = sum([(a_ < 0) for a_ in a])
num_p = sum([(a_ > 0) for a_ in a])
num_z = sum([(a_ == 0) for a_ in a])
negative_a, zero_a, positive_a = create_sign_split_a(a)
r_negative_a = copy(negative_a)
r_negative_a.reverse()

num_mul_p = num_n * (num_n - 1) // 2 + num_p * (num_p - 1) // 2
num_mul_z = num_n * num_z + num_p * num_z + num_z * (num_z - 1) // 2
num_mul_n = n * (n - 1) // 2 - num_mul_p - num_mul_z


if num_mul_n >= k:
    ans = solve_negative()
elif num_mul_n < k <= num_mul_n + num_mul_z:
    ans = solve_zero()
else:
    ans = solve_positive()
print(ans)


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

int main() {
    int S;
    cin >> S;
    int h = S / 3600;
    int m = (S - h * 3600) / 60;
    int s = ((S - h * 3600) - m * 60);
    cout << h << ':' << m << ':' << s << endl;
    return 0;
}

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

using namespace std;

int main() {
	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	if (a == f && c == d && b == e) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# B - Strings with the Same Length
import sys
import os

def problem148B(N ,S, T):
	
	st = ""
	for i in range(N):
		st += S[i] + T[i]
		
	print(st)

if __name__ == "__main__":
	N = int(input())
	S, T = input().split()

	problem148B(N, S, T)



Measured memory_bytes: 2940
#%%
import fractions
def gcd_base(x, y):
    return fractions.gcd(x, y)

def gcd_list(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = gcd_base(tmp, l[i])
    return tmp

import fractions
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = lcm_base(tmp, l[i])
        if tmp > 10**9:
            tmp = -1
            break
    return tmp

n, m = map(int, input().split())
a = list(map(lambda x: int(x)//2 , input().split()))
f1 = True

lcm = lcm_list(a)
if lcm == -1:
    ans = 0
else:
    for i in range(n):
        if (lcm // a[i]) % 2 == 0:
            ans = 0 
            f1 = False
            break
    if f1:
        ans = (m + lcm) // (2 * lcm)
print(ans)





# %%


Measured memory_bytes: 89836
#include<iostream>
using namespace std;
int main(){
  int N;
  int L;
  cin >> N;
  int a[110];
  for (int i =0; i<110; i++){
    a[i]=0;
  }
  for (int i =0; i<2*N; i++){
    cin >> L;
    a[L-1]+=1;
  } 
  int count=1;
  int sum=0;
  for (int i=0; i<110; i++)
    while (a[i]!=0){
      sum+=count*(i+1);
      count=(count+1)%2;
      a[i]-=1;
    }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=200000+10;
int a1[maxn];
int an[maxn];
int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	int N,M;
	cin>>N>>M;
	int flag=0;
	memset(a1,0,sizeof(a1));
	memset(an,0,sizeof(an));
	for(int i=1;i<=M;i++)
	{
		int c,d,sum;
		cin>>c>>d;
		sum=c+d;
        if(c==1||d==1)
        {
        	a1[sum-1]=1;
        	if(an[sum-1]==1)
        	flag=1;
        	
		}
        if(c==N||d==N)
        {
        	an[sum-N]=1;
        	if(a1[sum-N]==1)
        	flag=1;
		}
	}
	if(flag)
	cout<<"POSSIBLE"<<endl;
	else
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	if(n % 2 == 1){
		cout << "No";
		return 0;
	}else{
		rep(i, n / 2){
			if(s[i] != s[i + n / 2]){
				cout << "No";
				return 0;
			}
		}
	}

	cout << "Yes";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int m1, d1, m2, d2;
	scanf("%d%d%d%d", &m1,&d1,&m2,&d2);
	switch(m1)
	{
		case 1: 
		    if(d1==31)
		        printf("1\n");
		    else printf("0\n"); break;
		case 2:
			if(d1==28)
		        printf("1\n");
		    else printf("0\n"); break;
		case 3:
			if(d1==31)
		        printf("1\n");
		    else printf("0\n"); break;
		case 4:
			if(d1==30)
		        printf("1\n");
		    else printf("0\n"); break;
		case 5:
			if(d1==31)
		        printf("1\n");
		    else printf("0\n"); break;
		case 6:
			if(d1==30)
		        printf("1\n");
		    else printf("0\n"); break;
		case 7:
			if(d1==31)
		        printf("1\n");
		    else printf("0\n"); break;
		case 8:
			if(d1==31)
		        printf("1\n");
		    else printf("0\n"); break;
		case 9:
			if(d1==30)
		        printf("1\n");
		    else printf("0\n"); break;
		case 10:
			if(d1==31)
		        printf("1\n");
		    else printf("0\n"); break;
		case 11:
			if(d1==30)
		        printf("1\n");
		    else printf("0\n"); break;
		case 12:
			if(d1==31)
		        printf("1\n");
		    else printf("0\n"); break;
	}
	return 0;
}

Measured memory_bytes: 128
n=int(input())
x=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n):
    ans=0
    for j in range(i,n-1):
        if ans%x[j][2]==0:
            a=0
        else:
            a=x[j][2]-(ans%x[j][2])
        ans=(max(ans+a,x[j][1]))
        ans+=x[j][0]
    print(ans)

Measured memory_bytes: 74288
#include <stdio.h>

int gcd(int a, int b, int c){
    int gcd;
    while(a%b!=0){
        int tmp=a;
        a=b;
        b=tmp%b;
    }
    gcd=b;
    while(c%gcd!=0){
        int tmp=c;
        c=gcd;
        gcd=tmp%gcd;
    }
    return gcd;

}
int main(){
    int k,sum=0;
    scanf("%d",&k);
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                sum+=gcd(i,j,l);
            }
        }
    }
    printf("%d\n",sum);
    return 0;
}

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

	#define scanI(n)    scanf("%d", &n)
	#define scanII(a, b) scanf("%d %d", &a, &b)
	#define scanIII(a, b, c) scanf("%d %d %d", &a, &b, &c)
	#define printI(n) printf("%d", n)
	#define printII(a,b) printf("%d %d", a, b)
	#define ALL(x) x.begin(), x.end()
	#define VI vector<int>
	#define LL long long
	#define PRINT(list) for(auto i : list) printf("%d ", i); printf("\n");
	#define PRINTARR(ar_, n_) for(int i_=0; i_<n_; i_++){printf("%d ", ar_[i_]);} printf("\n");
	#define DPRINT(dlist) for(auto list : dlist) { PRINT(list); printf("\n"); }
	#define INIT(ar, n, val) for(int _i=0; _i<n; _i++) ar[_i] = val;
	#define MOD 1000000007
        #define PI 3.142857
	#define MAX_OP [](int a, int b){return max(a,b);}
	#define MIN_OP [](int a, int b){return min(a,b);}


	using namespace std;

	void test(){

	}

	int main(){
		int n,a,b;
		scanIII(n,a,b);

		if(abs(n-a) < abs(n-b))
			printf("A");
		else
			printf("B");

	    return 0;
	}



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

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s) sort((s).begin(),(s).end(),greater<int>())

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

const double PI=acos(-1.0);

int N; vi d;
int input()
{  
    cin>>N;
    rep(i,N){
        int a; cin>>a; d.emplace_back(a);
    }
}

int solve()
{
    SORT(d);
    int ans=d[N/2]-d[N/2-1];
    cout<<ans<<endl;
}

int main(){
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}


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

int main(){
  int n,sum,i;
 
  while(cin >> n){
      sum=1;
      if( 0 < n && n <= 10000){
	for( i = 0 ; i <=  n ; i++){
	  sum = sum + i;
	}
	cout <<sum << endl;
      }

  }

    return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  vector<int> a;
  cin >> n;
  a.push_back(-1);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  int m = 0;
  vector<int> num(n + 1, 0);
  vector<int> ans;
  for (int i = n; i > 0; i--) {
    int tmp = 0;
    for (int j = i; j <= n; j += i) {
      tmp += num[j];
    }
    if (tmp % 2 != a[i]) {
      num[i]++;
      m++;
      ans.push_back(i + 1);
    }
  }
  cout << m << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3444
#include <iostream>

int main() {
  char c; std::cin >> c;
  switch( c ) {
    case 'A': std::cout << 'T'; return 0;
    case 'T': std::cout << 'A'; return 0;
    case 'G': std::cout << 'C'; return 0;
    case 'C': std::cout << 'G'; return 0;
  }
}


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

int main(){
    int n; cin>>n;
    int ans=0;
    rep(i,n){
        int a; cin>>a;
        ans+=a-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = input()

if(N[-1] == "2" or N[-1] =="4"or N[-1] =="5" or N[-1] =="7" or N[-1] =="9"):
    print("hon")
elif(N[-1] == "0" or N[-1] =="1" or N[-1] =="6" or N[-1] =="8"):
    print("pon")
elif(N[-1] == "3"):
    print("bon")

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

using namespace std;

typedef long long lol;
const int N = 55;
int _w;

lol f[N][N][N];
int n , G[N][N];
char str[N];

lol dp( int l , int r , int mid ) {
  if( l == mid || r == mid ) 
    return l == r;
  if( ~f[l][r][mid] ) return f[l][r][mid];
  lol & res = f[l][r][mid]; res = 0;
  for( int i = l ; i < mid ; ++i )
    for( int j = mid + 1 ; j <= r ; ++j )
      if( G[i][j] ) {
        for( int k = i ; k < mid ; ++k )
          for( int o = mid + 1 ; o <= j ; ++o ) {
            res += dp( l , k , i ) * dp( k + 1 , o - 1 , mid ) * dp( o , r , j );
          }
      }
  return res;
}

int main( void ) {
  memset( f , -1 , sizeof f );
  _w = scanf("%d",&n);
  n <<= 1;
  for( int i = 1 ; i <= n ; ++i ) {
    _w = scanf("%s",str+1);
    for( int j = 1 ; j <= n ; ++j )
      G[i][j] = str[j] == '1';
  }
  lol ans = 0;
  for( int i = 2 ; i <= n ; ++i )
    if( G[1][i] ) ans += dp( 2 , n , i );
  cout << ans;
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) ll a[n]; fab(i,0,n) cin>>a[i]
#define showdp(d,n,m) fab(i,0,n){ fab(j,0,m) if(d[i][j]==-1 || d[i][j]>9) cout<<d[i][j]<<" "; else cout<<" "<<d[i][j]<<" "; cout<<endl; }
#define prs(u) cout<<u<<" "
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 1000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define vvl vector<vl>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
const ll N =(ll)3e5;
const ll inf =(ll)1e18+7;
const ll mod =(ll)1e9+7;
 
bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}
 
bool isPrime(ll p)
{
    for(ll i=2;i*i<=p;i++)
        if(p%i==0)
            rr false;
    rr true;
}
 
void sieve(ll n,vl &v)
{
    v.pb(2);
    bool prime[n+1];
    memset(prime,true,sizeof(prime));
    for(ll i=3;i*i<=n;i+=2)
        if(prime[i])
            for(ll j=i;j*i<=n;j+=2)
                prime[j*i]=false;
        
    for(ll i=3;i<=n;i+=2)
        if(prime[i])
            v.pb(i);
}

ll phi(ll n)
{
    ll result=n;
    for(ll p=2;p*p<=n;p++)
    {
        if(n%p==0)
        {
            while(n%p==0)
                n/=p;
            result-=result/p;
        }
    }

    if(n>1)
        result-=result/n;
    return result;
}

ll nCr(ll n, ll k) 
{ 
    ll C[n + 1][k + 1]; 
    ll i, j;  
    for (i = 0; i <= n; i++) 
    { 
        for (j = 0; j <= min(i, k); j++) 
        { 
            if (j == 0 || j == i) 
                C[i][j] = 1;  
            else
                C[i][j] = C[i - 1][j - 1] + 
                          C[i - 1][j]; 
        } 
    }
    return C[n][k]; 
} 


int main()
{
	sup;
    
    ll h,n;
    cin>>h>>n;
    ll sum=0;
    fab(i,0,n)
    {
        in(a);
        sum+=a;
    }
    if(sum>=h) cout<<"Yes"<<endl;
    else pr("No");
    return 0;
}

Measured memory_bytes: 256
N, Y = gets.split.map(&:to_i)

(0..(Y / 10000)).each do |i|
  (0..((Y - 10000 * i) / 5000)).each do |j|
    if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y
      puts "#{i} #{j} #{N - i - j}"; exit
    end
  end
end

puts '-1 -1 -1'

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

int mx[4]={0, 1, 0, -1}, my[4]={1, 0, -1, 0};

signed main() {
    int h, w;
    cin >> h >> w;
    V(V(char)) bw(h, V(char)(w));
    int sum = 0;
    rep(i, h) rep(j, w) {
        cin >> bw[i][j];
        if(bw[i][j]=='.') sum++;
    }

    vvi dist(h, vi(w, 1e5));
    queue<P> q;
    q.push(P(0, 0));
    dist[0][0] = 0;
    while(!q.empty()) {
        P n = q.front();
        q.pop();
        rep(i, 4) {
            int ny=n.fi+my[i], nx=n.se+mx[i];
            if(ny>=0 && ny<h && nx>=0 && nx<w) {
                if(dist[ny][nx]==1e5 && bw[ny][nx]=='.') {
                    dist[ny][nx] = dist[n.fi][n.se]+1;
                    q.push(P(ny, nx));
                }
            }
        }
    }
    
    if(dist[h-1][w-1]!=1e5) cout << sum-1-dist[h-1][w-1] << endl;
    else cout << -1 << endl;

    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    int tot = 0;

    rep(i, h) {
        cin >> a[i];
        rep(j, w){
            if(a[i][j] == '#') tot ++;
        }
    }
    
    if(tot == h + w - 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl; 
    
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

using namespace std;

long long dp[150][234567];

int main(){
 int N, W; cin >> N >> W;
 int w[N+2], v[N+2];
 for(int i=1; i<=N; ++i) cin >> w[i] >> v[i];
 for(int i=1; i<=N; ++i){
  for(int wt=0; wt<=W; ++wt){
   if(wt < w[i])
     dp[i][wt] = dp[i-1][wt];
   else
     dp[i][wt] = max(dp[i-1][wt], dp[i-1][wt-w[i]] + v[i]); 
  }
 }
 cout << dp[N][W] << "\n";
 return 0;
}


Measured memory_bytes: 182784
h,n=map(int,input().split())
AB=[]
A=[]
for i in range(n):
    a,b=map(int,input().split())
    AB.append((a,b))
    A.append(a)
maA=max(A)

dp=[float("inf")]*(h+maA+1)
dp[0]=0

for i in range(h):
    for a,b in AB:
        dp[i+a]=min(dp[i+a],dp[i]+b)
print(min(dp[h:]))


Measured memory_bytes: 42332