akhauriyash/Code-Regression huggingface dataset:
// AOJ 1595 Traffic Tree
// 2018.5.4 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) { pc('0'); return; }
	if (n < 0) pc('-'), n = -n;
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]);
	pc('\n');
}

#define INF   0x10101010
#define MAX_N 100002

typedef struct { int s, d; } QUE;
QUE que[MAX_N*2]; int top, end;
int n;
int hi[MAX_N], *to[MAX_N];
int dist_a[MAX_N], dist_b[MAX_N];

void bfs(int s, int *dist)
{
	int i, t, d;

	memset(dist, INF, n<<2);
	que[0].s = s, que[0].d = 0, dist[s] = 0, top = 0, end = 1;
	while (top != end) {
		s = que[top].s, d = que[top++].d;
		if (dist[s] < d) continue;
		for (i = 0; i < hi[s]; i++) {
			t = to[s][i];
			if (dist[t] == INF) {
				dist[t] = d+1, que[end].s = t, que[end++].d = d+1;
			}
		}
	}
}

void calc()
{
	int i, max;
	int node_a, node_b;		// 木の直径を表す２つのノード
	
	bfs(0, dist_a);
	max = 0;
	for (i = 0; i < n; i++) {
		if (dist_a[i] > max) node_a = i, max = dist_a[i];
	}

	bfs(node_a, dist_a);
	max = 0;
	for (i = 0; i < n; i++) {
		if (dist_a[i] > max) node_b = i, max = dist_a[i];
	}

	bfs(node_b, dist_b);
}

int main()
{
	int s, t, i, j, ans;
	int *memo;

	n = in();
	memo = malloc(n<<3);
	j = 0; for (i = 1; i < n; i++) {
		memo[j++] = s = in()-1;
		memo[j++] = t = in()-1;
		hi[s]++, hi[t]++;
	}
	for (i = 0; i < n; i++) if (hi[i]) to[i] = malloc(hi[i]<<2);
	memset(hi, 0, n<<2);
	j = 0; for (i = 1; i < n; i++) {
		s = memo[j++], t = memo[j++];
		to[s][hi[s]++] = t;
		to[t][hi[t]++] = s;
	}
	free(memo);

	calc();

	// (t=)辺の数*2 - (ans=)頂点iを根とした根付き木の深さ
	t = (n-1)<<1;		// tは再定義
	for (i = 0; i < n; i++) {
		ans = dist_a[i];
		if (ans < dist_b[i]) ans = dist_b[i];
		out(t-ans);
	}
	return 0;
}



Measured memory_bytes: 7788
def main():
    s = int(input())
    f = int(s/100)
    b = s%100
    
    if f > 0 and f <= 12:
        if b > 0 and b <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if b > 0 and b <= 12:
            print("YYMM")
        else:
            print("NA")

main()


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


#define int long long


#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

int N,M,S1,S2,T;
vector<pint>G[1111];

int dist[111][1111];

void solve(){
    S1--;S2--;T--;

    rep(i,N)G[i].clear();

    rep(i,M){
        int a,b;
        string s;
        cin>>a>>b>>s;
        a--;b--;

        int c;
        if(s=="x"){
            c=-1;
        }
        else{
            c=0;
            for(int j=0;j<s.size();j++)c=c*10+s[j]-'0';
        }

        G[a].pb({b,c});
        G[b].pb({a,c});
    }


    fill_n(*dist,111*1111,INF);
    dist[0][T]=0;
    priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>>que;
    que.push(make_tuple(0,T,0));
    while(que.size()){
        int c,v,k;
        tie(c,v,k)=que.top();
        que.pop();
        if(dist[k][v]>c)continue;
        for(auto &e:G[v]){
            int nc,nk;
            if(e.se==-1){
                nc=c;
                nk=k+1;
            }
            else{
                nc=c+e.se;
                nk=k;
            }

            if(nk>100||dist[nk][e.fi]<=nc)continue;
            dist[nk][e.fi]=nc;
            que.push(make_tuple(nc,e.fi,nk));
        }
    }


    vint lis;
    lis.pb(0);
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(i==j)continue;
            if(dist[i][S1]==INF||dist[j][S1]==INF)continue;
            int t=(dist[j][S1]-dist[i][S1])/(i-j);
            if(t<0)continue;

            lis.pb(t);
            lis.pb(t+1);
        }
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(i==j)continue;
            if(dist[i][S2]==INF||dist[j][S2]==INF)continue;
            int t=(dist[j][S2]-dist[i][S2])/(i-j);
            if(t<0)continue;
            lis.pb(t);
            lis.pb(t+1);
        }
    }

    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(i==j)continue;
            if(dist[i][S1]==INF||dist[j][S2]==INF)continue;
            int t=(dist[j][S2]-dist[i][S1])/(i-j);
            if(t<0)continue;
            lis.pb(t);
            lis.pb(t+1);

        }
    }

    sort(all(lis));lis.erase(unique(all(lis)),lis.end());
    int ans=LLONG_MAX;
    for(auto x:lis){
        int d1=INF,d2=INF;
        rep(i,100+1){
            chmin(d1,dist[i][S1]+i*x);
            chmin(d2,dist[i][S2]+i*x);
        }

        chmin(ans,abs(d1-d2));
    }

    cout<<ans<<endl;
}

