akhauriyash/Code-Regression huggingface dataset:
use std::cmp::min;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n = read::<i64>();
    let mut xn = read_vec::<i64>();
    xn.sort();
    // if xn.contains(&0){
    //       xn.retain(|&x| x== 0);
    // }
  
    let mut ans = (xn[1],xn[0]);
    let mut v:Vec<i64> = Vec::new();
    let maxv = xn.iter().max().unwrap();
    let sub = xn.iter().filter(|&x| x != maxv).max_by_key(|&&x| min(x,(maxv -x))).unwrap();
    let ans = (maxv,sub);

    println!("{} {}",ans.0,ans.1 );
}
fn comb(a:i64, b:i64) -> i64 {
    let x = (a-b+1..a + 1).fold(1,|n,m| n * m);
  
    let y =(1..b+1).fold(1,|n,m| n * m);
  
    x / y
}

Measured memory_bytes: 8444
from numba import njit
@njit("i8(i8)")

def f(n):

    
    l = [1]*(n+1)
    l[0] = 0
    ans = l[1]
    for i in range(2,n+1):
        for j in range(i,n+1,i):
            l[j] += 1

        ans += (l[i]*i)
    return ans

n = int(input())
print(f(n))


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

int funcA(int x){
  return (x * 2);
}

int funcB(int x, int k){
  return (x + k);
}

int minAB(int x, int k){
  int a = funcA(x);
  int b = funcB(x, k);
  
  if(a < b){ return a;}
  else{ return b; }
}

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

  int x = 1;
  for(int i = 0;i < N; ++i){
    x = minAB(x, K);
  }
  
  cout << x << endl;
}


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

int main(){
	int x,y,w,h,r;
	cin >> w >> h >> x >> y >> r;
	
	if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) {
	cout << "Yes" << endl;
	}
	else{
	    cout << "No" << endl;
	}
	return 0;
}



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

using namespace std;

int main() {
  vector<int> p;
  long long sum = 0;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < k; i++) {
    sum += p[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair <int,ii>
#define iil pair<ll,ll>
#define iiil pair<ll,iil>
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define s(v) sort(v.begin(),v.end())
#define pf printf
#define sf scanf
#define MIN INT_MIN
#define MAX INT_MAX
#define accepted 0
#define GCD(x,y)  __gcd(x, y)
#define endl "\n"
using namespace std;
const int maxn = 1e5 + 69;
//int vis[maxn];
//int indegree[maxn];
//vector<int> graph[maxn];
//vector<int> order;
/**
int gx[]= {2,2,-2,-2,1,-1,1,-1};
int gy[] ={1,-1,1,-1,2,2,-2,-2};

void DFS(int a,bool tpsort){
        vis[a] = 1;
    for(int i=0;i<graph[a].size();i++){
        int r = graph[a][i];
            if(vis[r]==0){
                DFS(r,tpsort);
            }
    }
    if(tpsort)order.push_back(a);
}

int vis[maxn],l[maxn],l2[maxn];
vector<int> graph[maxn];
vector<int> cst[maxn];
int mx,ans;
void BFS(int root){
    memset(vis,0,sizeof(vis));
    memset(l,0,sizeof(l));
    vis[root] = 1;
    l[root] = 0;
    queue <int> q;
    ans = 0;
    mx = root;
    q.push(root);
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        int p = graph[cur].size();
        for(int i=0;i<p;i++){
            int r = graph[cur][i];
            if(vis[r]==0){
                vis[r] = 1 ;
                l[r] = l[cur] + cst[cur][i];
                if(l[r]>ans){
                    ans = l[r];
                    mx = r;
                }
                q.push(r);
            }
        }
    }
   // cout<< ans <<endl;
}
void ultapoth(int root){
    memset(vis,0,sizeof(vis));
    memset(l2,0,sizeof(l2));
    vis[root] = 1;
    l2[root] = 0;
    queue <int> q;
    q.push(root);
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        int p = graph[cur].size();
        for(int i=0;i<p;i++){
            int r = graph[cur][i];
            if(vis[r]==0){
                vis[r] = 1 ;
                l2[r] = l2[cur] + cst[cur][i];
                q.push(r);
            }
        }
    }
   // cout<< ans <<endl;
}
**/
int main(){
    //fast
    int n,cnt;
    double  a,b,d;
        cin>>n>>d;
    cnt = 0;
        while(n--){
            cin>>a>>b;
            double s = sqrt((a*a) + (b*b));
            if(s<=d)cnt++;
        }
            cout<< cnt <<endl;

    return accepted;
}


Measured memory_bytes: 3840
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	if(c^'-')k=1,x=c&15;else k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (200010)
struct R{int w,x;bool operator<(R b){return w<b.w;}}ra[N],rb[N];
multiset<int>rs;
struct Q{int d,i;}q[N];
int n,qr,s,t,x,ans[N],pa(1),pb(1);
signed main(){
	Rd(n),Rd(qr);
	Frn1(i,1,n)Rd(s),Rd(t),Rd(x),ra[i]={s-x,x},rb[i]={t-x,x};
	sort(ra+1,ra+n+1),sort(rb+1,rb+n+1);
	Frn1(i,1,qr)q[i]={read(),i};
	sort(q+1,q+qr+1,[](Q a,Q b){return a.d<b.d;});
	Frn1(i,1,qr){
		while(pa<=n&&ra[pa].w<=q[i].d)rs.insert(ra[pa++].x);
		while(pb<=n&&rb[pb].w<=q[i].d)rs.erase(rs.find(rb[pb++].x));
		ans[q[i].i]=rs.size()?*rs.begin():-1;
	}
	Frn1(i,1,qr)wr(ans[i]),Pe;
	exit(0);
}

Measured memory_bytes: 21504
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
ll n,k,a[200000];
cin >>n >>k;
  for(int i=1;i<=n;i++){
   cin >>a[i-1]; 
  }
for(ll i=k+1;i<=n;i++){
 if(a[i-1]>a[i-(k+1)])cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
}
return 0;
}






ll gcd(ll a, ll b){

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }

}

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

