akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod2;
        }
        now*=now;
        now%=mod2;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll a[n],b[n];
    vector<pll> v;
    rep(i,0,n){
        cin>>a[i];
        v.push_back({a[i],0});
    }
    rep(i,0,n){
        cin>>b[i];
        v.push_back({b[i],1});
    }
    sort(v.begin(),v.end());
    ll cnt[2];
    fill(cnt,cnt+2,0);
    ll ma=0;
    rep(i,0,v.size()){
        cnt[v[i].second]++;
        if(cnt[1]>cnt[0]){
            cout<<"No"<<endl;
            return 0;
        }
        ma=max(cnt[0]-cnt[1],ma);
    }
    if(ma>=2){
        cout<<"Yes"<<endl;
        return 0;
    }
    map<ll,ll> mpa,mpb;
    rep(i,0,n){
        mpa[a[i]]=b[i];
        mpb[b[i]]=a[i];
    }
    ll cn=0;
    for(ll i=1;i<v.size();i+=2){
        ll f=v[i-1].first,g=v[i].first;
        ll u=mpa[f];
        if(u!=g){
            cn++;
            ll ai=mpb[g];
            mpb[u]=ai;
            mpa[ai]=u;
            mpa[f]=g;
            mpb[g]=f;
        }
        
    }
    if(cn>=n-1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 18284
import java.util.Scanner;
class Main{
	static Scanner sc;
	static short top,north,east,south,west,bottom,tmp;
	static int freq,sum;
	static String str;
	public static void main(String[]args){
		sc=new Scanner(System.in);
		while(true){
			top=1;bottom=6;
			south=2;north=5;
			east=3;west=4;
			sum=1;
			freq=sc.nextInt();
			if(freq==0)break;
			for(int i=0;i<freq;i++){
				str=sc.next();
				if(str.equals("North")){
					tmp=top;
					top=south;south=bottom;bottom=north;north=tmp;
					sum+=top;
				}else if(str.equals("East")){
					tmp=top;
					top=west;west=bottom;bottom=east;east=tmp;
					sum+=top;
				}else if(str.equals("West")){
					tmp=top;
					top=east;east=bottom;bottom=west;west=tmp;
					sum+=top;
				}else if(str.equals("South")){
					tmp=top;
					top=north;north=bottom;bottom=south;south=tmp;
					sum+=top;
				}else if(str.equals("Right")){
					tmp=north;
					north=west;west=south;south=east;east=tmp;
					sum+=top;
				}else if(str.equals("Left")){
					tmp=north;
					north=east;east=south;south=west;west=tmp;
					sum+=top;
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 25448
n, k = list(map(int, input().split(' ')))
w = [int(input()) for i in range(n)]

left = 0
right = 100000 * 10000

def check(loaded_w):
  truck_num = 1
  tmp_w = 0
  i = 0
  while i < n:
    if tmp_w + w[i] > loaded_w:
      truck_num += 1
      tmp_w = 0
    else:
      tmp_w += w[i]
      i += 1
    if truck_num > k:
      return False
  return True

while left != right:
  mid = (left + right) // 2
  if check(mid):
    right = mid
  else:
    left = mid + 1
print(left)


Measured memory_bytes: 9564
import java.util.Scanner;

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

		while (true) {
			int count = 0;
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}

			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					if (i + j >= x) {
						break;
					} else {
						for (int k = j + 1; k <= n; k++) {
							if (i + j + k == x) {
								count++;
								break;
							}
						}
					}
				}
			}

			System.out.println(count);

		}

	}
}



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

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

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

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


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

  lint cur=26, sum=0;
  while(true) {
    if(n-sum<=cur) { break; }
    sum+=cur;
    cur*=26;
  }
  
  n -= (sum+1);
  cur /= 26;

  string s;
  while(cur>0) {
    s += 'a'+n/cur;
    n %= cur;
    cur /= 26;
  }

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3632
class Node:
  def __init__(self, num):
    self.key = num
    self.p = None
    self.left = None
    self.right = None

class BinarySearchTree:
  def __init__(self):
    self.root = None

  def insert(self, z):
    y = None
    x = self.root
    while x != None:
      y = x
      if z.key < x.key:
        x = x.left
      else:
        x = x.right
    z.p = y

    if y is None:
      self.root = z
    elif z.key < y.key:
      y.left = z
    else:
      y.right = z

def print_inorder(node):
  if node is None: return
  print_inorder(node.left)
  print(" {}".format(node.key), end="")
  print_inorder(node.right)

def print_preorder(node):
  if node is None: return
  print(" {}".format(node.key), end="")
  print_preorder(node.left)
  print_preorder(node.right)

def find(node, key):
  while node:
    if node.key == key: return True
    if key < node.key:
      node = node.left
    else:
      node = node.right
  return False

T = BinarySearchTree()
for i in range(int(input())):
  params = input().split()
  if params[0] == "insert":
    T.insert(Node(int(params[1])))
  if params[0] == "find":
    if find(T.root, int(params[1])):
      print("yes")
    else:
      print("no")
  if params[0] == "print":
    print_inorder(T.root)
    print("")
    print_preorder(T.root)
    print("")

Measured memory_bytes: 124476
import itertools

N, K = map(int, input().split())

num = []
for i in range(N+1):
    num.append(i)

ans = 0
for i in range(K, N+2):
    min_i = (i-1)*i//2 
    max_i = (2*N-i+1)*i//2
    ans += max_i - min_i + 1

print(ans%(10**9+7))

Measured memory_bytes: 16932
#include <bits/stdc++.h>
using namespace std;
 
// Type alias
using ll=long long;
using ld=double;
 
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;
 
using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;
 
// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();
 
// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl
 
#define ALL(a) a.begin(),a.end()
 
// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
 
 
void solve(){
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
}
 
int main(){
  // FastIO
  //ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}





















Measured memory_bytes: 256
s = gets.chomp
n = s.size
ans = 0
(2**(n-1)).upto(2**n - 1) do |i|
  x = 0
  0.upto(n) do |j|
    if i[j] == 1
      ans += s.slice(x..j).to_i
      x = j+1
    end
  end
end
puts ans

Measured memory_bytes: 1788
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38336
///
// File:  2300.cpp
// Author: ymiyamoto
//
// Created on Wed Nov 22 00:34:02 2017
//

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;

double distance(vector<tuple<double, double, double>> selected)
{
  double dist = 0.0;
  for (uint32_t i = 0; i < selected.size(); i++) {
    for (uint32_t j = i; j < selected.size(); j++) {
      dist += pow(get<0>(selected[i]) - get<0>(selected[j]), 2);
      dist += pow(get<1>(selected[i]) - get<1>(selected[j]), 2);
      dist += pow(get<2>(selected[i]) - get<2>(selected[j]), 2);
    }
  }
  return dist;
}

double comb(vector<tuple<double, double, double>> &colors, uint32_t index, uint32_t M, vector<tuple<double, double, double>> selected)
{
  if (selected.size() == M) {
    return distance(selected);
  } else if (colors.size() <= index) {
    return 0.0;
  } else {
    vector<tuple<double, double, double>> vec(selected);
    vec.push_back(colors[index]);
    return max(comb(colors, index + 1, M, selected), comb(colors, index + 1, M, vec));
  }
}

int32_t main()
{
  uint32_t N, M;
  cin >> N >> M;

  vector<tuple<double, double, double>> colors;
  for (uint32_t i = 0; i < N; i++) {
    double L, a, b;
    cin >> L >> a >> b;

    colors.push_back(make_tuple(L, a, b));
  }

  vector<tuple<double, double, double>> selected;
  double dist = comb(colors, 0, M, selected);

  cout << fixed << setprecision(8) << dist << endl;

  return 0;
}

Measured memory_bytes: 3308
#include<bits/stdc++.h>
#define ll long long
#define N 100010
#define pb emplace_back
using namespace std;
vector<int> e[N];
int m,n,w[N],x,y,f[N];
ll a[N],b[N],sb[N],dp[N];
void jb(int x,int y){e[x].pb(y);}
bool xi(int x,int y){return (a[x]-b[x]<a[y]-b[y])||(a[x]-b[x]==a[y]-b[y]&&x<y);}
bool c1(const int &x,const int &y){return xi(x,y);}
int quef(int x){if (f[x]!=x) f[x]=quef(f[x]);return f[x];}
void lb(int x,int y){
	if (x==y)return ;f[y]=x;
	sb[x]+=sb[y];dp[x]=min(dp[x],max(dp[y],a[x]-b[x])-sb[y]);
}
int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++){cin>>a[i]>>b[i];w[i]=f[i]=i;}
	for (int i=1;i<=m;i++){cin>>x>>y;jb(x,y);jb(y,x);}
	sort(w+1,w+n+1,c1);
	for (int i=1;i<=n;i++){
		dp[w[i]]=max(0ll,a[w[i]]-b[w[i]]),sb[w[i]]=b[w[i]];
		for (auto j:e[w[i]]){
			if (xi(j,w[i]))lb(w[i],quef(j));
		}
		dp[w[i]]+=sb[w[i]];
	}
	cout<<dp[w[n]]<<endl;
	return 0;
}

