akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
const int SIZE=5+1e6;
const int INF=10+1e9;
const LL p=7+1e9;
LL N;
VI incr;
LL A[SIZE];
LL sub[SIZE];
LL subplay[SIZE];
LL increr[SIZE];
LL ans[SIZE];
void dec(int x){
	int s=0,e=incr.size()-1;
	while(s<=e){
		int f=(s+e)/2;
		if(incr[f]<x)
			s=f+1;
		else
			e=f-1;
	}
	subplay[s]++;
	sub[s]+=incr[s]-x;
}
int main(){
	LL maxim=0;
	cin >> N;
	REP(i,N){
		cin >> A[i];
		if(maxim<A[i]){
			incr.PB(A[i]);
			increr[i]=incr.size();
		}
		else
			dec(A[i]);
		maxim=max(maxim,A[i]);
	}
	LL now=N;
	REP(i,incr.size()){
		ans[i]=incr[i]*now-sub[i];
		if(i) ans[i]-=incr[i-1]*now;
		now-=subplay[i];
		now--;
	}
	REP(i,N){
		if(increr[i]==0){
			cout << 0 << endl;
			continue;
		}
		else{
			cout << ans[increr[i]-1] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 13044
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n = I()
A = LI()
D = Counter(A)
min_a = min(A)
max_a = min_a * 2 if D[min_a] == 1 else min_a * 2 - 1
if D[min_a] > 2 or max(A) > max_a:
    print("Impossible")
    exit()

for i in range(min_a + 1, max_a + 1):
    if D[i] < 2:
        print("Impossible")
        exit()

print("Possible")



















Measured memory_bytes: 81516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first < b.first;
    }
}
// 入力



int main() {
    ll D,G;

    cin >>D>>G;

    vector<ll> p(D);
    vector<ll> c(D);
    vector<Pi> pc(D);

    rep(i,D){
        cin>>p[i]>>c[i];
        //pc[i] = mp(p[i],c[i]);
    }



    ll ans = INF;
    rep(bit,1<<D){
        vector<ll> S;
        rep(i,D){
            
            if(bit & (1<<i)){
                S.pb(i);
            }
        }
        ll sum = 0;
        ll num = 0;
        vector<ll> use(D);
        rep(i,S.size()){
            sum += (S[i]+1)*p[S[i]]*100 + c[S[i]];
            num += p[S[i]];
            use[S[i]] = p[S[i]];
            
            //cout<<S[i]<<" ";
        }
        //cout<<endl;
        ll cnt = D-1;
        while(sum<G){
            if(use[cnt] <p[cnt]){
                sum+=(cnt+1)*100;
                num++;
                use[cnt]++;
                if(use[cnt] == p[cnt]){
                    sum+=c[cnt];
                }
            }else{
                cnt--;
            }
        }

        chmin(ans,num);
    }
 


    cout<<ans<<endl;


    return 0;
    

}

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> vx;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    vx.push_back(x);
  }
  sort(vx.begin(), vx.end());
  int kecil = vx[0], besar = vx.back();
  vector<pair<int, int>> ans;
  for (int i = 1; i + 1 < n; ++i) {
    int x = vx[i];
    if (x >= 0)
      ans.emplace_back(kecil, x), kecil -= x;
    else
      ans.emplace_back(besar, x), besar -= x;
  }
  ans.emplace_back(besar, kecil);
  printf("%d\n", besar - kecil);
  for (auto it : ans)
    printf("%d %d\n", it.first, it.second);
  return 0;
}


Measured memory_bytes: 3188
digits = input()
op_cnt = len(digits) - 1
for i in range(op_cnt ** 2):
    op = ["-"] * 3
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[-j] = "+"
    
    formula = ""
    for p_n, p_o in zip(digits, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 9124
#include <bits/stdc++.h>
         
    using namespace std;
                 
    #define pb push_back
    #define ll long long
    #define mp make_pair
    #define MOD 1000000007
    #define MAX 100000000
    #define MIN -1000000000
    #define LLINF 0x3f3f3f3f3f3f    
    #define INF 0x3f3f3f3f
    #define MAXN 200200

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n;
        cin >> n;
        if(n % 1000 == 0){  
            cout << 0 << endl;
        }else{  
            int t = n/1000;
            t++;
            cout << 1000*t - n << endl;
        }
        return 0;
    }

Measured memory_bytes: 3628
N,M=map(int,input().split())
arr=[]
for i in range(M):
    arr.append(list(map(int,input().split())))
p=list(map(int,input().split()))
cnt=0

for i in range(2**N):
    bulb=[0]*M
    x=format(i,'b').zfill(N)   # x is switch
    #print('x',x)
    for j in range(M):
        #print('j',j)
        total=0
        for k in range(arr[j][0]):
            #print('arr[j][k+1]',arr[j][k+1])
            #print('x[.]',x[ arr[j][k+1]-1 ])
            #print('total',total)
            total+=int(x[ arr[j][k+1]-1 ])
        if total%2!=p[j]:
            break
        else:
            bulb[j]=1
    if sum(bulb)==M:
        cnt+=1
        #break
print(cnt)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	string n;

	cin >> n;

	FOR(i, 0, n.size() - 1) {
		if (n[i] == '1') {
			n[i] = '9';
		}
		else {
			n[i] = '1';
		}
	}
	
	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