namespace Allocation
{
    
    internal class Program
    {
        private static int n, k;
        public static void Main(string[] args)
        {
            var input = ReadLine().Split(' ').Select(int.Parse).ToList();
            n = input[0];
            k = input[1];
            var w = new List<int>();
            for (var i = 0; i < input[0]; i++)
            {
                w.Add(int.Parse(ReadLine()));
            }

            var left = 0;
            var right = 100000 * 10000;
            var mid = 0;
            while (right - left > 1)
            {
                mid = (left + right) / 2;
                var v = CheckStackNum(mid, w);
                if (v >= n) right = mid;
                else left = mid;
            }

            WriteLine(right);
        }

        private static int CheckStackNum(int max, List<int> weight)
        {
            var i = 0;
            for (var  j = 0; j < k; j++)
            {
                var s = 0;
                while (s + weight[i] <= max)
                {
                    s += weight[i];
                    i++;
                    if (i == n) return n;
                }
            }

            return i;
        }
    }
    
}


Measured memory_bytes: 18960
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>

using namespace std;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  set<int> s;
  int m = A % B;
  s.insert(m);
  while (true) {
    m = (m + A) % B;
    if (s.count(m) > 0) break;
    else s.insert(m);
  }
  if (s.count(C) > 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

void input(vector<int>& rvnBallCnt, int& rnVarie)
{
  int nBallSiz;
  cin >> nBallSiz >> rnVarie;

  rvnBallCnt.resize(nBallSiz);
  for (int i = 0; i < nBallSiz; i++)
  {
    int nBall;
    cin >> nBall;
    rvnBallCnt[nBall - 1]++;
  }
}

int calcRewCount(vector<int>& rvnBallCnt, int nVarie)
{
  sort(begin(rvnBallCnt), end(rvnBallCnt));
  int nRewCnt = 0;

  for (int i = 0; i < rvnBallCnt.size() - nVarie; i++)
    nRewCnt += rvnBallCnt[i];

  return nRewCnt;
}

int main()
{
  vector<int> vnBallCnt;
  int nVarie;

  input(vnBallCnt, nVarie);
  cout << calcRewCount(vnBallCnt, nVarie) << endl;

  return 0;
}

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

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

const int MAX_D = 10;
int D, G;
int p[MAX_D], c[MAX_D];

int dfs(int nokori, int num, int depth, int max_i){
    if(depth==D){
        if(nokori <= 0){
            return num;
        }else if(nokori > p[max_i]*100*(max_i+1)){
            return 1000;
        }else{
            return num + (nokori+100*(max_i+1)-1)/(100*(max_i+1));
        }
    }
    return min(dfs(nokori - p[depth]*100*(depth+1)-c[depth],num + p[depth],depth+1,max_i),
               dfs(nokori,num,depth+1,depth));
}

void solve(){
    int ans = dfs(G, 0, 0, 0);
    printf("%d",ans);
}

int main(){
    scanf("%d",&D);
    scanf("%d",&G);
    REP(i,D) scanf("%d %d",&p[i], &c[i]);
    solve();
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];/*hukasa*/

void print(int u){
 int i, c;
 printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

 if(T[u].p == NIL) printf("root, ");
 else if(T[u].l == NIL) printf("leaf, ");
 else printf("internal node, ");

 printf("[");
 for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
   if(i) printf(", ");
   printf("%d", c);
 }
 printf("]\n");

}

void calcDepth(int u, int p){
 D[u] = p;
 if(T[u].r!=NIL) calcDepth(T[u].r,p);
 if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
 int i, j, k;
 int n;
 int id, sib, child;
 int root = NIL;
 scanf("%d", &n);
 for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

 for(i=0; i<n; i++){
   scanf("%d %d", &id, &k);
   for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
     scanf("%d", &child);
     T[child].p = id;
     if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
     else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
     sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
   }
 }

 //根を求める (find the root)
 for(i=0; i<n; i++){
   if(T[i].p == -1) root = i;
 }

 //それぞれのノードの深さを求める (find depth of each node)
 calcDepth(root, 0);

 //出力 (output)
 for(i=0; i<n; i++) print(i);

 return 0;
}


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