Measured memory_bytes: 9852
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int getmax(string s) {
  int n = s.size();
  rep(i, n) {
    int z = s[i] - '0';
    if (z > 7) {
      FOR(j, i, n) s[j] = '7';
      break;
    }
    else if (z == 6) {
      s[i] = '5';
      FOR(j, i + 1, n) s[j] = '7';
      break;
    }
    else if (z == 4) {
      s[i] = '3';
      FOR(j, i + 1, n) s[j] = '7';
      break;
    }
    else if (z < 3) {
      s[i] = '0';
      FOR(j, i + 1, n) s[j] = '7';
    }
  }

  int k = 1, res = 0;
  repr(i, n - 1) {
    int z = s[i] - '0';
    if (z == 3) res += 1 * k;
    else if (z == 5) res += 2 * k;
    else if (z == 7) res += 3 * k;
    k *= 4;
  }

  return res;
}

bool check(int n) {
  vector<bool> f(4, false);

  while (n > 0) {
    f[n % 4] = true;
    n /= 4;
  }

  bool res = true;
  if (f[0]) res = false;
  FOR(i, 1, 4) {
    if (!f[i]) res = false;
  }

  return res;
}

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

  int n = getmax(s);

  int ans = 0;
  rep(i, n + 1) {
    if (check(i)) ans++;
  }
  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
