akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;       //     ____   _   _  __   __
#define ll long long       //    / ___| | |_| |   / /
const ll INF = 0x3f3f3f3f; //   | |     |  _  |   V /
const ll N   = 1e5 + 5;    //   | |___  | | | |   | |
const ll MOD = 1e9 + 7;    //    ____| |_| |_|   |_|
ll read() {
  ll   x = 0, f = 1;
  char ch = getchar();

  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1; ch = getchar();
  }

  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0'; ch = getchar();
  }
  return x * f;
}

ll n;
ll b[N];
ll a[N];
ll ans;

int main() {
  n = read();

  for (int i = 1; i < n; i++) b[i] = read();
  a[1] = b[1];
  a[2] = b[1];

  for (int i = 2; i < n; i++) {
    if (a[i] >= b[i]) a[i] = a[i + 1] = b[i];
    else a[i + 1] = b[i];
  }

  for (int i = 1; i <= n; i++) ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main(){
	char s,a;
	cin >>s;
	switch(s){
	case 'A':a='T';break;
	case 'C':a='G';break;
	case 'T':a='A';break;
	case 'G':a='C';break;
	}
	cout <<a<<endl;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	vector<bool> dp(k+1);
	for (int i=0; i<n; ++i){
		cin >> a[i];
		dp[a[i]] = true;
	}
	for (int i=0; i<=k; ++i){
		if (!dp[i]){
			for (int A:a){
				if (i-A >= 0 and !dp[i-A]){
					dp[i] = true;
					break;
				}
			}
		}
	}
	for (int i:a){
		if (!dp[k-i]){
			cout << "First";
			return 0;
		}
	}
	cout << "Second";
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long n; cin>>n;
  vector<char> ans;
  while(1){
    unsigned long idx=--n%26;
    ans.push_back('a'+idx);
    if(n/26==0) break;
    else n/=26;
  }
  reverse(ans.begin(),ans.end());
  string s="";
  for(char c:ans) s+=c;
  cout<<s;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll=pair<ll,ll>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) //a/bの除算の切り上げ
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; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = acos(-1);
 
//a^b=b^a
//a^(b^c)=(a^b)^c
//a^a=0
//a+b=a^b + 2(a&b)
//(4a)^(4a+1)^(4a+2)^(4a+3)=0
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_),siz(sz_, 1LL){
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
   }
   void init(ll sz_){
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x){ // 根の検索
      while (par[x]!=x){
           x=par[x]=par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y){
       x=root(x);
       y=root(y);
       if (x==y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x]<siz[y]) swap(x, y);
       siz[x]+=siz[y];
       par[y]=x;
       return true;
  }
 
  bool same(ll x, ll y){ // 連結判定
       return root(x)==root(y);
  }
 
  ll size(ll x){ // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n){
   x=x%mod;
   if(n==0) return 1;
 
   else if(n%2==1){
       return (x*modpow(x, n-1))%mod;
   }
   else return modpow((x*x)%mod, n/2)%mod;
}
 
ll com(ll n, ll k){
   ll x=1;
   for(int i=n-k+1; i<=n; i++){
      x=x*i%mod;
   }
 
   ll y=1;
   for(int i=1; i<=k; i++){
       y=y*i%mod;
   }
   y=modpow(y,mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  }
 
   if(n%2==0 || n%3==0) return false;
 
   for(unsigned i = 5; i*i<=n; i+=6) {
       if(n%i==0) return false;
       if(n%(i+2)==0) return false;
   }
 
   return true;
}
 
int digsum(int n){
   int res=0;
   while(n > 0) {
       res+=n%10; //ここをres++;に変えたら桁数を求める関数になる,res+=n%10;なら格桁の和
       n/=10;
   }
   return res;
}
vector<ll> divisor(ll n){
   vector<ll> ret;
   for(ll i=1; i*i<=n; i++){
       if(n%i==0){
           ret.push_back(i);
           if(i*i!=n) ret.push_back(n/i);
       }
   }
   sort(ret.begin(),ret.end());
   return ret;
}

vector<ll> yakusuu_cnt(ll n){
    vector<ll> cnt(n);
    for(ll i=1; i<=n; i++){
        for(ll j=i; j<=n; j+=i){
            cnt[j]++;
        }
    }
    return cnt;
}
 
