akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//____________________

int calXOR(int n) 
{ 
  switch(n & 3)  
  { 
    case 0: 
     return n;     
    case 1: 
     return 1;   
    case 2: 
     return n + 1;   
    case 3: 
     return 0; 
  } 
} 

int32_t main()
{ 
  io;
  
  
  int a,b,ans;
  cin>>a>>b;

  if(a==0)
  {
    ans=calXOR(b);
    ans=0LL^ans;
  }
  else if(a==1)
  {
    ans=calXOR(b);
  }
  else
  {
     ans=calXOR(b);
     ans=ans^calXOR(a-1);
  }
  
  cout<<ans;
  
 return 0;
}

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

n = int(input())
A = list(map(int, input().split()))

B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1

C = []
for b in B.keys():
    if B[b] >= 4:
        C.append(b)
        C.append(b)
    elif B[b] >= 2:
        C.append(b)

C.sort(reverse=True)

if len(C):
    print(C[0] * C[1])
else:
    print(0)


Measured memory_bytes: 18060
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)

    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            # 尺取り
            for i in range(len(plus)):
                while j < len(minus) and plus[i]*minus[j]<=mid:
                    j+=1 
                count += j
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            ## plus
            for i in range(len(plus)-1,-1,-1):
                if plus[i]**2 <= mid:
                    count -= 1

                while j < len(plus) and plus[i]*plus[j] <= mid:
                    j += 1
                count += j
            
            ## minus
            j = 0
            for i in range(len(minus)-1,-1,-1):
                if minus[i]**2 <= mid:
                    count -= 1
                while j < len(minus) and minus[i]*minus[j] <= mid:
                    j += 1
                count += j
            
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  cin >> s;
  int64_t bcnt = 0;
  int64_t cnt = 0;
  rep(i,s.size()){
    if(s.at(i) == 'W'){
      cnt += bcnt;
    }else{
      bcnt++;
    }
  }
  cout << cnt << endl;
  
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long K){
    i64 ans = 0;
    rep(i, 1, K + 1){
        rep(j, 1, K + 1){
            rep(k, 1, K + 1) ans += gcd(i, gcd(j, k));
        }
    }
    cout << ans << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 2100000000
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i).first;
    A.at(i).second=i;
  }
  sort(A.begin(),A.end());

  int count=0;
  for(int i=0;i<N;i++){
    if(A.at(i).second%2!=i%2){
      count++;
    }
  }
  cout<<count/2<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int a1[110];