signed main(){
    while(cin>>N>>M>>S1>>S2>>T,N||M||S1||S2||T)solve();
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> vec(n);
  for (auto &v : vec) {
    int a, b;
    cin >> a >> b;
    v = make_pair(a, b);
  }

  sort(vec.begin(), vec.end(), [](auto &lhs, auto &rhs) {
    return (lhs.first + lhs.second) > (rhs.first + rhs.second);});

  ll ans = 0;
  for (int i = 0; i < n; ++i)
    ans += i % 2 == 0 ? vec[i].first : -vec[i].second;

  cout << ans << endl;
}


Measured memory_bytes: 4012
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    ll final=-1e18;
    cin>>n;
    VV vec(n,V(10));
    rep(i,n)rep(j,10)cin>>vec[i][j];
    VV cost(n,V(11));
    rep(i,n)rep(j,11)cin>>cost[i][j];
    rep3(bit,1,(1<<10)){
        V temp(10);
        rep(i,10){
            if(bit&(1<<i)){
                temp[i]++;
            }
        }
        ll res=0;
        reverse(all(temp));
        rep(i,n){
            ll cnt=0;
            rep(j,10){
                if(temp[j]&&vec[i][j]){
                    cnt++;
                }
            }
            res+=cost[i][cnt];
        }
        chmax(final,res);
    }
    
    cout<<final<<endl;
    
}


Measured memory_bytes: 256
#C問題
N = int(input())
A = list(map(int,input().split()))
A.sort()
AMIN = A[0]
AMAX = A[-1]
anslist = []
if AMIN*AMAX < 0:
    for i in range(N-1):
        if i == 0:
            pass
        elif A[i] < 0:
            anslist.append([AMAX,A[i]])
            AMAX-=A[i]
        elif A[i] == 0:
            anslist.append([AMAX,A[i]])
        elif A[i] > 0:
            anslist.append([AMIN,A[i]])
            AMIN-=A[i]
    anslist.append([AMAX,AMIN])
    ans = (AMAX-AMIN)
elif AMIN*AMAX >= 0:
    if AMAX > 0:
        for i in range(N-1):
            if i == 0:
                pass
            elif i == 1:
                anslist.append([A[0],A[1]])
                AMIN = A[0]-A[1]
            else:
                anslist.append([AMIN,A[i]])
                AMIN-=A[i]
        anslist.append([AMAX,AMIN])
        ans = (AMAX-AMIN)
    else:
        B = []
        for i in range(N):
            B.append(-A[N-i-1])
        BMIN = B[0]
        BMAX = B[-1]
        for i in range(N-1):
            if i == 0:
                pass
            elif i == 1:
                anslist.append([-B[0],-B[1]])
                BMIN = B[0]-B[1]
            else:
                anslist.append([-BMIN,-B[i]])
                BMIN-=B[i]
        anslist.append([-BMIN,-BMAX])
        ans = (BMAX-BMIN)
        
print(ans)
for cell in anslist:
    print(cell[0],cell[1])

Measured memory_bytes: 29244
n=int(input())
a=list(map(int,input().split(' ')))
for i in range(n):
    v=a[i]
    j=i-1
    while j>=0 and a[j]>v:
        a[j+1]=a[j]
        j=j-1
    a[j+1]=v
    print(" ".join(map(str,a)))

Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define MAXN 1000

