akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int dfs(const vector<vector<int>>& losers, int winner) {
    vector<int> depth;
    for (auto& l : losers[winner]) {
        depth.push_back(dfs(losers, l));
    }
    sort(all(depth));
    reverse(all(depth));
    int res = 0;
    rep(i, 0, depth.size()) {
        chmax(res, depth[i] + i + 1);
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N - 1);
    for (auto& a : A) {
        cin >> a;
        --a;
    }
    vector<vector<int>> losers(N);
    rep(i, 0, N - 1) {
        losers[A[i]].push_back(i + 1);
    }
    cout << dfs(losers, 0) << endl;
    return 0;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
 
#define    pi          acos(-1) 
#define    all(x)      (x).begin(),(x).end()
#define    fill(x,y)   memset(x, y, sizeof(x))
#define    gcd(x,y)    __gcd(x,y)
#define    lcm(x,y)    (x*(y/gcd(x,y))
#define    trace(x)    cout << #x << " = " << x << endl
#define    bug         cout << "Bug check" << endl
#define    endl        '\n'
 
using namespace std;
 
int main(){
	//freopen("in.txt","r", stdin);
	//freopen("out.txt","w", stdout);
 
	//ios::sync_with_stdio(0);
	//cin.tie(0);

	double n,b; cin >> n >> b;
	cout << floor((double)log(n)/log(b))+1 << endl;
	return 0;
}

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

int main(){
    using namespace std;
    long A, B;
    unsigned long V, W, T;
    cin >> A >> V >> B >> W >> T;
    if(W > V)return 0 & puts("NO");
    puts(abs(A - B) <= T * (V - W) ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

const int size=10e5+2;
int sizeC;
int arr[size];
int state[size];

int main(){

  scanf("%d",&sizeC);
  for(int i=0;i<sizeC;i++)
    scanf("%d",&arr[i]);

  state[0]=0;
  state[1]=abs(arr[0]-arr[1]);

  for(int i=2;i<sizeC;i++)
    state[i]=min(state[i-1]+abs(arr[i]-arr[i-1]),state[i-2]+abs(arr[i-2]-arr[i]));

  cout<<state[sizeC-1]<<endl;

  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define  ll  long long
#define  pii pair<int,int>
#define  pll pair<ll , ll>
#define  debug cout << "this far" << endl;
#define  For(i, n) for(int i = 0; i < (n); ++i)
#define  lsb(x) ((x) & (-x))
#define  PI acos(-1)
#define  line cout << endl;
#define  getbit(n, i) (((n) & (1LL << (i))) != 0)
#define  resetbit(n, i) ((n) & (~(1LL << (i))))
#define  setbit(n, i) ((n) | (1LL << (i)))
#define  togglebit(n, i) ((n) ^ (1LL << (i)))
#define  gap " "
#define  ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
const int N = 5e5 + 4;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;
    cin >> k;
    int cnt = 1;
    int cr = 7;
    while (cnt < 1e7) {
        if (cr % k == 0) break;
        else {
            cr = (cr * 10 + 7) % k;
            ++cnt;
        }
    }
    if (cnt == 1e7) cout << "-1";
    else cout << cnt;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll> arr(n);
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    ll ans = 0;
    for(int i = 1; i < n; ++i)
        ans += min(a * (arr[i]-arr[i-1]),b);
    cout << ans << '\n';
}


Measured memory_bytes: 1024
import collections
N = int(input())

def make_divisors(n):
    divisors_set=set()
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            divisors_set.add(i)
            divisors_set.add(n//i)
    divisors_list=list(divisors_set)
    divisors_list.sort()
    return divisors_list

def make_primes(n):
    primes_list=[]
    while n % 2 == 0:
        primes_list.append(2)
        n = n//2
    f = 3
    while f * f <= n:
        if n % f == 0:
            primes_list.append(f)
            n = n//f
        else:
            f += 2
    if n != 1:
        primes_list.append(n)
    return primes_list

def cnt75(d):
    ans = 0
    for key in d.keys():
        if d[key] >= 75-1:
            ans += 1
    return ans

def cnt25_3(d):
    ans25 = 0
    ans3 = 0
    for key in d.keys():
        if d[key] >= 25-1:
            ans25 += 1
        elif d[key] >= 3-1:
            ans3 += 1
    #return ans25*(ans25-1+ans3)-(ans25*(ans25-1) )//2
    return ans25 * (ans25+ans3-1)

def cnt15_5(d):
    ans15 = 0
    ans5 = 0
    for key in d.keys():
        if d[key] >= 15-1:
            ans15 += 1
        elif d[key] >= 5-1:
            ans5 += 1
    #return ans15*(ans15-1+ans5)-(ans15*(ans15-1) )//2
    return ans15*(ans15+ans5-1)


def frac(n):
    if n == 1:
        return 1
    else:
        return n*frac(n-1)

def cnt5_5_3(d):
    ans5 = 0
    ans3 = 0
    for key in d.keys():
        if d[key] >= 5-1:
            ans5 += 1
        elif d[key] >= 3-1:
            ans3 += 1
    #return (ans5*(ans5-1))/2*ans3 + frac(ans5)//frac(2)//frac(ans5-2)
    return ans5*(ans5-1)*(ans5+ans3-2)//2 


#print( len(make_divisors(1*2*3*4*5*6*7*8*9*10) )) 
#cnt=0
#print(make_primes(6))
primes=[]
for i in range(1,N+1):
    #cnt+=len(make_primes(i))
    primes.extend(make_primes(i))
    #print(i,len(make_primes(i)))
    #print(make_primes(i))
#print(cnt)
#print(len(primes))
c=collections.Counter(primes)
#print(c)
print(cnt75(c)+cnt25_3(c)+cnt15_5(c)+cnt5_5_3(c) )
#print(2**8 * 3**4 * 5**2 * 7 )



Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int *vec;
int sinal(int a){
	if(a < 0) return -1;
	return 1;
}
int a = 0xEDU;
long long int min(long long a, long long b){return a > b ? b: a;}
int main(){
	int n, sumpos = 0, sumneg = 0;//, read;
	long long int altops = 0, altneg = 0;
	scanf("%d", &n);
	vec = malloc(sizeof(int) * n*2);
	for(int i = 0; i < n; ++i){
		scanf("%d", &vec[i]);
	}
	for(int i = 0; i < n; ++i){
		int sinalobjetivo = sinal(-(i%2));
		int toalt = -sumpos  -vec[i] +sinalobjetivo;
		if(sumpos + vec[i] != 0){
			if(sinal(sumpos + vec[i]) == sinalobjetivo){
				sumpos += vec[i];
				continue;
			}
		}else{
			toalt = sinalobjetivo;
		}
		sumpos += toalt + vec[i];
		altops += abs(toalt);
		//printf("p %d, %d\n", i, toalt);
	}
	for(int i = 0; i < n; ++i){
		int sinalobjetivo = sinal(-((i+1)%2));
		int toalt = -sumneg  -vec[i] +sinalobjetivo;
		if(sumneg + vec[i] != 0){
			if(sinal(sumneg +vec[i]) == sinalobjetivo){
				sumneg += vec[i];
				continue;
			}
		}else{
			toalt = sinalobjetivo;
		}
		sumneg += toalt + vec[i];
		altneg += abs(toalt);
		//printf("i %d, %d\n", i, toalt);

	}
		//printf("p %d %d n %d %d");
	printf("%lld\n", min(altops, altneg));
}

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

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

typedef long long lint;

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  char a[H][W];
  bool hf[H];
  REP(i,H)hf[i]=false;
  bool wf[W];
  REP(i,W)wf[i]=false;
  REP(i,H)REP(j,W){
    cin>>a[i][j];
    if(a[i][j]=='#'){
      hf[i]=true;
      wf[j]=true;
    }
  }
  REP(i,H){
    if(!hf[i])continue;
    REP(j,W){
      if(!wf[j])continue;
      cout<<a[i][j];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000000000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n;
    cin>>n;
    ll a[n+3];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll b[n+3];
    vll ans;
    for(ll i=n;i>0;i--)
    {
        ll q=a[i];
        for(ll j=(i*2);j<=n;j+=i)
        {
            q^=b[j];
        }
        b[i]=q;
        if(b[i]==1)
            ans.pb(i);
    }
    cout<<ans.size()<<endl;
    for(auto i:ans)
        cout<<i<<endl;
}


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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
#define INF (1e9)

typedef pair<int,int> P;
typedef vector<int> vi;

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

// 最小公倍数
int lcm(int a, int b) {return a*b/gcd(a,b);}

int a,b,c,d;

signed main() {
  cin>>a>>b>>c>>d;

  int e=b/c;
  int f=b/d;
  int g=b/lcm(c,d);
  int ans1=b-e-f+g;
  e=(a-1)/c;
  f=(a-1)/d;
  g=(a-1)/lcm(c,d);
  int ans2=a-1-e-f+g;
  cout<<ans1-ans2<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    
    int[] ans = new int[N-1];
    int min = 10000;
    for(int i =1;i<N;i++){
      for (int j = i+1;j<N+1;j++){
        min = Math.min((Math.abs(j-i)),(Math.abs(X-i)+1+Math.abs(Y-j)));
       // min = Math.min(min,Math.abs(Y-i)+1+Math.abs(X-j));
        ans[min-1]++;
      }
    }
    for(int k:ans){
      System.out.println(k);
    }
    
    
  }    
}



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


#define ll long long
#define MOD 1000000007



int main(){
    int s,w;
    cin>>s>>w;
    
    
    if(s>w){
        cout<<"safe"<<endl;
    }else{
        cout<<"unsafe"<<endl;
    }
}


Measured memory_bytes: 3560
for i in range(input()):
  I = 0
  H = 0
  o = 0
  while 1: 
          s = raw_input()
          if s=="OUT":
            o+=1
            if o == 3:
              o=0
              break
          elif s=="HIT":
            I+=1
            if I == 4:
              I-=1
              H +=1
          elif s=="HOMERUN":
            H+=I+1
            I=0
  print H

Measured memory_bytes: 4220
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, m;
	cin >> n >> m;
	n--; m--;
	cout << n * m << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a[5],i,flg,j;
	while(1){
		int g=0,t=0,p=0;
		int mflg,kflg;
		int aaflg;
		flg=0;
		for(i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==0) break;
			if(a[i]==1) g=1;
			else if(a[i]==2) t=1;
			else p=1;
		}
		if(a[0]==0) break;
		aaflg=0;
		for(i=1;i<5;i++) {
			if(a[0]!=a[i]) aaflg=1;
		}
		if(g==1 && t==1 && p==1 || aaflg==0) {
			for(i=0;i<5;i++) cout<<"3"<<endl;
		}
		else {
			for(i=0;i<5;i++){
				mflg=0;
				kflg=0;
				for(j=0;j<5;j++){
					if(a[i]==a[j]) ;
					else if(a[i]==1 && a[j]==3 || a[i]==2 && a[j]==1 || a[i]==3 && a[j]==2) mflg=1;
					else kflg=1;
				}
				if(mflg==1) cout<<"2"<<endl;
				else cout<<"1"<<endl;
			}
		}
	}	
	return 0;
}

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

int main(){
    const int COUNT = 5;
    uint64_t n;
    cin >> n;

    vector<uint64_t> max_capacity(COUNT);
    uint64_t min_capacity = UINT64_MAX, min_index = 0;
    for (auto i = 0; i < COUNT; i++) {
        cin >> max_capacity[i];
        if(min_capacity > max_capacity[i]){
            min_capacity = max_capacity[i];
            min_index = i;
        }
    }
//    cout << n << " " << min_capacity << " " << min_index << endl;

    cout << (n / min_capacity + ((n % min_capacity) ? 1 : 0) + (COUNT - 1)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

    int n, x, y, z, i, k, a[101] = {0}, b[101] = {0}, c[101] = {0};
    int h = 0;

    scanf("%d", &n);

    scanf("%d", &x);

    for(i = 0; i < x; i++) {
       scanf("%d", &k);
       a[k - 1] = 1;
    }

    scanf("%d", &y);

    for(i = 0; i < y; i++) {
       scanf("%d", &k);
       b[k - 1] = 1;
    }

    scanf("%d", &z);

    for(i = 0; i < z; i++) {
       scanf("%d", &k);
       c[k - 1] = 1;
    }

    for(i = 0; i < n; i++) {
       if(a[i] != 1 && c[i] == 1)
           h++;
       if(a[i] == 1 && b[i] == 1 && c[i] == 1)
           h++;
    }

    printf("%d\n", h);

    return 0;
}

Measured memory_bytes: 604
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
using namespace std;

int main(void) {
    int n;
    cin >> n;
    string s;
    for (int i = 0; i < n; i++)
    {   
        // char s;
        cin >> s;
        if (s == "Y") {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

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

int let[26];

int main()
{
    string a;
    bool ans = true;
    cin >> a;
    for (int i = 0; i < a.length(); i++)
    {
        let[a[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++)
    {
        if (let[i] & 1) 
        {
            ans = false;
            break;
        }
    }
    cout << (ans? "Yes": "No") << endl;
    return 0;
}


Measured memory_bytes: 256
heros = int(input())
monsters = list(map(int, input().split()))
capacity = list(map(int, input().split()))
killed = 0
for i in range(heros):
    left = min(monsters[i], capacity[i])
    killed += left
    capacity[i] -= left
    if capacity[i] > 0:
        left2 = min(monsters[i+1], capacity[i])
        killed += left2
        monsters[i+1] -= left2
print(killed)

Measured memory_bytes: 82020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> ans(n+1);
	for (int i = 0; i <= n; i++) {
		ans[i] = 0;
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i];
		ans[a[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/

int main() {
  int n,manager;
  cin >> n;
  vi v(n);
  rep(i,n-1){
    cin >> manager;
    v.at(manager-1)++;
  }
  couts(v);
  return 0;
}


Measured memory_bytes: 3972
'use strict'

function main(input) {

    let x = +input

    let max = 1
    let ans = 0

    for (let p = 2; p <= x; p++) {
        for (let i = 1; i <= x; i++) {

            ans = Math.pow(i, p)
            if (ans <= x) max = Math.max(max, ans)

        }

    }
    console.log(max)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    if(n%2==0){
        cout << (n/2)*(n/2);
    }
    else{
        cout << (n/2)*(1+(n/2));
    }
    
    
    
    return 0;
}

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

using ll = long long;

vector<int> toVec(string x) {
    vector<int> v;
    int n = x.size();
    for (auto c : x) {
        v.push_back(c - '0');
    }
    return v;
}

ll generar(int prof, int n, bool tight, int k, const vector<int>& digitos, vector<vector<vector<int>>>& dp) {
    if (prof == n) {
        // Acabé de generar un número
        return k == 0;
    }
    if (k < 0) {
        return 0;
    }
    if (dp[prof][k][tight] != -1) return dp[prof][k][tight];
    // tight: representa si cuento hasta 9 o solo hasta el dígito actual
    // true si el número está "ajustado" (solo llega hasta el dígito actual)
    int limSup = tight ? digitos[prof] : 9;
    ll ans = 0;
    for (int d = 0; d <= limSup; d++) {
        ans += generar(prof + 1, n, tight && (d == digitos[prof]), d > 0 ? k - 1: k, digitos, dp);
    }
    return dp[prof][k][tight] = ans;
}

int main() {
    string num;
    int k;
    cin >> num >> k;
    vector<int> digitos = toVec(num);
    vector<vector<vector<int>>> dp(digitos.size() + 1, vector<vector<int>>(k + 1, vector<int>(2, -1)));
    ll ans = generar(0, digitos.size(), true, k, digitos, dp);
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
 
using namespace std;

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  cout << (abs(a - x) < abs(b - x) ? "A" : "B") << endl;
}

Measured memory_bytes: 3548
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N;
  cin>>N;
  string S[N];
  bool CAN=false;
  REP(i,N){
    cin>>S[i];
    if(S[i]=="Y") CAN=true;
  }
  
  if(CAN) cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph_c = vector<vector<ll>>;
struct Z{
  ll y;
  ll x;
  ll depth;
};

ll H,W,K,y,x,depth,oo=1e12,xs,ys,xg,yg;
vector<ll> y_vec={1,0,-1,0};
vector<ll> x_vec={0,1,0,-1};
Graph_c A,B;
queue<Z> q;

ll bfs(){
  ll ans=oo;
  while(!q.empty()){
    Z now=q.front(); q.pop();
    y=now.y, x=now.x, depth=now.depth;
    if(y==yg && x==xg){
      ans=min(ans,depth);
      return ans;
    }
    for(ll i=0; i<4; i++){
      for(ll k=1; k<=K; k++){
        Z next={y+y_vec[i]*k, x+x_vec[i]*k, depth+1};
//cout<<"ny:"<<next.y<<" nx:"<<next.x<<endl;        
        if(next.y<=0 || next.y>H || next.x<=0 || next.x>W ||A[next.y][next.x]==-1) break;
        if(A[next.y][next.x]<next.depth) break;
        if(A[next.y][next.x]==next.depth) continue;
        A[next.y][next.x]=next.depth;
        q.push(next);
//cout<<" d:"<<next.depth<<endl;          
      }
    }
  }
  return oo;
}

int main(){
  cin>>H>>W>>K;
  cin>>ys>>xs>>yg>>xg;
  A.assign(H+2, vector<ll>(W+2,-1));
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      char a; cin>>a;
      if(a=='@') continue;
      A[i][j]=oo;
    }
  }
  Z start={ys,xs,0};
  A[ys][xs]=0;
  q.emplace(start);
  ll ans=bfs();
  if(ans==oo) ans=-1;
  cout<<ans<<endl;
}


Measured memory_bytes: 34360
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int s;
  cin >> s;
  map<int, int> mp;
  mp[s] = 1;
  int a = s;
  FORe(i, 2, 1e6){
    int b = (a%2) ? 3*a+1 : a/2;
    a = b;
    if(mp[b] == 0) mp[b] = i;
    else{
      cout << i << endl;
      return 0;
    } 
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    bool ans=false;
    ll h,n;
    cin>>h>>n;
    ll num=0;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        num+=a;
        if(num>=h){
            ans=true;
            break;
        }
    }

    {
        if(ans)cout <<"Yes"<<endl;
        else cout <<"No"<<endl;
    }


    return 0;

}

Measured memory_bytes: 256
/* ex4_3
   kento_titech*/
#include<stdio.h>
int snow_height(int h_west,int h_east);
int main(void){
    int a,b;//a,bはそれぞれ西と東に見える高さ
    scanf("%d %d",&a,&b);
    printf("%d\n",snow_height(a,b));//積雪を求める関数

    return 0;
}
int snow_height(int h_west,int h_east){//h_west,h_eastはそれぞれ西と東に見える部分の高さ
        int height;
        height=(h_east-h_west)*(h_east-h_west+1)/2-h_east;//1からh_east-h_westまでの総和が東側の塔の高さ。
                                    //積雪heightはそこからh_eastを引いたもの.
        return(height);

    }

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K;
  cin >> K;
  vector<int64_t> A(K);
  for (int i = 0; i < K; i++) {
    cin >> A[i];
  }
  reverse(A.begin(), A.end());
  int64_t lo = 2, hi = 2;
  for (int i = 0; i < K; i++) {
    if (lo % A[i] != 0 && lo / A[i] == hi / A[i]) {
      cout << -1 << '\n';
      return 0;
    }
    lo = (lo + A[i] - 1) / A[i] * A[i];
    hi = hi / A[i] * A[i] + A[i] - 1;
  }
  cout << lo << ' ' << hi << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(s.size()<=n){
    cout<<s<<"\n";
  }
  else{
    for(int i=0;i<n;i++){
      cout<<s[i];
    }
    cout<<"...\n";
  }
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

struct segtree{
private:
  vector<ll> node,lazy;
  ll siz;
public:
  segtree(int n){
    siz=1;
    while(siz<=n) siz*=2;
    node.resize(siz*2,0);
    lazy.resize(siz*2,0);
  }
  void eval(ll pos){
    node[pos]+=lazy[pos];
    if(pos<siz-1) {
      lazy[pos*2+1]+=(lazy[pos]/2);
      lazy[pos*2+2]+=(lazy[pos]/2);
    }
    lazy[pos]=0;
  }
  void add_q(ll a,ll b,ll x,ll l,ll r,ll pos){
    eval(pos);
    if(b<=l||r<=a) return;
    if(a<=l&&r<=b){
      lazy[pos]+=(x*(r-l));
      eval(pos);
      return;
    }
    ll mid=(l+r)/2;
    add_q(a,b,x,l,mid,pos*2+1);
    add_q(a,b,x,mid,r,pos*2+2);
    node[pos]=node[pos*2+1]+node[pos*2+2];
  }
  ll sum_q(ll a,ll b,ll l,ll r,ll pos){
    if(b<=l||r<=a) return 0;
    eval(pos);
    if(a<=l&&r<=b){
      return node[pos];
    }
    ll mid=(l+r)/2;
    return (sum_q(a,b,l,mid,pos*2+1)+sum_q(a,b,mid,r,pos*2+2));
  }
  void add(ll a,ll b,ll x){
    add_q(a,b,x,0,siz,0);
  }
  ll sum(ll a,ll b){
    return sum_q(a,b,0,siz,0);
  }
  void debug(){
    cout<<"Node:"<<endl;
    ll t=2;
    for(int i=2;i<=siz*2;i++) {
      cout<<node[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
    cout<<"Lazy:"<<endl;
    t=2;
    for(int i=2;i<=siz*2;i++){
      cout<<lazy[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
  }
};
int main(){
  int n,q;
  cin>>n>>q;
  segtree seg=segtree(n+3);
  for(int i=0;i<q;i++){
    int f;
    cin>>f;
    if(f==0){
      int s,t,x;
      cin>>s>>t>>x;
      seg.add(s,t+1,x);
    }
    else{
      int s,t;
      cin>>s>>t;
      cout<<seg.sum(s,t+1)<<endl;
    }
  }
}



Measured memory_bytes: 7060
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
X=input()
def popcount(x):
  x=x-((x>>1)&0x5555555555555555)
  x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333)

  x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f
  x=x+(x>>8)
  x=x+(x>>16)
  x=x+(x>>32)
  return x&0x0000007f

F=[0]*(n+1)
F[1]=1
for i in range(2,n+1):
  F[i]=1+F[i%popcount(i)]

ct=X.count("1")
if ct==0:
  for _ in range(n):
    print(1)
elif ct==1:
  for i in range(n):
    if X[i]=="1":
      cur=i
      break
  for i in range(n):
    if i==cur:
      print(0)
    else:
      if i==n-1 or cur==n-1:
        print(2)
      else:
        print(1)

else:
  a,b=0,0
  for i in range(n):
    if X[n-1-i]=="1":
      a=(a+pow(2,i,ct-1))%(ct-1)
      b=(b+pow(2,i,ct+1))%(ct+1)
  for i in range(n):
    if X[i]=="0":
      print(F[(b+pow(2,n-1-i,ct+1))%(ct+1)]+1)
    else:
      print(F[(a-pow(2,n-1-i,ct-1))%(ct-1)]+1)

Measured memory_bytes: 75480
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N), c(M), d(M);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < M; i++) cin >> c[i] >> d[i];
    for (int i = 0; i < N; i++) {
        int m = 4e8 + 1, ans = 0;
        for (int j = 0; j < M; j++) {
            int dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dis < m) {
                m = dis;
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
 
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 998244353;
const ll N = 2e4 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, s);
	readarr(a, n);
	
	int dp[3001] = {}, ans = 0;
	FOR (i, 1, n)
	{
	    if (s - a[i] > 0) ans = (ans + dp[s - a[i]] * (n - i + 1)) % mod;
	    else if (s == a[i]) ans = (ans + i*(n - i + 1)) % mod;
	    
	    FORD (j, s, a[i])
	        dp[j] = (dp[j] + dp[j - a[i]]) % mod;
	        
	    dp[a[i]] = (dp[a[i]] + i) % mod;
	}
	
	cout << ans;
}



















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  vi countw(N+1);
  rep(i,N) {
    countw[i+1]=countw[i];
    if(S[i]=='.') countw[i+1]++;
  }
  int ans=N;
  rep(i,N+1)
    ans=min(ans,i-2*countw[i]+countw[N]);
  
  cout << ans << endl;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int a,b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1)<< endl;
    return 0;
}

Measured memory_bytes: 256
s = list(input())
k = int(input())
num = len(s)
ans = 0

if len(set(s))==1:
    print(num*k//2)
else:
    now = s[0]
    cnt = 1
    fstflag = True
    for i in range(1,num):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            ans += (cnt//2)*k
            if fstflag:
                fstflag = False
                begin = cnt
            cnt = 1
    ans += (cnt//2)*k
    if fstflag:
        fstflag = False
        begin = cnt
    if s[0] == s[-1]:
        end = cnt
        ans -= (begin//2)*(k-1)
        ans -= (end//2)*(k-1)
        ans += ((begin+end)//2)*(k-1)
    print(ans)

Measured memory_bytes: 3064
def make_table
  i = 0
  j = 0
  table = Array.new(6)
  table.map!{Array.new(5)}

  "a".upto("z") do |c|
    table[i][j] = c
    j += 1
    i += 1 if j == 5
    j = 0  if j == 5
  end
  table[5][1] = '.'
  table[5][2] = '?'
  table[5][3] = '!'
  table[5][4] = ' '

  table
end

$table = make_table

readlines.each do |input|
  message = input.chomp

  if message.size.odd?
    puts "NA"
    next
  end

  message_int = []
  message.chars.map{|x| x.to_i-1}.each_slice(2){ |x| message_int << x }
  if message_int.map{ |cons| 0 <= cons.first && cons.first <= 5 && 0 <= cons.last && cons.last <= 4 }.include?(false)
    puts "NA"
    next
  end

  message_int.each { |set| print $table[set.first][set.last] }
  puts ""
end

Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

struct state
{
    int x,y,z,r;
    ll l;
};

struct cor
{
    int x,y,z;
};

bool collide(cor& c1,cor& c2,state& st)
{
    double a = (c2.x-c1.x)*(c2.x-c1.x) + (c2.y-c1.y)*(c2.y-c1.y) + (c2.z-c1.z)*(c2.z-c1.z);
    double b = (c1.x-st.x)*(c2.x-c1.x) + (c1.y-st.y)*(c2.y-c1.y) + (c1.z-st.z)*(c2.z-c1.z);
    double c = (c1.x-st.x)*(c1.x-st.x) + (c1.y-st.y)*(c1.y-st.y) + (c1.z-st.z)*(c1.z-st.z) - st.r*st.r;
    b = -b;
    if(b >= -EPS && b <= a+EPS && b*b - a*c >= -EPS){
        return true;
    }else{
        return false;
    }
}

int main()
{
    int n,q;
    cin >> n >> q;
    vector<state> vec(n);
    rep(i,n){
        int x,y,z,r;
        ll l;
        cin >> x >> y >> z >> r >> l;
        vec[i] = (state){x,y,z,r,l};
    }
    rep(i,q){
        int a,b,c,d,e,f;
        cin >> a >> b >> c >> d >> e >> f;
        cor red = (cor){a,b,c};
        cor blue = (cor){d,e,f};
        ll ans = 0;
        rep(j,n){
            if(collide(red,blue,vec[j])){
                ans += vec[j].l;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 3104
package main

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

var ReadString func() string

func init() {
	ReadString = newReadString()
}

/*------ scan ------*/

func newReadString() func() string {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), 2048)
	sc.Split(bufio.ScanWords)
	return func() string {
		if !sc.Scan() {
			panic("scanできなかった")
		}
		return sc.Text()
	}
}

func ReadInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		fmt.Println("scanできなかった")
		panic(err.Error())
	}
	return int64(i)
}

func ReadInt() int {
	i := ReadInt64()
	return int(i)
}

func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*------ number util ------*/

func GetIntAbs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func Atoi(a string) int {
	i, err := strconv.Atoi(a)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func FindMin(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	min := arr[0]
	for _, v := range arr {
		if v < min {
			min = v
		}
	}
	return min
}

func FindMax(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	max := arr[0]
	for _, v := range arr {
		if v > max {
			max = v
		}
	}
	return max
}


func main() {
	a := ReadInt()
	b := ReadInt()
  c := ReadInt()
  arr := []int{a + b, a + c, b + c}
  fmt.Println(FindMin(arr))
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<ll >    vecll;
typedef vector<string > vecstr;
int main()
{
  ll h;
  cin >> h;
  ll a = log2(h);
  vecll dp(a + 1);
  dp[0] = 1;
  REP(i,a + 1){
    if(i == 0) continue;
    dp[i] = 2*dp[i - 1] + 1;
  }
  cout << dp[a] << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define res register int
using namespace std;

inline long long read()
{
	char ch=getchar();
	long long x=0;int f=0;
	while(ch<'0'||ch>'9')
	{
		f|=ch=='-';
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f?-x:x;
}
inline long long gcd(long long a,long long b)
{
	return b==0?a:gcd(b,a%b);
}
inline long long f(long long a,long long b)
{
	long long tmp=gcd(a,b);
	if(tmp==1)
	return max(a,b)*3-3;
	else
	return f(a/tmp,b/tmp)*tmp;
}
int main()
{
	long long a=read(),b=read();
	printf("%lld\n",f(a,b));
}

Measured memory_bytes: 256
#include<iostream>
int main(){
int N;//人数
  int A,B;//A:電車,B:タクシー
  
  std::cin	>>N	>>A	>>B;
  
  if(N*A<=B)
    std::cout <<N*A;
  else
    std::cout <<B;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

  VAR(int, n);
  VEC(int, t, n);
  VAR(int, m);
  REP(i, m) {
    VAR(int, p, x);
    int ans = 0;
    REP(i, n) {
      if (i == p - 1) ans += x;
      else ans += t[i];
    }
    OUT(ans)BR;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int k;
  cin >> k;
  int ans = 0;
  if (k%2==0) ans = (k/2)*(k/2);
  else ans = (k-1)/2 * ((k-1)/2+1);

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""Untitled45.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1chuGB-wcuZOks_CainjNbE3q0Mhq_H-D
"""

n = int(input())
if n <= 1000:
  print(int(1000-n))
elif n <= 2000:
  print(int(2000-n))
elif n <= 3000:
  print(int(3000-n))
elif n <= 4000:
  print(4000-n)
elif n <= 5000:
  print(int(5000-n))
elif n <= 6000:
  print(int(6000-n))
elif n <= 7000:
  print(int(7000-n))
elif n <= 8000:
  print(int(8000-n))
elif n <= 9000:
  print(int(9000-n))
elif n <= 10000:
  print(int(10000-n))

Measured memory_bytes: 9204
from collections import Counter
import sys
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int,input().split()))

b = Counter(a)

ans = 1
if n % 2 == 0:
    for i in range(1,n,2):
        if b[i] == 2:
            ans = ans * 2 % MOD
        else:
            print(0)
            sys.exit()
            
else:
    if b[0] == 1:
        for i in range(2,n,2):
            if b[i] == 2:
                ans = ans * 2 % MOD
            else:
                print(0)
                sys.exit()
    else:
        print(0)
        sys.exit()
        
print(ans)

Measured memory_bytes: 55532
n = int(input())
s = input()
w = [0] + []
e = [] + [0]
w_cnt = 0
e_cnt = 0
for i in range(n):
    if s[i] == "W":
        w_cnt += 1
    if s[n - i - 1] == "E":
        e_cnt += 1
    w.append(w_cnt)
    e.append(e_cnt)
e = e[::-1]
ans = 10 ** 9
for i in range(n):
    ans = min(ans, w[i]+e[i+1])
print(ans)


Measured memory_bytes: 19988
#include <stdio.h>

int main() {
  char s[101];
  long long int k;
  int i;
  int tmp;

  scanf("%s", s);
  scanf("%lld", &k);

  for (i = 0; i < 100; i++) {
    tmp = s[i] - '0';
    if (tmp > 1) {
      printf("%d\n", tmp);
      break;
    } else if (i + 1 == k) {
      printf("%d\n", tmp);
      break;
    }
  }

  return 0;
}


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

int main() {
  vector<int> N(4);
  bool B1 = false, B9 = false, B7 = false, B4 = false;
  for (int i = 0; i < 4; i++) {
    cin >> N.at(i);
    if (N.at(i) == 1) B1 = true;
    if (N.at(i) == 9) B9 = true;
    if (N.at(i) == 7) B7 = true;
    if (N.at(i) == 4) B4 = true;
  }

  if (B1 && B9 && B7 && B4) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
K, A, B = map(int, input().split())


if B - A <= 2:
    print(K + 1)
else:
    # 最初の交換まで叩く
    K -= (A - 1)

    # 1円->B枚に
    K -= 2
    ans = B

    # できるだけ交換
    ans += (B - A) * (K // 2)
    K %= 2

    # 最後に１回余れば叩く
    ans += K % 2

    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <math.h>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	cout << k * (int)pow(k - 1, n - 1) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e4+10;

int d[N*2];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k, q; cin >> k >> q;
  for (int i = 0; i < k; i++) {
    cin >> d[i];
  }
  int nk = k;
  while (nk < N) nk += k;
  for (int i = k; i < nk; i++) {
    d[i] = d[i%k];
  }
  k = nk;
  while (q--) {
    int n, x, m; cin >> n >> x >> m;
    n--;
    x %= m;
    ll tot = 0;
    int zcnt = 0;
    for (int i = 0; i < k; i++) {
      tot += (d[i] % m);
      zcnt += (d[i] % m == 0);
    }
    int num_cyc = n / k, rem_cyc = n % k;
    ll ans = num_cyc * k - (x + tot * num_cyc) / m - num_cyc * zcnt;
    //cout << ans << nl;
    x = (x + tot * num_cyc) % m;
    for (int i = 0; i < rem_cyc; i++) {
      int nx = (x + d[i]) % m;
      //cerr << x << " " << nx << nl;
      ans += (x < nx);
      x = nx;
    }
    cout << ans << nl;
  }
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var N = ReadLine();
            var dic = new Dictionary<int, bool>();
            foreach (var A in ReadLine().Split().Select(int.Parse))
            {
                bool res;
                dic.TryGetValue(A, out res);
                if (res)
                {
                    WriteLine("NO");
                    return;
                }
                else dic.Add(A, true);
            }
            WriteLine("YES");
        }
    }
}


Measured memory_bytes: 34256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

struct BIT
{
    VI bit;

    BIT(int n) : bit(n + 1)
    {
        add(1, 1);
    }

    void add(int pos, int val)
    {
        for (int i = pos; i < SZ(bit); i += i & -i)
            bit[i] += val;
    }

    LL sum(int pos)
    {
        LL res = 0;
        for (int i = pos; i > 0; i -= i & -i)
            res += bit[i];
        return res;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    BIT right(n);
    BIT down(n);
    LL ans = (LL)(n - 2) * (n - 2);
    int mnD = n;
    int mnR = n;
    FOR(i, 0, q)
    {
        int t, x;
        cin >> t >> x;
        if (t == 1)
        {
            int cnt = down.sum(x);
            ans -= (n - 1) - cnt;
            if (x < mnD)
            {
                int old = right.sum(1);
                int dif = (n + 1 - x) - old;
                int r = n - cnt;
                right.add(1, dif);
                right.add(r + 1, -dif);
                mnD = x;
            }
        }
        else
        {
            int cnt = right.sum(x);
            ans -= (n - 1) - cnt;
            if (x < mnR)
            {            
                int old = down.sum(1);
                int dif = (n + 1 - x) - old;
                int r = n - cnt;
                down.add(1, dif);
                down.add(r + 1, -dif);
                mnR = x;
            }
        }
    }
    cout << ans;
    return 0;
}

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

int main() {
	// your code goes here
	long long s,t,a,b,c,d,i,j,l,r,m;
	cin >> s >> t  >> a >> c >> b >> d;
	if(s*a+t*c==s*b+t*d){
		cout << "infinity" << endl;
		return 0;
	}
	if(a<b){
		swap(a,b); swap(c,d);
	}
	if(a>b&&c>d){
		cout << "0" << endl;
		return 0;
	}
	l=s*(a-b); r=t*(c-d);
	if(l+r>0){
		cout << "0" << endl;
		return 0;
	}
	r=-r;
	if(l%(r-l)==0) m=l/(r-l);
	else m=floor(l/(r-l));
	if(l%(r-l)==0) cout << 2*m << endl;
	else cout << 2*m+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=5e2+10;
struct node
{
    int a,b,c,d;
}t[N];
int n,m,q,A[N];
bool cmp(node a,node b)
{
    return a.d>b.d;
}
int ans;
void dfs(int id,int now)
{
    if(id>n){
        int sum=0;
        //rep(i,1,n) printf("%d ",A[i]);
        //puts("");
        rep(i,1,q){
            if(A[t[i].b]-A[t[i].a]==t[i].c) sum+=t[i].d;
        }
        //printf("sum:%d\n",sum);
        ans=max(ans,sum);
        return ;
    }
    for(int i=now;i<=m;++i){
        A[id]=i;
        dfs(id+1,i);
    }
}
void solve()
{
    cin>>n>>m>>q;
    rep(i,1,q) cin>>t[i].a>>t[i].b>>t[i].c>>t[i].d;

    dfs(1,1);
    printf("%d\n",ans);

}
int main()
{
	///int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 3680
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

left = 0
right = 0
for _a in a:
    if _a < x:
        left += 1
    elif x < _a:
        right += 1

if left >= right:
    print(right)
else:
    print(left)


Measured memory_bytes: 2940