akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[1100][1100];
char tmp[1100][1100];
long long mod=1000000007;
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
long long mat[3][3];
long long val[3][3];
long long t2[3][3];
int main(){
	int a,b;
	long long c;scanf("%d%d%lld",&a,&b,&c);
	if(c==0){
		printf("1\n");return 0;
	}
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	bool H=false;
	bool W=false;
	for(int i=0;i<a;i++)if(in[i][0]=='#'&&in[i][b-1]=='#')H=true;
	for(int i=0;i<b;i++)if(in[0][i]=='#'&&in[a-1][i]=='#')W=true;
	if(H&&W){printf("1\n");return 0;}
	if(W){
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)tmp[j][i]=in[i][j];
		swap(a,b);
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)in[i][j]=tmp[i][j];
	}
	long long S=0;
	long long T=0;
	long long V=0;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(in[i][j]=='#')S++;
		if(j<b-1&&in[i][j]=='#'&&in[i][j+1]=='#')V++;
	}
	
	if(!H&&!W){printf("%lld\n",pw(S,c-1));return 0;}
	for(int i=0;i<a;i++)if(in[i][0]==in[i][b-1]&&in[i][0]=='#')T++;
	val[0][0]=val[1][1]=1;
	mat[1][1]=T;
	mat[0][0]=S;
	mat[0][1]=mod-V;
	c--;
	while(c){
		if(c%2){
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)t2[i][j]=0;
		for(int k=0;k<2;k++)for(int i=0;i<2;i++)for(int j=0;j<2;j++)t2[i][j]=(t2[i][j]+val[i][k]*mat[k][j])%mod;
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)val[i][j]=t2[i][j];
		}
		c/=2;
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)t2[i][j]=0;
		for(int k=0;k<2;k++)for(int i=0;i<2;i++)for(int j=0;j<2;j++)t2[i][j]=(t2[i][j]+mat[i][k]*mat[k][j])%mod;
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)mat[i][j]=t2[i][j];
	}
//	printf("%lld %lld\n",val[0][0],val[0][1]);
	printf("%lld\n",(val[0][0]+val[0][1])%mod);
}

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

const int MAX_N = int(3e6) + 10;

int n, m;
int fac[MAX_N], inv[MAX_N];

const int mod = 998244353;

int C(int n, int m) {
	return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int mypow(int x, int y, int m) {
	int r = 1;
	while (y) {
		if (y & 1)
			r = 1LL * r * x % m;
		x = 1LL * x * x % m;
		y >>= 1;
	}
	return r;
}

int f(int n, int m, int odd) {
	int r = 0;
	for (int i = 0; i <= n && i <= odd; ++i) {
		if (!(m - i & 1) && m >= i) {
			r = (r + 1LL * C(n, i) * C((m - i) / 2 + n - 1, n - 1) % mod) % mod;
		}
	}
	// printf("f(%d,%d,%d)=%d\n", n, m, odd, r);
	return r;
}

int main() {
	scanf("%d%d", &n, &m);
	fac[0] = inv[0] = 1;
	for (int i = 1; i <= n + 3 * m; ++i) {
		fac[i] = 1LL * fac[i - 1] * i % mod;
		inv[i] = mypow(fac[i], mod - 2, mod);
		// printf("%d %d\n", fac[i], inv[i]);
	}
	int ans = (f(n, 3 * m, m) - 1LL * n * (f(n, m, m) - f(n - 1, m, m)) % mod) % mod;
	if (ans < 0) ans += mod;
	printf("%d\n", ans);
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, A, B;

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

    if(A > B || (N == 1 && A != B)){
        cout << 0 << endl;
        return 0;
    } else if(N == 1 && A == B){
        cout << 1 << endl;
        return 0;
    }

    ll ans;
    ans = ((ll)(N-1) * B + A) - ((ll)(N-1)* A + B) + 1;

    cout << ans << endl;
}

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


int main()
{
	string s;
	int x=0;
	cin >> s;
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == '1') { x++; }
	}
	cout << x;


    return 0;
}



Measured memory_bytes: 256
import queue

k = int(input())

q = queue.Queue()

for i in range(1, 10):
    q.put(i)

for i in range(k):
    x = q.get()
    if x % 10 > 0:
        q.put(x*10 + x % 10 - 1)
    q.put(x*10 + x % 10)
    if x % 10 < 9:
        q.put(x*10 + x % 10 + 1)

