akhauriyash/Code-Regression huggingface dataset:
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]
xs = [int(sys.stdin.readline()) for i in range(Q)]
for x in xs:
    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: 16128
#include <stdio.h>
 
int main()
{
  int n[3], max, other;
  int i;
  scanf("%d%d%d", n+0, n+1, n+2);
  other = n[0] + n[1] + n[2];
  max = n[0];
  if ( max < n[1] ) max = n[1];
  if ( max < n[2] ) max = n[2];
  other -= max;
  if ( max == other ) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int N, D;
    cin >> N >> D;
    long X[N], Y[N];
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
    int num = 0;
    for (int i = 0; i < N; i++) {
        if (D >= sqrt(X[i] * X[i] + Y[i] * Y[i])) num += 1;
    }
    cout << num << endl;
}

Measured memory_bytes: 6800
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

const int mod = 998244353;
enum{N=3023};

ll f[N];
int main(){
	int n=ci(), s=ci();
	ll ans = 0;
	rep(i,1,n){
		int x=ci();
		if( x>s ) continue;
		ans = (ans+(n-i+1)*(f[s-x]+(x==s?i:0)))%mod;
		rev_rep(j,s,x) f[j] = (f[j]+f[j-x])%mod;
		f[x] = (f[x]+i)%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 128
n=int(input())
F=[list(map(int,input().split())) for i in range(n)]
P=[list(map(int,input().split())) for i in range(n)]
ans=-10**9
for i in range(1,2**10):
  tmp=0
  for j in range(n):
    cnt=0
    f=F[j]
    p=P[j]
    for k in range(10):
      if (i>>k)&1:
        cnt+= 1 if f[k] else 0
    tmp+=p[cnt]
  ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b,x,y,z,i;
    z=0;
    scanf("%d%d",&a,&b);
    for(i=1;i<=10000;i++)
    {
        x=a-b;
        if(x<=0)
        {
                printf("%d\n",i);
                break;
        }
      a=x;
    }



    return 0;
}


Measured memory_bytes: 128
class ModInt(x: Long) {

    companion object {
        const val MOD = 1e9.toLong() + 7
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { ModInt(it.toLong()) }

    fun f(n: ModInt): ModInt {
        var x = ModInt(1L)
        for (l in 2L..n.x) x *= ModInt(l)
        return x
    }

    val ans = when {
        n == m -> f(n) * f(m) * ModInt(2L)
        Math.abs(n.x - m.x) == 1L -> f(n) * f(m)
        else -> ModInt(0L)
    }

    println(ans)
}


Measured memory_bytes: 40560
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e20;

signed main(){
    int N,K;cin>>N>>K;
    vector<int>A(N);
    REP(i,N) cin>>A[i];
    sort(A.rbegin(),A.rend());
    int ans=0;
    REP(i,K){
        ans+=A[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
signed main(){
    int k,a,b,memo=1,yen=0;
    cin>>k>>a>>b;
    if(b==1){
        cout<<k+1<<endl;
        return 0;
    }
    k-=a-memo;
    memo=a;
    int i=1;
    while(1){
        if(i*(2+max(0ll,a-b))>k)break;
        if(memo+(b-a)*i<memo+i*(2+max(0ll,a-b)))break;
        i++;
    }
    i--;
    cout<<memo+(b-a)*i+k-i*(2+max(0ll,a-b))<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a, b = [], []
for _ in range(n):
    i, j = map(int, input().split())
    a.append(i)
    b.append(j)

a.sort()
b.sort()

if n % 2 == 1:
    mi = a[n // 2]
    ma = b[n // 2]
    print(ma - mi + 1)
    exit()

mi = a[n // 2 - 1] + a[n // 2]
ma = b[n // 2 - 1] + b[n // 2]
print(ma - mi + 1)

Measured memory_bytes: 25476
from collections import deque

N = int(input())

u = [None] * (N - 1)
v = [None] * (N - 1)
w = [None] * (N - 1)
for i in range(N - 1):
    uvw = input().split()
    u[i], v[i], w[i] = int(uvw[0]) - 1, int(uvw[1]) - 1, int(uvw[2])

# adjacency List + distance
# AL[i] = [(j, distance between i and j): j is a neighbor of i]
AL = [[] for _ in range(N)]

for i in range(N - 1):
    AL[u[i]].append((v[i], w[i]))
    AL[v[i]].append((u[i], w[i]))

color = [0] + [-1] * (N - 1) # vertex iの頂点の色 0/1
visited = [False] * N      # vertex iに訪問済みならTrue、まだならFalse
que = deque()   # 探索候補キュー
que.append(0) # vertex 0をキューに追加

while(len(que) > 0):
    current = que.popleft()
    visited[current] = True
    for next, dist in AL[current]:
        if not visited[next]:
            que.append(next)
            if dist % 2 == 0:  # 距離が偶数
                color[next] = color[current]
            else:
                color[next] = 1 - color[current]

for i in range(N):
    print(color[i])


Measured memory_bytes: 79704
S = input()
yes = 0;
if S[0] == S[1]:
  if S[2] == S[3]:
    if S[1] != S[2]:
      yes = 1
elif S[0] == S[2]:
  if S[1] == S[3]:
    if S[1] != S[2]:
      yes = 1
elif S[0] == S[3]:
  if S[1] == S[2]:
    if S[1] != S[0]:
      yes = 1
if yes == 1:
  print("Yes")
else:
  print("No")
  

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

int abs(int x, int y) {
  if (x < y) {
    return y-x;
  }
  else{
    return x-y;
  }
}
int main(){
  int S;
  cin >>S;
  int mae,ato;
  mae = S/100;
  ato = S%100;
  if(ato <= 12 && ato >= 1 && mae >12){
    cout << "YYMM" <<endl;
  }
  else if(ato <=12 &&ato>=1 && mae >=1 &&mae<=12  ){
    cout <<"AMBIGUOUS"<<endl;
  }
  else if(ato >12 && mae >=1 && mae <= 12 ){
    cout<<"MMYY"<<endl;
  }
  else if(mae ==0 && ato <=12 && ato>=1){
    cout<< "YYMM"<<endl;
  }
  else if(ato ==0 && mae <=12 && mae>=1){
    cout<< "MMYY"<<endl;
  }
  else{
    cout<< "NA" <<endl;
  }
}

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> d(n);
	for (auto& a : d) cin >> a;
	long long ans = 0, tmp = d[0];
	for (int i = 1; i < n; ++i) {
		ans += tmp * d[i];
        tmp += d[i];
    }
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 1; i <= n; ++i)

using namespace std;

int main() {
	string s;
	cin >> s;
	
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '?') s[i] = 'D';
	}
	
	cout << s << '\n';
	
	return 0;
}

Measured memory_bytes: 3760
def digits_sum(a)
    sum = 0
    
    while a > 0 do
        sum += a % 10
        a /= 10
    end
        
    sum
end


N = gets.to_i
p (1..N/2).inject(N){|res, i| res = [digits_sum(i) + digits_sum(N-i), res].min}

Measured memory_bytes: 1788
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int K;
    string s;
    cin >> s >> K;

    vector<string> v;
    REP(i, s.size()) {
        FOR(j, 1, K + 1) {
            string a = s.substr(i, j);
            v.push_back(a);
        }
    }
    SORT(v);
    v.erase(unique(ALL(v)), v.end());
    cout << v[K - 1] << endl;

    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std ;
template< class T > inl T read() {
	T x = 0 ; int f = 1 ; char k = getchar() ;
	for( ; k > '9' || k < '0'; k = getchar() ) if( k == '-' ) f = -1 ;
	for( ; k >= '0' && k <= '9'; k = getchar() ) x = x * 10 + k - '0' ;
	return x * f ;
}
template< class T > inl T read( T &x ) { return x = read<T>() ; }
int _num, _buf[20];
template< class T > il print( T x ) {
   	if( x == 0 ) return putchar( '0' ) ,void() ;
	if( x < 0 ) putchar( '-' ), x = -x ;
	while( x ) _buf[++_num] = x % 10, x /= 10 ;
	while( _num ) putchar( _buf[_num--] + '0' ) ;
}
ll mul( ll a, ll b, ll mod ) { long double c = 1. ; return ( a * b - (ll)( c * a * b / mod ) * mod ) % mod ; }
it qpow( int x, int m, int mod ) {
	int res = 1, bas = x ;
	while(m) {
		if( m & 1 ) res = ( 1ll * res * bas ) % mod ;
		bas = ( 1ll * bas * bas ) % mod, m >>= 1 ;
	}
	return res ;
}
const int mod = 1e9 + 7 ;
it add( int x, int y ) {
	return x + y >= mod ? x + y - mod : x + y ;
}
it mul( int x, int y ) {
	return 1ll * x * y % mod ;
}
il inc( int &x, int y ) {
	x = add( x, y ) ;
}
const int N = 2e6 + 5 ;
int n, k, fac[N], ifac[N];
char s[N];
it C( int n, int m ) {
	return mul( fac[n], mul( ifac[n - m], ifac[m] ) ) ;
}
int main() {
//	freopen( ".in", "r", stdin ) ;
//	freopen( ".out", "w", stdout ) ;
	k = read<int>(), scanf( "%s", s + 1 ) ;
	n = strlen( s + 1 ) ;
	fac[0] = 1 ;
	for( ri i = 1; i <= n + k; ++i )
		fac[i] = mul( fac[i - 1], i ) ;
	ifac[n + k] = qpow( fac[n + k], mod - 2, mod ) ;
	for( ri i = n + k - 1; i >= 0; --i )
		ifac[i] = mul( ifac[i + 1], i + 1 ) ;
	int ans = 0 ;
	for( ri i = 0; i <= k; ++i )
		inc( ans, mul( mul( C( n + i - 1, n - 1 ), qpow( 25, i, mod ) ), qpow( 26, k - i, mod ) ) ) ;
	print( ans ), puts( "" ) ;
	cerr << 1. * clock() / CLOCKS_PER_SEC << "\n" ;
	return 0;
}

Measured memory_bytes: 20408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  ll x,y;
  cin >> x >> y;
  if(x % y == 0)puts("-1");
  else cout << x << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

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

int main() {
    int N ;
    cin >> N ;
    vector<char> vec(N);
    int P=0,W=0,G=0,Y=0;
    for (char x : vec){
      cin >> x ;
      if(x=='P'){
          ++P;
      }
      else if(x=='W'){
         ++W;
      }
      else if(x=='G'){
          ++G;
      }
      else if(x=='Y'){
          ++Y;
      }
   }
   if(P>=1&&W>=1&&G>=1&&Y>=1) {
       cout <<"Four"<<endl;
   } 
   else if((P>=1&&W>=1&&G>=1)||(P>=1&&W>=1&&Y>=1)||(P>=1&&G>=1&&Y>=1)||(W>=1&&G>=1&&Y>=1)){
       cout <<"Three"<<endl;
   }   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  set<string>S;
  int N;
  cin >> N;
  for (int i = 0; i < N; i ++) {
    string k;
    cin >> k;
    S.insert(k);
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 19184
// B - Good Distance
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n, d;
	cin >> n >> d;
	vector<vector<int> > x(n, vector<int>(d));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < d; j++) cin >> x[i][j];
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++) {
			long long sum = 0;
			for (int k = 0; k < d; k++)
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			long long r = (long long) sqrt(sum + 0.5);
			if (r * r == sum) ans++;
		}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,s=0,r;
    scanf("%lld",&n);
    long long int hero[n+5],mons[n+5];
    for(i=0;i<=n;i++)
    {
        scanf("%lld",&mons[i]);
    }
    for(i=0;i<n;i++)
    {
        scanf("%lld",&hero[i]);
        if(i==0)
        {
            if(hero[i]>=mons[i]) {s=s+mons[i];
            r=hero[i]-mons[i];}
            else {
                s=s+hero[i];
                r=0;
            }
        }
        else
        {
            if(r>=mons[i]) {
                s=s+mons[i];
                r=hero[i];
            }
            else
            {
                s=s+r;
                mons[i]=mons[i]-r;
               if(hero[i]>=mons[i]) {s=s+mons[i];
            r=hero[i]-mons[i];}
            else {
                s=s+hero[i];
                r=0;
            }
            }
        }
    }
    if(r>=mons[n])
    {
        s=s+mons[n];
    }
    else
    {
        s=s+r;
    }
    printf("%lld\n",s);
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int num=s.length();
  int ans[num];
  for(int i=0; i<num; i++)ans[i]=0;
  int peo[2],flag=0;
  peo[0]=0;
  peo[1]=0;
  for(int i=0; i<num; i++){
    flag=i%2;
    if(s[i]=='R')peo[flag]++;
    else{
      ans[i]+=peo[flag];
      ans[i-1]+=peo[(flag+1)%2];
      peo[flag]=0;
      peo[(flag+1)%2]=0;
    }
  }
  for(int i=num-1; i>=0; i--){
    flag=i%2;
    if(s[i]=='L')peo[flag]++;
    else{
      ans[i]+=peo[flag];
      ans[i+1]+=peo[(flag+1)%2];
      peo[flag]=0;
      peo[(flag+1)%2]=0;
    }
  }
  for(int i=0; i<num-1; i++)cout<<ans[i]<<" ";
  cout<<ans[num-1]<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define for0(i,n) for (int i=0; i<n; i++)
#define forr(i,n) for (int i=n-1; i>=0; i--)
#define fori(i,a,b) for (int i=a; i<=b; i++)
#define iter(c,x) for(x::iterator it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define size(x) (int)(x).size()
#define read(x) int x; scanf("%d",&x);
#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<size(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

#define sgn(x) x == 0 ? 0 : (x < 0 ? -1 : 1)

using namespace std;

typedef long long ll;

const int INF = 999999999;
const long long INFL = 99999999999999999LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

ll A[100005];
ll sums[100005];

ll solve(int n, int init_sgn)
{
    ll ans = 0;
    int cur_sgn = init_sgn;
    ll csum = 0;

    for (int i=0; i<n; i++) {
        ll val = sums[i]+csum;
        pr(i) pr(cur_sgn) pr(val) nl
        prl(ans)
        if (cur_sgn == 1 && val <= 0) {
            ll moves = 1LL-val;
            ans += moves;
            csum += moves;
        }
        else if (cur_sgn == -1 && val >= 0) {
            ll moves = val-(-1);
            ans += moves;
            csum -= moves;
        }

        cur_sgn = -1*cur_sgn;
    }

    return ans;
}

int main()
{
    #ifdef DEBUG
    freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    read(n);
    for0(i,n) {
        read(x);
        A[i] = x;
        sums[i] = i == 0 ? A[i] : sums[i-1]+A[i];
    }
    //printa(A,n);
    printa(sums,n);

    ll ans1 = solve(n,1);
    ll ans2 = solve(n,-1);
    prl(ans1)
    prl(ans2)

    cout<<min(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

#インデックス付きソート
#(index,value)の順に格納
from operator import itemgetter
def index_sort(A):
    return sorted(enumerate(A),key=itemgetter(1))

ceil = math.ceil
floor = math.floor

N = I()
A = III()
B = III()

ans = float('inf')
for i in range(1<<N):
    bits = format(i,'b').zfill(N)
    last_odd_val = []
    last_even_val = []
    for j,b in enumerate(bits):
        if j%2==0:
            if b=='0':
                last_even_val.append([A[j],j])
            else:
                last_odd_val.append([B[j],j])
        else:
            if b=='0':
                last_odd_val.append([A[j],j])
            else:
                last_even_val.append([B[j],j])

    if len(last_even_val)!=ceil(N/2):
        continue

    s_odd = sorted(last_odd_val,key=lambda x:(x[0],x[1]))
    s_even = sorted(last_even_val,key=lambda x:(x[0],x[1]))
    flag = False
    eps = 10**(-2)
    for j in range(N//2):
        if floor(s_even[j][0])>floor(s_odd[j][0]):
            flag = True
            break
        if floor(s_even[j][0])==floor(s_odd[j][0]):
            s_odd[j][0] = s_even[j][0] + eps
        if len(s_even)>j+1:
            if floor(s_odd[j][0])>floor(s_even[j+1][0]):
                flag = True
                break
            if floor(s_odd[j][0])==floor(s_even[j+1][0]):
                s_even[j+1][0] = s_odd[j][0] + eps

    if flag:
        continue

    val = [0.0]*N
    for s in s_even:
        val[s[1]] = s[0]
    for s in s_odd:
        val[s[1]] = s[0]

    count = 0
    for i in range(N):
        for j in range(i+1,N):
            if val[i]>val[j]:
                count += 1
    
    if count<ans:
        ans = count

if ans == float('inf'):
    ans = -1
print(ans)

Measured memory_bytes: 65440
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if (a*500 + b*100 + c*50) == X:
                cnt+=1
print(cnt)

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

int Point( int x , int y ){
	if( x-y >  0 ) return 3;
	if( x-y == 0 ) return 1;
	if( x-y <  0 ) return 0;
}

int main(){
	
	int N;
	int team[110][2] = {};
	int a,b,c,d  ;
	
	cin >> N;
	for( int i=0 ; i<N ; i++ ){ team[i][1] = i+1 ; }
	for( int i=0 ; i<N*(N-1)/2 ; i++ ){
		cin >> a >> b >> c >> d ;
		
		team[a-1][0] += Point(c,d) ;
		team[b-1][0] += Point(d,c) ;
	}
	
	for( int i=0 ; i<N ; i++ ){
		for( int j=i+1 ; j<N ; j++ ){
			if( team[i][0] < team[j][0] ){
				swap( team[i]  ,team[j] ) ;
			}
			else if( team[i][0] == team[j][0] ){
				if( team[i][1] > team[j][1] ){
					swap( team[i] , team[j] ) ;
				}
			}
		}
	}
	
	for( int i=1 ; i<=N ; i++ ){
		int f = 0 ,cnt = 0 ,pnt=-1 ;
		for( int j=0 ; j<N ; j++ ){
			if( pnt != team[j][0] ){
				pnt = team[j][0] ;
				cnt += f+1 ; f=0 ;
			}else f++ ;
			
			if( team[j][1] == i ){
				cout << cnt << endl ;
				break ;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
double d[1003];
long long x[1003],y[1004],r[1004],v[1004];
long long inf =1000000000000000000;
long long int mod=1000000007;
long long int j=mod-2;
long long int modpow (long long int a) {
	long long int res = 1;
	j=mod-2;
	while (j > 0)
		if (j & 1) {
			res = (res * a) % mod;
			--j;
		}
		else {
			a = (a * a) % mod;
			j >>= 1;
		}
	return res %mod;
}
double dist(int l,int e)
{
    double s=x[l]-x[e];
    double q=y[l]-y[e];
    s=s*s+q*q;
    s=sqrt(s);
    return s;
}
int main()
{
    string s;
    cin>>s;
    long n=s.size();
    if(s[0]==s[n-1])
    {
        if(n%2==0)cout<<"First"<<endl;
        else cout<<"Second"<<endl;
    }
    else
    {
        if(n%2!=0)cout<<"First"<<endl;
        else cout<<"Second"<<endl;
    }

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main(){
  int n;cin>>n;ll a[100000];rep(i,n)cin>>a[i];sort(a,a+n);
  ll ans = 0;ll pre = 0;ll count = 0;
  rep(i,n){
    if(a[i] != pre){
      if(count >= pre)ans += count - pre;
      else ans += count;
      pre = a[i];count = 1;
    }else{
      count++;
    }
  }
  if(count >= pre)ans += count - pre;
  else ans += count;
  cout << ans << endl;
}


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

int main(){
  int t,s;
  cin>>t>>s;
  
  int ans=0;
  for(int i=0;i<=t;i++){
    for(int j=0;j<=t;j++){
      int z=s-i-j;
      if(t>=z&&z>=0) ans=ans+1;
    }
 
  }
 cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// Last Change: 09/10/2019 23:41:49.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

const int CSIZE = 26;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for (auto &&e : a) {
    cin >> e;
  }

  int cnt[4] = {0};
  /*
  if (H == 1 or W == 1) {
    if (H == 1 and W == 1) {
      cnt[0] = 1;
    } else {
      int tar = max(H, W);
      cnt[0] = tar % 2;
      cnt[1] = tar / 2;
    }
  } else {
    cnt[3] = H / 2 * W / 2;
    //
  }
  */

  int iptC[CSIZE] = {0};
  for (auto &&e : a) {
    for (int i = 0; i < W; ++i) {
      ++iptC[e[i] - 'a'];
    }
  }

  for (int i = 0; i <= H - 1 - i; ++i) {
    for (int j = 0; j <= W - 1 - j; ++j) {
      if (i < H - 1 - i and j < W - 1 - j) {
        ++cnt[3];
      } else {
        if (i < H - 1 - i or j < W - 1 - j) {
          ++cnt[1];
        } else {
          ++cnt[0];
        }
      }
    }
  }

  /*
  if (H % 2 == 1 and W % 2 == 1) {
    cnt[0] = 1;
    cnt[1] = H / 2 + W / 2;
    cnt[3] = (H / 2) * (W / 2);
  } else if (H % 2 == 1 or W % 2 == 1) {
    cnt[0] = 0;
    cnt[3] = (H / 2) * (W / 2);
    cnt[1] = (H * W - cnt[3] * 4) / 2;
  } else {
    cnt[0] = 0;
    cnt[1] = 0;
    cnt[3] = (H / 2) * (W / 2);
  }

  for (int i = 0; i < 4; ++i) {
    cout << cnt[i] << ' ';
  }
  cout << endl;
  */

  for (int i = 0; i < CSIZE; ++i) {
    if (iptC[i] / 4 >= cnt[3]) {
      iptC[i] -= cnt[3] * 4;
      cnt[3] = 0;
      break;
    } else {
      cnt[3] -= iptC[i] / 4;
      iptC[i] %= 4;
    }
  }
  for (int i = 0; i < CSIZE; ++i) {
    if (iptC[i] / 2 >= cnt[1]) {
      iptC[i] -= cnt[1] * 2;
      cnt[1] = 0;
      break;
    } else {
      cnt[1] -= iptC[i] / 2;
      iptC[i] %= 2;
    }
  }
  for (int i = 0; i < CSIZE; ++i) {
    if (iptC[i] >= cnt[0]) {
      iptC[i] -= cnt[0];
      cnt[0] = 0;
      break;
    } else {
      cnt[0] -= iptC[i];
    }
  }

  string ans = "Yes";
  for (int i = 0; i < 4; ++i) {
    if (cnt[i] > 0) {
      ans = "No";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
fn main() {
    let (H, W) = read_two::<u64>();
    if H == 1 || W == 1 {
        println!("1");
        return;
    }
    println!("{}", (H * W + 1) / 2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<vector<int>> g(N);
		for(int i=0;i<M;i++){
			int a, b; cin >> a >> b;
			--a; --b;
			g[a].push_back(b);
			g[b].push_back(a);
		}
		int Q; cin >> Q;
		vector<int> v(Q), d(Q), c(Q);
		for(int i=0;i<Q;i++){
			cin >> v[i] >> d[i] >> c[i];
			--v[i];
		}
		vector<int> color(N, 0);
		vector<int> time(N, -1);

		auto paint = [&](int pos, int t, int col){
			if(t < time[pos]) return;
			color[pos] = col;
			time[pos] = t;
		};

		for(int checkDist=0;checkDist<=10;checkDist++){
			vector<int> dist(N, 11);
			for(int i=Q-1;i>=0;i--){
				if(d[i] != checkDist) continue;
				if(dist[v[i]] == 0) continue;
				paint(v[i], i, c[i]);
				queue<int> qu; qu.push(v[i]);
				dist[v[i]] = 0;
				while(!qu.empty()){
					int p = qu.front(); qu.pop();
					if(dist[p] == checkDist) continue;
					for(auto next : g[p]){
						if(dist[next] <= dist[p] + 1) continue;
						dist[next] = dist[p] + 1;
						paint(next, i, c[i]);
						qu.push(next);
					}
				}
			}
		}
		for(auto res : color) cout << res << endl;
	}
}


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

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

  if(N/10==0){
    cout<<N<<endl;
  }
  else if(N/100==0){
    cout<<9<<endl;
  }
  else if(N/1000==0){
    cout<<N-90<<endl;
  }
  else if(N/10000==0){
    cout<<909<<endl;
  }
  else if(N/100000==0){
    cout<<N-9090<<endl;
  }
  else{
    cout<<90909<<endl;
  }
             
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int R, G;
    cin >> R >> G;
    cout << 2 * G - R << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    # 標準入力を取得
    N, M = list(map(int, input().split()))
    k, s = [], []
    for m in range(M):
        l = list(map(int, input().split()))
        k_m, s_m = l[0], l[1:]
        k.append(k_m)
        s.append(s_m)
    p = list(map(int, input().split()))

    return N, M, k, s, p


def lights_on(M: int, s: list, p: list, switches: int) -> bool:
    """
    電球がすべて点灯しているかどうかを確認する.

    Args:\n
        M (int): 電球の数
        s (list): 電球に対応するスイッチ
        p (list): スイッチと電球の点灯の関係
        switches (int): スイッチの状態

    Returns:\n
        bool: 電球がすべて点灯していれば真、そうでなければ偽
    """
    result = True
    for m in range(M):
        switch_on_count = 0
        for s_m_km in s[m]:
            if switches & (1 << (s_m_km - 1)):
                switch_on_count += 1
        if switch_on_count % 2 != p[m]:
            result = False

    return result


def main(N: int, M: int, s: list, p: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): スイッチの数
        M (int): 電球の数
        s (list): 電球に対応するスイッチ
        p (list): スイッチと電球の点灯の関係
    """
    # 求解処理
    ans = 0
    for switches in range(1 << N):
        if lights_on(M, s, p, switches):
            ans += 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, M, k, s, p = get_input()

    # メイン処理
    main(N, M, s, p)


Measured memory_bytes: 9252
import heapq
n = int(input())

vn = [int(i) for i in input().split()]
heapq.heapify(vn)

for i in range(n-1):
  a = heapq.heappop(vn)
  b = heapq.heappop(vn)
  heapq.heappush(vn, (a+b)/2)
  
h = heapq.heappop(vn)
print(h)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,d;
  cin >> n >> d;
  
  int s = 2 * d + 1;
  int a =  n / s;
  if (n%s>0) {
    a=a+1;
  }
  cout << a;
  
}

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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define all(x) x.begin(),x.end()

const int INF=INT_MAX;
const ld PI=acos(-1);//3.1415926535897932384626433
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
    vi bfsParetns=bfsParents(adj,src);
    vi ans;
    while(src!=dst){
        if(bfsParetns[src]==INF)
            return {};
        ans.push_back(src);
        src=bfsParetns[src];
    }
    return ans;
}
int powMod(int base,int exp,int mod){
    //(base^exp) %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}
int gcd(int a,int b){
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}

ld log (ld a,ld b){return log(b)/log(a);}
ll power(ll base, ll exp){
    ll res=1;
    while(exp){
        exp--;
        res*=base;
    }
    return res;
}
void solve();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}
void solve (){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << "\n";
}

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



signed main() {
	int i, j;
	string s;

	cin >> s;


	bool flag = false;
	int sum = 0, tumi = 0, cntb = 0;

	for (i = 0; i < s.length(); i++) {
		if (s[i] == 'B') {
			cntb++;

		}

		if (s[i] == 'W') {
			sum += cntb;
		}
		
	}


	//for (i = 0; i < s.length(); i++) {
	//	if (s[i] == 'B')flag = true;

	//	if (flag == true) {
	//		if (s[i] == 'W') {
	//			sum += (i - tumi);
	//			tumi++;
	//		}
	//	}
	//}



	cout << sum << endl;





	getchar();
	getchar();
	return 0;
}

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

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	sort(arr,arr+n);
	int sum=0;
	for(int i=0;i<k;i++)
	{
	    sum=sum+arr[i];
	}
	cout<<sum<<endl;

}


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

#ifdef ARTEM
	#define deb(x) x
#else
	#define deb(x)
	const int LIMIT = 2 * int(1e5) + 123;
#endif

void solve();

int main() {
	solve();
}

/* ================ actual code starts here ================ */

void solve() {
	int n;
	scanf("%d", &n);

	int ans = 0;
	for(int i = 0, x; i < n; i++) {
		scanf("%d", &x);
		ans += int(!(i & 1) && (x & 1));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int mapping[256];
  mapping['I'] = 1;
  mapping['V'] = 5;
  mapping['X'] = 10;
  mapping['L'] = 50;
  mapping['C'] = 100;
  mapping['D'] = 500;
  mapping['M'] = 1000;
  string str;
  while(cin >> str){
    int n = str.size();
    vector<int> v(n);
    int ans = 0;
    REP(i,n) v[i] = mapping[str[i]];
    REP(i,n){
      if(i != n-1){
	if(v[i] < v[i+1]) ans -= v[i];
	else ans += v[i];
      }else{
	ans += v[i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
// from https://atcoder.jp/contests/abc116/submissions/4055058
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
 
bool used[100010];
int main() {
    ll n, k;
    cin >> n >> k;
    pair<ll, ll> sushi[n];
    rep(i, n) {
        ll kind, value;
        cin >> kind >> value;
        sushi[i]={value, kind};
    }
    sort(sushi,sushi + n);
    reverse(sushi,sushi + n);
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    ll sum = 0;
    ll nKinds = 0;
    rep(i, k) {
        sum += sushi[i].first;
        if (used[sushi[i].second]) {
            pq.push(sushi[i].first);
        } else {
            nKinds++;
            used[sushi[i].second] = true;
        }
    }
    ll ans = sum + nKinds * nKinds;
    for (int i=k; i<n; i++) {
        if (!used[sushi[i].second]) {
            used[sushi[i].second] = 1;
            if (pq.size() > 0) {
                ll x = pq.top(); pq.pop();
                sum += sushi[i].first - x;
                nKinds++;
                ans = max(ans, sum + nKinds * nKinds);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2556
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

# N = int(readline())
# D = [int(d) for d in readline().split()]

import itertools

N = int(readline())
A = [int(x)-1 for x in readline().split()]
B = [int(x) for x in readline().split()]
C = [int(x) for x in readline().split()]

ans = 0
ans += sum(B)
temp = 30
for i in A:
    if temp + 1 == i:
        ans += C[i-1]
    temp = i

print(ans)


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

int main() {
  int N,M;
  cin >> N>>M;
  vector <int> pn(N);
  for(int i=0;i<2*M;i++){
    int n;
    cin >> n;
    pn.at(n-1)++;
  }
  for(int i=0;i<N;i++)
    cout<<pn.at(i)<<endl;
}

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

int n;
int main(){
	cin>>n;
	long long x[101],y[101],h[101];
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>h[i];
	}
	for(long long i=0;i<=100;i++){
		for(long long j=0;j<=100;j++){
			
			
			long long  height = 0;
			for(int k=0;k<n;k++){
				if(h[k]!=0){
					height = h[k]+abs(i-x[k])+abs(j-y[k]);
					break;
				}
			}
			
//			cout<<i<<":"<<j<<":"<<height<<endl;
			int wrong=0;
			for(int k=0;k<n;k++){
//				if(max(height-abs(i-x[k])-abs(j-y[k]),0) != h[k]){
//					
//				}
				
				if(h[k] == 0 ){
					if(height > h[k]+abs(i-x[k])+abs(j-y[k])){
						wrong = 1; 
						break;
					} 
				}else{
					if(height != h[k]+abs(i-x[k])+abs(j-y[k])){
						wrong = 1; 
						break;		
					} 
				}
				
			
			}
			if(wrong){
				continue;
			}
			cout<<i<<" "<<j<<" "<<height<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:https://agc006.contest.atcoder.jp/tasks/agc006_b>
 問題文============================================================
 N 段のピラミッドがあります。 段は上から順に 1, 2, …, N と番号が振られています。
 各 1≤i≤N について、i 段目には 2i−1 個のブロックが横一列に並んでいます。
 また、各段の中央のブロックに注目すると、これらは縦一列に並んでいます。
 
 すぬけ君は N 段目のブロックに (1, 2, …, 2N−1) を並べ替えたもの（順列）を書き込みました。
 さらに、次のルールに従い、残りすべてのブロックに整数を書き込みました。
 
 あるブロックに書き込まれる整数は、そのブロックの左下、真下、右下のブロックに書き込まれた整数の中央値である。
 
 その後、すぬけ君はすべてのブロックに書き込まれた整数を消してしまいました。
 すぬけ君は、1 段目のブロックに書き込まれた整数が x であったことだけを覚えています。
 
 N 段目のブロックに書き込まれた順列としてあり得るものが存在するか判定し、存在するならばひとつ求めてください。
 =================================================================
 
 解説=============================================================
 
 x が 1 or 2*n-1 の時、必ず N-1段目で消えるので　no
 それ以外の時は全部作ることができる
 
 以下のような形を取ればいい
 
     x
    oxx
   ooxxo
  oooxxoo
 aaaaaaaaa
 
 よって、このようになるように数列を取ればいいので頑張って復元する
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int a[200010] = {0};
    int n,x; cin >> n >> x;
    if(x == 1 || x == 2*n - 1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    if(n == 2){
        cout << 1 << endl;
        cout << 2 << endl;
        cout << 3 << endl;
        return 0;
    }
    if(x == 2){
        a[n] = 2; a[n-1] = 1; a[n-2] = 3; a[n+1] = 4;
        int cnt = 5;
        for(int i = 0; i < n*2 - 1;i++){
            if(a[i] == 0) a[i] = cnt++;
        }
    }else{
        a[n] = x; a[n-1] = x+1; a[n-2] = x-1; a[n+1] = x-2;
        int used[200010] = {false};
        for(int i = x-2; i <= x+1;i++) used[i] = true;
        int cnt = 1;
        for(int i = 0; i < 2*n-1;i++){
            if(a[i] == 0){
                while(used[cnt]) cnt++;
                a[i] = cnt; used[cnt] = true;
            }
        }
    }
    for(int i = 0; i < 2*n - 1;i++){
        cout << a[i] << endl;
    }
    return 0;
}


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

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

    map<string, int> mp;

    string s;
    for(int i=0; i<n; i++) {
        cin >> s;
        if (mp.count(s) == 0) mp[s] = 1;
        else mp[s]++;
    }

    int max_count = -1;
    for(auto itr = mp.begin(); itr != mp.end(); itr++) {
        int count = itr->second;
        if (count > max_count) max_count = count;
    }

    vector<string> vec;
    for(auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->second != max_count) continue;
        else {
            vec.push_back(itr->first);
        }
    }

    sort(vec.begin(), vec.end());

    for(int i=0; i<vec.size(); i++) {
        cout << vec[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 27252
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	int s, w;
	cin >> s >> w;
	if (w >= s) cout << "un";
	cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>

typedef long long ll;

ll ms(int a[], int l, int r) {
    if (l == r) {
        return 0;
    }

    ll ret = 0;
    int mi = (l + r) / 2;
    ret += ms(a, l, mi);
    ret += ms(a, mi + 1, r);

    int t[r-l+1];
    int i1 = l, i2 = mi + 1;
    for (int i = 0; i < r - l + 1; i++) {
        if (i2 == r + 1 || i1 <= mi && a[i1] <= a[i2]) {
            t[i] = a[i1++];
            ret += r + 1 - i2;
        } else {
            t[i] = a[i2++];
        }
    }

    memcpy(a + l, t, sizeof(t));
    
    return ret;
}

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    int l = 0, r = 1e9+1;
    while (r - l > 1) {
        int m = (l + r) / 2;

        int b[n+1];
        b[0] = 0;
        for (int i = 1; i <= n; i++) {
            b[i] = (a[i-1] >= m ? 1 : -1) + b[i-1];
        }
        
        if (ms(b, 0, n) * 2 >= 1ll * (n + 1) * n / 2) {
            l = m;
        } else {
            r = m;
        }
    }

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

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;


const int MAX_V = 101;
const ll INF = 1e18;

struct Edge {
    ll to;
    ll cost;
    Edge(ll t, ll c) {
        to = t;
        cost = c;
    }
};

typedef vector<vector<Edge>> Graph;

Graph G;
vector<ll> d;
vector<int> seen;

void dfs(ll node, ll cost) {
    d[node] = cost;
    seen[node] = 1;
    rep (i, G[node].size()) {
        auto& e = G[node][i];
        if (seen[e.to] == 0) {
            dfs(e.to, e.cost + cost);
        }
    }
}

void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> L(m), R(m), D(m);
    rep(i, m) cin >> L[i] >> R[i] >> D[i];

    G.assign(n + 1, vector<Edge>());
    d.assign(n + 1, 0);
    seen.assign(n + 1, 0);
    rep(i, m) {
        G[L[i]].push_back(Edge(R[i], D[i]));
        G[R[i]].push_back(Edge(L[i], -D[i]));
    }

    rep(i, n) {
        if (seen[i] == 0) {
            dfs(i, 0);
        }
    }

    rep(i, m) {
        ll dist = d[R[i]] - d[L[i]];
        if (dist != D[i]) {
            put("No");
            return;
        }
    }

    put("Yes");
}
signed main(){ Main();return 0;}

Measured memory_bytes: 24588
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	ll n, k, q;
	cin >> n >> k >> q;

	vector<ll> b(n, k);

	for (int i = 0; i < q; i++)
	{
		ll a;
		cin >> a;

		b.at(a - 1)++;
	}

	for (int i = 0; i < n; i++)
	{
		cout << (b.at(i) - q > 0 ? "Yes" : "No") << endl;
	}
}

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

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    std::string A, B, C;
    std::cin >> A >> B >> C;
    bool done = false;
    int indexA = 0, indexB = 0, indexC = 0;
    int turn = 0; // 0 = A, 1 = B, 2 = C
    while (!done) {
        switch (turn) {
            case 0:
                if (indexA >= A.length()) {
                    done = true;
                } else {
                    turn = A[indexA] - 'a';
                    ++indexA;
                }
                break;
            case 1:
                if (indexB >= B.length()) {
                    done = true;
                } else {
                    turn = B[indexB] - 'a';
                    ++indexB;
                }
                break;
            case 2:
                if (indexC >= C.length()) {
                    done = true;
                } else {
                    turn = C[indexC] - 'a';
                    ++indexC;
                }
            default:
                break;
        }
    }
    std::cout << (turn == 0 ? 'A' : turn == 1 ? 'B' : 'C') << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<queue>
#define Max 1005
using namespace std;


vector<int>vec[Max*Max];
int map[Max][Max],indegree[Max*Max];
queue<int>q;


void init(){
	int i,j;
	for(i=0;i<Max;i++){
		for(j=0;j<Max;j++){
			map[i][j] = -1;
			
		}	
	}

	for(i=0;i<Max*Max;i++){
		indegree[i] = 0;
		
	}
}

int main(){
	
	int n,i,j,x;
	
	init();

	scanf("%d",&n);
	int node = 1,prev_node;
	for(i=1;i<=n;i++){
		for(j=0;j<n-1;j++){
			scanf("%d",&x);
			if(map[i][x] == -1){
				map[i][x] = node;
				map[x][i] = node;
				node++;
			}

			if(j>0){
				vec[prev_node].push_back(map[i][x]);
				indegree[map[i][x]]++;
			}

			prev_node = map[i][x];

		}
	}

	int day = 0;
	
	for(i=1;i<node;i++){
		if(indegree[i] == 0){
			q.push(i);
		}
	}


	int src,u,totalMatch=0;
	while(!q.empty()){
		day++;
		queue<int>sq;
		while(!q.empty()){
			src = q.front();
			q.pop();
			totalMatch++;
			for(i=0;i<vec[src].size();i++){
				indegree[vec[src][i]]--;
				if(indegree[vec[src][i]] == 0){
					sq.push(vec[src][i]);
				}
			}	
		}

		q = sq;
		

	}

	x = (n*(n-1))/2;
	if(totalMatch == x){
		printf("%d\n",day);	
	}else 
		printf("-1\n");
	

	return 0;
}

Measured memory_bytes: 47360