int p = -1;
int q = 10000000;

int main() {
  string s;
  cin >> s;
  int a = 0;
  int z = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A') {
      if (i < q) q = i;
    }
    if( s.at(i) == 'Z') {
      if (i > p) p = i;
    }
  }
  cout << p - q + 1 << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    for (ll j = 1; j <= n; ++j) {
      for (ll k = 1; k <= n; ++k) {
        ans++;
      }
    }
  }

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

template <class T> class CumulativeSum2D {
    public:
        vector<vector<T>> s;
        int h, w;
        CumulativeSum2D(const vector<vector<T>> &a) {
            h = a.size();
            w = a[0].size();
            s = vector<vector<T>>(h + 1, vector<T>(w + 1, 0));
            rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
            rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
            rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
        }

        int sum(int i, int j, int h, int w) {
            return s[i + h][j + w] - s[i][j + w] + s[i][j] - s[i + h][j];
        }

        int maximumSubMatrix(){
            int ret = -INF;
            rep(i,h + 1) rep(j,w + 1) range(k,1,h - i + 1) range(l,1,w - j + 1){
                ret = max(ret, sum(i,j,k,l));
            }
            return ret;
        }
};

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

    vector<vector<int>> v(n, vector<int>(n));
    rep(i,n) rep(j,n) cin >> v[i][j];

    CumulativeSum2D<int> cumsum(v);
    cout << cumsum.maximumSubMatrix() << endl;
}

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

int main(){
    int n,arr[200],sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    int m;
    cin>>m;
    pair<int,int>p;
    vector<pair<int,int> >v;
    for(int j=0;j<m;j++){
        cin>>p.first>>p.second;
        v.push_back(p);
    }

    for(int i=0;i<m;i++){
        cout<<sum-arr[v[i].first]+v[i].second<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
n = input()
a = map(int, raw_input().split())

c = []
for i in xrange(2):
    if i == 0:
        p = True
    else:
        p = False

    cum = 0
    count = 0
    for j in xrange(n):
        cum += a[j]
        if p:
            if cum <= 0:
                count += (1 - cum)
                cum = 1
        else:
            if cum >= 0:
                count += - (-1 - cum)
                cum = -1
        p = not p
    c.append(count)
print min(c)



Measured memory_bytes: 11272
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-13;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110];
long long gcd(long long a,long long b){
	while(a){
		b%=a;
		swap(a,b);
	}
	return b;
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		long long a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(d<b||a<b){
			printf("No\n");continue;
		}
		long long g=gcd(d,b);
		long long q=(a-b)/g+1;
		if(q*g<a-c){
			printf("No\n");
		}else printf("Yes\n");
	}
}

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

signed main(){
	vector<int> A(3);
	cin>>A[0]>>A[1]>>A[2];
	sort(A.begin(),A.end());
	cout<<(A[0]==5 && A[1]==5 && A[2]==7 ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m = 0, l, ans1 = 0, ans2 = 0;
  cin >> n;
  int v[n];
  rep(i,n)
  {
    cin >> v[i];
    m += v[i];
  }
  m /= n;
  l = m + 1;
  rep(i,n)
  {
    ans1 += pow(v[i] - m, 2);
    ans2 += pow(v[i] - l, 2);
  }
  cout << min(ans1, ans2);
}


Measured memory_bytes: 256
from itertools import product
S = input()

n = len(S)
ans = 0
for P in product([0, 1], repeat= n - 1):
    b = 0
    tmp = 0
    for i in range(len(P)):
        if P[i] == 1:
            tmp += int(S[b:i + 1])
            b = i + 1
        else:
            pass
    tmp += int(S[b:n])
    ans += tmp
print(ans)

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


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

  sort(a.begin(), a.end(), greater<int>());
  int sumA = 0;
  int sumB = 0;
  for(int i=0; i<N; i++){
    if(i%2 == 0) sumA += a[i];
    else sumB += a[i];
  }

  cout << sumA - sumB << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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 ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll b(n); REP(i, n) cin >> b[i];
  V<bool> used(n, false);
  vll ans;
  REP(i, n) {
    ll j=1;
    ll maxk=-1;
    REP(k, n) {
      if (!used[k] && b[k] == j) chmax(maxk, k);
      if (!used[k]) j++;
    }
    if (maxk == -1) {cout << -1 << endl; return 0;}
    else {
      ans.push_back(b[maxk]);
      used[maxk] = true;
    }
  }
  reverse(ans.begin(), ans.end());
  REP(i, ans.size()) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;
  size_t pos = 0;
  int ans = 0;
  while ((pos = S.find("ABC", pos)) != string::npos) {
    ++ans;
    pos += 3;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))

A.sort()

cnt=0
ans=1
for i in range(1,N):
    if A[i-1]==A[i]:
        cnt+=1



if  cnt%2!=0:
    ans=N-(cnt+1)