N = input()
n = []
for i in N:
    n.append(int(i))
for i in range(len(n)):
    if i == len(n)-1:
        break
    if n[-(i+1)] != 9:
        n[-(i+1)] = 9
        n[-(i+2)] -= 1
print(sum(n))

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

string s,t;

int g[9]={};
int sA[101010]={}, sB[101010]={};
int tA[101010]={}, tB[101010]={};

void query(int a, int b, int c, int d)
{
    int S=((sA[b]-sA[a-1])%3)*3+(sB[b]-sB[a-1])%3;
    int T=((tA[d]-tA[c-1])%3)*3+(tB[d]-tB[c-1])%3;

    if(g[S] == g[T]) printf("YES\n");
    else printf("NO\n");
}

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

    rep(i,s.size())
    {
        sA[i+1] = sA[i]+(s[i]=='A');
        sB[i+1] = sB[i]+(s[i]=='B');
    }
    rep(i,t.size())
    {
        tA[i+1] = tA[i]+(t[i]=='A');
        tB[i+1] = tB[i]+(t[i]=='B');
    }

    g[1]=g[5]=g[6]=1;
    g[0]=g[8]=g[4]=2;
    
    int Q;
    scanf(" %d", &Q);
    while(Q--)
    {
        int a,b,c,d;
        scanf(" %d %d %d %d", &a, &b, &c, &d);
        query(a,b,c,d);
    }

    return 0;
}


Measured memory_bytes: 2432
#include <cstdio>

using namespace std;
 