int main()
{
    fio;
    int n,m;
    cin>>n>>m;
    int k1;
    loop(i,0,m)
    {
        cin>>k1;
        a1[k1] = 1;
    }
    int p = n , q = n;
    while(1)
    {
        if(!a1[p])
        {
            cout<<p<<endl;
            break;
        }
         if(!a1[q])
        {
            cout<<q<<endl;
            break;
        }
        p--;
        q++;
    }
    return 0;
}



Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderBS
{
    class Program
    {
        static void Main(string[] args)
        {
            bool Takahashi = false;
            int[] c1 = new int[3];
            int[] c2 = new int[3];
            int[] c3 = new int[3];

            int a1, a2, a3, b1, b2, b3 = 0;

            string[] str = new string[3];

            for (int i = 0; i < 3; i++)
            {
                str = Console.ReadLine().Split(' ');
                c1[i] = int.Parse(str[0]);
                c2[i] = int.Parse(str[1]);
                c3[i] = int.Parse(str[2]);
            }

            int c1Max = c1.Max();
            int c2Max = c2.Max();
            int c3Max = c3.Max();

            for (b1 = 0; b1 <= c1Max; b1++)
            {
                a1 = c1[0] - b1; // 1列目決定
                a2 = c1[1] - b1;
                a3 = c1[2] - b1;

                for (b2 = 0; b2 <= c2Max; b2++)
                {
                    if (a1 + b2 == c2[0] && a2 + b2 == c2[1] && a3 + b2 == c2[2]) // 2列目成立
                    {
                        for (b3 = 0; b3 <= c3Max; b3++)
                        {
                            if (a1 + b3 == c3[0] && a2 + b3 == c3[1] && a3 + b3 == c3[2]) // 3列目成立
                            {
                                Takahashi = true;
                                goto Fin;
                            }
                        }
                    }
                }
            }

            Fin:

            if (Takahashi)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.Read();
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return res;
}

ll inverse_element(ll t){
	return mod_pow(t,MOD-2);
}
ll n;
ll a[100100];
ll n1ck[100100];
ll lrnck1[100100];
int main(){
	cin>>n;
	REP(i,100100)a[i]=-1;
	int l;
	REP(i,n+1){
		int t1;
		cin>>t1;
		if(a[t1]==-1){
			a[t1]=i;
		}else{
			l=a[t1]-i;
		}
	}
	n1ck[0]=1;
	FOR(i,1,n+2){
		n1ck[i]=n1ck[i-1]*(n-i+2)%MOD*inverse_element(i)%MOD;
	}
	lrnck1[1]=1;
	FOR(i,2,l+n+2){
		lrnck1[i]=lrnck1[i-1]*(n+l-i+2)%MOD*inverse_element(i-1)%MOD;
	}
	for(int i=1;i<=n+1;i++){
		cout<<(n1ck[i]-lrnck1[i]+MOD)%MOD<<endl;
	}
	return 0;
}

Measured memory_bytes: 3584
a = input()
b = input()

arr = []
la = len(a)
lb = len(b)

for i in range(la-lb+1):
    c = a[i:i+lb] 
    cu = 0
    for j in range(lb):
        if c[j] != b[j]:
            cu += 1
    arr.append(cu)
    
print(min(arr))

Measured memory_bytes: 9024
#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(ll int j=x;j>=n;j--)
#define f1(k,x,n) for(ll int k=x;k<=n;k++)
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define MAX 1000001
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int a,b;
    cin>>a>>b;
    if(2*b>=a)
      cout<<0;
    else
      cout<<abs(2*b-a);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node{
  int v,w;
};
int knapsack(long long int w,vector<node> v)
{
//  int ts=0;
//  for(int i=0;i<v.size();i++)
//    ts+=v[i].v;
  vector<long long int> dp(100001,1000000000000);
  dp[0]=0;
  for(int i=0;i<v.size();i++)
    for(int j=100000;j>0 && j>=v[i].v;j--)
      if(dp[j]>dp[j-v[i].v]+v[i].w)
        dp[j]=dp[j-v[i].v]+v[i].w;
  
  for(int i=100000;i>=0;i--)
    if(dp[i]<=w)
    	return i;	
  return 0;
}
int main()
{
  long long int n,w;cin>>n>>w;
  vector<node> v(n);
  for(int i=0;i<n;i++)
    cin>>v[i].w>>v[i].v;
  cout<<knapsack(w,v)<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int64_t GetCombination(int64_t n, int64_t r) {
  cerr << "\033[93m" << n << " " << r << "\033[m" << endl;
  if (n / 2 < r) {
    r = n - r;
  }
  assert(r >= 0);
  assert(n >= 0);

  if (r == 0) return 1;
  return n * GetCombination(n - 1, r - 1) / r;
}

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int64_t n, a, b;
  cin >> n >> a >> b;
  std::vector<int64_t> v(n);
  int64_t sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  std::sort(v.begin(), v.end(), std::greater<int64_t>());

  bool all_same = true;
  for (int i = 0; i < a; i++) {
    sum += v[i];
    if (i >= 1 && v[i - 1] != v[i]) {
      all_same = false;
    }
  }

  int64_t pattern = 0;
  if (all_same) {
    cerr << "allsame" << endl;
    int64_t number_canchoose = 0;
    for (int i = 0; i < n; i++) {
      cerr << "\033[93m"
           << "roop 1"
           << "\033[m" << endl;
      if (v[i] == v[0]) {
        number_canchoose++;
      } else
        break;
    }
    for (int i = a; i <= b && i <= number_canchoose; i++) {
      pattern += GetCombination(number_canchoose, i);
    }
  } else {
    cerr << "not allsame" << endl;
    int64_t number_canchoose = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] == v[a - 1]) {
        number_canchoose++;
      }
    }
    int64_t number_shouldchoose = 0;
    for (int i = 0; i < a; i++) {
      if (v[i] == v[a - 1]) {
        number_shouldchoose++;
      }
    }
    pattern = GetCombination(number_canchoose, number_shouldchoose);
  }

  cout << (double)sum / a << endl;
  cout << pattern << endl;

  return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = MAP()