print(x)


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    int n;
    cin>>n;
    vector<pair<int,int>> p;
    rep(i,0,n){
        int x,y;
        cin>>x>>y;
        p.pb({x,y});
    }
    ll xx=0;
    int id=0;
    ll p1,p2;
    rep(i,0,n){
        if(xx<p[i].X+p[i].Y){
            xx=p[i].X+p[i].Y;
            p1=p[i].X;
            p2=p[i].Y;
            id=i;
        }
    }
    ll min=infl;
    ll p3,p4;
    rep(i,0,n){
        if(id!=i && min>p[i].X+p[i].Y){
            min=p[i].X+p[i].Y;
            p3=p[i].X;
            p4=p[i].Y;
        }
    }
    ll as=abs(abs(p1-p3)+abs(p2-p4));
     xx=0;
     id=0;
    rep(i,0,n){
        if(xx<p[i].X-p[i].Y){
            xx=p[i].X-p[i].Y; p1=p[i].X;
            p2=p[i].Y;
            id=i;
        }
    }
     min=infl;
    rep(i,0,n){
        if(id!=i && min>p[i].X-p[i].Y){
            min=p[i].X-p[i].Y;p3=p[i].X;
            p4=p[i].Y;
        }
    }
    ll as2=abs(abs(p1-p3)+abs(p2-p4));
    cout<<max(as,as2);
    return 0;
}



Measured memory_bytes: 5324
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll a,b,c;
int main()
{
    //IOS;
    cin>>a>>b>>c;
    if(a==b&&b!=c)
    {
        cout<<"Yes"<<endl;
    }
    else if(a==c&&b!=c)
    {
        cout<<"Yes"<<endl;
    }
    else if(c==b&&b!=a)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}
/*

*/


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

struct Card{char suit, value;};

void BubbleSort(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        for(int j = N - 1; j >= i; j--){
            if(A[j].value < A[j-1].value){
                Card t = A[j];
                A[j] = A[j-1];
                A[j-1] = t;
            }
        }
    }
}

void SelectionSort(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j].value < A[minj].value) minj = j;
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