else:
    ans=N-cnt

print(ans)




Measured memory_bytes: 14396
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    int H1;
    int M1;
    int H2;
    int M2;
    int K;

    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int delta = (H2-H1) * 60 + (M2 - M1);
    delta = abs(delta);

    cout << max(0, delta - K) << endl;

    return 0;
}

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

int main(){
    string A,B,C;
    cin >> A >> B >> C;
    if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
//wrong answer
#include<iostream>
#include<algorithm>

using namespace std;

int abs(int m, int n)
{
	return m - n > 0 ? m - n : n - m;
}

struct data {
	int x;
	int y;
	int h;
}d[105];

int main()
{
	int N, p=0;
	cin >> N;
	for (int i = 0;i < N;i++)
	{
		cin >> d[i].x >> d[i].y >> d[i].h;
	}
	while(d[p].h==0) p++;
	for (int i = 0;i < 101;i++)
		for (int j = 0;j < 101;j++)
		{
			int H = d[p].h + abs(d[p].x, i) + abs(d[p].y, j);
			int l = 0;
			for (int k = 0;k < N;k++)
			{
				if (max(0, H - abs(d[k].x, i) - abs(d[k].y, j)) == d[k].h) l++;
			}
			//		cout<<i<<" "<<j<<" "<<H;
			//	cout<<"  *  "<<l<<"   &  "<<N<<endl;
			if (l == N) {
				cout << i << " " << j << " " << H << endl;
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 256
let solve gpLst =
    let rec solve' gCnt pCnt lst result =
        match lst with
        | [] -> result
        | x::xs ->
            let nextGCnt, nextPCnt, nextResult =
                match x, gCnt > pCnt with
                | 'g', true -> gCnt, pCnt + 1, result + 1
                | 'g', false -> gCnt + 1, pCnt, result
                | 'p', true -> gCnt, pCnt + 1, result
                | _, _ -> gCnt + 1, pCnt, result - 1
            solve' nextGCnt nextPCnt xs nextResult
    solve' 0 0 gpLst 0


let () =
    let gpLst = stdin.ReadLine() |> List.ofSeq
    solve gpLst |> printfn "%d"

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

int main(){
    int p, q, r;
    cin >> p >> q >> r;
    int min_num = p+q;
    if(min_num > q+r) min_num = q+r;
    if(min_num > r+p) min_num = r+p;
    cout << min_num << endl;
}

Measured memory_bytes: 256
(let ((a (read))
      (b (read))
      (k (read)))
  (cond ((>= k (+ a b))
         (format t "0 0~%"))
        ((> k a)
         (format t "0 ~A~%" (- b (- k a))))
        (t
         (format t "~A ~A~%" (- a k) b))))


Measured memory_bytes: 24228
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] count = null;
    for (int i = 0; i < n; i++) {
      String s = sc.next();
      count = solve(s, count);
    }
    
    StringBuilder ans = new StringBuilder();
    for (int i = 0; i < count.length; i++) {
      for (int j = 0; j < count[i]; j++) {
        ans.append((char)('a'+i));
      }
    }
    System.out.println(ans.toString());
  }
  
  private static int[] solve(String s, int[] count) {
    int[] count2 = new int[26];
    for (int i = 0; i < s.length(); i++) {
      int idx = s.charAt(i) - 'a';
      count2[idx]++;
    }
    if (count == null) {
      return count2;
    }
    
    for (int i = 0; i < 26; i++) {
      count[i] = Math.min(count[i], count2[i]);
    }
    return count;
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;


ll str_len(char *s){
  ll len;
  while(*s++)
    len++;
  return len;
}

bool judge(char *s,char *t,ll n){
	rep(i,n){
		if(s[i]!=t[i])
			return false;
	}
	return true;
}

int main(){
	char s[100],t[100];
	cin >> s >> t;
	if(str_len(t)==str_len(s)+1 && judge(s,t,str_len(s))==true)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3632
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

int dp[3003][3003][2];
int main(){
    //freopen("A.in","r",stdin);
    //freopen("B.out","w",stdout);
    //cout<<setprecision(9)<<fixed;
    int i,j,k,ca=0,m,n;
    scanf("%d%d",&n,&m);
    rep(i,1,n+1)dp[0][i][0]=1;
    dp[0][0][1]=1;
    rep(i,0,m){
        rep(j,0,n+1){
            int r=j,b=n-r;
            if(r){
                rep(k,0,2){
                    int x=k|r==1;
                    add(dp[i+1][j][x],dp[i][j][k]);
                    add(dp[i+1][j-1][x],dp[i][j][k]);
                }
            }
            if(b){
                rep(k,0,2){
                    add(dp[i+1][j][k],dp[i][j][k]);
                    add(dp[i+1][j+1][k],dp[i][j][k]);
                }
            }
        }
    }
    int ans=0;
    rep(i,0,n+1)add(ans,dp[m][i][1]);
    printf("%d\n",ans);
    //cerr<<clock()*1./CLOCKS_PER_SEC<<"ms\n";
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int const MOD = 1e9+7;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  vector<int> c(26);
  rep(i, N) {
    c[S[i] - 'a']++;
  }
  ll ans = 1;
  rep(i, 26) {
    ans *= c[i] + 1;
    ans %= MOD;
  }
  cout << ans - 1 << endl;
}

/*
int main() {
  int N; cin >> N;
  string S; cin >> S;
  vector<int> c(26);
  ll sum = 0;
  rep(i, N) {
    const int sel_idx = S[i] - 'a';
    c[sel_idx]++;
    ll s = 1;
    rep(k, 26) if (k != sel_idx) {
      (s *= c[k] + 1) %= MOD;
    }
    (sum += s) %= MOD;
  }
  cout << sum << endl;
}
*/

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

int main(){
  ll n;
  cin >> n;
  vector<ll> A(n);
  vector<ll> B(n);
  rep(i,n){
    cin >> A[i] >> B[i];
  }
  sort(A.rbegin(),A.rend());
  sort(B.begin(),B.end());
  ll ans = 0;
  rep(i,n-1){
    ans += min(A[i]-A[i+1],B[i+1]-B[i]);
  }
  ans += A[n-1]+B[0];
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 1792
loop do
    n, k = gets.split.map(&:to_i)
    break if n == 0 && k == 0
    cs = k.times.map{gets.to_i}.sort
    if cs[0] == 0
        max = Array.new
        i = 1
        while i < cs.size - 1
            s = cs[i]
            while cs[i] + 1 == cs[i+1]
                i += 1
            end
            t = cs[i]
            max.push([s, t])
            i += 1
            s = i
        end
        max1 = max.map{|s,t| t - s + 1}.max
        max2 = 0
        max.each_with_index do |st,i|
            next if i == 0
            if st[0] == max[i-1][1] + 2
                max2 = st[1] - max[i-1][0] + 1 if st[1] - max[i-1][0] + 1 > max2
            end
        end
        p [max1,max2].max
    else
        max = 0
        i = 1
        while i < cs.size - 1
            count = 1
            while cs[i] + 1 == cs[i+1]
                count += 1
                i += 1
            end
            max = count if count > max
            i += 1
        end
        p max
    end
end

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

using namespace std;
using ll = long long int;

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

    string s;
    cin >> s;
    if(s.size() == 1) {
        cout << s << endl;
        return 0;
    }

    bool a = true;
    for(ll i=1; i<s.size(); i++)
        if(s[i] != '9') a = false;
    cout << 9*(s.size()-1) + (s[0]-'0') - (!a) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,m,q,a[2010][2010],b[2010][2010],c[2010][2010];
char map[2010][2010];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void calc(int (*a)[2010])
{
    repu(i,1,n)
        repu(j,1,m)
            a[i][j]+=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
}

int query(int (*a)[2010],int x1,int y1,int x2,int y2)
{
    return a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];
}

int main()
{
    scanf("%d%d%d",&n,&m,&q);
    repu(i,1,n)
        scanf("%s",map[i]+1);
    repu(i,1,n)
        repu(j,1,m)
            if (a[i][j]=map[i][j]=='1')
            {
                b[i][j]=map[i][j+1]=='1';
                c[i][j]=map[i+1][j]=='1';
            }
    calc(a),calc(b),calc(c);
    while (q--)
    {
        int x1=getint(),y1=getint(),x2=getint(),y2=getint();
        printf("%d\n",query(a,x1,y1,x2,y2)-query(b,x1,y1,x2,y2-1)-query(c,x1,y1,x2-1,y2));
    }
    return 0;
}

Measured memory_bytes: 52992
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

inline double square(double x){return x*x;}
inline double Roundoff(double x){
	if( x<0 ){
		x*=-1;
		x=(x-(x-int(x*1000)/1000))+(((x*1000)-int(x*1000))*10)>=4?0.001:0;
		x*=-1;
	}else{
		x=(x-(x-int(x*1000)/1000))+(((x*1000)-int(x*1000))*10)>=4?0.001:0;
	}
	return x;
}

void SolveSimultEq(double &x,double &y,double a,double b,double c,double d,double e,double f);
int main(){
	int datanum;
	double *x1,*y1,*x2,*y2,*x3,*y3;
	cin>>datanum;
	x1=new double[datanum];
	y1=new double[datanum];
	x2=new double[datanum];
	y2=new double[datanum];
	x3=new double[datanum];
	y3=new double[datanum];
	
	for( int i=0;i<datanum;i++ ){
		cin>>x1[i]>>y1[i]>>x2[i]>>y2[i]>>x3[i]>>y3[i];
	}
	for( int i=0;i<datanum;i++ ){
		double px,py,r;
		
		SolveSimultEq(px,py,2*(x1[i]-x2[i]),2*(y1[i]-y2[i]),square(x1[i])-square(x2[i])+square(y1[i])-square(y2[i]),
  			  	    2*(x2[i]-x3[i]),2*(y2[i]-y3[i]),square(x2[i])-square(x3[i])+square(y2[i])-square(y3[i]));
		r=sqrt(square(x1[i]-px)+square(y1[i]-py));
		cout<<fixed<<setprecision(3)<<px<<" "<<setprecision(3)<<py<<" "<<setprecision(3)<<r<<endl;

	}

	delete x1;
	delete y1;
	delete x2;
	delete y2;
	delete x3;
	delete y3;
	return 0;
}

void SolveSimultEq(double &x,double &y,double a,double b,double c,double d,double e,double f){
	double delta=a*e-b*d;
	
	x=(c*e-b*f)/delta;
	y=(a*f-c*d)/delta;
}

Measured memory_bytes: 1292
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int w[1001];
int v[1001];

int dp[1001][10001];

int W,N;

int main(){
    int t=1;
    while(cin >> W, W){
        memset(dp, 0, sizeof(dp));
        memset(w, 0, sizeof(w));
        memset(v, 0, sizeof(v));
        cin >> N;
        for(int i=0; i<N; i++){
            scanf("%d,%d",&v[i],&w[i]);
        }
        cout << "Case " << t++ << ":" << endl;

        
        for(int i=0; i<N; i++){
            for(int j=0; j<=W; j++){
                if(j - w[i] >= 0){
                    dp[i+1][j] = max(dp[i][j] , dp[i][j-w[i]] + v[i]);
                }else{
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
        cout <<  dp[N][W] << endl;

        
        int i = N, j = W;
        int wei = 0;
        while(i != 0){
            if(w[i-1] <= j){
                int take = dp[i-1][j - w[i-1]] + v[i-1];
                if(take == dp[i][j]){
                    wei += w[i-1];
                    j -= w[i-1];
                }
            }
            i--;
        }
        cout << wei << endl;
    }
}

Measured memory_bytes: 40364
#include <iostream>
#include <iomanip>
/*cout<<setprecision(5)<<ret<<endl;で、数字部分を計5桁表示かつゼロ埋め無*/
/*cout<<fixed<<setprecision(5)<<ret<<endlで、小数部のみ5桁表示かつゼロ埋め有*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

/* [Shift+Command+b]（コンパイル）ー＞[Ctrl+Shift+^]（ターミナル起動）ー＞[./a.out] */


//////////////////
//  A
/*int main(void){
    string a;cin>>a;
    sort(a.begin(),a.end());
    if(a[0]==a[1] && a[2]==a[3] && a[0]!=a[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}*/
//////////////////
//  B
/*int main(void){
    int n;cin>>n;
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];
    }
    int cnt=0;
    for(int i=1;i<n-1;i++){
        if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}*/
//////////////////
//  C
int main(void){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    int low=a[n/2-1],high=a[n/2];
    cout<<high-low<<endl;
    return 0;
}
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3788
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	if (S.length() + 1 != T.length()) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < S.length(); i++) {
		if (S[i] != T[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;


}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;
typedef long long ll;

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

	string S;
	int N;

	cin >> N >> S;

	if (N >= 3200)
	{
		cout << S << endl;
	}
	else
	{
		cout << "red\n";
	}

	return 0;
}

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

int main() {
  string a;
  string b;
  int c = 0;
  
  cin >> a;
  cin >> b;
  
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i]) {
      c++;
    }
  }
  
  cout << c;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s,t;cin>>s>>t;
    int len=s.length();
    bool f=true;
    map<char,char> mp,rev;
    for(int i=0;i<len;i++){
        if(mp.find(s[i])==mp.end()){
            mp[s[i]] = t[i];
            rev[t[i]] = s[i];
        }
        else if(mp[s[i]] != t[i]) f=false;
    }
    for(int i=0;i<len;i++){
        if(rev[t[i]]!=s[i]) f=false;
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if(n%2!=0) cout << "No" <<endl;
  else{
    bool ans=1;
    for(int i=0;i< n/2;i++){
      if(s.at(i)!=s.at(n/2+i)){
        ans=0;
      }
    }
    if(ans) cout << "Yes" <<endl;
    else cout << "No" <<endl;
  }
      
}

Measured memory_bytes: 256
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMOD = 998244353;

def getval(n):
    i = 1
    while ((i * (i+1))//2 <= n):
        i += 1
    return i-1

if __name__ == "__main__":
    # sys.stdin = open("input.txt","r")  # <<<  ^o^  Comment this line  ^_^  >>>
    d = {}
    n = int(input())
    i = 2
    while i * i <= n:
        if n % i == 0:
            d[i] = d.get(i, 0)
            d[i] += 1
            n //= i
        else:
            i += 1
    if n!=0 and n!=1:
        d[n] = d.get(n, 0)
        d[n] += 1
    ans = 0
    # print(d)
    for k, v in d.items():
        ans += getval(v)
    print(ans)


# #############################################################################
'''
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
>>> DO NOT PLAGIARISE.
TESTCASES:
'''

Measured memory_bytes: 63640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    int n;
    cin >> n;
    map<int, int> d;
    for (int i = 0; i < n; ++i) {
        int dd;
        cin >> dd;
        d[dd]++;
    }
    int m;
    cin >> m;
    vl t(m);
    for (int i = 0; i < m; ++i) {
        cin >> t[i];
    }
    bool ok = true;
    for (int i = 0; i < m; ++i) {
        if (d[t[i]] == 0) {
            ok = false;
            break;
        } else {
            d[t[i]]--;
        }
    }
    if (ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<time.h> 
#define loop(i,c,n) for(long long i=c;i<n;i++) 
#define iter(v) for(auto x : v)  // to iterate over entire vector/sets/map
using namespace std; 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii; 
typedef set<int> si;  
int ab(int a){if(a<0)return -a;return a;}
int max(int a,int b){if(a>b)return a;
return b;} 
//optimised school method
bool isPrime(ll a){ 
if(a<=1)return false ;
if(a<=3)return true ;
if(a%2==0 || a%3==0)return false;
for(ll i=5;i*i<=a;i=i+6){//Instead of checking till n, we can check till √n because a larger factor of n 
//must be a multiple of smaller factor that has been already checked.
if(a%i==0 || a%(i+2)==0)return false;}return true;}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);  
	cout.tie(0);
	//  to read input from local files  
	 #ifndef ONLINE_JUDGE 
	clock_t clocktime; 
	clocktime= clock(); 
	 freopen("input.txt", "r",stdin);
	 freopen("output.txt", "w",stdout);
	#endif
	// to read entire line with spaces 
	// string s;
	// getline(cin,s);
	
	// when amount of data is unknown
	// while(cin>>x){}    
	
 int x,n;
	int l,r;
	
	 cin>>x>>n ;
	 vi v(n);
	 l=x;r=x; 

	  loop(i,0,n){cin>>v[i]; }  
	  sort(v.begin(),v.end());
	

	 loop(x,0,n){if(r==v[x])r++;}
	 for(int j=n-1;j>=0;j--)if(l==v[j])l--;
	if(abs(l-x)>abs(r-x))cout<<r;
	else cout<<l;

	
	#ifndef ONLINE_JUDGE
	clocktime = clock()-clocktime; 
	double runtime  = (((double)clocktime)/CLOCKS_PER_SEC); 
	cout<<"\n--------\nTimeUsed -- "<<runtime<<"s"; 
	#endif
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    string t[] = {"dreamer", "eraser", "dream",  "erase"};
    int itr = s.size(), pos = s.size();
    eper(i, s.size()-1, 0) {
        rep(j, 0, 4) {
            string sub = s.substr(i, pos - i);
            if (sub == t[j]) {
                itr -= sub.size();
                pos = i;
            }
        }
    }
    if (itr == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
N,K =map(int,input().split())
R,S,P = map(int,input().split())
T = input()
ans = [0,0,0]
if N%K != 0:
  for _ in range(K - N%K):
    T = T + "W"
A = len(T)//K
r = [[] for _ in range(K)]
for i in range(K):
  for j in range(A):
    r[i].append(T[i + j*K])
for i in range(K):
  f = r[i]
  for j in range(len(f)-1):
    if f[j+1] == f[j]:
      f[j+1] = "W"
  for h in range(len(f)):
    if f[h] == "r":
      ans[2] += 1
    elif f[h] == "s":
      ans[0] += 1
    elif f[h] == "p":
      ans[1] += 1
a = ans[0]*R + ans[1]*S + ans[2]*P
print(a)

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

using namespace std;

int n;
int s[100]={};
int count = 0;
int dai,syou;
int ans[1000]={};
int judge = 0;

int main()
{
    while(1){
        scanf("%d",&n);
        if(n == 0){
            break;
        }
        dai = 0;
        syou = 1000;
        for(int i=0;i<n;i++){
            scanf("%d",&s[i]);
            if(dai <= s[i]){
                dai = s[i];
            }
            if(syou >= s[i]){
                syou = s[i];
            }
        }
        int dai_count = 0;
        int syou_count = 0;
        for(int i=0;i<n;i++){
            if(s[i]==dai && dai_count ==0){
                dai_count=1;
                
            }else if(s[i] == syou && syou_count ==0){
                syou_count = 1;
            }else{
                ans[judge] += s[i];
            }
        }
        ans[judge] = ans[judge] / (n-2);
        
        judge++;

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

    
    return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;

int main()
{
    string s;
    cin>>s;
    string f,ss;
    int n=s.size();
    if(n%2==0)
    {
        f=s.substr(0,n/2);
        ss=s.substr(n/2,n/2);
    }
    else
    {
        f=s.substr(0,n/2);
        ss=s.substr(n/2+1,n/2);
    }
    int ans=0;
    rep(i,n/2)
    {
        if(f[i]!=ss[n/2-1-i])ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    priority_queue<pair<int64_t, int64_t>> pq;
    for(int64_t i=0; i<n; i++){
        pq.push(make_pair(a.at(i), i));
    }
    int64_t max_num = pq.top().first;
    int64_t max_i = pq.top().second;
    pq.pop();
    int64_t sub_max_num = pq.top().first;
    for(int64_t i=0; i<n; i++){
        if(i==max_i){
            cout << sub_max_num << endl;
        }else{
            cout << max_num << endl;
        }
    }
}


Measured memory_bytes: 8048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// Scanner sc = new Scanner(System.in);
		// 整数の入力
		// int a = sc.nextInt();
		// スペース区切りの整数の入力
		// int b = sc.nextInt();
		// int c = sc.nextInt();
		// 文字列の入力
		// String s = sc.next();
		// 出力
		// System.out11.println((a+b+c) + " " + s);
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		String ans = "No";

		if (Math.abs(a-c) <= d) {
			ans = "Yes";
		} else if (Math.abs(a- b) <= d && Math.abs(c - b) <= d) {
			ans = "Yes";
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 22228
#include <stdio.h>


int main() {
	int n, x, count[100];
	int i, j, k, l, ll;


	for (l = 0; l < 100; l++) {
		scanf("%d %d", &n, &x);
		count[l] = 0;
		for (i = 0; i < n - 2; i++) {
			for (j = i + 1; j < n - 1; j++) {
				for (k = j + 1; k < n; k++) {
					if (i + j + k + 3 == x) {
						count[l]++;
//debug log				printf("%d %d %d\n", i, j, k);
					}
				}
			}
		}


		if (n == 0 && x == 0) {
			ll = l;
			break;
		}
	}

	

	
	for (i = 0; i < ll; i++) {
		printf("%d\n", count[i]);
	}




	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main()
{
    int X,A;
    scanf("%d %d",&X,&A);
    if(A  <X)
    {
        printf("%d",10);
    }
     else if(A>X)
    {
        printf("%d",0);
    }
     else if(A==X)
    {
        printf("%d",10);
    }

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int X,N,tmp;
bool arr[105];
int diff(int a, int b){
	if(a>b)return a-b;
	return b-a;
}
int main(){
	cin>>X>>N;
	for(int i=0; i<N; i++){
		cin>>tmp;
		arr[tmp]=true;
	}
	int temp1=X,temp2=X;
	while(temp1>0){
		if(!arr[temp1]){
			break;
		}
		temp1--;
	}
	while(true){
		if(!arr[temp2]){
			break;
		}
		temp2++;
	}
	if(diff(X,temp1)<=diff(X,temp2)){
		cout<<temp1<<'\n';
	}else{
		cout<<temp2<<'\n';
	}
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<int,int>
const ll INF=1e+9;
P p[90001];
ll dist[200000];

int dst(P l, P r){
  return abs(l.first-r.first)+abs(l.second - r.second);
}

int main(){
  int h,w,d,a;
  cin >> h >> w >> d;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> a;
      p[a]=P(i,j);
    }
  }

  for(int a = h * w - d; a > 0; a--){
      dist[a] = dist[a+d] + dst(p[a], p[a+d]);
  }

  int q;
  cin>>q;
  int l,r;
  for(int i=0;i<q;i++){
    cin>>l>>r;
    cout << dist[l] - dist[r] << endl;
  }
}

Measured memory_bytes: 2560
from fractions import*
from functools import*
M=10**9+7
_,a=open(0)
*a,=map(int,a.split())
s=reduce(lambda x,y:x//gcd(x,y)*y,a)%M
c=0
for i in a:
    c+=s*pow(i,M-2,M)
    c%=M
print(c)

Measured memory_bytes: 67944
#include "bits/stdc++.h"
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int add(int a , int b){
	int res = a + b;
	if(res >= mod){
		return res - mod;
	}
	return res;
}
int mult(int a , int b){
	long long res = a;
	res *= b;
	if(res >= mod){
		return res % mod;
	}
	return res;
}
int power(int a , int b){
	int res = 1;
	while(b){
		if(b & 1){
			res = mult(res , a);
		}
		a = mult(a , a);
		b >>= 1;
	}
	return res;
}
int fact[N];
int ifact[N];
void pre(){
	fact[0] = 1;
	for(int i = 1 ; i < N ; ++i){
		fact[i] = mult(fact[i - 1] , i);
	}
	ifact[N - 1] = power(fact[N - 1] , mod - 2);
	for(int i = N - 2 ; i >= 0 ; --i){
		ifact[i] = mult(ifact[i + 1] , i + 1);
	}
}
int ncr(int n , int r){
	return mult(fact[n] , mult(ifact[r] , ifact[n - r]));
}
int n , m , a , b;
int ans;
int ways(int x1 , int y1 , int x2 , int y2){
	return ncr(x2 + y2 - x1 - y1 , x2 - x1);
}
int main(){
	pre();
	cin >> n >> m >> a >> b;
	ans = ways(1 , 1 , n , m);
	int x = n - a + 1;
	int c = b;
	while(x <= n && c >= 1){
		//cout << ans << " " << x << " " << c << endl;
		ans = add(ans , mod - mult(ways(1 , 1 , x , c) , ways(x , c , n , m)));
		//cout << ans << " " << x << " " << c << endl;
		++x;
		--c;
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 1792