int arrayMax(int a[], const int N){
    int maxv = 0;
    rep(i, N)maxv = max(a[i], maxv);
    return maxv;
}
/* -- template -- */

int main(){
    int X, Y, Z;cin >> X >> Y >> Z;
    cout << Z << ' ' << X << ' ' << Y << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<bool> rem(N, 1);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }

    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) if (A[i] % 10 == 0) rem[i] = 0;

    int ans = sum;
    if (sum % 10 == 0) for (int i = 0; i < N; i++) if (rem[i]) {
        ans -= A[i];
        break;
    }

    if (sum % 10 == 0 && ans == sum) ans = 0;

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

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

#define B 200

struct UnionFind{
  vector<int> v;
  vector<int> sav;
  vector<int> hist;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : find(v[x]); }
  void rollback(){
    while(hist.size()){
      v[hist.back()]=sav[hist.back()];
      hist.pop_back();
    }
  }
  void snapshot(){
    sav=v;
    hist.clear();
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);

    hist.push_back(x);
    hist.push_back(y);
    v[x] += v[y];
    v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

struct query{
  int typ,u,v;
};

int N,Q;
vector<query> qs;
set<P> es;

int main(){
  cin>>N>>Q;
  rep(i,Q){
    int t,u,v;
    cin>>t>>u>>v;
    qs.push_back((query){t,u,v});
  }

  for(int sq=0; sq<Q; sq+=B){
    map<P,bool> qes;
    set<P> est;
    UnionFind uf(N);
    for(int i=sq; i<min(sq+B,Q); i++){
      query q=qs[i];
      if(q.typ<=2)qes[P(q.u,q.v)]=true;
    }

    for(P e : es){
      if(qes[P(e.fi,e.se)]){
        est.insert(e);
      }else{
        uf.unite(e.fi,e.se);
      }
    }
    uf.snapshot();

    for(int i=sq; i<min(sq+B,Q); i++){
      query q=qs[i];
      if(q.typ==1){
        est.insert(P(q.u,q.v));
        es.insert(P(q.u,q.v));
      }else if(q.typ==2){
        est.erase(P(q.u,q.v));
        es.erase(P(q.u,q.v));
      }else{
        uf.rollback();
        for(P e : est){
          uf.unite(e.fi,e.se);
        }

        if(uf.same(q.u,q.v))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 7656
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 1000000000+7;
    int[] id; // for UF
    int[] remain; // even in the "connected component", how many heavy edges remaining
    long[] tot_X;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
//        main.solve();
        out.println(main.solve());
        out.flush();
    }
    long solve() throws IOException {
        int n = sc.nextInt(), m = sc.nextInt();
        if(m==0) return 0;
        id = new int[n];
        remain = new int[n];
        for(int i=0;i<n;i++) id[i] = i;
        Arrays.fill(remain,0);
        long[] X = new long[n];
        for(int i=0; i<n;i++) X[i] = sc.nextLong();
        tot_X = new long[n];
        for(int i=0; i<n;i++) tot_X[i] = X[i];
        PriorityQueue<Edge> pq = new PriorityQueue<>(m, (o1,o2)->(Long.compare(o1.weight, o2.weight)));
        for(int i=0; i<m;i++){
            int u = sc.nextInt()-1, v = sc.nextInt()-1;
            long y = sc.nextLong();
            pq.add(new Edge(u, v, y));
        }
        long ans = m;
        while(pq.size()>0){
            // lighter edges comes out first
            Edge e = pq.poll();
            int from = e.u, to = e.v;
            int i = find(from), j = find(to);
            if(i==j){
                if(tot_X[i]>=e.weight){
                    ans --;
                } else{
                    remain[i] += 1; // current component not heavy enough. needs further vertex
                }
            } else{
                // no harm to suppose that i and j are being connected, as long as we don't change the value of ans.
                // i.e., the edge now is still considered taken away. until further heavier edges contribute by
                // connecting more vertex. That time, the current e are automatically put back
                long left = tot_X[i], right = tot_X[j];
                if(left+right>=e.weight){
                    ans -= 1+remain[i]+remain[j];
                    remain[i] = 0; remain[j] = 0;
                } else{
                    remain[i] += 1+remain[j];
                }
                tot_X[i] += tot_X[j];
                id[j] = i;
            }
        }
        return ans;
    }
    int find(int p){
        while(p!=id[p]){
            id[p] = id[id[p]];
            p = id[p];
        }
        return p;
    }

    class Edge {
        int u, v;
        long weight;
        public Edge(int _u, int _v, long _w){
            u = _u; v = _v; weight = _w;
        }
    }
}

Measured memory_bytes: 113016
#include <stdio.h>
#define N 100001

typedef struct{

  int par; //parent node
  int l_child; //left child node
  int r_sib; //right child noed
 
} node;

node tree[N];

int depth(int);

int main(){
 
  int n,id,cnum,lef,child;
  int i,j; 

  scanf("%d",&n);
  
  for(i=0;i<n;i++){

    tree[i].par = -1;
    tree[i].l_child = -1;
    tree[i].r_sib = -1;

  }
  
  for(i=0; i<n; i++){

    scanf("%d %d", &id, &cnum);

    for(j=0; j<cnum; j++){

      scanf("%d", &child);

      if(j == 0) tree[id].l_child = child;

      else tree[lef].r_sib = child;
      tree[child].par = id;
      lef = child;

    }
  }

  for(i=0; i<n; i++){ //how the tree looks 

    printf("node %d: parent = %d, depth = %d, ", i, tree[i].par, depth(i));

    if(tree[i].par == -1) printf("root, [");

    else if(tree[i].l_child == -1) printf("leaf, [");

    else printf("internal node, [");

    lef = tree[i].l_child;

    for(j=0; ; j++){

      if(lef == -1) break; //no leaf break needed

      if(j != 0) printf(", ");

      printf("%d",lef);

      lef = tree[lef].r_sib;

    }

    printf("]\n");
  }
  
  return 0;
  
}

int depth(n){

  if(tree[n].par == -1) return 0;

  return depth(tree[n].par)+1;
}

Measured memory_bytes: 1784
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    int A, B, C;
    cin >> A >> B >> C;
    if(A==B){ cout << C << endl; }
    else if(A==C){ cout << B << endl; }
    else { cout << A << endl; }

    return;
}



Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

int main(void) {
  int N;
  vector<int> D;
  int M;
  vector<int> T;
  cin >> N; D.resize(N);
  REP(i, N) cin >> D[i];
  cin >> M; T.resize(M);
  REP(i, M) cin >> T[i];
  sort(D.begin(), D.end());
  sort(T.begin(), T.end());
  int idx = 0; bool fail = false;
  for (int i = 0; i < T.size(); i++) {
    for (;;) {
      if (idx >= N) {
        fail = true;
        break;
      }
      if (T[i] == D[idx++]) break;
    }
  }
  cout << (fail ? "NO" : "YES") << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  int H[N];
  for (int i = 0; i < N; i++)
  {
    cin >> H[i];
  }
  sort(H, H + N);
  long long cost = 0;
  for (int i = 0; i < N - K; i++)
  {
    cost += H[i];
  }
  cout << cost << endl;
}


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

struct CROPS{
  string name;
  double total;

};

int main(){
  int i,j,n;
  double p,a,b,c,d,e,f,s,m,efficient;
  CROPS crop[51];
   while(1){
    cin >> n;
     if(n==0)break;
    for(i = 0; i < n; i++){
      cin >> crop[i].name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      efficient=(f*s*m-p)/(a+b+c+(d+e)*m);
      crop[i].total=efficient;
    }
      
    for(i = 0; i < n; i++){
      for(j = 0; j < n-1; j++){
	if(crop[j].total < crop[j+1].total){
	  swap(crop[j],crop[j+1]);
	}
      }
    }

    for(i = 0; i < n; i++){
      for(j = 0; j < n-1; j++){
	if(crop[j].total == crop[j+1].total && crop[j].name>crop[j+1].name){
	  swap(crop[j],crop[j+1]);
	}
      }
    }
  
    for(i = 0; i < n; i++){
      cout << crop[i].name << endl;      
    }

    cout << "#" << endl;
     }
  return 0;
}

Measured memory_bytes: 1244
Row=int(input())
X=[]
Y=[]
for i in range(Row):
    n,a=input().split()
    X.append(int(n))
    Y.append(int(a))
A=[]
B=[]
for i in range(len(X)):
    A.append(X[i]-Y[i])
    B.append(X[i]+Y[i])
maxmax1=A[0]
maxmax2=B[0]
minmin1=A[0]
minmin2=B[0]
for i in range(len(A)):
    maxmax1=max(maxmax1,A[i])
    minmin1=min(minmin1,A[i])
for i in range(len(B)):
    maxmax2=max(maxmax2,B[i])
    minmin2=min(minmin2,B[i])
print(max((maxmax1-minmin1),(maxmax2-minmin2)))

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll C[202020];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>C[i];
	sort(C,C+N);
	reverse(C,C+N);
	ll p=1,q=1;
	FOR(i,N) q=q*2%mo;
	ll sum=1;
	ll ret=0;
	FOR(i,N) {
		q=q*(mo+1)/2%mo;
		(ret+=(C[i]*sum)%mo*q)%=mo;
		sum=(sum*2+p)%mo;
		p=p*2%mo;
	}
	cout<<ret*p%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define A first
#define B second

const ll p = 1e9+7;

ll h, w, k, t;
bool a[2005][2005], vis[2005][2005];
queue<pii> q;
pii ans;

ll b[2][2], c[2][2];

void proc(ll x, ll y, ll e, ll f) {
	if (x < 0 || x >= e || y < 0 || y >= f)
		return;
	if (vis[x][y] || !a[x][y])
		return;
	q.push(pii(x, y));
	vis[x][y] = 1;
}

bool conn(ll e, ll f) {
	memset(vis, 0, sizeof(vis));
	bool y = 0;

	for (ll i = 0; i < e; ++i)
		for (ll j = 0; j < f; ++j) {
			if (y == 1)
				continue;
			if (a[i][j]) {
				q.push(pii(i, j));
				vis[i][j] = 1;
				y = 1;
			}
		}

	while (!q.empty()) {
		pii t = q.front();
		q.pop();
		ll u = t.A, v = t.B;
		proc(u-1, v, e, f);
		proc(u+1, v, e, f);
		proc(u, v-1, e, f);
		proc(u, v+1, e, f);
	}

	for (ll i = 0; i < e; ++i)
		for (ll j = 0; j < f; ++j)
			if (a[i][j] && !vis[i][j])
				return 0;
	return 1;
}

ll exp(ll x, ll k) {
	if (k == 0)
		return 1;
	ll y = exp(x, k/2);
	if (k%2 == 0)
		return y*y%p;
	else
		return y*y%p*x%p;
}

void expm(ll k) {
	if (k == 0) {
		b[0][0] = b[1][1] = 1;
		return;
	}

	expm(k/2);
	ll b1[2][2];
	memset(b1, 0, sizeof(b1));

	for (ll i = 0; i < 2; ++i)
		for (ll j = 0; j < 2; ++j)
			for (ll h = 0; h < 2; ++h)
				b1[i][h] = (b1[i][h] + b[i][j] * b[j][h])%p;
	memcpy(b, b1, sizeof(b));

	if (k%2 == 1) {
		memset(b1, 0, sizeof(b1));
		for (ll i = 0; i < 2; ++i)
			for (ll j = 0; j < 2; ++j)
				for (ll h = 0; h < 2; ++h)
					b1[i][h] = (b1[i][h] + b[i][j] * c[j][h])%p;	
		memcpy(b, b1, sizeof(b));	
	}

	// cout << b[0][0] << ' ' << b[0][1] << "\n" << b[1][0] << ' ' << b[1][1] << endl;
}

int main() {
	cin >> h >> w >> k;
	for (ll i = 0; i < h; ++i)
		for (ll j = 0; j < w; ++j) {
			char x; cin >> x;
			a[i][j] = (x == '#');
			t += a[i][j];

			a[i+h][j] = a[i][j+w] = a[i][j];
		}

	if (k == 0 || k == 1) {
		cout << "1\n";
		return 0;
	}

	bool conu = conn(2*h, w);
	bool conr = conn(h, 2*w);

	if (conu && conr) {
		cout << "1\n";
		return 0;
	} if (!conu && !conr) {
		cout << exp(t, k-1) << endl;
		return 0;
	}

	if (conu && !conr) {
		for (ll i = 0; i < h; ++i)
			for (ll j = 0; j < w; ++j)
				vis[i][j] = a[i][j];
		for (ll i = 0; i < h; ++i)
			for (ll j = 0; j < w; ++j)
				a[j][i] = vis[i][j];

		swap(h, w);
		//now it's not connected up and it's connected sideways
	}

	for (ll i = 0; i < h; ++i) {
		bool l = a[i][0];
		bool r = a[i][w-1];
		ll g = 0;

		for (ll j = 1; j < w; ++j) {
			if (!a[i][j] && a[i][j-1])
				g++;
		}

		g += r;

		ans.A += (g - (l&r));
		ans.B += (l&r);
	}

	// cout << ans.A << ' ' << ans.B << endl;
	c[0][0] = ans.B, c[0][1] = ans.A, c[1][1] = t;

	expm(k-1);
	cout << (b[0][0] + b[0][1])%p << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
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 MOD 1000000007 //998244353


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

    // solution comes here

    ll A, B, C;
    cin >> A >> B >> C;

    if(C>=(A+B)) cout << 2*(A+B) - A  + (C>A+B)<< nl;
    else cout << B+C << nl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{

int i,n;

int number;

long long int sum=0;

int min=0;

int max=0;

scanf("%d",&n);

for(i=0;i<n;i++)

{

scanf("%d",&number);

if(i==0)

{

min = number;

max = number;

}

if(number<min) min = number;

if(number>max) max = number;

sum += number;

}

printf("%d %d %lld\n",min,max,sum);

return 0;

}

Measured memory_bytes: 600
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

int[] group(string s, string t) {
    int[] gs;

    auto n = s.length;
    int p = 0;
    while (p < s.length) {
        if (s[p] == t[p]) {
            gs ~= 1;
            p += 1;
        }
        else {
            gs ~= 0;
            p += 2;
        }
    }
    return gs;
}

void main() {
    readln;
    auto s = readln.chomp;
    auto t = readln.chomp;

    const MOD = 1000000007L;
    auto gs = group(s, t);
    long ans = 1;
    //    writeln(gs);
    if (gs[0] == 0)
        ans = 6;
    else
        ans = 3;
    for (int i = 1; i < gs.length; i++) {
        int prev = gs[i - 1];
        int next = gs[i];

        if (prev == 0) { // 横
            if (next == 0) {
                ans = (ans * 3) % MOD;
            }
        }
        else {
            if (next == 0) {
                ans = (ans * 2) % MOD; // 上下で色かえ
            }
            else if (next == 1) {
                ans = (ans * 2) % MOD;
            }
        }
    }
    writeln(ans);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		long a[] = new long[n];
		long b[] = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			b[i] = Math.abs(a[i] - x);
		}
Arrays.sort(b);
long now=b[0];
for (int i = 0; i < n; i++) {
now=gcd(now,b[i]);

}
System.out.println(now);

	}

	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}

}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main(){
	int n;
	cin >> n;
	vi d(n);
	rep(i,n) cin >> d[i];
	sort(all(d));
	cout << d[n/2] - d[n/2-1] << endl; 
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 640
n=input()
k=int(input())
dp=[[[0]*(k+1)for i in range(2)] for i in range(len(n)+1)]
dp[0][0][0]=1
for i in range(1,len(n)+1):
    for j in range(int(n[i-1])):
        if j==0:
            for h in range(k+1):
                dp[i][1][h]+=dp[i-1][0][h]
        else:
            for h in range(k):
                dp[i][1][h+1]+=dp[i-1][0][h]
    for j in range(10):
        if j==0:
            for h in range(k+1):
                dp[i][1][h]+=dp[i-1][1][h]
        else:
            for h in range(k):
                dp[i][1][h+1]+=dp[i-1][1][h]
    if int(n[i-1])==0:
        for h in range(k+1):
            dp[i][0][h]+=dp[i-1][0][h]
    else:
        for h in range(k):
            dp[i][0][h+1]+=dp[i-1][0][h]
print(dp[-1][0][-1]+dp[-1][1][-1])

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
po="n"
pr=A[0]
T=[]
for i in range(1,N):
    if po=="n":
        if pr<A[i]:
            T.append(["Kai",A[0]])
            po="UP"
            pr=A[i]
        else:
            po="DWN"
            pr=A[i]
    elif po=="UP":
        if pr<=A[i]:
            pr=A[i]
        else:
            T.append(["Uri",pr])
            po="DWN"
            pr=A[i]+0
    elif po=="DWN":
        if pr>=A[i]:
            pr=A[i]
        else:
            T.append(["Kai",pr])
            po="UP"
            pr=A[i]
if po=="UP":
    T.append(["Uri",pr])

#print(T)
Money=1000
Kabu=0
for i in range(len(T)):
    if T[i][0]=="Kai":
        Kabu+=Money//T[i][1]
        Money%=T[i][1]
    else:
        Money+=Kabu*T[i][1]
        Kabu=0
print(Money)

Measured memory_bytes: 61896
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  char c;
  cin >> c;
  if ('a' <= c && c <= 'z')
    cout << 'a' << endl;
  else
    cout << 'A' << endl;
  return 0;
}


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