int main(){

    ll n;
    cin >> n;
    auto x=yakusuu_cnt(n);
    ll ans=0;
    for(ll i=1; i<=n; i++){
        ans+=(i*x[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 81364
import java.util.*;
public class Main {
    static int[] nums;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int q=sc.nextInt();
        nums=new int[n+1];
        nums[n]=Integer.MAX_VALUE;
        for(int i=0;i<n;i++){
            nums[i]=sc.nextInt();
        }
        Arrays.sort(nums);
        for(int i=0;i<q;i++){
            System.out.println(-(nibul(sc.nextInt())-nibur(sc.nextInt())));
        }
    }
    static int nibul(int q){
        int ans=nums.length/2;
        int toadd=nums.length/2;
        while(true){
            if(ans<0||ans>=nums.length){
                break;
            }
            if(nums[ans]>=q){
                ans-=Math.max(toadd/=2,1);
            }else if(nums[ans+1]<q){
                ans+=Math.max(toadd/=2,1);
            }else{
                break;
            }
            
        }
        return ans;
    }
    static int nibur(int q){
        int ans=nums.length/2;
        int toadd=nums.length/2;
        while(true){
            if(ans<0||ans>=nums.length){
                break;
            }
            if(nums[ans]>q){
                ans-=Math.max(toadd/=2,1);
            }else if(nums[ans+1]<=q){
                ans+=Math.max(toadd/=2,1);
            }else{
                break;
            }
            
        }
        return ans;
    }


    
}


Measured memory_bytes: 106108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
  
int main(){
  int N,total =0; cin >> N;
  int a[N]; 
  rep(i,N) {
    cin >> a[i]; total += a[i];
  }
  
  int ave =total / N;
  int ans, ans1 =0, ans2 =0;
  rep(i,N) ans1 += (a[i] - ave) * (a[i] - ave);  
  rep(i,N) ans2 += (a[i] - ave -1) * (a[i] - ave -1);  
  
  ans = min(ans1,ans2);
  cout << ans << endl;
}

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

int main() {
  int n; cin >>n;
  int max=0, ans = 0;
  int buf;
  for (int i=0; i<n; i++){
    cin >>buf;
    if (buf>=max){
      max = buf; ans++;
    }
  }
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
L.sort()
# print(L)

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if L[i] == L[j]:
            continue
        for k in range(j + 1, N):
            if L[j] == L[k]:
                continue
            if L[i] + L[j] > L[k]:
                # print(i, j, k)
                ans += 1
            else:
                break
print(ans)

Measured memory_bytes: 9192
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
from itertools import combinations
ans = float("inf")
for c in combinations(range(n), k):
    c = sorted(c)
    val = 0
    m = -1
    for i in range(n):
        if i in c:
            if m>=a[i]:
                val += (m+1)-a[i]
                m = m + 1
            else:
                m = a[i]
        else:
            m = max(m, a[i])
#     print(val, c)
    ans = min(ans, val)
print(ans)

Measured memory_bytes: 72160
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    vector<long long> m(0), p(0);
    long long cz = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] < 0) m.push_back(-A[i]);
        else if(A[i] == 0) cz++;
        else p.push_back(A[i]);
    }
    sort(m.begin(), m.end());
    sort(p.begin(), p.end());
    sort(A.begin(), A.end());
    long long ub = 2e18, lb = -2e18;
    while(ub - lb > 1){
        long long count = 0;
        long long cen = (ub + lb) / 2;
        long long temp = 0;
        for(int i = 0; i < N; i++){
            if(A[i] != 0) temp = (abs(cen) + abs(A[i]) - 1) / abs(A[i]);
            if(cen < 0){
                if(A[i] > 0) count += m.end() - lower_bound(m.begin(), m.end(), temp);
                else if(A[i] < 0) count += p.end() - lower_bound(p.begin(), p.end(), temp);
            }
            else if(cen == 0){
                if(A[i] > 0) count += cz + m.size();
                else if(A[i] == 0) count += N;
                else count += cz + p.size();
            }
            else{
                if(A[i] > 0) count += cz + m.size() + (upper_bound(p.begin(), p.end(), cen / A[i]) - p.begin());
                else if(A[i] < 0) count += cz + p.size() + (upper_bound(m.begin(), m.end(), cen / abs(A[i])) - m.begin());
                else count += N;
            }
            if(A[i]*A[i] <= cen) count--;
        }
        if(count >= 2*K) ub = cen;
        else lb = cen;
    }
    cout << ub << endl;
}

