akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if((a==1&&b==2)||(a==2&&b==1))
    {
        printf("3\n");
    }
    else if((a==1&&b==3)||(a==3&&b==1))
    {
        printf("2\n");
    }
    else
    {
        printf("1\n");
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
//{{{ templates
#define TMPINL_(...) template<__VA_ARGS__>inline
#define TT_ TMPINL_(typename T)
#define TTF_ TMPINL_(typename T,typename F)
#define TTTS_ TMPINL_(typename T,typename...Ts)
#define TITS_ TMPINL_(size_t I=0,typename...Ts)
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TITS_ typename enable_if<I==tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t));}
TITS_ typename enable_if<I<tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t))+s+join<I+1>(s,t);}
TT_ string join(string s,T t){return to_string(t);}
TTTS_ string join(string s,T t,Ts...ts){return join(s,t)+s+join(s,ts...);}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
inline int puts(const string&s){ return puts(s.c_str()); }
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;

int main()
{
  ll way[128][128];
  for (int i = 0; i < 128; i++){
    for (int j = 0; j < 128; j++){
      way[i][j] = 1ll << 60;
    }
  }
  for (int i = 0; i < 128; i++) way[i][i] = 0;

  int V, E;
  V = in(), E = in();
  for (int i = 0; i < E; i++){
    int s, t, d;
    s = in(), t = in(), d = in();
    way[s][t] = d;
  }
  for (int k = 0; k < V; k++){
    for (int i = 0; i < V; i++){
      for (int j = 0; j < V; j++){
        way[i][j] = min(way[i][j], way[i][k] + way[k][j]);
      }
    }
  }
  for (int i = 0; i < V; i++){
    if (way[i][i] < 0){
      puts("NEGATIVE CYCLE");
      return 0;
    }
  }
  for (int i = 0; i < V; i++){
    for (int j = 0; j < V; j++){
      if (way[i][j] >= (1ll << 59)) cout << "INF";
      else cout << way[i][j];
      if (j == V - 1) cout << "\n";
      else cout << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 1324
def nextn(n):
    if n == 0:
        return 3
    elif n % 10 == 3:
        return n+2
    elif n % 10== 5:
        return n+2
    elif n % 10 ==7:
        return nextn(n//10)*10 + 3

N = int(input())
n = 357
ans = 0
while n <= N:
    s = str(n)
    a = [False,False,False]
    for c in s:
        if c == '3':
            a[0] = True
        elif c == '5':
            a[1] = True
        elif c == '7':
            a[2] = True
        else:
            print(s)
    if all(a):
        ans += 1
    n = nextn(n) 
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

long long lcm(long long x, long long y) {
  return x / gcd(x, y) * y;
}

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

  long long l = 1;
  for (int i = 0; i < n; i++) {
    long long t;
    cin >> t;
    l = lcm(l, t);
  }

  cout << l << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define ull unsigned long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char s[4];
    for(int i = 0; i < 4; ++i){
        cin >> s[i];
    }

    int first = (int)(s[0]-'0')*10+(s[1]-'0');
    int second = (int)(s[2]-'0')*10+(s[3]-'0');

    if(first == 0 || first > 12){
        if(second == 0 || second > 12) cout << "NA" << "\n";
        else cout << "YYMM" << "\n";
    }else{
        if(second == 0 || second > 12) cout << "MMYY" << "\n";
        else cout << "AMBIGUOUS" << "\n";
    }
}

Measured memory_bytes: 256
#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,m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i,n) {   
        cin >> a[i];
        sum += a[i];
    }
    int ans = 0;
    double lim = (double)sum/4.0/m;
    rep(i,n){
        if((double)a[i] >= lim) ans++;
    }
    if(ans >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>

using namespace std;

int main(){
  
  int a,b,c,d,e,k;
  
  cin >> a >> b >> c >> d >> e >> k;
  
  if((e-a)>k){
    cout << ":(";
  }else{
  cout <<"Yay!";
  }

return 0;
}

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

int findmax(map<int, int>mp, long long x, long long maxi)
{
	long long totalscore = 0;
	long long ct = 0;

	while (totalscore < maxi)
	{
		int y = mp[x];
		totalscore += y;
		ct++;
	}
	return ct;
}

int main(int argc, char const *argv[])
{

#if !ONLINE_JUDGE

	freopen("in1.txt", "r", stdin);
	freopen("out1.txt", "w" , stdout);

#endif

	string s1;
	cin >> s1;


	int i = 0;
	int zx = s1.size() - 1;

	while (i < s1.size() and s1[i] != 'A')
	{
		i++;
	}
	while (zx >= 0 and s1[zx] != 'Z')
	{
		zx--;
	}

	cout << zx - i + 1 << endl;





	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[100005][2];
bool flag[100005];
vector<ll>g[100005];

void f(ll now,ll root){
    if(flag[now])return;
    flag[now]=true;
    dp[now][0]=1;
    dp[now][1]=1;
    for(ll i=0;i<g[now].size();i++){
        ll next = g[now][i];
        if(next==root)continue;
        f(next,now);
        dp[now][0]=dp[now][0]*(dp[next][0]+dp[next][1]);
        dp[now][0]=dp[now][0]%mod;
        dp[now][1]=dp[now][1]*dp[next][0];
        dp[now][1]=dp[now][1]%mod;
    }
}
 
int main(void){
    ll n;
    cin>>n;
    for(ll i=0;i<n-1;i++){
        ll x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    f(1,-1);
    //for(ll i=1;i<=n;i++)cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    cout<<(dp[1][0]+dp[1][1])%mod<<endl;
	return 0; 
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

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

ll n,cou;
int str[1111];
ll nijou[1111];

bool dfs(int keta,int now,int fir,int sec){
	
	if(keta == now){
		cou++;
		if(n == cou)return true;
		else return false;
	}
	
	if(fir == -1){
		for(int i = 1;i < 10;i++){
			str[now] = i;
			if(dfs(keta,now+1,i,sec))return true;
		}
	}
	else if(sec == -1){
		REP(i,10){
			if(i == fir){
				if(now + 1 < keta){
					str[now] = fir;
					if(dfs(keta,now+1,fir,sec))return true;
				}
			}
			else{
				str[now] = i;
				if(dfs(keta,now+1,fir,i))return true;
			}
		}
	}
	else{
		if(cou + nijou[keta - now] < n){
			cou += nijou[keta - now];
			return false;
		}
		
		str[now] = min(fir,sec);
		if(dfs(keta,now+1,fir,sec))return true;
		str[now] = max(fir,sec);
		if(dfs(keta,now+1,fir,sec))return true;
	}
	return false;
}

int main(){
	
	nijou[0] = 1;
	REP(i,1110)nijou[i+1] = nijou[i] * 2LL;

	while(cin >> n,n){
		cou = 0;
		
		for(int i = 2;i < 10000;i++){
			if(dfs(i,0,-1,-1)){
				REP(j,i){
					cout << str[j];
				}
				cout << endl;
				break;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int n,a;
priority_queue<int>q;
inline int gcd(int a,int b){return (a%b==0?b:gcd(b,a%b));}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a,q.push(a);
	while(q.size()>=2)
	{
		int x=q.top();q.pop();
		int y=q.top();q.pop();
		q.push(gcd(x,y));
	}
	cout<<q.top();
	return 0;
}

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

using namespace std;

bool is_palin(int a)
{
	stringstream ss;
	string s;
	ss << a;
	ss >> s;
	
	int n = s.length();
	for (int i = 0; i < n / 2 + 1; i++){
		// cout << s[i] << " " << s[n - i - 1] << endl;
		if (s[i] != s[n - i - 1]) return false;
	}

	return true;
}

int main(void)
{
	int x;
	cin >> x;

	int nmin = x, nmax = x;
	while (1){
		if (is_palin(nmin)){
			cout << nmin << endl;
			break;
		}
		if (is_palin(nmax)){
			cout << nmax << endl;
			break;
		}
		nmin--;
		nmax++;
	}

	return 0;
}

Measured memory_bytes: 1220
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

    a = int(input())

    print(a + a**2 + a**3)


if __name__ == '__main__':
    main()


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

#define int long long
using namespace std;


signed main() {
  int n, m; cin >> n >> m;
  while(m--) {
    int x; cin >> x;
    n -= x;
  }
  if(n >= 0) {
    cout << n << endl;
  }
  else cout << -1 << endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int x,n;
	cin>>x>>n;
	int arr[n];
	int mark[102]={0};
	for(int i=0;i<n;i++){
		cin>>arr[i];
		mark[arr[i]]=1;
	}
	int minimum=100;
	int ans=0;
	for(int i=0;i<102;i++){
		if(mark[i]==0){
			int fake=abs(x-i);
			if(fake<=minimum){
				if(fake<minimum){
					minimum=fake;
					ans=i;
				}
				if(fake==minimum&&i<ans)
				{
					ans=i;
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3576
import sys
readline = sys.stdin.readline
X,Y,Z,K = map(int, readline().split())
a = sorted(list(map(int, readline().split())), reverse=True)
b = sorted(list(map(int, readline().split())), reverse=True)
c = sorted(list(map(int, readline().split())), reverse=True)

ab = []
for ai in a:
    for bj in b:
        ab.append(ai+bj)
ab.sort(reverse=True)
ab = ab[:K]
cond = []
for abi in ab:
    for cj in c:
        cond.append(abi+cj)
cond = sorted(cond, reverse=True)[:K]
for condi in cond:
    print(condi)


Measured memory_bytes: 148204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if (s.size()!=6)
	{
		cout<<"No";
		return 0;
	}
	if (s[2]==s[3]&&s[4]==s[5]) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define MAX_N 100
#define MAX_T 100
using namespace std;

double mbg(int N, int T, int L, int B, int Lose[], int Back[]) {
	int t;
	double p_goal = 0;
	double ways[MAX_T + 2][MAX_N + 1] = { { 0 } };

	t = 0;
	ways[0][0] = 1.0;
	while (t < T) {
		for (int i = 0; i < N; ++i) {
			for (int j = 1; j <= 6; ++j) {
				if ((i + j) <= N) {
					for (int k = 0; k < L; ++k) {
						if ((i + j) == Lose[k]) {
							ways[t + 2][i + j] += ways[t][i] / 6;
							goto escape1;
						}
					}
					for (int k = 0; k < B; ++k) {
						if ((i + j) == Back[k]) {
							ways[t + 1][0] += ways[t][i] / 6;
							goto escape1;
						}
					}
					ways[t + 1][i + j] += ways[t][i] / 6;
				escape1:;
				}
				else{
					for (int k = 0; k < L; ++k) {
						if ((2 * N - (i + j)) == Lose[k]) {
							ways[t + 2][2 * N - (i + j)] += ways[t][i] / 6;
							goto escape2;
						}
					}
					for (int k = 0; k < B; ++k) {
						if ((2 * N - (i + j)) == Back[k]) {
							ways[t + 1][0] += ways[t][i] / 6;
							goto escape2;
						}
					}
					ways[t + 1][2 * N - (i + j)] += ways[t][i] / 6;
				escape2:;
				}
			}
		}
		t++;
	}

	for (int i = 1; i <= T; ++i) {
		p_goal += ways[i][N];
	}
	return p_goal;
}

int main() {
	int N, T, L, B;
	while (1) {
		int *Lose, *Back;
		Lose = new int[MAX_N]; Back = new int[MAX_N];
		cin >> N >> T >> L >> B;
		if (N == 0 && T == 0 && L == 0 && B == 0) break;
		for (int i = 0; i < L; ++i) cin >> Lose[i];
		for (int i = 0; i < B; ++i) cin >> Back[i];
		printf("%.6f\n", mbg(N, T, L, B, Lose, Back));
		delete[] Lose; delete[] Back;
	}
	return 0;
}

Measured memory_bytes: 1304
#include<stdio.h>
int A,B;
void game(int a,int b)
{
  if(a==b)
    {
      A+=a;
      B+=b;
    }
  else if(a>b) A+=a+b;
  else B+=a+b;
}
int main()
{
  int a,b,c,i;

  while(1)
    {
      scanf("%d",&c);
      if(c==0)return 0;

      A=0;
      B=0;

      for(i=0;i<c;i++)
	{
	  scanf("%d%d",&a,&b);
	  game(a,b);
	}
      printf("%d %d\n",A,B);
    }
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    int cnt=0;
    int n=s.size();
    for(int i=0;i<(n/2);i++)
    {
        if(s[i]!=s[n-1-i])cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int h[n+1];
  for(int i=1;i<=n;i++)
  {
    cin>>h[i];
  }
  int k=0;
  for(int i=2;i<=n;i++)
  {
    int c=0;
    for(int j=1;j<i;j++)
    {
       if(h[j]>h[i])
       {
         c++;
       }
    }
    if(c==0)
      k++;
  }
  cout<<k+1;
  return 0;
}
      
         

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

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

    int n;
    cin >> n;
    vector<int> V(n);
    REP(i, n) cin >> V[i];

    unordered_map<int, int> mp[2];
    REP(i, n) mp[i%2][V[i]]++;
    
    vector<pair<int, int>> P[2];
    REP(i, 2){
        mp[i][0] = 0;
        for(auto x : mp[i]){
            P[i].push_back({x.second, x.first});
        }
        sort(P[i].rbegin(), P[i].rend());
    }
    
    int ans = 0;
    if(P[0][0].second != P[1][0].second){
        ans = (n/2 - P[0][0].first) + (n/2 - P[1][0].first);
    }else{
        if(P[0][1].first >= P[1][1].first){
            ans = (n/2 - P[0][1].first) + (n/2 - P[1][0].first);
        }else{
            ans = (n/2 - P[0][0].first) + (n/2 - P[1][1].first);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5908
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

std::vector<long long> binomial_coefficient(long long N){
    std::vector<long long> fac;
    std::vector<long long> facIE;
    std::vector<long long> comb;
    for(int i=0;i<=N;i++){
        if(i==0){
            fac.push_back(1);
        }else{
            fac.push_back(i*fac[i-1]%MOD);
        }
    }
    for(int i=0;i<=N;i++){
        long long r=1,b=fac[i],e=MOD-2;
        while(e){
            if(e&1){
                r=(r*b)%MOD;
            }
            b=(b*b)%MOD;
            e >>=1;
        }
        facIE.push_back(r);
    }
    for(int i=0;i<=N;i++){
        long long r=fac[N];
        r = (r*facIE[i])%MOD;
        r = (r*facIE[N-i])%MOD;
        comb.push_back(r);
    }
    return comb;
}

signed main(void){
    int N,K;
    cin >> N >> K;
    vector<int> G = binomial_coefficient(N);
    vector<int> H = binomial_coefficient(N-1);
    int Ans=0;
    REP(i,min(N-1,K)+1){
        int num = G[i]*H[i];num%=MOD;
        Ans+=num;Ans%=MOD;
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
int n;
ll s[maxn],a[maxn];
bool solve(int i) {
	int pos=i,l,r,mid,res;
	ll ans=s[pos];
	while (pos<n) {
		l=pos,r=n;
		while (l<=r) {
			mid=(l+r)/2;
			if (a[mid]<=ans*2) res=mid,l=mid+1;
			else r=mid-1;
		}
		if (res==pos) return 0;
		ans+=s[res]-s[pos]; pos=res;
	}
	return 1;
}
int main() {
//	freopen("1.txt","r",stdin);
	read(n); int l=1,r=n,res,mid;
	for (int i=1;i<=n;i++) read(a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
	while (l<=r) {
		mid=(l+r)/2;
		if (solve(mid)) res=mid,r=mid-1;
		else l=mid+1;
	} printf("%d\n",n-res+1);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N,K; cin>>N>>K;
  ll x[N]; CINA(x,N);
  ll r = -1;
  for(int i=0;i<=N-K;++i){
    ll left = x[i];
    ll right = x[i+K-1];
    if(left<=0 && right<=0){right=0;}
    else if(left>=0 && right>=0){left=0;}
    ll a = abs(left);
    ll b = abs(right);
    ll temp = a+b+min(a,b);
    if(r==-1 || temp<r ){ r = temp;}
    
  }
  cout << r;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
using namespace std;

struct MyStruct
{
	char name[11];
	int time;
};

int main() {

	int n, q;
	scanf("%d%d", &n, &q);
	
	const int MAX = n + 10;
	MyStruct *queue = new MyStruct[MAX];
	int head = 0, tail = 0;

	for (int i = 0; i < n; i++)	{
		MyStruct temp;
		scanf("%s%d", temp.name, &temp.time);
		queue[tail++] = temp;
	}

	int sum = 0;
	while (tail != head) {

		MyStruct temp = queue[head];
		if (temp.time > q) {
			temp.time -= q;
			sum += q;
			queue[tail] = temp;
			tail = (tail + 1) % MAX;
		}
		else {
			sum += temp.time;
			cout << temp.name << " " << sum << endl;
		}
		head = (head + 1) % MAX;
	}
	delete[] queue;
	return 0;
}



Measured memory_bytes: 3576
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set> 
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{int n,a=0,b1=0,b2=0;
 cin>>n;
 int s[n+1];
 memset (s,0,sizeof(s));
 for (int i=1;i<=n;i++){
 cin>>s[i];
 a+=s[i];
 }

 if (a%10!=0){
 cout<<a; 
 system("pause");
 return 0;}
 for (int i=1;i<=n;i++){
 if ((a-s[i])%10==0)
 {continue;} 
 else{b2=b1;
 if (a-s[i]>b2)
 b1=a-s[i];
 else
 b1=b1;}}
 cout<<b1;
 
 
 
 
 system("pause");
 return 0;  
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define N 10000
vector<int> par(N);
vector<int> ranks(N);

void init(int n)
{
  int i;
  rep(i,n)
  {
    par[i]=i;
    ranks[i]=0;
  }
}

int find(int x)
{
  if(par[x]==x)return x;
  else return par[x] = find(par[x]);
}

void unite(int x, int y)
{
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(ranks[x]<ranks[y])par[x]=y;
  else
  {
    par[y]=x;
    if(ranks[x]==ranks[y])ranks[x]++;
  }
}

bool same(int x, int y)
{
  return find(x) == find(y);
}

int main()
{
  int v,e;cin>>v>>e;
  vector<int> s(e);
  vector<int> t(e);
  vector<int> w(e);
  int i;
  rep(i,e)cin>>s[i]>>t[i]>>w[i];
  vector<pair<int,int>> w_ind(e);
  rep(i,e)w_ind[i]=make_pair(w[i],i);
  sort(all(w_ind));
  init(v);
  int ans=0;
  rep(i,e)
  {
    int ind=w_ind[i].second;
    if(!same(s[ind],t[ind]))
    {
      unite(s[ind],t[ind]);
      ans+=w_ind[i].first;
    }
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 4956
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)

Measured memory_bytes: 60588
import java.util.*;

public class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long d=sc.nextLong();
		
		long[] x=new long[n];
		long[] y=new long[n];
		int count=0;
		for(int i=0;i<n;i++){
			x[i]=sc.nextLong();
			y[i]=sc.nextLong();
		}
		
		for(int i=0;i<n;i++){
			long num=x[i]*x[i]+y[i]*y[i];
			if(num<=d*d)count++;
		}
		System.out.println(count);
		sc.close();
		return;
	}
}

Measured memory_bytes: 62468
c=[0,2,5,5,4,5,6,3,7,6];N,M=gets.split.map &:to_i;A=gets.split.map &:to_i;d=Array.new(N+1,p);d[0]=0;0.upto(N){|i|q=A.map{|x|c[x]<=i&&d[t=i-c[x]]?d[t]*10+x:p}.compact;q.any?&&d[i]=q.max};p d[N]

Measured memory_bytes: 36220
try:
    data = []
    while True:
        data.append(raw_input())

except EOFError:
    pass

for i in data:
    x, y = i.split()
    a, b = int(x), int(y)
    for j in range(1, 8): 
        if (a + b) / (10 ** j) < 1:
            print j
            break

Measured memory_bytes: 4220
n = int(input())
s = input()
eng = list("abcdefghijklmnopqrstuvwxyz")
ans = 0
for i in range(1, n):
  count = 0
  t = list(s[:i:])
  u = list(s[i::])
  for j in range(26):
    if (eng[j] in t) and (eng[j] in u) :
      count += 1
  ans = max(count, ans)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(int i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const int N=1e5+7;
const int INF=1e9+7;
char s[N];
int a[N],d[N];

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(s[n]!='0'){printf("-1\n"); return 0;}
	rep(i,n)a[i]=s[i]-'0';
	rep(i,n-1)if(a[i]^a[n-i]){printf("-1\n"); return 0;}
	if(!a[1]){printf("-1\n"); return 0;}
	a[n]=1;
	for(int i=n;i;i--){
		if(a[i])d[i]=i;
		else d[i]=max(d[i],d[i+1]);
	}
	rep(i,n-1){
		if(!a[i])printf("%d %d\n",i,d[i]);
		else printf("%d %d\n",i,d[i+1]);
	}
	return 0;
}


Measured memory_bytes: 2304
n = int(input())

res = [0] * n
for s in range(1, 101):
    for t in range(1, 101):
        for u in range(1, 101):
            temp = (s + t) ** 2 + (s + u) ** 2 + (t + u) ** 2
            if temp > 2 * n:break
            if temp %2 == 0:
                res[temp//2 - 1] += 1

for i in range(n):
    print(res[i])

Measured memory_bytes: 9136
import Data.List

choice n d =
  let c = dropWhile (<= n) d
  in
    if c == []
    then (0,d)
    else
      let n'= head c
          d'= filter (/= n') d
      in
        (n',d')

play ta n a b = 
  let (n',a') = choice n a
  in
    if a' == []
    then if ta
         then [length b, 0]
         else [0, length b]
    else play (not ta) n' b a'

ans' n a =
  let b = [1..2*n] \\ a
  in
    play True 0 a b

ans (0:_) = []
ans (n:x) =
  let a = (sort . take n) x
      r = drop n x
  in
    (ans' n a):(ans r)

main = do
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = concat $ ans i
  mapM_ print o

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

int main(){
  int n, expensive, sum = 0;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++)
  {
    cin >> p.at(i);
    sum += p.at(i);
    if (i == 0) {
      expensive = p.at(i);
    }
    else if (expensive < p.at(i)) {
      expensive = p.at(i);
    }
    
  }
  cout << sum - expensive/2 << endl;
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	map<ll, map<ll, ll>> dic;

	ll N, a, b,cnt=0;
	std::cin >> N;

	vll x(N), y(N);
	rep(i, 0, N) {
		std::cin >> x[i] >> y[i];
	}

	rep(i, 0, N - 1) {
		rep(j, i + 1, N) {
			a = x[i] - x[j];
			b = y[i] - y[j];
			if (a < 0) {
				a *= -1;
				b *= -1;
			}
			else if (a == 0 && b < 0) {
				b *= -1;
			}
			else if (b == 0 && a < 0) {
				a *= -1;
			}
			dic[a][b]++;
			cnt = max(cnt, dic[a][b]);

		}
	}

	std::cout << N - cnt << endl;
	return 0;
}


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


int main() 
{
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    int ans = b[0] + b[n - 1 - 1];
    rep(i,n-2)
    {
        ans += min(b[i], b[i+1]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
w = int(input())
n = int(input())
lst = [i for i in range(1, w+1)]
for i in range(n) :
    a, b = map(int, input().split(','))
    lst[a-1], lst[b-1] = lst[b-1], lst[a-1]
for i in lst :
    print(i)


Measured memory_bytes: 5596
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, point[2] = {0};
	char taro[101], hanako[101];
	int i, f;

	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%s %s", taro, hanako);
		f = strcmp(taro, hanako);

		if(f > 0)
			point[0]+=3;
		else if(f == 0){
			point[0]++;
			point[1]++;
		}
		else
			point[1]+=3;
	}

		printf("%d %d\n", point[0], point[1]);

	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,sum=0;
	cin>>a>>b>>c;
	if(a!=b)
	{
		sum++;
	}
	if(a!=c)
	{
		sum++;
	}
	if(b!=c)
	{
		sum++;
	}
	if(a==b && a==c)
	{
		cout<<"1";
		return 0;
	}
	cout<<sum;
 	return 0;
}


Measured memory_bytes: 256
using System;

namespace abc174
{
    class Program
    {
        static void Main(string[] args)
        {
            var buf=Console.ReadLine().Trim().Split();
            int N=int.Parse(buf[0]);
            int D=int.Parse(buf[1]);
            decimal d2=(decimal)D*(decimal)D;

            int res=0;
            for(int i=0;i<N;i++){
                buf=Console.ReadLine().Trim().Split();
                int x=int.Parse(buf[0]);
                int y=int.Parse(buf[1]);
                decimal dist2=(decimal)x*(decimal)x+(decimal)y*(decimal)y;
                if(dist2<=d2) res++;
            }
            Console.WriteLine(res);

        }
    }
}


Measured memory_bytes: 40392
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 410000;

int n,N,a[maxn];

int main()
{
	scanf("%d",&n); N=3*n;
	for(int i=1;i<=N;i++) scanf("%d",&a[i]);
	sort(a+1,a+N+1);
	
	ll sum=0;
	for(int i=n+1;i<=N;i+=2) sum+=(ll)a[i];
	printf("%lld\n",sum);
	
	return 0;
}


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

typedef unsigned long long ll;

ll combination(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main() {
    int N;
    cin >> N;
    map<string, ll> freq;
    string str;
    for(int i = 0; i < N; i++) {
        cin >> str;
        sort(str.begin(), str.end());
        freq[str]++;
    }

    // cout << "loaded" << endl;
    ll ans = 0;
    for(pair<string, ll> p : freq) {
        if(p.second >= 2) {
            // cout << p.first << ":" << p.second << endl;
            ans += combination(p.second, 2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ull INF = 1e15;

int main(){
    
    long double a, b;
    cin >> a >> b;

    ull ans;
    ans = a*b;

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

Measured memory_bytes: 3808
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

long[] make_lucas()
{
    long[] ls = [2,1];
    for (int i = 2; i < 87; ++i) {
        ls ~= ls[i-1] + ls[i-2];
    }
    return ls;
}

enum LS = make_lucas();

void main()
{
    writeln(LS[readln.chomp.to!int]);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>  
using namespace std;
int w,k,r;
int main(){
	while(1){
		cin>>w>>k>>r;
		if(w==-1&&k==-1&&r==-1){
		break;}
		if(w==-1){cout<<"F"<<endl;}else
		if(k==-1){cout<<"F"<<endl;}else
		if(w+k>=80){cout<<"A"<<endl;}else
		if(w+k>=65){cout<<"B"<<endl;}else
	    if(w+k>=50){cout<<"C"<<endl;}else
	    if(w+k<30){cout<<"F"<<endl;}else
			if(r>=50){cout<<"C"<<endl;}else{
			cout<<"D"<<endl;}}
return 0;}


Measured memory_bytes: 1152
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	int n=s.size();
	if(s.size()%2)
	{
		string t=s;
		reverse(all(t));
		if(s==t)
		{
			string k,kr;
			k=s.substr(0,(n-1)/2);
			kr=k;
			reverse(all(kr));
			bool ans=(kr==k);
			k=s.substr((n+3)/2-1);
			kr=k;
			reverse(all(k));
			ans=ans && (kr==k);
			if(ans)
			{
				cout<<"Yes";
			}
			else cout<<"No";
		}
		else {
			cout<<"No";
		}
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n;
	int i;
	
	for(;;)
	{
		cin >> n ;
		if(n==-1)
			break;
		
		int ans=0;
		
		if(n>=30)
		{
			ans+=(n-30)*160;
			ans+=1400;
			ans+=1250;
			ans+=1150;
		}
		else if(n>=20)
		{
			ans+=(n-20)*140;
			ans+=1250;
			ans+=1150;
		}
		else if(n>=10)
		{
			ans+=(n-10)*125;
			ans+=1150;
		}
		else
			ans=1150;
		cout << 4280-ans << endl;
	}
}

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

signed main(){
    int n;cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    int cnt[n+1][22];
    rep(i,n+1)rep(j,22)cnt[i][j] = 0;
    
    rep(i,n){
        rep(j,22)if(a[i]>>j&1)cnt[i+1][j]++;
        rep(j,22)cnt[i+1][j]+=cnt[i][j];

    }
    int ans = 0;
    rep(i,n){
        int l = i;
        int bot = l-1,top = n;
        while(top - bot > 1){
            int mid = (top+bot)/2;
            auto ok = [&](int x){
                int mx = 0;
                rep(j,22)mx = max(mx,cnt[mid+1][j] - cnt[l][j]);
                return mx <= 1;
                

            };
            if(ok(mid))bot = mid;
            else top = mid;

        }
        ans += top - l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 36224
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;


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

	for (int i = 1; i <= n; i++) {
		int count = 0;
		for (int x = 1; x <= 100; x++) {
			if (x * x  > i) break;
			for (int y = 1; y <= 100; y++) {
				if (x * x + y * y + x * y > i) break;
				for(int z = 1; z <= 100; z++) {
					int ans = x * x + y * y + z * z + x * y + y * z + z * x;
					if (ans == i) count++;
					if (ans >= i) break;
						
				}
			}
		}
		cout << count << endl;
	}


	return 0;
}


Measured memory_bytes: 3256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define in(x) cin >> x
#define inv(x)                                                                 \for (auto &t : (x)) cin >> t
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define outv(x)                                                                \
  for (auto &t : (x))                                                          \
  out((x))
#define outsv(x)                                                               \for (auto &t : (x)) outs((x))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i++)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(n)-1; i < (int)(x); i++)
#define sz(x) ((int)(x).size())
#define sz(x) ((int)(x).size())
#define inf 1e9
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = int64_t;
ll Main();
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

ll Main() {
  string s;
  in(s);
  int count = 0;
  for (size_t i = 0; i < 3; i++) {
    if (s[i] == '1') {
      count++;
    }
  }

  out(count);

  return 0;
}


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

int N;
const int MAX_N = 310;

int A[MAX_N][MAX_N];
int B[MAX_N][MAX_N];
int main(){

	scanf("%d",&N);

	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			scanf("%d",&A[i][j]);
			B[i][j]=1e9;
			if(i==j)B[i][j]=0;
		}
	}


	long long ans = 0;

	for(int i=1;i<=N;i++){
		for(int j=i+1;j<=N;j++){
			int X=1e9+1;
			for(int k=1;k<=N;k++){
				if(k==i||k==j)continue;
				X=min(X,A[i][k]+A[k][j]);
			}
			if(X>A[i][j]){
				B[i][j]=A[i][j];
				B[j][i]=B[i][j];
				ans+=A[i][j];
			}
			else if(X<A[i][j]){
				puts("-1");
				return 0;
			}
		}
	}

	for(int k=1;k<=N;k++){
		for(int i=1;i<=N;i++){
			for(int j=1;j<=N;j++){
				B[i][j]=min(B[i][j],B[i][k]+B[k][j]);
			}
		}
	}

	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			if(A[i][j]!=B[i][j]){
				puts("-1");
				return 0;
			}
		}
	}

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

}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define rep(i, a, N) for(int i = a; i < N; i++)
#define rrep(i, a, N) for(int i = a; i >= N; i--)

const int inf = 1000000000;

//#define DEBUG

int main() {
    int a[3][3];
    int c[3][3];
    rep(i, 0, 3) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        c[i][0] = 0;
        c[i][1] = 0;
        c[i][2] = 0;
    }
    int n;
    cin >> n;
    rep(i, 0, n) {
        int b;
        cin >> b;
        rep(x, 0, 3) {
            rep(y, 0, 3) {
                if (a[x][y] == b) {
                    c[x][y] = 1;
                }
            }
        }
    }

    bool ans = false;
    rep(i, 0, 3) {
        if (c[i][0] * c[i][1] * c[i][2] == 1) ans = true;
        if (c[0][i] * c[1][i] * c[2][i] == 1) ans = true;
    }
    if (c[0][0] * c[1][1] * c[2][2] == 1) ans = true;
    if (c[2][0] * c[1][1] * c[0][2] == 1) ans = true;

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

    #ifdef DEBUG
    rep(x, 0, 3) {
        rep(y, 0, 3) {
            cout << c[x][y];
        }
        cout << endl;
    }
    #endif
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>

typedef long long int64;

int main(void) {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> ps;

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

  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += ps.at(i);
  }

  int max = sum;
  for (int i = 1; i < n - k + 1; i++) {
    sum = sum - ps.at(i - 1) + ps.at(i + k - 1);
    max = std::max(sum, max);
  }

  double ans = (double)(max + k) / 2;
  printf("%.12f\n", ans);

  return 0;
}


Measured memory_bytes: 1400
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

ll sign(ll n) {
  return n < 0 ? -1 : n == 0 ? 0 : 1;
}

void solve() {
  ll T1, T2; cin >> T1 >> T2;
  ll A1, A2, B1, B2; cin >> A1 >> A2 >> B1 >> B2;
  ll X1 = T1 * A1 + T2 * A2, X2 = T1 * B1 + T2 * B2;
  ll v1 = A1 - B1, v2 = A2 - B2;
  if (v1 < 0) {
    v1 *= -1;
    v2 *= -1;
  }
  ll up = v1 * T1;
  ll down = v2 * T2;
  ll d = up + down;
  if (sign(v1) == sign(v2)) {
    cout << 0 << endl;
    return;
  }
  if (d == 0) {
    cout << "infinity" << endl;
    return;
  }
  if (abs(up) > abs(down)) {
    cout << 0 << endl;
    return;
  }
  ll t = up / (-d);
  ll ans = t * 2 + 1;
  if (up % (-d) == 0) {
    --ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
aMin = 30
for i in a:
    aCnt = 0
    while n > 0:
        if i % 2 != 1:
            aCnt += 1
            i /= 2
        else:
            break
    if aCnt < aMin:
        aMin = aCnt
print(aMin)


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

int main(){
    int k, a, b;
    cin >> k;
    cin >> a >> b;
    int i;
    bool c = false;
    for(i=a; i<b+1; i++){
        if(i%k==0){
            c = true;
        }
    } 
    if(c){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vi v(m);
	REP(i, m) {
		cin >> v[i];
		v[i]--;
	}
	sort(ALL(v));
	vi cnt = { 2,5,5,4,5,6,3,7,6 };
	vvi dp(m + 1, vi(n + 1, -INF));
	dp[0][0] = 0;
	REP(i, m) {
		REP(j, n + 1) {
			dp[i + 1] = dp[i];
		}
		REP(j, n + 1) {
			if (j + cnt[v[i]] <= n) {
				chmax(dp[i + 1][j + cnt[v[i]]], dp[i + 1][j] + 1);
			}
		}
	}
	int d = dp[m][n];
	int tmp = n;
	string res;
	RREP(i, m) {
		while (tmp >= cnt[v[i]] && dp[i + 1][tmp - cnt[v[i]]] == d - 1) {
			res += '1' + v[i];
			d--;
			tmp -= cnt[v[i]];
		}
	}
	cout << res << endl;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int test;
	long long int sum = 0;
	cin >> test;
	for (int i = 1; i <= test; ++i){
	if (!(i % 3 == 0 || i % 5 == 0)) sum += i;
	}
	cout << sum << "\n";	
	return 0;
}


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

int main(){
    int N;

    int ans = 0;

    std::cin >> N;
    vector<int> V(N), C(N);

    for(int i = 0; i < N; i++){
        std::cin >> V[i];
    }
    for(int i = 0; i < N; i++){
        std::cin >> C[i];
    }

    for(int i = 0; i < N; i++){
        if(V[i] - C[i] > 0){
            ans = ans + V[i] - C[i];
        }
    }

    std::cout << ans;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];
    sort(ALL(p), greater<int>());
    sort(ALL(q), greater<int>());
    sort(ALL(r), greater<int>());

    vector<int> ans;
    rep(i, x) ans.push_back(p[i]);
    rep(i, y) ans.push_back(q[i]);
    sort(ALL(ans));
    int rcnt = 0;
    int n = min(c, (int)ans.size());
    rep(i, n) {
        if(r[rcnt] >= ans[i]) {
            ans[i] = r[rcnt];
            rcnt++;
        } else break;
    }
    ll res = 0;
    for(auto x : ans) res += x;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5464
#include<cstdio>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    char s[n+1];
    scanf("%s", s);
    int c = 0;
    for(int i = 1; i < n; i++){
        if (s[i] == 'E') c++;
    }
    // printf("%d\n", c);
    int c_min = c;
    for(int i = 1; i < n; i++){
        if (s[i-1] == 'W'){
            c++;
        }
        if (s[i] == 'E'){
            c--;
        }
        if (c_min > c) {
            c_min = c;
        }
        
    }
    printf("%d\n", c_min);
}

Measured memory_bytes: 512