int main()
{
  i64 a, b;
  cin >> a >> b;
  for (i64 i = 0; i < max(a, b); i++)
    cout << min(a, b);
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
d = gets.split.map(&:to_i).sort
c = 0

f = d[0..(d.count/2 - 1)]
l = d[(d.count/2)..(d.count - 1)]

if f.last == l.first
  c = 0
else
  c += Range.new((f.last + 1), l.first).count
end

puts c


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

int main(){
    std::vector<int> a(2), b(2), c(2), d(2);
    std::cin >> a.at(0) >> a.at(1) >> b.at(0) >> b.at(1);

    if(0 == b.at(1) - a.at(1)){
        c.at(0) = b.at(0);
        c.at(1) = b.at(1) + (b.at(0) - a.at(0));
        d.at(0) = a.at(0);
        d.at(1) = a.at(1) + (b.at(0) - a.at(0));
    }else if(0 == b.at(0) - a.at(0)){
        c.at(0) = b.at(0) - (b.at(1) - a.at(1));
        c.at(1) = b.at(1);
        d.at(0) = a.at(0) - (b.at(1) - a.at(1));
        d.at(1) = a.at(1);
    }else{
        c.at(0) = b.at(0) - (b.at(1) - a.at(1));
        c.at(1) = b.at(1) + (b.at(0) - a.at(0));
        d.at(0) = a.at(0) - (b.at(1) - a.at(1));
        d.at(1) = a.at(1) + (b.at(0) - a.at(0));
    }

    std::cout << c.at(0) << " " << c.at(1) << " " << d.at(0) << " " <<  d.at(1) << std::endl;

    return 0;
}


Measured memory_bytes: 504
n = int(input())
# co=0
ac=wa=tle=re=0
for i in range(n):
    s = input()
    if(s=="AC"):
        ac+=1
    elif(s=="WA"):
        wa+=1
    elif(s=="TLE"):
        tle+=1
    elif(s=="RE"):
        re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[1] << s3[2] << endl;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main() {
	int a, b, c, d, e, aa, bb, cc, dd, ee;
	cin >> a >> b >> c >> d >> e;

	aa = a / 10 * 10;
	if (a % 10) { aa += 10; }
	bb = b / 10 * 10;
	if (b % 10) { bb += 10; }
	cc = c / 10 * 10;
	if (c % 10) { cc += 10; }
	dd = d / 10 * 10;
	if (d % 10) { dd += 10; }
	ee = e / 10 * 10;
	if (e % 10) { ee += 10; }
	cout << min({ a + bb + cc + dd + ee,aa + b +cc + dd + ee,aa + bb + c + dd + ee,aa + bb + cc + d + ee,aa + bb + cc + dd + e }) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k,i,n;
	double v[50];
	cin>>n;
	for (i=0;i<n;i++) cin>>v[i];
	for (i=0;i<n-1;i++)
	{
		sort(v,v+n);
		v[i+1]=(v[i]+v[i+1])/2;
	}
	cout<<v[n-1];
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int N,A,B,C,D,goal;
    char S[200001];
    int twocount = 0, threecount = 0, twoflag = 0, threeflag = 0;
    scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
    scanf("%s",S);
    
    for(int i = A-1; i < B-2 && twoflag == 0; i++)
    {
        if(S[i] == '#')
        {
            twocount++;
            if(twocount >= 2)
                twoflag = 1;
        }
        else
        {
            twocount = 0;
        }
    }
    if(D>C)
    {
        for(int i = B-2; i <= D-1 && twoflag == 0; i++)
        {
            if(S[i] == '#')
            {
                threecount = 0;
                twocount++;
                if(twocount >= 2)
                    twoflag = 1;
            }
            else
            {
                twocount = 0;
                threecount++;
                if(threecount >= 3)
                    threeflag = 1;
            }
        }
    }
    else
    {
        for(int i = B-2; i <= D && twoflag == 0; i++)
        {
            if(S[i] == '#')
            {
                threecount = 0;
                twocount++;
                if(twocount >= 2)
                    twoflag = 1;
            }
            else
            {
                twocount = 0;
                threecount++;
                if(threecount >= 3)
                    threeflag = 1;
            }
        }
        for(int i = D+1; i <= N && twoflag == 0; i++)
        {
            if(S[i] == '#')
            {
                twocount++;
                if(twocount >= 2)
                    twoflag = 1;
            }
            else
            {
                twocount = 0;
            }
        }
    }
    
    if(C>D)
        printf("%s\n",(threeflag == 1 && twoflag == 0)? "Yes":"No");
    else
        printf("%s\n",(twoflag == 0)? "Yes":"No");
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    if (N % 1000 != 0) cout << (1000 - (N % 1000)) << endl;
    else cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define maxx 1000001
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main() {
    FASTIO
    int x,y;
    cin>>x;
    y=x^1;
    cout<<y<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <math.h>
int main(void){
   double x1, y1, x2, y2;
   double X, Y;
   scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
   X = pow((x2 - x1), 2);
   Y = pow((y2 - y1), 2);
   printf("%.8f\n", sqrt(X + Y));
   return 0;
    
}


Measured memory_bytes: 2080
n=list(input())
if n[-1]=="2" or  n[-1]=="4" or n[-1]=="5" or n[-1]=="7" or n[-1]=="9":
  print("hon")
elif n[-1]=="0" or n[-1]=="1" or n[-1]=="6" or n[-1]=="8":
  print("pon")
elif n[-1]=="3":
  print("bon")


Measured memory_bytes: 8936
N,K=map(int,input().split())
H=list(map(int,input().split() ))
J=[]
import heapq

for i in range(N):
  J.append((-1)*H[i])

heapq.heapify(J)
for l in range(K):
  if l <N:
    heapq.heappop(J)
  
print((-1)*sum(J))

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

// ----------- define ---------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getbit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(), (x).end()
// ----------------------------------

void MAIN() {
  int n, h;
  cin >> n >> h;
  vector<ii> a(n);
  int ma = 0;
  for (auto &i : a) {
    cin >> i.fi >> i.sc;
    ma = max(ma, i.fi);
  }
  sort(all(a), [](ii &a, ii &b) -> bool {
    return a.sc > b.sc;
  });
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].sc > ma) {
      ans++;
      h -= a[i].sc;
      if (h <= 0) {
        cout << ans << '\n';
        return;
      }
    }
    else break;
  }
  sort(all(a), greater<ii>());
  /*while (h > 0) {
    h -= a[0].fi;
    ans++;
  }*/
  ans += (h + a[0].fi - 1) / a[0].fi;
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 4712
using System;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n=int.Parse(Console.ReadLine());

            if (n < 1000) Console.WriteLine("ABC");
            else Console.WriteLine("ABD");

        }

    }
}


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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e6 + 5;