Measured memory_bytes: 3956
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[][] items = new int[n][4];
			
			for(int i = 0; i < n; i++){
				for(int j = 0; j < 4; j++){
					items[i][j] = sc.nextInt();
				}
			}
			
			int[] limits = new int[4]; 
			for(int i = 0; i < 4; i++){
				limits[i] = sc.nextInt();
			}
			
			boolean found = false;
			START:for(int i = 0; i < n; i++){
				for(int j = 1; j < 4; j++){
					if(items[i][j] > limits[j-1]){
						continue START;
					}
				}
				
				if(items[i][1]*4 + items[i][2]*9 + items[i][3]*4 > limits[3]){
					continue START;
				}
				
				found = true;
				System.out.println(items[i][0]);
			}
			
			if(!found){
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll MOD=1000000007;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

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

   int cnt=0;

   rep(i,1000000000){
      if(cnt+i>=n){
         cout<<i;
         break;
      }
      else cnt+=i;
   }

   
   return 0;
}


Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int m=n;
    int q=0;
    while(m!=0){
        q+=m%10;
        m/=10;
    }
    if(n%q==0){
        cout<<"Yes"<<endl;
    }
    else 
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#define MAX 101
using namespace std;

int main() {
	string s[MAX];
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		cin >> s[i];
	}

	for (int i = 0; i < 2*h; ++i) {
		for (int j = 0; j < w; ++j) {
			string c {s[i/2][j]};
			cout << c;
		}
		cout << endl;
	}
	return 0;
}


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

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

    int ans = 1;

    for(int i = 0; i < N; i++){
        if(ans <= K){
            ans *= 2;
        }else{
            ans += K;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8
#
    
def main(x1, y1, x2, y2):
    x3 = x2 + (- (y2 - y1))
    y3 = y2 + ((x2 - x1))
    x4 = x3 + (- (y3 - y2))
    y4 = y3 + ((x3 - x2))
    print('{} {} {} {}'.format(x3, y3, x4, y4))
    
if __name__ == '__main__':
    try:
        x1,y1,x2,y2 = list(map(int,input().strip().split(' ')))
        main(x1, y1, x2, y2)
    except EOFError:
        pass


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF 1e15

#define MAX_N 1000

int h,w;
int g[222][222];
ll dp[444][222][222];

ll dfs(int d,int x1,int x2){
	int y1=d-x1,y2=d-x2;
	if((x1<0||x1>=w||y1<0||y1>=h)||(x2<0||x2>=w||y2<0||y2>=h))return -INF;
	if(dp[d][x1][x2]!=-1)return dp[d][x1][x2];
	if(d==h+w-2)return g[y1][x1];
	ll res=-INF;
	maxch(res,dfs(d+1,x1,x2));
	maxch(res,dfs(d+1,x1+1,x2));
	maxch(res,dfs(d+1,x1,x2+1));
	maxch(res,dfs(d+1,x1+1,x2+1));
	res+=g[y1][x1]; res+=g[y2][x2];
	if(x1==x2)res-=g[y1][x1];
	return dp[d][x1][x2]=res;
}

int main(){
	cin.sync_with_stdio(false);
	cin>>h>>w;
	rep(i,h)rep(j,w)cin>>g[i][j];
	memset(dp,-1,sizeof(dp));
	cout<<dfs(0,0,0)<<endl;
	return 0;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };
 
typedef long long ll;
using namespace std;
 
int main() {
  int n,l;
  scanf("%d%d",&n,&l);

  string s[n],r;
  rep(i,0,n){
    cin >> s[i];
  }
  
  sort(s,s+n);
  
  rep(i,0,n){
    cout << s[i];
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


int n, k, q;
int cnt[114514];
signed main() {
	cin >> n >> k >> q;
	rep(i, q) {
		int a; cin >> a; cnt[a - 1]++;
	}
	rep(i, n) {
		if (k - (q - cnt[i]) <= 0)cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
using namespace std;
 int main(){
	long long x;
	cin>>x;
for(long long i=-1000;i<1000;i++){
	for(long long j=-1000;j<1000;j++){
		if(j*j*j*j*j-i*i*i*i*i==x){
			cout<<j<<" "<<i;
			return 0;
		}
	}
}
}

Measured memory_bytes: 3560
N = int(input())
a = list(map(int, list(input())))
t = [0 for i in range(N+1)]
i = 2
while i < N:
	for j in range(i, N+1, i):
		t[j] += 1
	i *= 2
sum_t = [0]
for i in range(1, N+1):
	sum_t.append(sum_t[-1] + t[i])

x = [max(a[i], a[i+1]) - min(a[i], a[i+1]) for i in range(N-1)]


def isCombOdd(n,k):
	bunshi = sum_t[n] - sum_t[n-k]
	bunbo = sum_t[k]
	return bunshi == bunbo

f1 = False
for n in x:
	if n == 1:
		f1 = True
		break
if f1:
	x = [n if n != 2 else 0 for n in x]

candidate = 1 if f1 else 2
ans = 0
for i in range(N-1):
	if x[i] > 0 and isCombOdd(N-2, i):
		ans = 1 - ans

print(0 if ans == 0 else candidate)

Measured memory_bytes: 146172
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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 long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int N;  ll K; 
std::vector<ll> A,F;

ll f (ll m) {
  ll k = 0;
  rep(i,N) {
    ll s = m / F[i];
    k += std::max(0LL, A[i] - s);
  }
  return k;
}

ll binarysearch(ll left, ll right) {
  if ( left >= right ) return left;
  ll mid = (left+right)/2;
  if ( K < f(mid) ) return binarysearch(mid+1, right);
  else return binarysearch(left, mid);
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::cin >> N;
  std::cin >> K;
  A.resize(N); F.resize(N);
  rep(i,N) std::cin >> A[i];
  rep(i,N) std::cin >> F[i];

  std::sort( all(A) );
  std::sort( all(F) );
  std::reverse( all(F) );

  std::cout << binarysearch(0, 1e16) << std::endl;

  return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;

int i,j,k,n,t,a;
bitset<4000010> b;

int main(){
	scanf("%d", &n);
	b[0]=1;
	for(t=i=0;i<n;i++){
		scanf("%d", &a);
		b |= b<<a;
		t +=a;
	}
	for(t=(t+1)/2;!b[t];t++);
	printf("%d\n", t);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    rep(query,q){
        ll a,b;
        cin>>a>>b;
        if(a>b) swap(a,b);
        ll c=sqrt(a*b);
        cout<<c+(a*b-1)/c-2+(a==b)<<"\n";
    }
}


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

int main() {
	int N, A = 0, B = 0, BA = 0, ans = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < s.size() - 1; ++j) {
			if (s[j] == 'A' && s[j + 1] == 'B') ++ans;
		}
		if (s[0] == 'B' && s[s.size() - 1] == 'A') ++BA;
		else if (s[0] == 'B') ++B;
		else if (s[s.size() - 1] == 'A') ++A;
	}
	if (BA != 0) {
		ans += BA - 1;
		if (A != 0) {
			--A;
			++ans;
		}
		if (B != 0) {
			--B;
			++ans;
		}
	}
	ans += min(A, B);
	cout << ans;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
ll len[18];
int main() {
	for (ll i = 1, k = 1; i < 18; i++, k *= 10) {
		len[i] = len[i - 1] + k * 9 * i - k * 9 / 3 * (i - 4) - k * 9 / 5 * (i - 4) + k * 9 / 15 * i;
	}
	ll s;
	cin >> s;
	int n = lower_bound(len, len + 18, s) - len - 1;
	ll a = (s - len[n] - 1) / ((n + 1) * 8 + 4 * 8);
	int o = (s - len[n] - 1) % ((n + 1) * 8 + 4 * 8);
	ll k = 1;
	for (int i = 1; i <= n; i++)k *= 10;
	string buf;
	for (ll i = k + a * 15; i < k + a * 15 + 30; i++) {
		if (i % 3 == 0) {
			buf += "Fizz";
			if (i % 5 == 0) {
				buf += "Buzz";
			}
		}
		else if (i % 5 == 0) {
			buf += "Buzz";
		}
		else {
			buf += to_string(i);
		}
	}
	string res(buf.begin() + o, buf.begin() + o + 20);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3284
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preorder(int u)  {
  if (u == NIL)
    return;
  printf (" %d", u);
  preorder(T[u].l);
  preorder(T[u].r);
}

void inorder(int u)  {
  if (u == NIL)
    return;
  inorder(T[u].l);
  printf(" %d", u);
  inorder(T[u].r);
}

void postorder(int u)  {
  if (u == NIL)
    return;
  postorder(T[u].l);
  postorder(T[u].r);
  printf(" %d", u);
}

int main(void)  {
  int i, v, l, r, root;

  scanf("%d", &n);
  for (i = 0; i < n; i++)  {
    T[i].p = NIL;
  }
  
  for (i = 0; i < n; i++)  {
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if (l != NIL)
      T[l].p = v;
    if (r != NIL)
      T[r].p = v;
  }
  
  for ( i = 0; i < n; i++)
    if (T[i].p == NIL)
      root = i;
  printf("Preorder\n");
  preorder(root);
  printf("\nInorder\n");
  inorder(root);
  printf("\nPostorder\n");
  postorder(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 1856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct SegmentTree {
private:
    int n;
    vector<int> node;
 
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = (node[2*i+1] + node[2*i+2]);
    }
 
    void add(int x, int val) {
        x += (n - 1);
        node[x] += val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = (node[2*x+1] + node[2*x+2]);
        }
    }
    // hannkaikukann 
    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr);
    }
};


#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    ll n;
    cin >> n;
    int a[100050];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    if(n == 1){
        cout << a[1] << endl;
        return 0;
    }
    ll ok = 1;
    ll ng = 1000000005;
    while(ng - ok > 1){
        ll mid = (ok + ng) / 2;
        int b[200050];
        for(int i = 1; i <= n; i++){
            if(a[i] >= mid){
                b[i] = 1;
            } else {
                b[i] = -1;
            }
        }
        int sum = 100000;
        vector<int> v(200050);
        SegmentTree seg(v);
        ll inversion = 0;
        bool checker = false;
        seg.add(100000, 1);
        for(int i = 1; i <= n; i++){
            sum += b[i];
            inversion += seg.getsum(0, sum + 1);
            //cout << mid << " " << i << " " << seg.getsum(0, sum + 1) << " " << inversion << endl;
            seg.add(sum, 1);
            if(inversion >= (n * (n + 1) / 4)){
                checker = true;
                break;
            }
        }
        if(checker){
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 4700
n=int(input())
a=[int(i) for i in input().split()]

for i in range(n-1):
    a[i+1]+=a[i]

j=0
k=2
ans=10**9

for i in range(1,n-1):
    while abs(a[j]*2-a[i])>abs(a[j+1]*2-a[i]):
        j+=1
    while abs(a[k]*2-a[i]-a[n-1])>abs(a[k+1]*2-a[i]-a[n-1]):
        k+=1
    t=[a[j],a[i]-a[j],a[k]-a[i],a[n-1]-a[k]]
    ans=min(ans,max(t)-min(t))
print(ans)


Measured memory_bytes: 108792
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;

int main(void)
{
	int A, B, C; cin >> A >> B >> C;
	bool flag = false;
	rep(i, 1, B+1) {
		if ((A*i)%B == C) {
			flag = true;
			break;
		}
	}

	if (flag)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N; cin >> N;

    ll ans = 1;
    for(ll i = 1; i <= N; i++){
        ans *= i;
        ans %= MOD;
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
cnt = Counter(map(int, input().split()))

L = []
for a, c in cnt.items():
    if c >= 2:
        L += [a] * (c // 2)
L.sort()

ans = 0 if len(L) < 2 else L[-1] * L[-2]
print(ans)


Measured memory_bytes: 24104
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    V< V< P< P<int, int>, int> > > rd(n);
    for (int i = 0; i < m; i++) {
        int l, r, d; cin >> l >> r >> d;
        l--, r--;
        rd[l].emplace_back( make_pair( make_pair(r, d), i) );
        rd[r].emplace_back( make_pair( make_pair(l, -d), i) );
    }

    V<int> used(m, 0);
    map<int, int> cood;
    for (int i = 0; i < n; i++) {
        if (rd[i].size() == 0) continue;
        queue< P< int, P<int, int> > > que;
        for (int j = 0; j < rd[i].size(); j++) {
            if (used[rd[i][j].second] == 1) continue;
            used[rd[i][j].second] = 1;
            que.push( make_pair(i, rd[i][j].first));
        }
        while (!que.empty()) {
            P<int, P<int, int> > q = que.front(); que.pop();
            int l = q.first, r = q.second.first, d = q.second.second;
            if (rd[r].size() > 0) {
                for (int j = 0; j < rd[r].size(); j++) {
                    if (used[rd[r][j].second] == 1) continue;
                    used[rd[r][j].second] = 1;
                    que.push( make_pair(r, rd[r][j].first));
                }
            }

            if (cood.find(l) == cood.end()) {
                if (cood.find(r) == cood.end()) {
                    cood[l] = 0, cood[r] = d;
                } else {
                    int dr = cood[r];
                    d = dr - d;
                    cood[l] = d;
                }
            } else {
                if (cood.find(r) == cood.end()) {
                    int dl = cood[l];
                    d = dl + d;
                    cood[r] = d;
                } else {
                    if (cood[r] - cood[l] != d) {
                        cout << "No\n";
                        return 0;
                    }
                }
            }
        }
    }

    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 16564
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    while (n--) {
        int a[3];
        for (int i = 0; i < 3; i++) {
            cin >> a[i];
        }
        sort(a, a + 3);

        if (a[2] * a[2] == a[0] * a[0] + a[1] * a[1]) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }

    return 0;
}

Measured memory_bytes: 1136
#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>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  double N;
  cin >> N;
  vector<double> v(N);
  rep(i,N) cin >> v[i];

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

  double sum = 0;

  sum += v[0] / pow(2.0, N-1);
  //cout << sum << endl;
  rep(i, N-1) sum += v[i+1] / pow(2.0 , N-1-i);
  cout << sum << endl;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

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

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

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

from itertools import product

N = I()
S = str(input())

# 右側半分の組の全列挙
d = defaultdict(lambda:defaultdict(int))
A = list(product([0,1],repeat=N))
for a in A:
    x = []
    y = []
    for i in range(N):
        if a[i]:
            x.append(S[N+i])
        else:
            y.append(S[N+i])
    x = ''.join(x)
    y = ''.join(y)
    d[x][y] += 1

# 左側半分で各塗り方を全列挙
# 右側半分の赤，青の値が決まる
ans = 0
for a in A:
    x = []
    y = []
    for i in range(N):
        if a[i]:
            x.append(S[i])
        else:
            y.append(S[i])
    x = ''.join(x[::-1])
    y = ''.join(y[::-1])
    ans += d[x][y]
    
print(ans)

Measured memory_bytes: 298492
def solve():
    rowstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    h, w = map(int, input().split())
    snaketable = [input().split() for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if "snuke" in snaketable[i][j]:
                print("{0}{1}".format(rowstr[j], i+1))
                return


if __name__=="__main__":
    solve()

Measured memory_bytes: 38384
import collections
p = 2019
s=input()
n=len(s)
arr=[int(s[i]) for i in range(len(s))] #文字列の各文字をそれぞれ数字に変換しておく
if p==2 or p==5: #P=2,5のときは10を割り切るので連続部分列の右端のみを見ればよい
 ans=0
 for i in range(n):
   if arr[i]%p==0:
     ans+=i+1
 print(ans)
else: #Pが2でも5でもないとき
 dic=collections.defaultdict(int)
 tmp=0
 for i in range(n-1,-1,-1): #右端の要素を右端とする連続部分列のあまりを順に求める
   tmp+=arr[i]*pow(10,n-1-i,p)
   tmp%=p
   dic[tmp]+=1
 ans=0
 rem=0 #調べるあまりの値(初期値は0)
 for i in range(n-1,-1,-1):
   ans+=dic[rem]
   rem+=arr[i]*pow(10,n-1-i,p) #調べるあまりの値に(i番目の要素)*10^(n-1-i)を加える
   rem%=p
   dic[rem]-=1 #右端の要素が右端、i番目の要素が左端となる連続部分列のあまりの個数を1減らす
 print(ans)

Measured memory_bytes: 11216
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    vector<int> pos(N+1);
    FOR(i, 1, N+1) pos[a[i-1]] = i;

    long long ans = 0;
    //set<int> s{0, N+1};
    set<int> s;
    s.insert(0);
    s.insert(N+1);
    // 1 から順に l, r を求めていく
    FOR(i, 1, N+1){
        auto r = s.upper_bound(pos[i]);
        auto l = r; --l;
        ans += (long long) i * (*r-pos[i])*(pos[i]-*(l));
        s.insert(pos[i]);
    }
    cout << ans << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int main()
{
	fastio;

	ll d, t, s;
	cin >> d >> t >> s;

	cout << (t * s >= d ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3616
import sys,os,math
from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import Queue


# sys.stdin = open('input')
# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())


def main():
    n = map(int, raw_input().split())[0]
    da = [map(int, raw_input().split()) for i in range(n)]
    need = [0 for i in range(n+2)]
    t = [0 for i in range(n+2)]
    idx = [0 for i in range(n+2)]
    l = n*(n-1)/2
    ans = 0
    q = deque()
    for i in range(1, n+1):
        da[i-1].append(n+1)
        need[i] = da[i-1][idx[i]]
        if i == need[need[i]]:
            q.append(i);
    # print da
    while q:
        # print q
        fr = q.popleft()
        x, y = fr, need[fr]
        # print x,y,"sssssssss"
        # print need
        if not (x == need[y] and y == need[x]):
            continue
        ti = max(t[x], t[y]) + 1
        t[x] = t[y] = ti
        ans = max(ans, ti)
        l-=1
        idx[x] += 1
        idx[y] += 1
        need[x] = da[x-1][idx[x]]
        need[y] = da[y-1][idx[y]]
        if x == need[need[x]]:
            q.append(x)
        if y == need[need[y]]:
            q.append(y)
    # print l
    if l==0:
        print ans
    else:
        print -1






main()


Measured memory_bytes: 51352
n,d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

ans=0
for i in range(n):
    if x[i]**2+y[i]**2<=d**2:
        ans+=1

print(ans)

Measured memory_bytes: 116560
#include <stdio.h>

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

    int num[n];
    for(i=0;i<n;i++){
    scanf("%d",&num[i]);//配列は個別の要素に指定するときは＆演算子が必要
    }
    
    for(i=n-1;i>=0;i--){
        printf("%d",num[i]);
        if(i!=0)printf(" ");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
#define NUM 200

int digit(int a,int b){
  int cont;
  int i=0;
  cont=a+b;
  do{
    cont/=10;
    i++;
  }while(cont>0);
  return(i);
}

int main (void){
  int a,b,i,x,str[NUM];
  while(scanf("%d %d",&a,&b)!=EOF){
    x=digit(a,b);
    printf("%d\n",x);
  }
  return (0);
}

Measured memory_bytes: 596
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
import itertools

a, b, c, d = map(int, input().split())

ans = "No"
if abs(c - a) <= d:
    ans = "Yes"
elif abs(b - a) <= d and abs(c - b) <= d:
    ans = "Yes"

print(ans)


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

int main() {
  int N; cin >> N;
  string s; cin >> s;
  int E = count(s.begin(), s.end(), 'E');
  int W = 0;
  int res = N;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'E') E--;
    res = min(res, W + E);
    if (s[i] == 'W') W++;
  }
  cout << res << endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int MAX = 200005;
/* global variables */
vector<vector<int> > G(MAX, vector<int>());
vector<int> counter;
int N;
/* function */
void bfs() {
    vector<int> visited(N, 0);
    stack<int> q;
    q.push(0);
    visited[0] = 1;
    while (!q.empty()) {
        int from = q.top(); q.pop();
        for (int to : G[from]) {
            if (visited[to]) continue;
            counter[to] += counter[from];
            visited[to] = 1;
            q.push(to);
        }
    }
}

/* main */
int main(){
    int Q, a, b, p, x;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    counter.assign(N, 0);
    for (int i = 0; i < Q; i++) {
        cin >> p >> x;
        p--;
        counter[p] += x;
    }
    bfs();
    for (int c : counter) cout << c << ' ';
    cout << '\n';
}


Measured memory_bytes: 15588
#include<stdio.h>
int main(){
	int k,a,b,i,j=0;
	scanf("%d\n",&k);
	scanf("%d %d",&a,&b);
	for(i=a;i<=b;i++){
//	printf("%d",i%k);
		if(i%k==0)
		j=1;
		
	}
	if(j==1){
		printf("OK");
	}
	if(j==0){
		printf("NG");
	}
	
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#define MAX 100010

using namespace std;

int w,h;
vector<pair<int,int> > v;
long long a,b;
long long ans;

int main() {
    cin >> w >> h;
    for (int i = 0; i < w; i++) {
        int p;
        cin >> p;
        v.push_back(make_pair(p,0));
    }
    for (int i = 0; i < h; i++) {
        int p;
        cin >> p;
        v.push_back(make_pair(p,1));
    }

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

    for (auto p : v) {
        long long c = p.first;
        if (p.second == 0) {
            ans += c * (h+1 - b);
            a++;
        } else {
            ans += c * (w+1 - a);
            b++;
        }
    }

    cout << ans << '\n';
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
int main(void){
   int N;
   cin >> N;
   long long int a[N],ans=0;

   for(long long  i = 0; i < N; i++) {
       cin >> a[i];
       ans += a[i]-1;
   }
   
   cout << ans << endl;
   
    
}


Measured memory_bytes: 256
use std::io;

fn get_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_string()
}

fn main() {
    let n = get_line().parse::<u32>().unwrap();
    let k = get_line().parse::<u32>().unwrap();
    let x = get_line().parse::<u32>().unwrap();
    let y = get_line().parse::<u32>().unwrap();

    if k < n {
        println!("{}", k * x + (n - k) * y);
    } else {
        println!("{}", n * x);
    }
}


Measured memory_bytes: 380
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c - max(a, max(b, c)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a + b ==15){
        cout << "+" << endl;
    }else if(a * b == 15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }

    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 < (n); i++)
typedef pair<int, int> P;

int main() {
    int N;
    cin >> N;
    vector<stack<int>> player_matches(N, stack<int>());
    vector<pair<int, int>> matches;

    int player;

    rep(i, N) {
        rep(j, N - 1) {
            cin >> player;
            player_matches[i].push(player - 1);
        }
    }

    auto check = [&](int i) {
        if (player_matches[i].size() == 0) {
            return;
        }
        int battler = player_matches[i].top();

        if (i == player_matches[battler].top()) {
            P match = make_pair(i, battler);
            if (match.first > match.second) swap(match.first, match.second);
            matches.push_back(match);
        }
    };

    int days = 0;

    rep(i, N) {
        check(i);
    }

    vector<pair<int, int>> next_candidates;

    while (matches.size() > 0) {
        days++;

        sort(matches.begin(), matches.end());
        matches.erase(unique(matches.begin(), matches.end()), matches.end());
        next_candidates = matches;

        for (P match : next_candidates) {
            player_matches[match.first].pop();
            player_matches[match.second].pop();
        }

        matches.erase(matches.begin(), matches.end());

        for (P match : next_candidates) {
            check(match.first);
            check(match.second);
        }
    }

    rep(i, N) {
        if (player_matches[i].size() > 0) {
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << days << endl;
}


Measured memory_bytes: 4736
// Problem : B - Bingo
// Contest : AtCoder - AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

int in[3][3], a[3][3], n;

bool bingo(){
    for(int i=0;i<3;i++){
        bool ok = true;
        for(int j=0;j<3;j++) ok &= (a[i][j] == 1);
        if(ok) return true;
    }
    for(int i=0;i<3;i++){
        bool ok = true;
        for(int j=0;j<3;j++) ok &= (a[j][i] == 1);
        if(ok) return true;
    }
    bool ok = true;
    for(int i=0;i<3;i++) ok &= (a[i][i] == 1);
    if(ok) return true;
    ok = true;
    for(int i=0;i<3;i++) ok &= (a[i][2-i] == 1);
    return ok;
}

void mark(int x){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(in[i][j] == x) a[i][j] = 1;
        }
    }
}

void solve(){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) cin>>in[i][j];
    }
    cin>>n;
    while(n--){
        int x; cin>>x;
        mark(x);
    }
    if(bingo()) cout<<"Yes\n";
    else cout<<"No\n";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
k, n = [int(w) for w in input().split()]
a_li = [int(w) for w in input().split()]

dist = k - a_li[-1] + a_li[0]

for a1, a2 in zip(a_li[:-1], a_li[1:]):
    dist = max(dist, a2-a1)

print(k - dist)


Measured memory_bytes: 31428
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(a + b + c - Math.max(a, Math.max(b, c)));
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <stdlib.h>
 
int compare_int(const void* a, const void* b)
{
    int aNum = *(int*)a;
    int bNum = *(int*)b;
    return bNum - aNum;
}
 
using namespace std;
 
int main() {
    int n, m, x;
    cin >> n >> m;
    int y[n];
    int sum = 0;
    double judge = 0.0;
    for (int i = 0; i < n; i++) {
	    cin >> x;
        y[i] = x;
        sum += x;
	}
    judge = (double)sum / (4 * m);
    int count = 0; 
    qsort(y, n, sizeof(int), compare_int);
    for (int i = 0; i < m; i++) {
        if(y[i] >= judge) {
            count++;
        }
	}
    if(count == m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int ans = min({A+B,B+C,C+A});
    cout << ans << endl;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>n;
    x=n/2;
    y=x;
    if(n%2) x++;
    cout<<x*y<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
using namespace std;
const long long MOD = 1000000007;

typedef long long ll;

int
main(int argc, char *argv[])
{
  int n, m, a;
  cin >> n >> m;
  priority_queue<int> p;
  for (int i = 0; i < n; i++) {
    cin >> a;
    p.push(a);
  }
  int b;
  for (int i = 0; i < m; i++) {
    b = p.top();
    p.pop();
    p.push(b / 2);
  }
  ll ans = 0;
  while (!p.empty()) {
    ans += (ll)p.top();
    p.pop();
  }

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

  return 0;
}


Measured memory_bytes: 892