int main()
{
	int n, ch[MAXN], ans;
	char c[MAXN];
	scanf("%d",&n);
	for(int i=1; i<=n; i++) cin>>c[i];
	for(int i=1; i<=n; i++)
	{
		if(c[i]=='G') ch[1]=1;
		if(c[i]=='W') ch[2]=1;
		if(c[i]=='P') ch[3]=1;
		if(c[i]=='Y') ch[4]=1;
	}
	for(int i=1; i<=4; i++)
	if(ch[i]==1) ans++;
	if(ans==3) printf("Three");
	if(ans==4) printf("Four");
}

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    string s;
    cin>>s;
    int n = s.size();
    string pre = "";
    int p=0;
    ll ans = 0;
    string add = "";
    while(p<n){
        add+=s[p];
        p++;
        if(add!=pre){
            pre=add;
            add = "";
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define w(t) int t;cin>>t;while(t--)
#define pb   push_back
#define mk   make_pair
#define u_s  unordered_set
#define endl "\n"
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
#define ll long long int
#define ipair pair<int,int>
#define all(x) (x).begin(), (x).end()

const int mod=pow(10,9)+7;

bool compare(pair<int,int>p1,pair<int,int>p2){
    return p1.second<p2.first;
}
void open_file(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
void fast_io(){
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
      
}
/*
  ll C(ll n,ll k){
  
  if(k>n)return 0;
  
  ll ans=1;

  if(k>n-k)
    k=n-k;
  for(ll i=1;i<=k;i++)
    ans*=(n-i+1),ans/=i;

  return ans;
  }
  unsigned long long fact(long long a)
  {
  unsigned long long res=1;
  for(long long i=a;i>0;i--)
    res*=i;
  return res;
  }
  unsigned long long comb(long long a,long long b)
  {
  if((a-b)<b) b=a-b;
  if(a<=19) return fact(a)/(fact(a-b)*fact(b));
  if(a==b||b==0) return 1;
  if(b==1) return a;
  return comb(a-1,b-1)+comb(a-1,b);
  }
*/




void solve(vector<int>&A,int n,int k){
     
   ll dp[n+2][k+2]; memset(dp,0,sizeof dp);
   
   for(int j=0;j<=k;j++){
     dp[1][j]=(j>A[1]) ? 0 :1;
   }

   for(int i=2;i<=n;i++){

      for(int j=0;j<=k;j++){

          if(j==0)
            dp[i][j]=dp[i-1][j];
          else
            dp[i][j]=(mod+ dp[i][j-1] + dp[i-1][j]-( (j-A[i]-1>=0) ? dp[i-1][j-A[i]-1]:0) )%mod;
      }
      
   }
   cout<<dp[n][k];
}

int main(){

 // open_file();
  fast_io();
  
  int n,k; cin>>n>>k;
  vector<int>A(n+1); for(int i=1;i<=n;i++)cin>>A[i];

  solve(A,n,k);
  
  return 0;  
    
}


Measured memory_bytes: 83296
#include<bits/stdc++.h>
using namespace std;
int a, b, c, counter, counter1;
int main(){
	while(cin>>a>>b){
		c=a+b;
		counter=0;
		while(c>0){
			counter++;
			c=c/10;
		}
		cout<<counter<<endl;
	}
	
	
}

Measured memory_bytes: 3112
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<queue>
//#include<time.h>
//#include<complex>
#include<algorithm>
#include<stdlib.h>
using namespace std;

int n;
#define maxn 200011
int a[maxn], b[maxn], na[maxn], nb[maxn];
int main()
{
	scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	int ans = 0;
	for (int i = 0; i <= 28; i++)
	{
		for (int j = 1; j <= n; j++)
			na[j] = a[j] & ((1 << (i + 1)) - 1), nb[j] = b[j] & ((1 << (i + 1)) - 1);
		sort(nb + 1, nb + 1 + n);
		int t1 = 1 << i, t2 = 2 * t1, t3 = 3 * t1, t4 = 4 * t1;
		int now = 0;
		for (int j = 1; j <= n; j++)
		{
			now ^= (lower_bound(nb + 1, nb + 1 + n, t2 - na[j]) - lower_bound(nb + 1, nb + 1 + n, t1 - na[j])) & 1;
			now ^= (lower_bound(nb + 1, nb + 1 + n, t4 - na[j]) - lower_bound(nb + 1, nb + 1 + n, t3 - na[j])) & 1;
		}
		ans |= now << i;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
using namespace std;
int n; int p[10005]; int dep[10005];
int findx(int x)
{
  if(x != p[x])
    p[x] = findx(p[x]);
  //x = p[x]
  return p[x];
}

void uni(int x, int y)
{
  int px = findx(x), py = findx(y);
  if(dep[px] < dep[py])
  {
    p[px] = py;
  }
  else
  {
    p[py] = px;
    if(dep[px] == dep[py])
      dep[px]++;
  }
}

void same(int x, int y)
{
  if(findx(x) == findx(y))
    printf("1\n");
  else printf("0\n");
}
int main()
{
  int q;
  scanf("%d%d", &n, &q);
  for(int i=0; i<n; i++)
  {
    p[i] = i; dep[i] = 0;
  }

  for(int i=0; i<q; i++)
  {
    int c, x, y;
    scanf("%d%d%d", &c, &x, &y);
    if(c == 0)
    {
      uni(x, y);
    }
    else
    {
      same(x, y);
    }
  }


  return 0;
}



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

typedef long long ll;
const int C=1000000007;
const int M=100010;

struct Edge
{
	int u,v,c;
	bool operator < (const Edge &b) const {return c<b.c;}
}e[M<<1];

struct Point
{
	int x,y,id;
}a[M];

bool cmp1(Point a,Point b)
{
	return a.x<b.x;
}

bool cmp2(Point a,Point b)
{
	return a.y<b.y;
}

ll ans;
int n,tot;
int f[M];

inline int getf(int x) {return f[x]==x?x:f[x]=getf(f[x]);}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i].x>>a[i].y,a[i].id=i;
	sort(a,a+n,cmp1);
	for(int i=0;i+1<n;i++)
		e[tot++]=(Edge){a[i].id,a[i+1].id,abs(a[i].x-a[i+1].x)};
	sort(a,a+n,cmp2);
	for(int i=0;i+1<n;i++)
		e[tot++]=(Edge){a[i].id,a[i+1].id,abs(a[i].y-a[i+1].y)};
	for(int i=0;i<n;i++)
		f[i]=i;
	sort(e,e+tot);
	for(int i=0;i<tot;i++)
	{
		int u=e[i].u,v=e[i].v;
		if(getf(u)!=getf(v)) ans+=e[i].c,f[getf(u)]=getf(v);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
     
    using namespace std;
     
     
    int main() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
     
        int n;
        cin >> n;
        long long a[n + 1];
        long long pos[n + 1];
        long long sum[n + 1];
        long long xor_sum[n + 1];
        a[0] = 0;
        pos[0] = 0;
        sum[0] = 0;
        xor_sum[0] = 0;
     
        long long val;
        long long prev = 0;
        for (int i = 1; i <= n; ++i) {
            cin >> val;
            pos[i] = prev;
            if (val) {
                prev = i;
            }
            // scanf("%lli", &val);
            a[i] = val;
            sum[i] = sum[i - 1] + val;
            xor_sum[i] = xor_sum[i - 1] ^ val;
        }
     
        long long cnt = 0;
                
        for (int i = 1; i <= n; ++i) {
            for (int j =1; j <= i; ++j) {
                if (j  > 2 && pos[i - j + 2] != i - j + 1) {
                    long long diff = (i - j + 1) - pos[i - j + 1];
                    cnt += diff;
                    j +=  diff - 1;
                    continue;
                }
                long long sum_diff = sum[i] - sum[i - j];
                long long xor_sum_diff = xor_sum[i] ^ xor_sum[i - j];
                if (sum_diff != xor_sum_diff) break;
                // cnt += sum_diff == xor_sum_diff;
                cnt ++;
                // if (xor_sum_diff < sum_diff) break;
            }
        }
     
        cout << cnt << '\n';
     
        return 0;
    }

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

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

    
    ll dp[h+1] = {};
    rep(i,0,h+1) dp[i] = LINF;
    dp[0] = 0;

    ll a[n] = {},b[n] = {};
    rep(i,0,n) cin >> a[i] >> b[i];

    rep(i,0,n){
        rep(j,0,h+1){
            dp[min(h,j+a[i])] = min(dp[min(h,j+a[i])],dp[j] + b[i]);
        }
    }
    
    cout << dp[h] << endl;
    return 0;
}


Measured memory_bytes: 3644
import sys
sys.setrecursionlimit(1000000)
L = sys.stdin.readlines()
for i in range(len(L)):
    L[i] = list(map(int, L[i].split()))
n =L[0][0]

rin = [[] for _ in range(n)]
for v in L[1:n]:
    rin[v[0]-1].append(v[1]-1)
    rin[v[1]-1].append(v[0]-1)
    
score = [0 for _ in range(n)]
for ele in L[n:]:
    score[ele[0]-1] +=ele[1]
#print(score)
 
def dfs(p, bp=-1):
    for c in rin[p]:
        if c != bp:
            #print(c)
            score[c]+= score[p]
            dfs(c, p)
 
dfs(0)
print(*score)

Measured memory_bytes: 351060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int n,m,i,a,b;
	bool fro[225816], ton[225816], flag = false;
	fill(fro,fro+225816,false);
	fill(ton,ton+225816,false);
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> a >> b;
		if(a == 1){
			fro[b] = true;
		}else if(b == n){
			ton[a] = true;
		}
	}
	for(i=2; i<n; ++i){
		if(fro[i] && ton[i]){
			cout << "POSSIBLE" << endl;
			flag = true;
			break;
		}
	}
	if(!flag){
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 X1 = 0;
	SINT32 Y1 = 0;
	SINT32 X2 = 0;
	SINT32 Y2 = 0;

	SINT32 X3 = 0;
	SINT32 Y3 = 0;
	SINT32 X4 = 0;
	SINT32 Y4 = 0;

	cin >> X1>>Y1>>X2>>Y2;

	if ((X2-X1) > 0) {
		if ((Y2-Y1) > 0) {
			X3 = X2 - ABS(Y1-Y2);
			Y3 = Y2 + ABS(X1-X2);
			X4 = X1 - ABS(Y1-Y2);
			Y4 = Y1 + ABS(X1-X2);

		} else {
			X3 = X2 + ABS(Y1-Y2);
			Y3 = Y2 + ABS(X1-X2);
			X4 = X1 + ABS(Y1-Y2);
			Y4 = Y1 + ABS(X1-X2);

		}
	} else {
		if ((Y2-Y1) > 0) {
			X3 = X2 - ABS(Y1-Y2);
			Y3 = Y2 - ABS(X1-X2);
			X4 = X1 - ABS(Y1-Y2);
			Y4 = Y1 - ABS(X1-X2);
		} else {
			X3 = X2 + ABS(Y1-Y2);
			Y3 = Y2 - ABS(X1-X2);
			X4 = X1 + ABS(Y1-Y2);
			Y4 = Y1 - ABS(X1-X2);
			
		}
	}


	cout << X3 << " ";
	cout << Y3 << " ";
	cout << X4 << " ";
	cout << Y4 << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();

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

int main() {
	while (true)
	{
		int n,s[1000];
		double m,a = 0;
		cin >> n;
		if (n == 0)break;
		for (size_t i = 0; i < n; i++)
		{
			cin >> s[i];
			a += s[i];
		}
		m = (float)a / n;
		a = 0;
		for (size_t i = 0; i < n; i++)
		{
			a += pow(s[i] - m,2);
		}
		cout << pow(a / n, 0.5) << endl;
	}
	return 0;
}


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

int main(){
  int N;
  int a[101];
  cin >> N;
  for(int i = 0;i < N;i++)cin >> a[i];
  
  sort(a, a+N, greater<int>());
  int alice = 0;
  int bob = 0;
  for(int i = 0;i < N;i++){
    if(i % 2 == 0){
      alice += a[i];
    }
    else{
      bob += a[i];
    }
  }
  cout << alice - bob << endl;
}
    
    

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

int main() {
	int n;
	cin >> n;
	
	set<string> ans;
	
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		ans.insert(s);
	}
	
	cout << ans.size() << endl;
}

Measured memory_bytes: 19240
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1000000000+7)

int w[101];
int v[101];
ll dp[100001][101];
int main() {
    ll N, W;
    cin >> N >> W;
    REP(i, N) {
        cin >> w[i+1] >> v[i+1];
    }
    REP(i, W+1) {
        REP(j, N+1) {
            if (i-w[j] >= 0) {
                REP(k, j) {
                    dp[i][j] = max(dp[i-w[j]][k]+v[j], dp[i][j]);
                }
                
            }
        }
    }
    
    ll maxv = 0;
    REP(i, N+1) {
        maxv = max(dp[W][i], maxv);
    }
    cout << maxv << endl;
}


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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }
    ll addPerCycle = (N*(N+1))/2;
    // cerr << "addPerCycle=" << addPerCycle  <<"sum=" << sum<< endl;
    if(sum%addPerCycle != 0){
        cout <<"NO" << endl;
        return 0;
    }
    ll div = sum/addPerCycle;
    vector<ll> diffA(N);
    for(int i=0;i<N;i++){
        diffA[i] = A[i] -A[(N+i-1)%N];
    }
    ll xSum = 0; 
    for(int i=0;i<N-1;i++){
        ll temp = (div-diffA[i])/N;
        if((div -diffA[i])%N != 0 || temp <0 || temp>div){
            // cerr <<"temp=" <<temp << endl;
            cout <<"NO" << endl;
            return 0;
        }
        xSum += temp;
    }

    // cerr <<"xSum = " << xSum << endl;

    if(div-(div-xSum) *N == diffA[N-1]){
        cout <<"YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    

    return 0;
}