int32_t main()
{
	GO;
	int k;
	cin >> k;
	int value = 7; int ans = -1;
	for (int i = 1; i <= maxr; i++) {
		if (value % k == 0) {
			ans = i;
			break;
		}
		value = (value * 10 + 7) % k;
	}
	cout << ans << endl;
	return 0;
}

//!

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

bool is_kaibun(string s) {
  int f = 0, l = s.length() - 1;

  while (f < l) {
    if (s[f++] != s[l--]) {
      return false;
    }
  }

  return true;
}

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

  int len = s.length();
  if (is_kaibun(s) && is_kaibun(s.substr(0, (len - 1) / 2)) && is_kaibun(s.substr((len + 1) / 2, (len - 1) / 2))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
# dp[i][j] SとTの最後の文字を採用するような文字列の個数。これにより各DPテーブルの値が排反になる。元の文字列の最後を必ず採用するので
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (M + 2) for _ in range(N + 2)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
sdp[1][1] = 1
for i in range(N + 1):
    for j in range(M + 1):
        if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
        sdp[i + 1][j + 1] %= MOD
        sdp[i + 1][j + 1] %= MOD
print(sdp[N + 1][M + 1])


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int ans = 1e9;
    for(int i = 0; i < s.size()-2; i++){
        string str = "";
        str += s[i];
        str += s[i+1];
        str += s[i+2];
        //cout << "str = " << str << endl;
        int dis = abs(753 - toInt(str));
        ans = min(ans, dis);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  vector<ll> a;
  int n;
  cin >> n;
  ll A;
  rep(i, 0, n - 1) {
    cin >> A;
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    a.push_back(A);
  }

  ll prod = 1;
  rep(i, 0, n - 1) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << prod << endl;
  return 0;
}


Measured memory_bytes: 4252
#include<iostream>
#include<queue>
using namespace std;
int main(){
  int n,k,m,c;
  queue<int> stone;
  while(cin >>n>>k>>m,n||k||m){
    for(int i=0; i<n; i++){stone.push(i+1);}
    for(int i=0; i<m-1; i++){
      c = stone.front();
      stone.pop();
      stone.push(c);
    }
    stone.pop();
    for(int i=1; i<n; i++){
      for(int i=0; i<(k-1)%stone.size(); i++){
	c = stone.front();
	stone.pop();
	stone.push(c);
      }
      c = stone.front();
      stone.pop();
    }
    cout <<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 1268