if int(int(str(a)+str(b))**(1/2)) == int(str(a)+str(b))**(1/2):
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5204
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define ll long long
#define ull unsigned long long
#define MAXM 100010
#define MAXN 110
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) < (b) ? (b) : (a)
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
#define mii map<int, int>
#define umii unordered_map<int, int>
#define allof(x) x.begin(), x.end()
#define DEBUG 1
// #define NOT_DMOJ 0
#ifdef DEBUG
	#define D(x...) printf(x)
#else
	#define D(x...)
#endif
using namespace std;

inline int GCD (int a, int b) { return b == 0 ? a : GCD(b, a % b); }
inline int LCM (int a, int b) { return a * b / GCD(a, b); }
inline ll PowMod (ll a, ll b, ll mod) { ll val = 1; while (b) { if (b & 1) val = (val * a) % mod; a = (a * a) % mod; b >>= 1; } return val; }

ll N, W;
ll w[MAXN], v[MAXN];
ll DP[2][MAXM];

int main (int argc, char const *argv[]) {
	#ifdef NOT_DMOJ
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif // NOT_DMOJ
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> W;
	for (int i=0; i<N; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i=0; i<N; i++) {
		for (int j=1; j<=W; j++) {
			DP[i & 1][j] = max(DP[i & 1][j - 1], DP[(i & 1) ^ 1][j]);
			if (j >= w[i]) {
				DP[i & 1][j] = max(DP[i & 1][j], DP[(i & 1) ^ 1][j - w[i]] + v[i]);
			}
		}
	}
	cout << DP[(N - 1) & 1][W] << "\n";
	return 0;
}

/* 
 * Look for:
 * the exact constraints (multiple sets are too slow for n=10^6 :( ) 
 * special cases (n=1?)
 * overflow (ll vs int?)
 * array bounds
 */

Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split()))
assert len(A) == N

def solve():
    negcnt = len([a for a in A if a<0])
    aa = [abs(a) for a in A]
    if negcnt % 2 == 0:
        return sum(aa)
    mv = min(aa)
    return sum(aa) -2*mv
print(solve())


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

using namespace std;

int N, ans = 0, cnt[100009], ap[100009];
vector < int > v[100009];

bool dfs (int nod, int tata, bool soFar)
{
    int sons = 0;
    for (auto it : v[nod])
        if (it != tata)
            sons ++;
    int isBamboo = 0;
    for (auto it : v[nod])
        if (it != tata)
        {
            bool curr = dfs (it, nod, soFar & (sons <= 1));
            cnt[nod] += (curr == 1);
            isBamboo ++, isBamboo += (curr == 0);
        }
    if (tata != -1) cnt[nod] += soFar;
    return (isBamboo <= 1);
}

int rand15 () {return rand () & 32767;}
int rand30 () {return (rand15 () << 15) | rand15 ();}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
if (N == 1)
{
    printf ("0\n");
    return 0;
}
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y), x ++, y ++;
    v[x].push_back (y);
    v[y].push_back (x);
}
int root = -1;
for (int i=1; i<=N; i++)
    if (v[i].size () >= 3)
        root = i;
if (root == -1)
{
    printf ("1\n");
    return 0;
}
for (int i=1; i<=N; i++)
    if (v[i].size () == 1)
        root = i;
dfs (root, -1, 1);
int ans = 1;
for (int i=1; i<=N; i++)
    if (cnt[i] > 1)
        ans += cnt[i] - 1;
queue < int > cc;
for (int i=1; i<=N; i++)
    if (v[i].size () == 1)
        cc.push (i), ap[i] = 1;