Measured memory_bytes: 4792
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools



sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
a = [int(i) for i in input().split()]
ans = 0

for i in range(N):
    if((i+1)%2==1):
        if(a[i]%2==1):
            ans+=1



print(ans)


Measured memory_bytes: 68704
//<--sbhmsh-->//

#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
#define lli long long int
#define endl '\n'
#define deb cout<<"sab_badhiya"<<endl;
// const long long INF = 1000 * 1000 * 1000 * 1ll * 1000 * 1000 * 1000;
const long INF = 1000 * 1000 * 1000;
const long long int mod = 1000000007;
int main(){
  FASTIO
  int n, k, count=0;
	cin>>n>>k;
	int a[n+1];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>=k)count++;
	}
	cout<<count<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int n,v;
int main(){
	scanf("%d%d",&n,&v);
	for (int i=0;i<=n;i++)
		for (int j=0;j+i<=n;j++)
			if (i*10000+j*5000+(n-i-j)*1000==v)
				return printf("%d %d %d",i,j,n-i-j),0;
	printf("-1 -1 -1"); 
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else 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;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int a,b;
  cin>>a>>b;
  int ans=a+b;
  int tmp=a-b;
  if(ans<tmp)ans=tmp;
  tmp=a*b;
  if(ans<tmp)ans=tmp;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 125568
#include<bits/stdc++.h>
#include<string>
#include<cctype> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
 
  int N,K,i;
  int ans=0;
  cin >> N >> K;
  int l[N];
  int m[K];
  rep(i,N){
    cin >> l[i];
  }
  sort(l,l+N);
  for(i=N-1;i>=N-K;i--){
    ans+=l[i];
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;


 int main()
 {
   string s;
   while(cin>>s)
   {
     int cnt=0;
     for(int i=0;i<s.length();i++)
     {
       if(s[i]=='1') cnt++;        
     }  
     cout<<cnt<<endl;
   }
   return 0;
 }

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

typedef vector<int> vi;
#define FOR(i,n) for (int i=0;i<(n);++i)

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;cin>>n;
    vi a(n);
    FOR(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    n /= 2;
    cout << a[n]-a[n-1];
    return 0;
}



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


int main() {

	string S;
	cin >> S;

    bool a[26];
    for (int i = 0; i < 26 ; ++i) a[i] = false;

    for (int i = 0; i < S.size(); ++i) {
        a[S[i] - 'a'] = true;
    }

    for (int i = 0; i < 26; ++i) {
        if (!a[i]) {
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }
    
    cout << "None" << endl;
    return 0;

}


Measured memory_bytes: 3688
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  const dh=[1,1,1,-1,-1,-1,0,0]
  const dw=[1,-1,0,1,-1,0,1,-1]
  const [h,w]=tnn(2)
  const mp=tss(h)
  for(let i=0;i<h;i++){
    let tr=''
    for(let j=0;j<w;j++){
      if(mp[i][j]=='#'){
        tr+='#'
        continue
      }
      let cnt=0
      for(let k=0;k<8;k++){
        const [th,tw]=[i+dh[k],j+dw[k]]
        if(th<0||tw<0||th>=h||tw>=w)continue
        if(mp[th][tw]=='#')cnt++
      }
      tr+=cnt
    }
    to(tr)
  }
}
main()

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v = {a, b, c};
  vector<int> ffs = {5, 5, 7};
  
  sort(v.begin(), v.end());
  if (v == ffs) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000000000
using namespace std;


int main(void){
  ll n,m,p;
  cin >> n >> m >> p;

  vector<vector<pair<ll,ll> > > list(n+1);
  vector<vector<int> > list2(n+1);
  rep(i,m){
	ll a,b,c;
	cin >> a >> b >> c;
	list[a].emplace_back(b,c-p);
	list2[b].push_back(a);
  }

  
  vector<bool> flag(n+1,false),reach(n+1,false);
  flag[n] = true;
  rep(i,n){
	rep(j,n){
	  //cout << "size:" << list2[j+1].size() << endl;
	  if(!flag[j+1]) continue;
	  for(int k=0;k<list2[j+1].size();k++){
		int to = list2[j+1][k];
		//cout << "goto" << j+1 << "->" << to << endl;
		flag[to] = true;
	  }
	}
  }
  //rep(i,n)cout << flag[i+1] << " ";
  //cout << endl;  
  vector<ll> cur(n+1,-MAX),tmp(n+1,0);
  
  cur[1] = 0;
  reach[1] = true;
  ll ans;

  rep(i,n){
	rep(j,n){
	  if(!reach[j+1]) continue;
	  rep(k,list[j+1].size()){
		ll to = list[j+1][k].first,cost = list[j+1][k].second;
	    reach[to] = true;
		if(cur[to] < cur[j+1]+cost){
		  cur[to] = cur[j+1]+cost;
		}
	  }
	}
	//rep(j,n) cout << cur[j+1] << " ";
	//cout << endl;
	if(i == n-2){
	  ans = cur[n];
	  tmp = cur;
	}
	if(i == n-1){
	  rep(j,n){
		if(tmp[j+1] < cur[j+1] && flag[j+1]) cur[n] = ans+1;
	  }
	}
  }

  if(ans < cur[n]) cout << -1 << endl;
  else cout << max(ans,0LL) << endl;

  return 0;
}


Measured memory_bytes: 768
// A Lucky 7 2020 04 12
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
    string N;
    cin >> N;
    for (int i; i < 3; i++) {
        if(N[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;

string s;
int z=0,o;
bool zero;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s;

	zero=true;
	if(s[0]=='1')
		z++;

	for(int i=1;i<s.size();i++){
		if(zero && s[i]=='0')
			z++;
		else if(!zero && s[i]=='1')
			z++;
		zero=!zero;
	}
	o=s.size()-z;
	cout<<min(z,o);
	return 0;
}

Measured memory_bytes: 512
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 0
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
 
//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


//}

int lcm,n,m,ans;
string s,t;
map<int,char> c;

main(){
	cin>>n>>m>>s>>t;
	lcm=m*n/__gcd(n,m);
	debug(lcm);
	rep(i,n){
		int tmp;
		tmp=lcm/n*i;
		debug(tmp,s[i]);
		c.insert(mp(tmp,s[i]));
		c[tmp]=s[i];
	}
	//cout<<endl;
	rep(i,m){
		int tmp;
		tmp=lcm/m*i;
		if((c.count(tmp)!=0)&&(c[tmp]!=t[i])){
			dump(-1);
			return 0;
		}
		debug(tmp,t[i]);
		c.insert(mp(tmp,t[i]));
	}
	dump(lcm);
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;
template<class T> void add(T &a, T b) { a = (a + b) % MOD; }

ll dp[101010][13];
int main() {
    string S; cin >> S;
    int N = S.size();
    dp[0][0] = 1;
    rep(i, 0, N) rep(j, 0, 13) {
        if(S[i] == '?') {
            rep(d, 0, 10) {
                int a = (j * 10 + d) % 13;
                add(dp[i+1][a], dp[i][j]);
            }
        } else {
            int d = S[i] - '0';
            int a = (j * 10 + d) % 13;
            add(dp[i+1][a], dp[i][j]);
        }
    }
    cout << dp[N][5] << endl;
    return 0;
}


Measured memory_bytes: 10752
size = 10 ** 5 + 1
is_primes = [True] * size
is_primes[0] = False
is_primes[1] = False
for n in range(2, size):
    if not is_primes[n]:
        continue

    m = n * 2
    while m < size:
        is_primes[m] = False
        m += n

dp = [0] * size
for i in range(1, size):
    dp[i] = dp[i - 1]
    if i % 2 == 1 and is_primes[i] and is_primes[(i + 1) // 2]:
        dp[i] += 1

Q = int(input())
for _ in range(Q):
    left, right = map(int, input().split(' '))
    print(dp[right] - dp[left - 1])


Measured memory_bytes: 4980
import sys
import bisect
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
bl = bisect.bisect_left

A, B, Q = map(int, input().split())
inf = 10**18
S = [-inf]+[int(input()) for _ in range(A)]+[inf]
T = [-inf]+[int(input()) for _ in range(B)]+[inf]


def path(x):
    sl = S[bl(S, x) - 1]
    sr = S[bl(S, x)]
    tl = T[bl(T, x) - 1]
    tr = T[bl(T, x)]

    res = 10 ** 18
    res = min(res, abs(x - sl) + abs(sl - tl))
    res = min(res, abs(x - sl) + abs(sl - tr))
    res = min(res, abs(x - sr) + abs(sr - tr))
    res = min(res, abs(x - sr) + abs(sr - tl))
    res = min(res, abs(x - tr) + abs(tr - sl))
    res = min(res, abs(x - tr) + abs(tr - sr))
    res = min(res, abs(x - tl) + abs(tl - sl))
    res = min(res, abs(x - tl) + abs(tl - sr))
    return res


X = [int(input()) for _ in range(Q)]
for x in X:
    print(path(x))

Measured memory_bytes: 17808
from collections import deque

target_1 = [[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]
def func(a=deque() , targetlist=target_1):
    x1 = a.count(targetlist[0])
    x2 = a.count(targetlist[1])
    x3 = a.count(targetlist[2])
    x4 = a.count(targetlist[3])
    x5 = a.count(targetlist[4])
    x6 = a.count(targetlist[5])
    if((x1+x2+x3+x4+x5+x6)==3):
        return True
    else:
        return False

N = int(input())
D_array = [list(map(int, input().split())) for i in range(N)]
Q = deque([[0] * 2 for i in range(3)])

j = 0
ans = 0
while j < N:
    Q.pop()
    Q.appendleft(D_array[j])
    if(func(Q,target_1)):
        print("Yes")
        ans = 1
        break
    else:
        j = j+1

if(ans==0):print("No")



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

int main() {
 int count = 0,sum = 0;
 double n=0 ,m = 0;
  cin >> n >> m;
  vector<int> vec(n);
  for(int i = 0 ; i < n ; i++) cin >> vec.at(i);
  for(int i = 0 ; i < n ; i++) {
    sum += vec.at(i);
  }
    //受け取り終わり
    
    
  sort(vec.begin() , vec.end());
  reverse(vec.begin() , vec.end());
  //でかい順に並べる
  
  
  for(int i = 0 ; i < m ; i++){
    if(vec.at(i) >= sum / (4*m)) count++;
  }
  if ( count == m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
c0 = a0b0
c1 = a0b1 + a1b0
c2 = a0b2 + a1b1 + a2b0
c3 = a0b3 + a1b2 + a2b1 + a3b0
https://kopricky.github.io/code/FFTs/ntt.html

*/
// 特殊な剰余と原始根
// (924844033, 5)
// (998244353, 3)
// (1012924417, 5)
// (167772161, 3)
// (469762049, 3)
// (1224736769, 3)
 
#define MOD 998244353
#define root 3
 
unsigned int add(const unsigned int x, const unsigned int y)
{
    return (x + y < MOD) ? x + y : x + y - MOD;
}
 
unsigned int sub(const unsigned int x, const unsigned int y)
{
    return (x >= y) ? (x - y) : (MOD - y + x);
}
 
unsigned int mul(const unsigned int x, const unsigned int y)
{
    return (unsigned long long)x * y % MOD;
}
 
unsigned int mod_pow(unsigned int x, unsigned int n)
{
    unsigned int res = 1;
    while(n > 0){
        if(n & 1){ res = mul(res, x); }
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}
 
unsigned int inverse(const unsigned int x)
{
    return mod_pow(x, MOD - 2);
}
 
void ntt(vector<int>& a, const bool rev = false)
{
    unsigned int i, j, k, l, p, q, r, s;
    const unsigned int size = a.size();
    if(size == 1) return;
    vector<int> b(size);
    r = rev ? (MOD - 1 - (MOD - 1) / size) : (MOD - 1) / size;
    s = mod_pow(root, r);
    vector<unsigned int> kp(size / 2 + 1, 1);
    for(i = 0; i < size / 2; ++i) kp[i + 1] = mul(kp[i], s);
    for(i = 1, l = size / 2; i < size; i <<= 1, l >>= 1){
        for(j = 0, r = 0; j < l; ++j, r += i){
            for(k = 0, s = kp[i * j]; k < i; ++k){
                p = a[k + r], q = a[k + r + size / 2];
                b[k + 2 * r] = add(p, q);
                b[k + 2 * r + i] = mul(sub(p, q), s);
            }
        }
        swap(a, b);
    }
    if(rev){
        s = inverse(size);
        for(i = 0; i < size; i++){ a[i] = mul(a[i], s); }
    }
}
 
vector<int> convolute(const vector<int>& a, const vector<int>& b)
{
    const int size = (int)a.size() + (int)b.size() - 1;
    int t = 1;
    while(t < size){ t <<= 1; }
    vector<int> A(t, 0), B(t, 0);
    for(int i = 0; i < (int)a.size(); i++){ A[i] = a[i]; }
    for(int i = 0; i < (int)b.size(); i++){ B[i] = b[i]; }
    ntt(A), ntt(B);
    for (int i = 0; i < t; i++){ A[i] = mul(A[i], B[i]); }
    ntt(A, true);
    A.resize(size);
    return A;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N, 0), B(M, 0);
  rep(i, N) cin >> A[i];
  rep(i, M) cin >> B[i];
  auto C = convolute(A, B);
  rep(i, N+M-1){
    cout << C[i];
    if (i == N+M-2)
      cout << endl;
    else
      cout << " ";
  }
}


Measured memory_bytes: 25248
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;



int main() {
    int a; cin >> a;
    int r = a;
    r += a*a;
    r += a*a*a; 
    cout <<r << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    std::map<int, int> a;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    
    std::map<int, int>::reverse_iterator itr = a.rbegin();
    for(int i=0; i<m; i++){
        itr = a.rbegin();
        int org = itr->first;
        int tmp = org >> 1;
        
        a[tmp]++;
        if(a[org] > 1) a[org]--;
        else a.erase(org);
        if(a.size() == 0) break;
       
    }
    
    long long int sum = 0;
    std::map<int, int>::iterator j = a.begin();
    while(j != a.end()){
        for(int i=0; i<j->second; i++){
            sum += j->first;
        }
        ++j;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4992
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut ls: [i64; n],
    }
    ls.sort();
    let mut ans = 0;
    for (&x, &y, &z) in ls.iter().tuple_combinations() {
        if x == y || y == z {
            continue;
        }
        if x + y <= z {
            continue;
        }
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2124
result = {"left": [0] * 4, "right": [0] * 4}

def update(value, dest):
    if value >= 1.1: dest[0] += 1
    elif value >= 0.6: dest[1] += 1
    elif value >= 0.2: dest[2] += 1
    else: dest[3] += 1

while True:
    try:
        left, right = map(float, raw_input().split())
        update(left, result["left"])
        update(right, result["right"])
    except (EOFError):
        break

for i in range(4): print result["left"][i], result["right"][i]

Measured memory_bytes: 4268
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
//list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
$a = explode(" ",trim(fgets(STDIN)));
rsort($a);

printf("%d\n",$a[0]*10+$a[1]+$a[2]);


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

signed  main(){
    using pii =pair<int,int>;
    using piii=pair<pii,int>;
    int v,e,s; cin>>v>>e>>s;
    vector<int>d(v,LLONG_MAX);
    vector<piii>edge;
    rep(i,e){
        int from,to,cost; cin>>from>>to>>cost;
        edge.push_back(piii(pii(from,to),cost));
    }
    d[s]=0;
    rep(i,v){
        bool update=false;
        rep(j,edge.size()){
            int to=edge[j].first.second;
            int from=edge[j].first.first;
            int cost=edge[j].second;
            if(d[from]==LLONG_MAX)continue;
            if(d[to]>d[from]+cost){
                d[to]=d[from]+cost;
                update=true;
            }
        }
        if(i==v-1&&update)return puts("NEGATIVE CYCLE")*0;
    }
    rep(i,v)if(d[i]!=LLONG_MAX)cout<<d[i]<<endl; else cout<<"INF"<<endl;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 123
int a[N];
vi v;

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%d", a+i);
	REP(i, n) a[i]--;
	for(int i=n; i>0; i--){
		for(int j=i-1; j>=0; j--){
			if(a[j]==j){
				v.EB(j);
				FOR(k, j, i-1){
					a[k]=a[k+1];
				}
				goto ok;
			}
		}
		printf("-1\n");
		return 0;
ok:
		continue;
	}
	reverse(v.begin(), v.end());
	for(int i : v) printf("%d\n", i+1);
}


Measured memory_bytes: 256