int main(){
	int S;
	int h; 
	int m;
	int s;
	scanf("%d",&S);
	h = S/3600;
	m = (S-(3600*h))/60;
	s = S-(3600*h)-(60*m);
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int H, W;
char board[2000][2000];
int lsum[2000][2000], rsum[2000][2000], usum[2000][2000], dsum[2000][2000];

int main() {
  cin >> H >> W;
  rep (i, H) rep (j, W) cin >> board[i][j];

  rep (i, H) {
    for (int j = 0; j < W; j++) {
      if (board[i][j] == '.') {
        if (j - 1 >= 0) lsum[i][j] = lsum[i][j - 1] + 1;
        else lsum[i][j] = 1;
      }
    }
    for (int j = W - 1; j >= 0; j--) {
      if (board[i][j] == '.') {
        if (j + 1 < W) rsum[i][j] = rsum[i][j + 1] + 1;
        else rsum[i][j] = 1;
      }
    }
  }

  rep (j, W) {
    for (int i = 0; i < H; i++) {
      if (board[i][j] == '.') {
        if (i - 1 >= 0) usum[i][j] = usum[i - 1][j] + 1;
        else usum[i][j] = 1;
      }
    }
    for (int i = H - 1; i >= 0; i--) {
      if (board[i][j] == '.') {
        if (i + 1 < H) dsum[i][j] = dsum[i + 1][j] + 1;
        else dsum[i][j] = 1;
      }
    }
  }

  int ans = 0;
  rep (i, H) rep (j, W) if (board[i][j] == '.') {
    ans = max(ans, lsum[i][j] + rsum[i][j] + dsum[i][j] + usum[i][j] - 3);
  }

  cout << ans << endl;
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if (A > B){
        if (A > C){
            cout << 10 * A + B + C << endl;
        } else{
            cout << A + B + 10 * C << endl;
        }
    }else{
        if (B > C){
            cout << A + 10 * B + C << endl;
        } else{
            cout << A + B + 10 * C << endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  string t="CODEFESTIVAL2016";
  int ans=0;
  for(int i=0;i<16;i++){
    if(s[i]!=t[i])ans++;
  }
  cout<<ans<<endl;
}

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

bool contain(string &str, char c) {
  return str.find(c) != string::npos;
}

int main() {
  char c;
  cin >> c;
  string vowel = "aeiou";
  cout << (contain(vowel, c) ? "vowel" : "consonant") << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,h,w,i,ans,a,b;cin >> n >> h >> w;ans = 0;
  for(i=0;i<n;i++){
    cin >> a >> b;
    ans += int(a >= h && b >= w);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
  
    ll n,q,k,i,j=0,s=0,s2=0;
    cin>>n>>k>>q;
    ll a[100005], b[n];
    map<ll,ll>m;

    memset(b,0,sizeof(b));
    for(i=0;i<q;i++)
    {
      cin>>s;
      m[s]++;
    }
for(i=1;i<100005;i++)
{
  a[i]=k-q+m[i];
}
for(i=1;i<=n;i++)
  {if(a[i]<=0)
  {
    cout<<"No"<<endl;
  }
  else
  {
    cout<<"Yes"<<endl;
  } 
  }
    

  return 0;
} 

Measured memory_bytes: 10112
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define P(x, y) make_pair(x, y)

const int INF = 1000000009;
const double INF_D = INF+0.1;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);


const int MAX = 1e5+2; /// 最大頂点数

ll N, M; /// N:頂点数、M:辺の数

vector<pair<int, ld> > G[MAX]; /// G[i]は頂点iから出る辺、<行き先、距離>
ld dist[MAX]; /// dist[j]は注目する頂点kからの最短距離、特にdist[k]=0

struct Circle {
  int x, y, r;

  ld dist(Circle& other) {
    return max(
        0.0, 
        pow(pow(x-other.x, 2) + pow(y-other.y, 2), 0.5) - (r+other.r)
    );
  }
};

Circle circles[MAX];

void dijkstra(int s) { /// sは始点
  fill_n(dist, N+2, INF_D);
  priority_queue<pair<ld, int> > q;
  q.push(make_pair(0.0, s)); /// queueは距離、始点の順で使う。大きい方が優先されるので、距離は負の値で扱う
  while (!q.empty()) {
    int t;
    ld d; /// t:終点、d:始点からtまでの距離
    tie(d, t) = q.top(); q.pop();
    if (dist[t] != INF_D) continue;
    dist[t] = -d;
    FORE (e, G[t]) {
      q.push(make_pair(d-e.second, e.first));
    }
  }
}

int main() {

  Circle s, t;
  cin >> s.x >> s.y >> t.x >> t.y;
  s.r = 0, t.r = 0;

  cin >> N;
  circles[0] = s; circles[N+1] = t;

  REP (i, N) {
    Circle c;
    cin >> c.x >> c.y >> c.r;
    circles[i+1] = c;
  }

  REP (j, N+2) REP (i, j) {
    ld d = circles[i].dist(circles[j]);
    G[i].push_back(make_pair(j, d));
    G[j].push_back(make_pair(i, d));
  }

  dijkstra(0);

  cout << fixed;
  cout << setprecision(10) << dist[N+1] << endl;

  return 0;
}

Measured memory_bytes: 70116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			String str1 = stdIn.nextLine();
			if(str1.equals("END OF INPUT")){
				return;
			}
			String[] str2 = str1.split(" ");
			for(int i=0;i<str2.length;i++){
				System.out.print(str2[i].length());
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
#define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

 

 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}

const int N = 100005; 

void selfadd(int& a, int b){
    a = (a+b)%mod;
}

int dp[3001][3001];

void solve(){
    int n;
    cin>>n;
    int* arr = new int[n];
    int* ca = new int[n+1]();
    forn(i,0,n-1)
        cin>>arr[i];

    ca[n-1] = arr[n-1];
    fornd(i,n-2,0){
        ca[i] = arr[i]+ca[i+1];
    }

    memset(dp,0,sizeof(dp));

    for(int i=0;i<n;i++){
        dp[i][i] = arr[i];
    }


    for(int i=n-1;i>=0;i--){

        for(int j=i+1;j<n;j++){
            dp[i][j] = ca[i] - ca[j+1] - min(dp[i+1][j], dp[i][j-1]);
        }
    }

    cout<<(dp[0][n-1] - min(dp[1][n-1], dp[0][n-2]));



}   
 
int32_t main()
{
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 70656
import java.util.*;

public class Main{
	public static void main(String[] arg){
    	Scanner sc=new Scanner(System.in);
      int x=sc.nextInt();
      int y=sc.nextInt();
      int a=sc.nextInt();
      int b=sc.nextInt();
      int c=sc.nextInt();
      Integer ra[]=new Integer[a];
      for(int i=0;i<a;i++)ra[i]=sc.nextInt();
      Integer ga[]=new Integer[b];
      for(int i=0;i<b;i++)ga[i]=sc.nextInt();
      Integer ca[]=new Integer[c];
      for(int i=0;i<c;i++)ca[i]=sc.nextInt();
      ArrayList<Integer> list=new ArrayList<>();
      Arrays.sort(ra,Collections.reverseOrder());Arrays.sort(ga,Collections.reverseOrder());Arrays.sort(ca,Collections.reverseOrder());
      for(int i=0;i<x;i++)list.add(ra[i]);
      for(int i=0;i<y;i++)list.add(ga[i]);
      for(int i=0;i<Math.min(c,x+y);i++)list.add(ca[i]);
      Collections.sort(list,Collections.reverseOrder());
      long ans=0;
      for(int i=0;i<y+x;i++)ans+=list.get(i);
      System.out.println(ans);
    }
}

Measured memory_bytes: 102996
import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	}

}

Measured memory_bytes: 28584
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main(){
    int h,w;cin>>h>>w;
    vector<vector<char>> s(h,vector<char>(w));
    vector<vector<int>> dp(h,vector<int>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i==0){
                if(j==0){
                    if(s[0][0]=='#') dp[0][0]=1;
                    else dp[0][0]=0;
                }
                else{
                    if(s[0][j]=='#'&s[0][j-1]=='.') dp[0][j]=dp[0][j-1]+1;
                    else dp[0][j]=dp[0][j-1];
                }
            }
            else{
                if(j==0){
                    if(s[i-1][0]=='.'&s[i][0]=='#') dp[i][0]=dp[i-1][0]+1;
                    else dp[i][0]=dp[i-1][0];
                }
                else{
                    int a,b;
                    if(s[i][j]=='#'&s[i][j-1]=='.') a=dp[i][j-1]+1;
                    else a=dp[i][j-1];
                    if(s[i][j]=='#'&s[i-1][j]=='.') b=dp[i-1][j]+1;
                    else b=dp[i-1][j];
                    dp[i][j]=min(a,b);
                }
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 256
import java.math.*

fun main(args: Array<String>) {
    val (a, b, c, d) = readInputLine().split(" ").map{it.toInt()}
    
    if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) {
        println("Yes")
    } else {
        println("No")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36084
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<numeric>

using namespace std;

int main(void){

  int n,m;
  cin >> n;
  cin >> m;

  vector<int> a(m);
  vector<int> b(m);
  vector<pair<int,int> > c(m,make_pair(0,0));
  vector<int> d(m,1);

  for(int i=0;i<m;i++){
    cin>>a[i];
    cin>>b[i];
    c[i] = make_pair(b[i],a[i]);
  }

  sort(c.begin(),c.end() );
  for(int i=0;i<m;i++){
    //cout << c[i].first << "," << c[i].second << endl;
  }
  //cout << endl;
  for(int i=0;i<m;i++){
    if(d[i]){
      for(int j=i+1;j<m;j++){
        if(c[j].second < c[i].first ){
          d[j]=0;
        }
      }
    }
  }
  for(int i=0;i<m;i++){
    //cout << d[i] << endl;
  }
  cout << accumulate(d.begin(),d.end(),0) << endl;


  return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 5100;

int K, Q;
ll d[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> K >> Q;
    for (int i = 0; i < K; i++)
        cin >> d[i];

    for (int i = 0; i < Q; i++)
    {
        int n;
        ll x, m;
        cin >> n >> x >> m;

        ll y = x;
        for (int j = 0; j < K; j++)
        {
            ll nv = (n - 1) / K;
            if ((n - 1) % K > j) nv++;

            ll cv = d[j] % m;
            if (cv == 0) cv = m;
            y += nv * (ll) cv;
        }

        cout << (n - 1) - (y / m - x / m) << "\n";
    }
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    class Program
    {

        static bool[,] g;
        static bool[] visit;
        static int N;
        static int M;
        
        static void dfs(int u)
        {
            visit[u] = true;

            for(int v = 0; v < N; v++)
            {
                if (g[u, v] && !visit[v]) dfs(v);
            }
            
        }


        
        static void Main(string[] args)
        {
            string[] str1 = Console.ReadLine().Split(' ');
            N = int.Parse(str1[0]);
            M = int.Parse(str1[1]);

            int[] a = new int[M];
            int[] b = new int[M];

            g = new bool[N, N];
            visit = new bool[N];
            
            for(int i = 0; i < M; i++)
            {
                string[] str2 = Console.ReadLine().Split(' ');
                a[i] = int.Parse(str2[0]) - 1;
                b[i] = int.Parse(str2[1]) - 1;

                g[a[i], b[i]] = true;
                g[b[i], a[i]] = true;
            }

            int cnt = 0;

            

            for(int i = 0; i < M; i++)
            {
                g[a[i], b[i]] = false;
                g[b[i], a[i]] = false;

                for(int j = 0; j < N; j++)
                {
                    visit[j] = false;
                }

                dfs(0);

                
                bool bridge = false;
                for(int j = 0; j < N; j++)
                {
                    if (!visit[j])
                    {
                        bridge = true;
                        break;
                    }                  
                }

                if (bridge) cnt++;

                g[a[i], b[i]] = true;
                g[b[i], a[i]] = true;

            }
            
            Console.WriteLine(cnt);

        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn = 1e5 + 10;
typedef struct point
{
	ll x, v;
};
point p[maxn];
int n;
ll c;
ll ans = 0;
ll sum[maxn];
bool cmp(const point &a, const point &b)
{
	return a.x<b.x;
}
void solve()
{
	sort(p + 1, p + n + 1, cmp);
	ll cur = 0;
	ll mx = 0;
	for (int i = 1; i <= n; i++)
	{
		cur += p[i].v - (p[i].x - p[i - 1].x);
			if (cur>mx)mx = cur;
		sum[i] = mx;
	}
	ans = max(ans, sum[n]);
	ll now = 0;
	for (int i = n; i>0; i--)
	{
		now += p[i].v;
		ans = max(ans, sum[i - 1] - 2 * (c - p[i].x) + now);
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> c;
	for (int i = 1; i <= n; i++)
		cin >> p[i].x >> p[i].v;
	solve();
	for (int i = 1; i <= n; i++)
		p[i].x = c - p[i].x;
	solve();
	cout << ans << endl;
	return 0;
}

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

// LongestIncreasingSubsequence
template<class T> int LIS(vector<T>& v, T v_inf = (T)1e18 ) {
    int n = v.size();
    vector<T> dp(n+1, v_inf);  // dp[i]:長さi+1の増加部分列の最後の値の最小値
    for ( int i = 0; i < n; i++ ) {
        int p = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
        dp[p] = v[i];
    }
    int r = lower_bound(dp.begin(), dp.end(), v_inf) - dp.begin();
    return r;
};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=jp
using ll = long long;
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for ( int i = 0; i < n; i++ ) {
        cin >> a[i];
    }
    int ans = LIS(a);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4416
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

int answer = INT32_MAX;
int N;
vector<int> abc(3);
vector<pair<int,int> > unit(4,pair<int,int>(0,0));
void dfs(int depth,vector<int> &l){
    if(depth < N){
        REP(i,4){
            unit[i].first+=l[depth];
            unit[i].second+=1;
            dfs(depth+1,l);
            unit[i].first-=l[depth];
            unit[i].second-=1;
        }
    }
    else{
        int tmp=0;
        
        REP(i,3){
            if(unit[i].second == 0)return;
            tmp += abs(unit[i].first-abc[i])+10*(unit[i].second-1);
        }
        
        answer = min(answer,tmp);
    }
}
int main(){
    cin >> N;
    vector<int>l(N);
    REP(i,3){
        cin >> abc[i];
    }
    REP(i,N)cin >> l[i];
    dfs(0,l);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N,a,b,c,d;
	scanf("%d",&N);
	d=N%10;
	N/=10;
	c=N%10;
	N/=10;
	b=N%10;
	N/=10;
	a=N;
	
	if(a+b+c+d==7){
		printf("%d+%d+%d+%d=7",a,b,c,d);
		return 0;
	}
	if(a+b+c-d==7){
		printf("%d+%d+%d-%d=7",a,b,c,d);
		return 0;
	}
	if(a+b-c+d==7){
		printf("%d+%d-%d+%d=7",a,b,c,d);
		return 0;
	}
	if(a+b-c-d==7){
		printf("%d+%d-%d-%d=7",a,b,c,d);
		return 0;
	}
	if(a-b+c+d==7){
		printf("%d-%d+%d+%d=7",a,b,c,d);
		return 0;
	}
	if(a-b+c-d==7){
		printf("%d-%d+%d-%d=7",a,b,c,d);
		return 0;
	}
	if(a-b-c+d==7){
		printf("%d-%d-%d+%d=7",a,b,c,d);
		return 0;
	}
	if(a-b-c-d==7){
		printf("%d-%d-%d-%d=7",a,b,c,d);
		return 0;
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 2000000
#define swap(a, b) { int t; t = a; a = b; b = t; }

const int INF = (1 << 30);
int a[MAX_N + 1];
int h;

void
max_heapify(int i)
{
	int largest;

	int l = 2 * i;
	int r = 2 * i + 1;

	/* ????????????????????????????????§???????????§???node????????¶ */
	if (l <= h && a[l] > a[i])
		largest = l;
	else
		largest = i;

	if (r <= h && a[r] > a[largest])
		largest = r;

	if (largest != i) /* ????????????????????§????????´?????? */
	{
		swap(a[i], a[largest]);
		max_heapify(largest);
	}
}

int
extract()
{
	if (h < 1)
		return -INF;

	int maxv = a[1];
	a[1] = a[h--];
	max_heapify(1);
	return maxv;
}

void
increase_key(int i, int key)
{
	if (key < a[i])
		return;

	a[i] = key;
	while (i > 1 && a[i / 2] < a[i])
	{
		swap(a[i], a[i / 2]);
		i /= 2;
	}
}

void
insert(int key)
{
	h++;
	a[h] = -INF;
	increase_key(h, key);
}

int
main(int argc, char** argv)
{
	char command[8];
	int key;

	h = 0;
	while (true)
	{
		scanf("%s", command);
		if (command[0] == 'e' && command[1] == 'n')
			break;

		else if (command[0] == 'e' && command[1] == 'x')
			printf("%d\n", extract());

		else if (command[0] == 'i')
		{
			scanf("%d", &key);
			insert(key);
		}
	}

	return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=3005;
const ll MOD=1e9+7;
ll add(ll a, ll b){a+=b; if(a>=MOD)a-=MOD; return a;}
ll sub(ll a, ll b){a-=b; if(a<0)a+=MOD; return a;}
ll mult(ll a, ll b){return (a*b)%MOD;}
string s;int n;

ll f[N][N];
void upd(ll *f, int i, ll v){
	for(++i;i<N;i+=i&-i)f[i]=add(f[i],v);
}
ll sum(ll *f, int i){
	if(i<0)return 0;
	ll r=0;for(++i;i;i-=i&-i)r=add(r,f[i]);return r;
}

int main(){FIN;
	cin >> n >> s;
	upd(f[n-1],1,1);
	for(int x=n-2; x>=1; x--){
		for(int y=n-x; y>=1; y--){
			int l=0, r=y-1;
			if(s[x]!=s[x-1]){
				int t=(n-x)-y;
				l+=t;r+=t;
			}
			r=min(N-1,r);l=min(N-1,l);
			ll ans = sub(sum(f[x+1],r),sum(f[x+1],l-1)); 
			upd(f[x],y,ans);
		}
	}
	
	cout << sum(f[1],N-1) << "\n";
}

Measured memory_bytes: 70400
import sys
input = sys.stdin.readline
import math
def get_primenumber(number):
    prime_list = []
    #2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2,number+1))
    while True:
      #search_listの先頭の値が√nの値を超えたら処理終了
      if search_list[0] > math.sqrt(number):
        #prime_listにsearch_listを結合
        prime_list.extend(search_list)
        break
      else:
        #search_listの先頭をprime_listに入れる
        head_num = search_list[0]
        prime_list.append(head_num)
        #search_listの先頭をpopする
        search_list.pop(0)
        #head_numの倍数を取り除く
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list
X = int(input())
K = 0
li = get_primenumber(100010)
for i in range(len(li)) :
    if li[i] >= X :
        K = li[i]
        break
print(K)

Measured memory_bytes: 7496
s = list(map(str, input()))
k = int(input())
basic = 0
repeat = 0
counter = 0
s_a = s*2
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        counter += 1
        basic += (counter % 2)
    else:
        counter = 0
if counter == len(s)-1:
    print(len(s)*k // 2)
else:
  counter = 0
  for i in range(1,len(s_a)):
    if s_a[i] == s_a[i-1]:
        counter += 1
        repeat += (counter % 2)
    else:
        counter = 0
  repeat -= basic
  print(basic + repeat * (k - 1))

Measured memory_bytes: 3064
def main():
    N = int(input())
    a = list(map(int, input().split()))

    for i in range(N):
        a[i] -= i+1
    a = sorted(a)
    s = a[N//2]
    ans = 0
    for i in range(N):
        ans += abs(s - a[i])
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 25200
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string str;

	cin >> str;

	long long sum = 0;
	vector<bool> neq;
	vector<long long> num;
	long long j = 0;

	if (str[0] == '<') {
		neq.push_back(false); //<
	}
	else {
		neq.push_back(true); //>
	}
	num.push_back(1);
	
	for (int i = 1; i < (int)str.length(); i++) {
		if (str[i - 1] == str[i]) {
			num[j]++;
		}
		else {
			if (str[i] == '<') {
				neq.push_back(false); //<
			}
			else {
				neq.push_back(true); //>
			}

			num.push_back(1);
			j++;
		}
	}

	j++;

	if (num.size() == 1) {
		for (int i = 0; i <= num[0]; i++) {
			sum += i;
		}
		cout << sum << endl;
		return 0;
	}

	if (str[0] == '<') {
		if (num[0] > num[1]) {
			for (int k = 1; k <= num[0]; k++) {
				sum += k;
			}
		}
		else {
			for (int k = 1; k < num[0]; k++) {
				sum += k;
			}
		}
	}
	else {
		for (int k = 1; k <= num[0]; k++) {
			sum += k;
		}
	}
	

	for (int i = 1; i < j-1; i++) {
		if (neq[i]) {
			if (num[i] >= num[i - 1]) {
				for (int k = 1; k <= num[i]; k++) {
					sum += k;
				}
			}
			else {
				for (int k = 1; k < num[i]; k++) {
					sum += k;
				}
			}
		}
		else {
			if (num[i] > num[i + 1]) {
				for (int k = 1; k <= num[i]; k++) {
					sum += k;
				}
			}
			else {
				for (int k = 1; k < num[i]; k++) {
					sum += k;
				}
			}
		}
	}

	
	if (str[str.length() - 1] == '<') {
		for (int k = 1; k <= num[num.size() - 1]; k++) {
			sum += k;
		}
	}
	else {
		if (num[num.size() - 2] > num[num.size() - 1]) {
			for (int k = 1; k < num[num.size() - 1]; k++) {
				sum += k;
			}
		}
		else {
			for (int k = 1; k <= num[num.size() - 1]; k++) {
				sum += k;
			}
		}
	}
	
	

	cout << sum << endl;

	return 0;
}

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

const int maxn = 1e5+5;
const int mod=998244353;
typedef long long ll;
int a[maxn],b[maxn],c[maxn];
int m[maxn],M[maxn];
long long d[5];
string str;

ll C[1000][1000];

void handle() {
    C[0][0] = 1;
    C[1][0] = C[1][1] = 1;
    for(int i=2; i<1000; ++i) {
        for(int j=0; j<=i; ++j) {
            C[i][j] = j==0 ? 1 : C[i-1][j]+C[i-1][j-1];
            C[i][j] %= mod;
        }
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	//handle();
	cin>>n>>str;
	int cnt1=0,cnt2=0,cnt3=0;
	for(int i=0; i<3*n; i++){
		if(str[i]=='R') a[++cnt1] = i;
		if(str[i]=='B') b[++cnt2] = i;
		if(str[i]=='G') c[++cnt3] = i;
 	}
 	for(int i=1; i<=n; i++){
 		m[i] = min( a[i],min(b[i], c[i]));
 		str[m[i]] = 'h';
 		M[i] = max( a[i],max(b[i], c[i]));
 		str[M[i]] = 't';
 	}
 	// bool flag=1;
 	long long ans=1;
 //	cout<<str<<endl;
 	int hm=0,h=0,t=0,m=0;
 	for(int i=0; i<3*n; i++){
 		if(str[i] == 'h'){
 			// if(!hm)
 				h++;
 		}
 		else if(str[i] == 't'){
 			ans = ans*m%mod;
 			hm--;
 			m--;
 		}
 		else{
 			m++;
 			hm++;
 			ans = ans*h%mod;
 			h--;
 		}
 	}
 	for(int i=2; i<=n; i++){
 		ans = (1ll*ans*i)%mod;
 	}
 	cout<<ans%mod<<endl;
}

Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int> A(N);
    rep(n,0,N) cin>>A.at(n);

    uint64_t ans=0;
    rep(n,0,N) ans+=A.at(n)-1;
    cout<<ans<<endl;
}

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

using namespace std;

const long long md = 1e9 + 7;
const int N = 2e5 + 10;

long long cnt[N], dp[N], ans[N], fact[N];
vector <int> adj[N];

long long power(long long a ,long long b) {
  long long res = 1;
  while (b) {
    if (b%2 == 1) res = (res * a) % md;
    b /= 2;
    a = (a  *a ) % md;
  }
  return res;
}

long long inv(long long x) {
  return power(x, md - 2);  
}

long long mulm(long long a, long long b) {
  return ((a % md) * (b % md)) % md;
}

long long dfs(int u, int par = 1) {
  cnt[u] = 1;
  for (auto v : adj[u]) if (v != par) cnt[u] += dfs(v, u);
  return cnt[u];
}

long long f(int u, int par) {
  if (dp[u] != -1) return dp[u];
  dp[u] = fact[cnt[u] - 1];
  for (auto v : adj[u]) {
    if (v != par) {
      dp[u] = mulm(dp[u], mulm(f(v, u), inv(fact[cnt[v]])));
    }
  }
  return dp[u];
}

void nroot(int u, int par) {
  ans[u] = dp[u];
  for (auto v: adj[u]) {
    if (v != par) {
      long long temp1, temp2, temp3, temp4;
      temp1 = dp[u];
      temp2 = cnt[u];
      temp3 = dp[v];
      temp4 = cnt[v];
      dp[u] = mulm(dp[u], inv(fact[cnt[u] - 1]));
      cnt[u] -= cnt[v];
      dp[u] = mulm(dp[u], fact[cnt[u] - 1]);      
      dp[u] = mulm(mulm(dp[u], fact[cnt[v]]), inv(dp[v]));
      
      dp[v] = mulm(dp[v], inv(fact[cnt[v] - 1]));  
      cnt[v] += cnt[u];
      dp[v] = mulm(dp[v], fact[cnt[v] - 1]);
      dp[v] = mulm(dp[v], mulm(dp[u], inv(fact[cnt[u]])));

      nroot(v, u);

      dp[u] = temp1;
      cnt[u] = temp2;
      dp[v] = temp3;
      cnt[v] = temp4;


    }
  }
}

int main() {
  fact[0] = 1;for (int i = 1; i <= N; i++) fact[i] = (fact[i - 1] * i) % md;
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  
  dfs(1);
  memset(dp, -1, sizeof dp);
  //cout << cnt[5] << endl;
  //cerr << power(2, 15)<<"***\n";
  ans[1] = f(1, 1);
  //cout << ans[1] << "***" << endl;
  nroot(1, 1);
  for (int i = 1; i <= n; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}

Measured memory_bytes: 20212
#include <bits/stdc++.h>
using namespace std;
int n, l, t;
#define LL long long
const int N = 200000;
int xi[N], dir[N], xx[N];
int main()
{
    cin >> n >> l >> t;
    LL c = 0;
    for (int i = 0; i < n; ++ i)
    {
        cin >> xi[i] >> dir[i];
        if (dir[i] == 2) dir[i] = -1;
        int nx = xi[i] + t * dir[i];
        c += (nx > 0? nx / l: (nx - l + 1) / l);
        xx[i] = (nx % l + l) % l;
    }
    sort(xx, xx + n);
    for (int i = 0; i < n; ++ i)
        cout << xx[((i + c) % n + n) % n] << "\n";
}


Measured memory_bytes: 2432
#include <stdio.h>
int main(void){
    int m,f,r;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1 && f==-1 && r==-1){
            break;
        }
        if((m+f)>=80){
            printf("A\n");
        }
        else if((m+f)>=65 && (m+f)<80){
            printf("B\n");
        }
        else if((m+f)>=50 && (m+f)<65){
            printf("C\n");
        }
        else if((m+f)>=30 && (m+f)<50){
            if(r>=50){
                printf("C\n");
            }
            else if((m+f)==49 && r==-1){
                printf("F\n");
            }
            else{
                printf("D\n");
                }
        }
        else if((m+f)<30){
            printf("F\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2068
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll h; cin >> h;
  int n=0;
  if(h==1){
    cout << "1\n";
    return 0;
  }else{
    for(int i=0; i<1e7; i++){
      h /= 2; n++;
      if(h==1) break;
    }
  }
  ll ans = 1;
  ll temp = 1;
  for(int i=0; i<n; i++){
    temp *= 2;
    ans += temp;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

# heap
class Heap
  def initialize(&func)
    @heap = []
    @sz = 0
    @func = func
  end
  attr_reader :heap

  def size
    @sz
  end

  def empty?
    @sz.zero?
  end

  def push(x)
    i = @sz
    @sz += 1
    while i > 0
      p = (i - 1) / 2
      break if @func.call(@heap[p], x)

      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end

  def pop
    ret = @heap[0]
    @sz -= 1
    x = @heap[@sz]
    i = 0
    while i * 2 + 1 < @sz
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @func.call(@heap[b], @heap[a])

      break if !@func.call(@heap[a], x)

      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    ret
  end

  def top
    @heap[0]
  end
end

heap = Heap.new{|x, y| x > y}

a.each do |e|
  heap.push e
end

m.times do
  heap.push(heap.pop / 2)
end
puts heap.heap.inject(:+)


Measured memory_bytes: 10764
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int x, y;
    scanf("%d%d", &x, &y);
    int i;
    for (i = 0; i <= x; i++) {
        int tmp=i * 2 + (x - i) * 4;
        if (tmp == y) {
            printf("Yes\n"); return;
        }
    }
    printf("No\n");
    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}





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

int divide(int a, int b) {
	return (a + b - 1) / b;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	int ans = divide(b - 1, a - 1);
	cout << ans << endl;
}


Measured memory_bytes: 256
N,M,K=map(int,input().split())
mod=10**9+7
X=N*M%mod
C=[1]
for i in range(K+1):
  C.append(C[i]*(X-2-i)*pow(i+1,mod-2,mod)%mod)
P=0
for i in range(N):
  P=(P+(i*(i+1)//2)+((N-i)*(N-i-1)//2))%mod
P=P*M*M%mod
Q=0
for i in range(M):
  Q=(Q+(i*(i+1)//2)+((M-i)*(M-i-1)//2))%mod
Q=Q*N*N%mod
print((P+Q)*C[K-2]*((mod+1)//2)%mod)

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

int main() {
  int N; 
  cin >> N;
  N %= 10;
  if (N == 3)
    cout << "bon" << endl;
  if (N == 0 || N == 1 || N == 6 || N == 8)
    cout << "pon" << endl;
  if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) 
    cout << "hon" << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
}node;
typedef node* Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while (x->left != NIL) x = x->left;
  return x;
}

Node treeSearch(Node u, int key){
  while (u != NIL && u->key != key) {
    if (key < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;

  if (x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }

  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if (y->left != NIL) x = y->left;
  else x = y->right;

  if (x != NIL) x->parent = y->parent;

  if (y->parent == NIL) root = x;
  else if (y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if (y != z) z->key = y->key;

}

void insert(int key){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if (y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, key;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( *com == 'f' ){
      scanf("%d", &key);
      Node t = treeSearch(root, key);
      if ( t != NIL ) puts("yes");
      else puts("no");
    } else if ( *com == 'i' ){
      scanf("%d", &key);
      insert(key);
    } else if ( *com == 'p' ){
      inorder(root);
      puts("");
      preorder(root);
      puts("");
    } else if ( *com == 'd' ){
      scanf("%d", &key);
      treeDelete(treeSearch(root, key));
    }
  }

  return 0;
}

Measured memory_bytes: 19360
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Set<String> set = new HashSet<String>() ;
        int n = sc.nextInt();
        for(int i = 0; i < n; i++){
            String ord = sc.next();
            String str = sc.next();
            if(ord.equals("insert")){
                set.add(str);
            }
            else {
                if(set.contains(str)) System.out.println("yes");
                else System.out.println("no");
            }

        }

        sc.close();
    }
}



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

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

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    bool flg = true;
    for(int i = 0; i < 4; ++i) {
        int nx = x + r*dx[i];
        int ny = y + r*dy[i];
        if(0 <= nx && nx <= W && 0 <= ny && ny <= H) continue;
        else flg = false;
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    double N;
    double K;
    cin >> N >> K;
    double ans = 0;
    for(ll i = 1; i <= N; i++) {
        double tmp = 0;
        int cnt = 0;
        ll j = i;
        while(j < K) {
            cnt++;
            j *= 2;
        }
        tmp = (1 / N) * pow((1.0 / 2.0), cnt);
        ans += tmp;
    }
    cout << fixed;
    cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


const int N = 500002;
int n, next_[N][28], jump[20][N];
char str[N];


bool check(int src, int dest){
	for(int i=19;i>=0;i--)
		if(jump[i][src] != -1 && jump[i][src] <= dest)
			src = jump[i][src];
	return (src == dest);
}


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>(str+1);
    n = strlen(str+1);
    memset(next_, -1, sizeof(next_));
    for(int i=n;i>=1;i--){
    	int ch = str[i]-'a'+1;
    	next_[i][ch] = i+1;
    	for(int j=ch+1;j<=27;j++)
    		if(next_[i][j-1] != -1)
    			next_[i][j] = next_[next_[i][j-1]][j-1];
    	for(int j=1;j<ch;j++)
    		if(next_[i][27] != -1)
    			next_[i][j] = next_[next_[i][27]][j];
    }


// cout<<"next_:\n";
// for(int i=1;i<=n;i++){
// 	cout<<i<<": ";for(int j=1;j<=27;j++)	cout<<next_[i][j]<<" ";cout<<endl;
// }cout<<endl;


	memset(jump, -1, sizeof(jump));
	for(int i=n;i>=1;i--){
		jump[0][i] = next_[i][27];
		for(int j=0;j<19;j++)
			if(jump[j][i] != -1)
				jump[j+1][i] = jump[j][jump[j][i]];
	}

// cout<<"jump:\n";
// for(int i=1;i<=n;i++){
// 	cout<<i<<": ";for(int j=0;j<5;j++)	cout<<jump[j][i]<<" ";cout<<endl;
// }cout<<endl;


	int q;
	cin>>q;
	while(q--){

		int l, r;
		cin>>l>>r;

		if(check(l, r+1))	cout<<"Yes\n";
		else	cout<<"No\n";
	}

    return 0;
}







Measured memory_bytes: 94848
#include <stdio.h>

int main() {
	int n,x,i,j,k,s,count=0;

	while(1)
	{
		s=0;
		count=0;
		scanf("%d %d",&n,&x);

		if(n==0 && x==0) break;
		
		for(i=1;i<=n-2;i++)
		{
			for(j=1+i;j<=n-1;j++)
			{
				for(k=1+j;k<=n;k++)
				{
					s=i+j+k;
					if(x==s) count++;
					//printf("%d+%d+%d=%d\n",i,j,k,s);
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}


Measured memory_bytes: 2768