void print(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        if(i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
    for(int i = 0; i < N; i++){
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main(){
    Card C1[100], C2[100];
    int N;
    char ch;

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }

    for(int i = 0;i < N; i++) C2[i] = C1[i];

    BubbleSort(C1, N);
    SelectionSort(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if(isStable(C1, C2, N)){
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;
typedef long double ldouble;

typedef pair<lint, int> E; 
int n;

int cnt(int x) {
    int res = 0;
    while (x != 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

int main(int, char**) {
    std::ios::sync_with_stdio(false);
    cin >> n;

    int minV = 1e6;
    for (int a = 1; a < n; ++a) {
        int b = n - a;
        minV = min(minV, cnt(a) + cnt(b));
    }
    cout << minV << endl;

    return 0;
}


Measured memory_bytes: 256
import bisect
import sys
A, B, Q = map(int, input().split())
INF = 10 ** 13
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(sys.stdin.readline())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 14080
import math

n,m = map(int,input().split())
m_div = []
for i in range(1,math.ceil(math.sqrt(m)+1)):
  if m%i ==0:
    m_div.extend([i,m//i])
m_div = list(set(m_div))
m_div.sort(reverse = True)
for div in m_div:
  if div >= n:
    ans = m//div
  else:
    break
print(ans)
    

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

int main(){
    int n;
    ll d;
    cin >> n >> d;
    int res=0;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        if(x*x + y*y <= d*d) res+=1;
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


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

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

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

	ll ret[n];
	for (int i = 0; i < n; i++) {
		ll ans = INT_MAX;
		for (int j = 0; j < m; j++) {
			ll tmp = abs(a[i]-c[j]) + abs(b[i]-d[j]);
			if (tmp<ans) {
				ret[i] = j+1;
				ans = tmp;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ret[i] << "\n";
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

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

	ll sum = 0;
	repn(i, N - 1) {
		ll u, v;
		cin >> u >> v;
		if (u > v) { swap(u, v); }
		sum += u * (N - v + 1);
	}

	ll all = 0;
	rep(i, N)all += i * (N - i);

	ll ans = N * (N + 1) / 2 + all - sum;
	cout << ans << endl;


}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = ab[0];
        var b = ab[1];

        var c = new [] { a * 2 - 1, a + b, b * 2 - 1 }.Max();
        Console.WriteLine(c);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	string s,t,u;
	int a,b;

	cin >> s >> t >> a >> b >> u;
	if(s==u){
		cout << a -1 << " " << b;
	}else{
		cout << a << " " << b-1;
	}
	return(0);
}


Measured memory_bytes: 256
def main():
    N, K, S = map(int, input().split())
    AS = [S] * K
    if S == pow(10, 9):
        AS1 = [1] * (N-K)
    else:
        AS1 = [S+1] * (N-K)
    ans = AS + AS1
    print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7380
#include<stdio.h>
#define MAX 100
#define INF 10000000

void dijkstra();


int n,m[MAX][MAX];


int main(){
  int i,j,r,k,c,u,v;
  
  scanf("%d",&n);
  
  for(i=0;i<=n-1;i++){
    for(j=0;j<=n-1;j++){
      m[i][j] = INF;
    }
  }
  
  for(i=0;i<=n-1;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<=k-1;j++){
      scanf("%d%d",&v,&c);
      m[u][v]=c;
    }
  }
  dijkstra();
  return 0;
}


void dijkstra(){
  int i,u,j,mincost,d[MAX],c[MAX];
  
  for(i=0;i<=n-1;i++){
    d[i]=INF;
    c[i]=-1;
  }
  
  d[0] = 0;
  c[0]=0;
  
  while(1){
    mincost=INF;
    u=-1;
    
    for(i=0;i<=n-1;i++){
      if(mincost>d[i]&&c[i]!=1){
        u=i;
        mincost=d[i];
      }
    }
    
    if(u==-1)break;
    
    c[u]=1;
    
    for(j=0;j<=n-1;j++){
      if(c[j]!=1&&m[u][j]!=INF){
        if(d[j]>d[u]+m[u][j]){
          d[j]=d[u]+m[u][j];

          c[j]=0;
        }

      }
    }
  }

  for(i=0;i<=n-1;i++){
    printf("%d %d\n",i,(d[i] == INF ? -1 : d[i]));
  }
}



Measured memory_bytes: 2076
#include <iostream>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int ca = 0;
  int cb = 0;
  for (int i = 0; i < s.length(); i++) {
    if (i & 0x01) {
      if (s[i] == '0') {
        ca++;
      }
      else {
        cb++;
      }
    }
    else {
      if (s[i] == '0') {
        cb++;
      }
      else {
        ca++;
      }
    }
  }

  cout << ((ca <= cb) ? ca : cb) << endl;
  return 0;
}

Measured memory_bytes: 512
N,K = map(int,input().split())
Hs = [ int(input()) for i in range(N)]
Hs.sort()
MinDiff = 10**9
for i in range(1 + N - K):
    MinDiff = min(MinDiff, Hs[i+K-1] - Hs[i])
print(MinDiff)  

Measured memory_bytes: 7384
// I/O
#include <iostream>
#include <iomanip>

// data structures
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

// manipulations
#include <algorithm>

// others
#include <cassert>

#define rep(i,n) for(int (i)=0;(i)< (n);++(i))
#define REP(i,n) for(int (i)=1;(i)<=(n);++(i))
#define for_lowercase(c) for(char (c)='a';(c)<='z';++(c))
#define for_uppercase(c) for(char (c)='A';(c)<='Z';++(c))
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PII  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPII = std::vector<PII>;
template<class T> bool is_odd (T x){ return   x%2 ; }
template<class T> bool is_even(T x){ return !(x%2); }
LLI combination(LLI n,LLI k,bool reset=false){
    static VVI C; static LLI n_hashed = -1;
    if(n<0){ std::cerr << "[ERROR] n must be non-negative in combination()" << std::endl; exit(1); }
    if(!(0<=k&&k<=n)){ std::cerr << "[WARNING] k should be in range [0,n] in combination()" << std::endl; return 0; }
    if(n_hashed<n || reset){
        C.resize(n+1);
        for(int i=0;i<=n;++i) C[i].resize(i+1,1); // filled with 1
        for(int i=1;i<=n;++i)for(int j=1;j<i;++j) C[i][j] = C[i-1][j-1] + C[i-1][j];
        n_hashed = n;
    }
    return C[n][k];
}
namespace compProg{
    template<class T> std::ostream& ostream_iterable_impl(std::ostream &os,
                                                          const T &t,
                                                          const std::string &LEFT,
                                                          const std::string &RIGHT,
                                                          const std::string &DELIMITER){
        bool first = true;
        os << LEFT;
        for(const auto &x:t){
            if(first) first = false;
            else os << DELIMITER;
            os << x;
        }
        os << RIGHT;
    }
    void please_never_call_this_function_to_eliminate_warning(){
        is_odd(0); is_even(0); combination(0,0); LCM(0,0);
        rep(i,0)REP(j,0)for_lowercase(c)for_uppercase(c);
        std::sort(ALL(std::string("")));
    }
}
template<class T> std::ostream& operator<<(std::ostream &os,const std::vector<T> &t){
    return compProg::ostream_iterable_impl(os,t,"[","]",", ");
}
template<class T> std::ostream& operator<<(std::ostream &os,const std::set<T> &t){
    return compProg::ostream_iterable_impl(os,t,"{","}",", ");
}
template<class T> std::ostream& operator<<(std::ostream &os,const std::multiset<T> &t){
    return compProg::ostream_iterable_impl(os,t,"{","}",", ");
}

// begin library
// end library

int main() {
    std::ios::sync_with_stdio(false);

    LLI N, i;
    std::cin >> N >> i;
    std::cout << N - i + 1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]
if 2*c[0][2]-c[1][2]-c[2][2]+c[1][0]+c[2][0] == 2*c[0][0]:
  if 2*c[1][0]-c[2][0]-c[0][0]+c[2][1]+c[0][1] == 2*c[1][1]:
    if 2*c[2][1]-c[0][1]-c[1][1]+c[0][2]+c[1][2] == 2*c[2][2]:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 9220
//#include <bits/stdc++.h>
//#define endl '\n'
//using namespace std;
//typedef long long ll;
//typedef long double ld;
////typedef __int128 bll;
//const int maxn = 1e3 + 100;
//const int mod = 1e9+7;
//const ll inf = 1e9;
//
//ll n,m;
//char str[maxn][maxn];
//
//
//int main()
//{
//	ios::sync_with_stdio(false);
//	cin.tie(0),cout.tie(0);
//	
//	cin >> n >> m;
//	for(ll i = 1; i <= n; i++)
//	{
//		cin >> str[i]+1;
//	}
//	
//	ll q;
//	cin >> q;
//	while(q--)
//	{
//		ll x1,y1,x2,y2;
//		cin >> x1 >> y1 >> x2 >> y2;
//		
//		
//		
//		
//	}
//	
//	
//	
//	
//	
//	
//	
//	
//	return 0;
//}
//


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef __int128 bll;
const int maxn = 1e3 + 100;
const int mod = 1e9+7;
const ll inf = 1e18;




int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	
	ll n;
	cin >> n;
	
	ll ans = inf;
	for(ll i = 1; i < sqrt(n); i++)
	{
		ll t1 = i,t2 = n/i;
		
		if(t1*t2 == n)
		{
			ans = min(ans,t1+t2-2);
		}
	}
	
	ll t1 = sqrt(n);
	if(t1*t1 == n)
	{
		ans = min(ans,t1+t1-2);
	}
	
	cout << ans << endl;
	
	
	
	
	
	return 0;
}



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

using namespace std;
string s;
int n;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i]+n > 90) cout << (char)(s[i]+n-26);
        else cout << (char)(s[i]+n);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int p,q,r;
  cin >> p >> q >> r;
  cout << min({p+q,q+r,r+p}) << endl;
  return 0;
}

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

int main(){
    string s; cin >> s;
    int sum = 0;
    int len = s.length();
    if(len == 1) {cout << s[0] << endl; return 0;}
    for(int i = 1; i < len; i++){
        if(s[i] == '9') continue;
        else {cout << (len-1)*9 + (s[0]-'0'-1) << endl; return 0;}
    }
    cout << (len-1)*9 + (s[0]-'0') << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  int p, n, m;
  std::vector<int> vec;
  std::cin >> n >> m;

  for(int i = 0; i<n; i++){
    std::cin >> p;
    vec.push_back(p);
  }

  int sum = std::accumulate(vec.begin(), vec.end(), 0);
  //int thr = sum / (4 * m);
  std::sort(vec.begin(), vec.end(), std::greater<int>() );
  int count = 0;

  for(int i = 0; i<m; i++){
    //if(thr <= vec[i]){
    if(vec[i] * (4 * m) >= sum){
      count += 1;
    }
  }
  if(count >= m){
    std::cout << "Yes" <<std::endl;
  }else{
    std::cout << "No" <<std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  string s;
  cin >> s;
  map<char, int> mp;
  rep (i, s.size()) {
    auto itr = mp.find(s[i]);
    if (itr != mp.end()) mp[s[i]]++;
    else mp[s[i]] = 1;
  }

  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    if (itr->second != 2) {
      No;
      return 0;
    }
  }
  Yes;
  return 0;

}

Measured memory_bytes: 256
from collections import Counter

def solve(n, V):
    if len(set(V)) == 1:
        return n // 2
    return min(
        n - oc - ec
        for o, oc in Counter(V[0::2]).most_common(2)
        for e, ec in Counter(V[1::2]).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))


Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){
  int n;
  cin>>n;
  int ans=INF;
  for(int i=1;i<n;i++){
    int a=i,b=n-i;
    int sum=0;
    while(a){
      sum+=a%10;
      a/=10;
    }
    while(b){
      sum+=b%10;
      b/=10;
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn dfs(
    cur: usize,
    parent: usize,
    graph: &Vec<Vec<usize>>,
    color: &mut Vec<i32>,
    parents: &mut Vec<Option<usize>>,
) {
    for &to in graph[cur].iter() {
        if to == parent {
            continue;
        }
        color[to] = -1 * color[cur];
        parents[to] = Some(cur);
        dfs(to, cur, graph, color, parents);
    }
}

fn main() {
    let n = read::<usize>();
    let mut graph = vec![vec![]; n];
    for i in 0..n - 1 {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut color = vec![0; n];
    color[0] = 1;
    let mut parents = vec![vec![None; n]; 3];
    dfs(0, 0, &graph, &mut color, &mut parents[0]);
    let ones = color.iter().filter(|&&x| x == 1).count();
    let minus = n - ones;

    let mut residuals = vec![vec![]; 3];
    for i in 1..n + 1 {
        residuals[i % 3].push(i);
    }

    let mut assign = vec![0; n];
    if ones <= n / 3 || minus <= n / 3 {
        let three_color = if ones <= n / 3 { 1 } else { -1 };

        let mut pointer = [0; 3];
        for i in 0..n {
            if color[i] == three_color {
                assign[i] = residuals[0][pointer[0]];
                pointer[0] += 1;
            }
        }
        for i in 0..n {
            if color[i] != three_color {
                'inner: for pi in 0..3 {
                    if pointer[pi] < residuals[pi].len() {
                        assign[i] = residuals[pi][pointer[pi]];
                        pointer[pi] += 1;
                        break 'inner;
                    }
                }
                assert!(assign[i] != 0);
            }
        }
    } else {
        let mut pointer = [0; 3];
        for i in 0..n {
            let ci = if color[i] == 1 { 1 } else { 2 };
            if pointer[ci] < residuals[ci].len() {
                assign[i] = residuals[ci][pointer[ci]];
                pointer[ci] += 1;
            } else {
                assign[i] = residuals[0][pointer[0]];
                pointer[0] += 1;
            }
        }
    }
    for ans in assign {
        print!("{} ", ans);
    }
    println!("");
}

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()
}


Measured memory_bytes: 42492
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int mtoi(string m) {
	const string mcxi = "mcxi";
	const int mcxiK[] = {1000, 100, 10, 1};
	int res = 0;
	int index, x;

	for (int i = 0; i < 4; i++) {
		x = 1;
		index = m.find(mcxi[i], 0);
		if (index != string::npos) {
			if (index != 0) {
				x = m[index - 1] - '0';
				if (x >= 10) {
					x = 1;
				}
			}
			res += mcxiK[i] * x;
		}
	}

	return res;
}

string itom(int integer) {
	const string mcxi = "mcxi";
	const int mcxiK[] = {1000, 100, 10, 1};
	string res("");
	int x;

	for (int i = 0; i < 4; i++) {
		x = integer / mcxiK[i];
		if (x != 0) {
			if (x != 1) {
				res += x + '0';
			}
			res += mcxi[i];
		}
		integer %= mcxiK[i];
	}
	
	return res;
}

int main(void) {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string m1, m2;
		cin >> m1 >> m2;
		
		int sum = mtoi(m1) + mtoi(m2);

		cout << itom(sum) << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    string S;cin>>S;
    if(S.size()%2!=0){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<S.size();i+=2){
        if(S[i]=='h'&&S[i+1]=='i')continue;
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
const
f:array[1..11,1..5] of longint=((4,2,0,9,7),
                               (1,10,8,6,4),
                               (9,7,5,3,1),
                               (6,4,2,0,9),
                               (3,1,10,8,6),
                               (0,9,7,5,3),
                               (8,6,4,2,0),
                               (5,3,1,10,8),
                               (2,0,9,7,5),
                               (10,8,6,4,2),
                               (7,5,3,1,10));
var
n,k,s,p,i,j:longint;
begin
readln(n,k);
n:=n-2;
p:=n mod 11;
n:=n div 11;
s:=n*5;
if n<=2 then
  for i:=1 to p do
    for j:=1 to 5 do
      if f[i,j]=k then inc(s)
        else begin end
          else
            for i:=1 to p do
              for j:=1 to 5 do
                if f[i,j]=k then inc(s);
writeln(s);
end.

Measured memory_bytes: 128
import java.util.Scanner;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ss = String.valueOf(s.charAt(0)) + (s.length()-2) + String.valueOf(s.charAt(s.length()-1)); 
		System.out.println(ss);
	}
}


Measured memory_bytes: 22996
#include <iostream>
using namespace std;
long long int n,a[5000];
int main(){
	long long int i,j,t,tmp;
	while(cin >> n && n){
		tmp = 0;
		t = -1000000;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n;i++){
			tmp += a[i];
			if(t < tmp) t = tmp;
			if(i!=n-1){
				for(j=i+1;j<n;j++){
					tmp += a[j];
					if(t < tmp) t = tmp;
				}
			}
			tmp = 0;
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<bits/stdc++.h> 
#include<string>
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define IN insert
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define NL cout<<endl
#define ll long long int
#define ld long double
#define vl vector<ll>
#define sl set<ll>
#define ml map<ll,ll>
#define sc set<char>
#define li list<ll>
#define vp vector<pair<ll, ll> >
#define vs vector<string>
#define ss set<string>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define REPIT(it,a) for(auto it=a.begin();it!=a.end();it++)
#define N (ll)pow(2,32)-1
#define mod (ll)1000000007
using namespace std;
vl f;
void sieve(ll m){
  REP(i,1,sqrt(m)+1){
    if(m%i==0){
      f.PB(i);
      if(m/i!=i)
       f.PB(m/i);
    }
  }
}
int main()
{

ios::sync_with_stdio(0);
cin.tie(0);
ll t=1;
//cin>>t;
while(t--){
 string s,t,a=""; cin>>s>>t; a+=t; a+=s; cout<<a<<endl; 
 }
return 0; 
}

Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# たぶんマンハッタン距離使うやつ
N =  int(sys.stdin.readline())
L =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]

current = [0, 0, 0]
for l in L:
    if l[0] < abs(current[1] - l[1]) + abs(current[2] - l[2]):
        print("No")
        exit()
    if (l[0] - current[0]) % 2 != (abs(current[1] - l[1]) + abs(current[2] - l[2])) % 2:
        print("No")
        exit()
    current = l[:]
print("Yes")

Measured memory_bytes: 82136
s = input()
ans = 0;ls = ['A','T','G','C'];o = 0
for i in range(len(s)):
    check = False
    for j in range(4):
        if ls[j] == s[i]:check = True
    if check:ans += 1
    else:
        ans = 0
    o = max(ans,o)
print(o)

Measured memory_bytes: 38384
import sys
def parse_base10_to_basen(x, n):
    if (int(x/n)):
        return parse_base10_to_basen(int(x/n), n) + str(x%n)
    return str(x%n)

sys.setrecursionlimit(10000)
n, k = map(int, input().split())

a = parse_base10_to_basen(n, k)
print(len(a))

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
from collections import *

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()[:-1]
T = input()[:-1]
U, D, L, R = 0, H-1, 0, W-1

for i in range(N-1, -1, -1):
    if T[i]=='U':
        D = min(H-1, D+1)
    elif T[i]=='D':
        U = max(0, U-1)
    elif T[i]=='L':
        R = min(W-1, R+1)
    else:
        L = max(0, L-1)
    
    if S[i]=='U':
        U += 1
    elif S[i]=='D':
        D -= 1
    elif S[i]=='L':
        L += 1
    else:
        R -= 1
    
    if U>D or L>R:
        print('NO')
        exit()

if U<=sr-1<=D and L<=sc-1<=R:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 75064
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int a, b, h, m;
    cin>>a>>b>>h>>m;

    long double cosA;
    if((1.0 / 30.0 * M_PI * m) < (1.0 / 360.0 * M_PI * (60 * h + m))) cosA = cos((1.0 / 360.0 * M_PI * (60 * h + m)) - (1.0 / 30.0 * M_PI * m));
    else cosA = cos((1.0 / 30.0 * M_PI * m) - (1.0 / 360.0 * M_PI * (60 * h + m)));
   
    long double c = (a * a) + (b * b) - (2.0 * a * b * cosA);
    cout<<fixed<<setprecision(20)<<sqrtl(c)<<endl;
    return 0;
}

Measured memory_bytes: 4164
groupcheck::Int->Int->String
groupcheck x y 
    |elem x a && elem y a = "Yes"
    |elem x b && elem y b = "Yes"
    |elem x c && elem y c = "Yes"
    |otherwise = "No"
    where
        a = [1,3,5,7,8,10,12]
        b = [4,6,9,11]
        c = [2]

main::IO ()
main = do
    [a,b] <- map read . words <$> getLine::IO[Int]
    putStrLn $ groupcheck a b


Measured memory_bytes: 508
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

k = input_n
a, b = input_a
flag = 0
(a..b).each do |num|
  if num % k == 0
    puts "OK"
    exit
  end
end
puts "NG"


Measured memory_bytes: 14296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String inp = br.readLine();
			String chr[] = in.split(" ");
			String s[] = inp.split("");
			int n = Integer.parseInt(chr[0]);
			int k = Integer.parseInt(chr[1]);
			String ans ="";
			for(int i =0; i<n;i++) {
				if(i==k-1) {
					s[i]=s[i].toLowerCase();
				}
				ans+=s[i];
			}
			 System.out.println(ans);
		}
	}
}

Measured memory_bytes: 25464
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> G(N,vector<ll>(N, LINF));
    REP(i,M){
        int a, b;
        ll d;
        cin >> a >> b >> d;
        G[a][b] = d;
    }
    vector<vector<ll>> dp(N, vector<ll>(1<<N,LINF));
    dp[0][0] = 0;
    for(int i=1;i<(1<<N);i++){
        REP(j,N) if(i >> j & 1){
            REP(k,N) if(G[j][k] != LINF){
                ll cost = dp[j][i-(1<<j)] + G[j][k];
                chmin(dp[k][i],cost);
            }
        }
    }
    if(dp[0][(1<<N) - 1] == LINF) cout << -1 << endl;
    else cout << dp[0][(1<<N)-1] << endl;
}


Measured memory_bytes: 7028
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,p;
  while(cin>>n>>p,n||p){
    vector<int>pe(n,0);
    int ba=p;
    int i=0;
    while(1){
      if(ba){
	pe[i]++;
	ba--;
      }
      else {
	ba=pe[i];
	pe[i]=0;
      }
      if(pe[i]==p)break;
      i++;
      if(i==n)i=0;
    }
    cout<<i<<endl;
  }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define modulo 1000000007
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int main() {
	ll n;
	cin >> n;
	vector<ll> d(n);
	for(int i=0;i<n;i++) cin >> d[i];

	sort(d.begin(),d.end());
	
	int ans(0);
	ll k1 = d[n/2-1];
	ll k2 = d[n/2];
	
	if(k1!=k2){
		ans = k2-k1;
	}

	cout << ans << endl;

	return 0;
}



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

int main()
{
    long long k,n;
    cin>>k>>n;
    long long sum=0;
    while(n--)
    {
        long long a;
        cin>>a;
        sum+=a;
    }
    if(k-sum<0)cout<<-1<<endl;
    else cout<<k-sum<<endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    int c[3][3];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }

    bool flg=false;
    for(int a1=-100;a1<=100;a1++){
        int b1 = c[0][0] - a1;
        int b2 = c[0][1] - a1;
        int b3 = c[0][2] - a1;
        int a2 = c[1][0] - b1;
        int a3 = c[2][0] - b1;

        if(a2+b2==c[1][1]
        && a2+b3==c[1][2]
        && a3+b2==c[2][1]
        && a3+b3==c[2][2]
        ){
            flg=true;
            break;
        }
    }
    Yes(flg)
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,m,i,sum=0;
    cin>>n>>m;
    for(i=1;i<n;i++)
    {
        sum=sum+n-i;
    }
    for(i=1;i<m;i++)
    {
        sum=sum+m-i;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main() {
	int a,b,c,temp;
	cin>>a>>b>>c;
	int cnt;
	if(a>b) temp=a,a=b,b=temp;
	if(b>c) temp=b,b=c,c=temp;
	if(a>b) temp=a,a=b,b=temp;//小->大
	cnt+=(c-b)/2+(c-b)%2;
	cnt+=(c-a)/2+(c-a)%2;
	if((c-b)%2==1&&(c-a)%2==1) {
		cnt-=1;
	}
	if((b-a)%2==1) {
		cnt+=1;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    while(N){
        vector<int> Haccum(N+1),Waccum(M+1);
        rep(i,1,N+1){
            int h;
            cin >> h;
            Haccum[i] = Haccum[i-1] + h;
        }
        rep(i,1,M+1){
            int w;
            cin >> w;
            Waccum[i] = Waccum[i-1] + w;
        }
        map<int,int> mp;
        rep(i,0,M){
            rep(j,i+1,M+1){
                mp[Waccum[j] - Waccum[i]]++;
                //cout << i << " " << j << " " << Waccum[j] - Waccum[i] << endl;
            }
        }
        ll cnt = 0;
        rep(i,0,N){
            rep(j,i+1,N+1){
                int num = Haccum[j] - Haccum[i];
                cnt += mp[num];
            }
        }
        cout << cnt << endl;
        cin >> N >> M;
    }
}


Measured memory_bytes: 20936
n,m=map(int,input().split())
h=list(map(int,input().split()))
ans=[1]*n
for i in range(m):
  ab=list(map(int,input().split()))
  if h[ab[0]-1]==h[ab[1]-1]:
    ans[ab[0]-1],ans[ab[1]-1]=0,0
  elif h[ab[0]-1]<h[ab[1]-1]:
    ans[ab[0]-1]=0
  elif h[ab[0]-1]>h[ab[1]-1]:
    ans[ab[1]-1]=0
print(sum(ans))

Measured memory_bytes: 20116
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<algorithm>
#include<deque>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 80100;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline int getint2() {
	int pn = 1;
	if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
	int A = ct - '0';
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return pn * A;
}

ll dat[10200];
bool yatta[5000];
int P[5000], C[5000];

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


	fread(cn, 1, cm, stdin);

	int N = getint(), K = getint();
	rep(i, N) P[i] = getint() - 1;
	rep(i, N) C[i] = getint2();

	ll kotae = -2e18;
	rep(i, N) if (!yatta[i]) {
		int L = 0;
		auto kari = dat;
		kari[0] = 0;
		int j = i;
		while (!yatta[j]) {
			yatta[j] = 1;
			kari[L + 1] = kari[L] + C[j];
			L++;
			j = P[j];
		}
		ll hue = kari[L];
		for (int j = L + 1; j <= L + L; j++) {
			kari[j] = kari[j - L] + hue;
		}
		ll amari = K % L;
		ll wari = K / L;
		if (hue > 0) {
			if (amari > 0) {
				deque<int> dq;
				rep1(i, L + amari - 1) {
					while (dq.size() && kari[dq.back()] <= kari[i]) dq.pop_back();
					dq.push_back(i);
					if (i < amari) continue;
					while (dq.size() && dq.front() <= i - amari) dq.pop_front();
					chmax(kotae, hue * wari + kari[dq.front()] - kari[i - amari]);
				}
			}			
			if (wari > 0) {
				deque<int> dq;
				rep1(i, L + L - amari - 1) {
					while (dq.size() && kari[dq.back()] <= kari[i + amari]) dq.pop_back();
					dq.push_back(i + amari);
					if (i < L - amari) continue;
					while (dq.size() && dq.front() <= i + amari - L) dq.pop_front();
					chmax(kotae, hue * (wari - 1) + kari[dq.front()] - kari[i + amari - L]);
				}
			}
		}
		else {
			deque<int> dq;
			int are = min(K, L);
			rep1(i, L + are - 1) {
				while (dq.size() && kari[dq.back()] <= kari[i]) dq.pop_back();
				dq.push_back(i);
				if (i < are) continue;
				while (dq.size() && dq.front() <= i - are) dq.pop_front();
				chmax(kotae, kari[dq.front()] - kari[i - are]);
			}
		}
	}

	printf("%lld\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 3296
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
namespace Solve
{
	const int MAXN=200005;
	char s[MAXN];
	void work()
	{
		while(scanf("%s",s)!=EOF)
		{
			int tot=0;
			for(int i=0;s[i];i++)
				tot+=s[i]-'0';
			if(tot%9==0) printf("Yes\n");
			else printf("No\n");
		}
		return;
	}
}
int main()
{
	#ifdef LOCAL
	freopen("00test.in","r",stdin);
	freopen("00test.out","w",stdout);
	#endif
	Solve::work(); 
	return 0;
}

Measured memory_bytes: 3872
#include<bits/stdc++.h>
#define sr register short
#define su unsigned short
#define r register int
#define u unsigned int
#define ll long long
#define llr register long long
#define llu unsigned long long
#define lf double
#define Lf long double
using namespace std;
int main()
{
/*#ifndef ONLINE_JUDGE 
    freopen("cpp.in","r",stdin); 
#endif*/
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    ll n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    printf("%lld",max(0ll,(n-2ll)*(b-a)+1ll));
    puts("");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] S = new int[n];
		
		for(int i = 0; i < n; i++){
			S[i] = sc.nextInt();
		}

		int q = sc.nextInt();
		int[] T = new int[q];

		for(int i = 0; i < q; i++){
			T[i] = sc.nextInt();
		}

		int low,mid,high,key,cnt = 0;

		for(int i = 0;i < q;i++){
			low = 0;
			high = n - 1;
			key = T[i];
			while(low <= high){
				mid = (low + high) / 2;
				if(S[mid] == key){
					cnt++;
					break;
				} else if(S[mid] < key){
					low = mid + 1;
				} else if(S[mid] > key) {
					high = mid - 1;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 13000
#include <stdio.h>
 
int main(void){
	int H,W;
	int i,f;
	for(;;){
	scanf("%d%d",&H,&W);
	if(H==0&&W==0)break;
	for(f=0;f<H;f++){
	for(i=0;i<W;i++){
	if(f==0||f==H-1||i==0||i==W-1){
	printf("#");
	}else{
	printf(".");
	}
	}
	printf("\n");
	}
	printf("\n");
	}
    return 0;
}


Measured memory_bytes: 2056
N, A, B, C, D = map(int, input().split())
S = "." + input() + "."

def move_b():
  i = B
  keep_next_to_lock = (S[i+1] == "#" or S[i-1] == "#")
  while i != D:
    if S[i+1] == ".":
      i += 1
      keep_next_to_lock = keep_next_to_lock & (S[i+1] == "#" or S[i-1] == "#")
    elif S[i+1] == "#" and S[i+2] ==".":
      i += 2
    else:
      return False
  return True and not (keep_next_to_lock and D < C)

def check_a_b():
  for i in range(A, B-1):
    if S[i+1] == "#" and S[i+2] == "#":
      return False
  return True

if move_b() and check_a_b():
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3636