while (!cc.empty ())
{
    int nod = cc.front ();
    cc.pop ();
    for (auto it : v[nod])
    {
        if (v[it].size () == 1) continue;
        bool isBetween = (v[it].size () == 2 && cnt[it] == 1);
        if (isBetween == 1 && ap[it] == 0)
            cc.push (it), ap[it] = 1;
        else
        if (cnt[it] >= 2)
        {
            printf ("%d\n", ans - 1);
            return 0;
        }
    }
}
//fprintf (stderr, "special\n");
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    int k, a, b, c, d;
    cin >> k;
    a = k / 1000;
    b = (k % 1000) / 100;
    c = (k % 100) / 10;
    d = k % 10;
    if (a + b + c + d == 7) {
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a - b + c + d == 7) {
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a + b - c + d == 7) {
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a - b - c + d == 7) {
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a + b + c - d == 7) {
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if (a + b - c - d == 7) {
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if (a - b - c - d == 7) {
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if (a - b + c - d == 7) {
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
// Aizu Vol0 0038: Poker Hand
// 2017.7.30

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

#define MAX 14

int main()
{
	int card[MAX+3];
	int max;
	int i, j, d[5];
	
	while (scanf("%d,%d,%d,%d,%d", &d[0], &d[1], &d[2], &d[3], &d[4]) == 5) {
		for (i = 1; i <= MAX; i++) card[i] = 0;
		max = 0;
		for (i = 0; i < 5; i++) {
			if (++card[d[i]] > max) max = card[d[i]];
			if (d[i] == 1) card[14] = 1;
		}
		if (max == 4) {
			puts("four card");
			goto DONE;
		}
		if (max == 3) {
			for (i = 1; i < MAX; i++) {
				if (card[i] == 2) {
					puts("full house");
					goto DONE;
				}
			}
		}
		if (max == 1) {
			i = 1;
		NEXT:
			for (; card[i] == 0; i++);
			for (j = 1; ; j++) {
				if (j >= 5) {
					puts("straight");
					goto DONE;
				}
				if (card[i + j] == 0) break;
			}
			if (i == 1) {
				i++;
				goto NEXT;
			}
		}
		if (max == 3) {
			puts("three card");
			goto DONE;
		}
		if (max == 2) {
			for (i = 1; card[i] < 2; i++);
			for (j = i + 1; j < MAX; j++) {
				if (card[j] == 2) {
					puts("two pair");
					goto DONE;
				}
			}
			puts("one pair");
			goto DONE;
		}
		puts("null");
	DONE:;
	}
	return 0;
}

Measured memory_bytes: 576
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toLong)

    val l1 = mutableListOf(a.first())
    val l2 = mutableListOf(a.last())
    a.forEach { l1.add(gcd125(it, l1.last())) }
    a.reversed().forEach { l2.add(0, gcd125(it, l2.first())) }
    l1.removeAt(0)
    l2.removeAt(l2.size-1)

    var max = Math.max(l1[l1.size - 2], l2[1])
    (1 until n - 1).forEach { max = Math.max(max, gcd125(l1[it - 1], l2[it + 1])) }
    println(max)
}

fun gcd125(a: Long, b: Long): Long = if (b > 0) gcd125(b, a % b) else a


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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll A, P;
    cin >> A >> P;

    ll k = P + 3*A;
    p(k/2);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  ll n,i;
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(b.begin(),b.end());
  ll max1=b[n-1];
  ll max2=b[n-2];
  rep(i,n){
    if(a[i]==max1){
      cout<<max2<<endl;
    }else{
      cout<<max1<<endl;
    }
  }
}


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

int main() {
    string S;
    cin>>S;
    
    int lose=0;
    for (int i=0; i<S.size(); i++) {
        if (S[i]=='x') {
            lose++;
        }
    }
    
    if (lose<8) {
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define ll long long
#define il inline
#define rgi register int

using namespace std;

const int N = 100000 + 10;

int len, ans[N], close[N], cur_l, cur_r;
char str[N];

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main()
{
	scanf("%s", str + 1);
	len = strlen(str + 1);
	for(rgi i = 1; i <= len; ++i)
	{
		if(str[i] == 'R')
			cur_r = i;
		if(str[i] == 'L')
			close[i] = cur_r;
	}
	for(rgi i = len; i >= 1; --i)
	{
		if(str[i] == 'L')
			cur_l = i;
		if(str[i] == 'R')
			close[i] = cur_l;
	}
	for(rgi i = 1; i <= len; ++i)
	{
		if(str[i] == 'R')
		{
			int pos = close[i];
			int times = pos - i;
			if(times & 1)
				ans[pos - 1]++;
			else
				ans[pos]++;
		}
		else if(str[i] == 'L')
		{
			int pos = close[i];
			int times = i - pos;
			if(times & 1)
				ans[pos + 1]++;
			else
				ans[pos]++;
		}
	}
	for(rgi i = 1; i <= len; ++i)
		printf("%d ", ans[i]);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  ll ans = 0;
  vector<ll> h(n);
  for (int i = 0; i < n; i++){
    cin >> h[i];
  }
  
  for (int i = 0; i < n; i++){
    int ok = 1;
    for (int j = 0; j < i; j++){
      if (h[i] < h[j])
        ok = 0;
    }
    if (ok)
      ans++;
  }
  
  cout << ans << endl;

  return 0;
}


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

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)
#define INF 1000000000
#define MOD 1000000007
typedef  long long ll;
using namespace std;

ll conv(ll n,ll r){
    if(r == 0 || n==r){
        return 1;
    }
    return conv(n-1,r)+conv(n-1,r-1);
}


void solve(void){
    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    rep(i,0,n) {
        cin >> a[i];
        sum += a[i];
    }
    ll ans[n];

    //１つ決まると全部決まる.
    ans[0] = -sum/(ll)2;
    rep(i,0,n/2+1) ans[0] += a[2*i];
    rep(i,0,n-1) ans[i+1] = a[i]-ans[i];
    rep(i,0,n) cout << 2*ans[i] << " ";
    
    cout << endl;
   
}


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



Measured memory_bytes: 2944
#include <iostream>

using namespace std;

int main()
{
    int L;

    while (cin >> L, L) {
        int M, N;
        int ans = 0;

        for (int i = 0; i < 12; i++) {
            cin >> M >> N;
            L -= (M - N);
            if (L <= 0 && ans == 0) 
                ans = i + 1;
        }
        if (ans == 0)
            cout << "NA" << endl;
        else
            cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
    
#define endl '\n'
//#define int long long

using namespace std;
signed main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    bool ha = true;
    if (t.size() != s.size() + 1) {
        ha = false;
    } else {
        int i = 0;
        int n = s.size();
        for (int i =0;i < n; i++) {
            if (s[i] != t[i]) {ha = false; break;}
        }
    }

    if (ha) cout << "Yes";
    else cout << "No";
}


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

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

int main() {
    string s;
    cin>>s;
    ll ans=s.size();
    bool a=true;
    for(ll i=1;i<s.size();i++){
        if(a && s[i]==s[i-1]){
            i++;
            ans--;
            a=false;
        }else if(a){
            
        }else{
            a=true;
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define FOR(I,N) for(I=0;I<N;++I)
ll n,k;
vector<ll> v,w;
//unordered_map<ll,ll> memo;

int main()
{
	ll W,i,j,x,y,sum=0;
	cin>>n>>W;
	FOR(i,n)
	{
		cin>>x>>y;
		w.pb(x);
		v.pb(y);
		sum+=y;
	}
	vector<ll> dp(sum+1,1e18);
	dp[0]=0;
	FOR(i,n)
	{
		for(j=sum-v[i];j>=0;--j)
		{
			dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
		}
	}
	x=0;
	FOR(i,sum+1)
	{
		if(dp[i]<=W)
			x=i;
	}

	cout<<x;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();

        if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3])
        {
            Console.WriteLine("No");
        }
        else if (
            s[0] == s[1] && s[2] == s[3] ||
            s[0] == s[2] && s[1] == s[3] ||
            s[0] == s[3] && s[1] == s[2])
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
# https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_A
import sys
input = sys.stdin.readline

n, q = map(int, input().split())

class RMQ:
    def __init__(self, n, e):
        # 単位元
        self.e = e
        # num_min:n以上の最小の2のべき乗
        self.num_min =2**(n-1).bit_length()
        self.seg_min=[self.e]*2*self.num_min

    def init_min(self, init_min_val):
        #初期値が指定されている場合
        #set_val
        for i in range(n):
            self.seg_min[i+self.num_min-1]=init_min_val[i]
        #built
        for i in range(self.num_min-2,-1,-1) :
            self.seg_min[i]=min(self.seg_min[2*i+1],self.seg_min[2*i+2])

    def update_min(self, k, x):
        k += self.num_min-1
        self.seg_min[k] = x
        while k:
            k = (k-1)//2
            self.seg_min[k] = min(self.seg_min[k*2+1],self.seg_min[k*2+2])

    def query_min(self, p, q):
        q += 1
        if q<=p:
            return self.e
        p += self.num_min-1
        q += self.num_min-2
        res=self.e
        while q-p>1:
            if p&1 == 0:
                res = min(res,self.seg_min[p])
            if q&1 == 1:
                res = min(res,self.seg_min[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = min(res,self.seg_min[p])
        else:
            res = min(min(res,self.seg_min[p]),self.seg_min[q])
        return res

e = (2**31) - 1
rmq = RMQ(n, e)

for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        rmq.update_min(x, y)
    else:
        ans = rmq.query_min(x, y)
        print(ans)



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

int main(){
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++){
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  
  for (int i = 0; i < k; i++){
    ans += p[i];
  }

  cout << ans << endl;
  //今回のように複数ある選択肢からk種類選んで最小合計値を求めたい場合は、一個づつ最小値を求めて採用していき、k種類探す。和を求める。
  //もしくはsort
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int n, K; int main(){n = read(); K = read(); return !printf("%d\n",(n-2)/(K-1)+1);}

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

using namespace std;

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

    long ans=0;
    long cnt=0;

    for (auto & x : S)
    {
        if(x=='A'||x=='T'||x=='G'||x=='C'){
            cnt++;
            ans=max(ans,cnt);
        }
        else
        {
            cnt=0;
        }
        
    }
    

    cout<<ans<<endl;
}

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

template<typename T, typename E, typename F, typename G, typename H>
class LazySegmentTree {
  int n, height;
  F f; G g; H h; const T ti; const E ei;
  vector<T> dat; vector<E> laz; vector<int> highest;

  void propagate(int k) {
    if(laz[k] != ei) {
      laz[2*k] = h(laz[2*k],laz[k]); laz[2*k+1] = h(laz[2*k+1],laz[k]);
      dat[k] = g(dat[k],laz[k],n/highest[k]);
      laz[k] = ei;
    }
  }
  inline void recalc(int k) {
    while(k >>= 1) dat[k] = f(g(dat[2*k],laz[2*k],n/highest[2*k]),g(dat[2*k+1],laz[2*k+1],n/highest[2*k+1]));
  }
  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }
public:
  LazySegmentTree(int _n, F f, G g, H h, T ti, E ei): f(f), g(g), h(h), ti(ti), ei(ei) {
    n = 1; height = 0;
    while(n < _n) n <<= 1, height++;
    dat.assign(2*n,ti); laz.assign(2*n,ei); highest.assign(2*n,0);
    int c = 1;
    for(int i = 1; i < 2*n; i++) {
      if(c*2 <= i) c <<= 1;
      highest[i] = c;
    }
  }
  void set(int k, T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int a, int b, const E x) {
    thrust(a += n); thrust(b += n-1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l],x), ++l;
      if(r & 1) --r, laz[r] = h(laz[r],x);
    }
    recalc(a); recalc(b);
  }
  T query(int a, int b) {
    thrust(a += n); thrust(b += n-1);
    T l = ti, r = ti; b++;
    while(a < b) {
      if(a & 1) l = f(l,g(dat[a],laz[a],n/highest[a])), a++;
      if(b & 1) b--, r = f(g(dat[b],laz[b],n/highest[b]),r);
      a >>= 1; b >>= 1;
    }
    return f(l,r);
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  auto f = [](ll a, ll b){return min(a,b);};
  auto g = [](ll a, ll b, int l){return a+b;};
  auto h = [](ll a, ll b){return a+b;};
  LazySegmentTree<ll,ll,decltype(f),decltype(g),decltype(h)> lst(n,f,g,h,INF,0);
  rep(i,n) lst.set(i,0);
  lst.build();
  vector<ll> ans;
  rep(i,q) {
    int t;
    cin >> t;
    if(t == 0) {
      int l, r; ll x;
      cin >> l >> r >> x;
      lst.update(l-1,r,x);
    } else {
      int p;
      cin >> p;
      ans.push_back(lst.query(p-1,p));
    }
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const long long MOD = 1000000007;

long long mod_pow(long long a, long long b)
{
  if (b == 0) return 1;
  long long ret = mod_pow(a, b/2);
  ret = ret * ret % MOD;
  if (b % 2 == 1) ret = a * ret % MOD;
  return ret;
}

long long comb(long long a, long long b)
{
  if (b > a - b) return comb(a, a - b);

  long long num = 1;
  long long denom = 1;

  for (int i = 1; i <= b; i++) {
    num = num * (a - i + 1) % MOD;
    denom = denom * i % MOD;
  }

  return num * mod_pow(denom, MOD-2) % MOD;
}

ll calc(ll n, ll m, ll k) {
  ll c = comb((n*m-2+MOD)%MOD,k-2);
  ll res = 0;
  for (int d = 1; d < n; d++) {
    res = (res + d*(n-d)*m%MOD*m*c%MOD) % MOD;
  }
  return res;
}

ll n,m,k;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> m >> k;

  ll res = (calc(n,m,k) + calc(m,n,k)) % MOD;

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b;
    
    scanf("%d %d\n",&a,&b);
    
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    
    
    return(0);
    
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(all(p));
  ll ans = 0, in = 0;
  multiset<ll, greater<ll>> st;
  rep(i, m) {
    while(in < n && p[in].first <= i + 1) {
      st.insert(p[in].second);
      in++;
    }
    if(st.empty()) continue;
    ans += *st.begin();
    st.erase(st.begin());
  }
  cout << ans << endl;
}

Measured memory_bytes: 9596
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int n[12];
	int e[101] = {};
	for (int i = 0; i < 12; ++i) {
		cin >> n[i];
		e[n[i]] += 1;
	}
	for (int i = 0; i < 101; ++i) {
		
		if (e[i] % 4 == 0) {

			if (i == 100) {
				cout << "yes" << endl;
			}
		}
		else { cout << "no" << endl; break; }
	}
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define mpr make_pair
#define fr first
#define se second
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{
     Senky_Bansal
     IIIT_ALLAHABAD
  
     string s;
     ll ans=0;
     cin>>s;
     ll mx=0;
     int i=0;
     while(i<s.size())
     {
         ll f=0;
         mx=0;
         while((s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C') && i<s.size())
         {
             i++;
             mx++;
             f=1;
         }
         if(!f) i++;
         ans=max(ans,mx);
     }
     cout<<ans;
     
      
    
}




Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int M,K;
  cin >> M >> K;
  if(K == 0){
    vector<int> ans;
    for(int i=0; i<(1LL<<M); i++){
      ans.emplace_back(i);
      ans.emplace_back(i);
    }
    for(int i=0; i<ans.size(); i++){
      cout << ans[i] <<" \n"[i+1==ans.size()];
    }
    return 0;
  }
  if(K >= (1LL<<M)){
    cout << -1 << "\n";
    return 0;
  }
  if(M == 1){
    cout << -1 << "\n";
    return 0;
  }
  vector<int> ans;
  ans.emplace_back(K);
  for(int i=(1LL<<M)-1; i>=0; i--){
    if(i == K) continue;
    ans.emplace_back(i);
  }
  ans.emplace_back(K);
  for(int i=0; i<(1LL<<M); i++){
    if(i == K) continue;
    ans.emplace_back(i);
  }
  for(int i=0; i<ans.size(); i++){
    cout << ans[i] << " \n"[i+1==ans.size()];
  }
  return 0;
}


Measured memory_bytes: 4288
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=1000+10;

int n;
int aa[maxn];
int b[maxn][maxn];
vector<int> a[maxn*maxn];
int d[maxn*maxn],deg[maxn*maxn]={0};
int queue[maxn*maxn],front,rear;
int kq;

int id(int i,int j){
  return b[i][j];
}

int main(){
  //freopen("input.txt","r",stdin);
  scanf("%d",&n);int nn=0;
  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++){
      nn++;b[i][j]=b[j][i]=nn;
    }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n-1;j++) scanf("%d",&aa[j]);
    for(int j=1;j<=n-2;j++){
      int u=id(i,aa[j]);int v=id(i,aa[j+1]);
      //cout<<"make("<<u<<"->"<<v<<")\n";
      a[u].push_back(v);deg[v]++;
    }
  }
  //cout<<"NN= "<<nn<<endl;
  front=1;rear=0;
  for(int i=1;i<=nn;i++) d[i]=-1;
  for(int i=1;i<=nn;i++)
    if (deg[i]==0){
      rear++;queue[rear]=i;d[i]=1;
    }
  while(front<=rear){
    int u=queue[front];front++;
    for(int i=0;i<a[u].size();i++){
      int v=a[u][i];
      if (deg[v]>0){
        deg[v]--;
        if (deg[v]==0){
          d[v]=d[u]+1;rear++;queue[rear]=v;
        }
      }
    }
  }
  if (rear<nn) cout<<-1;
  else{
    kq=0;for(int i=1;i<=nn;i++) kq=max(kq,d[i]);
    cout<<kq;
  }
}


Measured memory_bytes: 55552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

#define INF 1LL << 59
struct edge {
    ll to, cost;
};
typedef pair<ll, ll> P;
ll d[202020];
ll bef[202020];
ll V;
vector<edge> G[202020];

edge makeedge(ll t, ll c) {
    edge e;
    e.to = t;
    e.cost = c;
    return e;
}

void addedge(ll s, ll t, ll c) {
    G[s].push_back(makeedge(t, c));
    G[t].push_back(makeedge(s, c));  //双方向
}

void dijkstra(ll s) {
    // priority_queue<P, vector<P>, greater<P> > que;
    queue<P> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;
        for (ll i = 0; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                bef[e.to] = v;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n, m;
    cin >> n >> m;
    V = n + 1;
    for (i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        addedge(a, b, 1);
    }
    dijkstra(1);
    cout << "Yes" << endl;
    for (i = 2; i <= n; i++) {
        cout << bef[i] << endl;
    }
}

Measured memory_bytes: 20636
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
ll n,k,ans;
ll dp[1000005];
int main(){
    cin>>n;
    dp[0]=1;
    for(int i=3;i<=n;i++){
		for(int j=3;i-j>=0;j++){
			dp[i]=(dp[i]+dp[i-j])%1000000007;
		}
	}
	cout<<dp[n];
	//system("pause");
    return 0;
}


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

int main(){
  int a,b,c,d,e,k,maxa,mina;
  cin>>a>>b>>c>>d>>e>>k;
  maxa=max(max(max(max(a,b),c),d),e);
  mina=min(min(min(min(a,b),c),d),e);
  if((maxa-mina)>k){
    cout<<":("<<endl;
    return 0;
  }
  cout<<"Yay!"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<map>
#include<vector>
#include<ctime>
#include<stack>
#define mp make_pair
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long

using namespace std;

inline ll read()
{
	long long f=1,sum=0;
	char c=getchar();
	while (c<'0' || c>'9')
	{
		if (c=='-')	f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum*f;
}
int p[5];
int main()
{
	int a,b,c;
	scanf("%d%d%d",&p[1],&p[2],&p[3]);
	sort(p+1,p+1+3);
	a=p[1],b=p[2],c=p[3];
	int ans=0;
	if ((b-a)&1)
	{ 
		ans+=(b-a-1)/2;
		a=b-1;
		c++,a++,ans++;
		ans+=(c-b);
	}
	else
	{
		ans+=(b-a)/2;
		ans+=(c-b);	
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main (void){

    int a, b, k;
    int flg = 0;

    cin >> k >> a >> b;
    for(int i = a;i <= b;i++){
        if(i % k == 0){
            flg = 1;
            break;
        }
    }
    if(flg == 1)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;


    return 0;
}

Measured memory_bytes: 3596
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val A = nextIntList()
    var broke = 0
    var target = 1
    A.forEach { a ->
        if (a == target) {
            target++
        } else {
            broke++
        }
    }
    println(if (broke != N) broke else -1)
}

Measured memory_bytes: 83060