akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    long a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') {
        cout << a + b << endl;
    }
    else if (op == '-') {
        cout << a - b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e9+7;
ll ksm(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%maxn;
		a=a*a%maxn;
		b>>=1;
	}
	return ans;
}
ll kl(ll a,ll b)
{
	ll ca=1,cb=1;
	if(a<b)
	{
		return 0;
	}
	else if(a==b)
	{
		return 1;
	}
	else
	{
		for(ll i=0;i<b;i++)
		{
			ca=ca*(a-i)%maxn;
			cb=cb*(b-i)%maxn;
		}
	}
	return ca*ksm(cb,maxn-2)%maxn;
}
int	main()
{
	
	ll x,y,m,n,k;
	scanf("%lld%lld",&x,&y);
	if((x+y)%3!=0)
	{
		printf("0\n");
	}
	else
	{
		m=(2*y-x)/3;
		n=(2*x-y)/3;
		if(m<0||n<0)
		{
			printf("0\n");
		}
		else printf("%lld\n",kl(m+n,m));
	}
	return 0;
 } 

Measured memory_bytes: 256
import queue

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
q = queue.Queue()

ans = A[0]
q.put( (A[0], A[1]) )
q.put( (A[0], A[1]) )
for i in range(2, len(A)):
  t = q.get()
  ans += min(t[0], t[1])
  q.put((t[0], A[i]))
  q.put((t[1], A[i]))
  
print(ans)


Measured memory_bytes: 32132
#include <stdio.h>

int main() {
	int l[10];
	int v1, v2;
	int len_sum;
	double t;
	int i;

	while(scanf("%d,", &l[0]) != EOF) {
		for(i = 1; i < 10; i++)
			scanf("%d,", &l[i]);
		scanf("%d,%d", &v1, &v2);

		for(i = 0, len_sum = 0; i < 10; i++)
			len_sum += l[i];

		t = (double)len_sum / (v1 + v2);

		for(i = 0, len_sum = 0; (double)len_sum / v1 < t; i++)
			len_sum += l[i];

		printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 592
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/16/20 07:31:34
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll x,y; cin>>x>>y;
  auto z = y/x;
  int ans = 0;
  while ((z>>ans) > 0) ++ans;
  cout << ans << endl;

  return 0;
}


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

int main()
{
    int n, c, d, sum = 0;

    cin >> n >> c;

    for( int i = 0; i < c; i++ )
    {
        cin >> d;
        sum += d;
    }

    if( sum % ( n + 1 ) == 0 )
        cout << sum / ( n + 1 ) << endl;
    else
        cout << sum / ( n + 1 ) + 1 << endl;

    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
const long long INF = 1LL << 60;

int H,W;
char S[100][100];
int dx[8] = {-1,-1,0,1,1,1,0,-1}, dy[8] = {0,-1,-1,-1,0,1,1,1};
char mine_map[100][100];
int main(){
  cin >> H >> W;
  rep(y,H) rep(x,W) cin >> S[y][x];
  
  rep(y,H){
    rep(x,W){
      if(S[y][x] == '#'){
        mine_map[y][x] = '#';
        continue;
      }
      int b = 0;
      rep(i,8){
        if(S[y + dy[i]][x + dx[i]] == '#') b++;
      }
      mine_map[y][x] = b + 48;
    }
  }
  rep(y,H){
    rep(x,W){
      cout << mine_map[y][x];
    }
    cout << endl;
  }
  return 0;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A=in();
    int P=in();

    P+=A*3;
    cout<<P/2<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }

void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int maxsum,maxssum;
int A,B,C,D,E,F;

double fn3(int a,int b){
	return (double)100*b/(a+b);
}

int fn2(int wmax){
	int ssum=0;
	int smax=min(wmax/100*E,F-wmax);
	REP(i,smax/C+1)
		chmax(ssum,C*i+D*((smax-C*i)/D));
	return ssum;
}

void fn(int wmax){
	if(wmax>F) return;
	int smax=fn2(wmax);
	if(fn3(maxsum,maxssum)<fn3(wmax,smax)){
		maxsum=wmax;
		maxssum=smax;
	}
	fn(wmax+A);
	fn(wmax+B);
}

int main(void){	
	cin>>A>>B>>C>>D>>E>>F;
	maxsum=A*100;maxssum=0;
 
	A*=100;B*=100;
 
	fn(0);
	printf("%d %d\n",maxsum+maxssum,maxssum);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,l;
	int jp,ma,sum,abc,sa;
	bool bo=false;
	cin>>l>>a>>b>>c>>d;
	if(a%c!=0){
		jp=a/c;
		jp++;
	}
	else{
		jp=a/c;
	}
	if(b%d!=0){
		ma=b/d;
		ma++;
	}
	else {
		ma=b/d;
	}
	if(jp<=ma){
		cout<<l-ma<<endl;
	}else{
		cout<<l-jp<<endl;
	}
	return 0;
}

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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for (int i = s; i < (e); ++i)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define FILEIO                          \
    freopen("./input.txt", "r", stdin); \
    freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                               \
    for (                                                                       \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second;                                                       \
        debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T &x) { return x > 0 ? x : -x; }
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }

const int N = 110;
int visited[N];

int main()
{
    FASTIO
#ifdef LOCAL
    FILEIO
#endif
    int x, n;
    cin >> x >> n;
    forn(i, 0, n)
    {
        int foo;
        cin >> foo;
        visited[foo] = 1;
    }
    int Min = INT_MAX, ans = INT_MAX;
    forn(i, -201, 201)
    {
        if (visited[i] != 1)
        {
            int diff = ABS(i - x);
            if (diff < Min)
            {
                Min = diff;
                ans = i;
            }
            else if (diff == Min)
            {
                ans = min(ans, i);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
from collections import defaultdict
def main():
    n=int(input())
    A=list(map(int,input().split()))
    d=defaultdict(int)
    m=max(A)
    for a in A:
        d[a]+=1
    c=0
    for i in range(1,m+1):
        if d[i]>=2:
            c+=(d[i]*(d[i]-1))//2
    for a in A:
        if d[a]<2:
            print(c)
        else:
            print(c-(d[a]-1))
    
if __name__=='__main__':
    main()

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

int main(){
    long long x;
    cin >> x;
    int a=0,b=-63;
    bool ok=true;
    while(true){
        long long tmp=a*a*a*a*a-b*b*b*b*b;
        if(tmp==x){ok=false;cout << a << " " << b << endl;break;}
        b++;
        if(b==1){
            a++;
            if(a==64)break;
            b=-63;
            }
    }
    if(ok){
        for(int i=1;i<=120;i++){
            bool aa=false;
            for(int j=0;j<i;j++){
                if(i*i*i*i*i-j*j*j*j*j==x){aa=true;cout << i << " " << j << endl;break;}
            }
            if(aa)break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll ans, m;
  m = min({a, b ,c, d, e});
  ans = ((n+m-1)/m)+4;
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 504
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N, M;
  cin >> N >> M;
  out(N * M);
}


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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define endl "\n"

const int MOD = 998244353;
const int N = 2e5 + 5;

int fact[N], invfact[N];

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD - 2, MOD);
}

void precompute()
{
	fact[0] = fact[1] = 1;
	for (int i = 2; i < N; i++)
	{
		fact[i] = fact[i - 1] * i;
		fact[i] %= MOD;
	}
	invfact[N - 1] = modinv(fact[N - 1]);
	for (int i = N - 2; i >= 0; i--)
	{
		invfact[i] = invfact[i + 1] * (i + 1);
		invfact[i] %= MOD;
	}
}

int nCr(int x, int y)
{
	if (y > x)
		return 0;
	int num = fact[x];
	num *= invfact[y];
	num %= MOD;
	num *= invfact[x - y];
	num %= MOD;
	return num;
}

int32_t main()
{
	IOS;
	int n, m, k;
	cin >> n >> m >> k;
	precompute();
	int ways = 0;
	for (int i = 0; i <= k; i++)
	{
		int ans = m * pow(m - 1, n - 1 - i, MOD);
		ans %= MOD;
		ans *= nCr(n - 1, i);
		ans %= MOD;
		ways += ans;
		ways %= MOD;
	}
	cout << ways << endl;

	return 0;
}

Measured memory_bytes: 6780
//in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   for(int i=0;;i++)
   {
       if(i%2==0)
       {
            c=c-b;
            if(c<=0)
            {
                cout<<"Yes"<<endl;
                break;
            }
       }
       else
        {
            a=a-d;
            if(a<=0)
            {
                cout<<"No"<<endl;
                break;
            }
        }

   }
}


Measured memory_bytes: 3632
use std::io;
fn main() {
    let mut buf = String::new();

    std::io::stdin().read_line(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();

    let a: u32 = iter.next().unwrap().parse().unwrap();
    let b: u32 = iter.next().unwrap().parse().unwrap();
    let c: u32 = iter.next().unwrap().parse().unwrap();
    
    let mut count5: u32 =0;
    let mut count7: u32 =0;
    
    if a == 5 {
        count5=count5+1;
    }
    if a == 7 {
        count7=count7+1;
    }
    if b == 5 {
        count5=count5+1;
    }
    if b == 7 {
        count7=count7+1;
    }
    if c == 5 {
        count5=count5+1;
    }
    if c == 7 {
        count7=count7+1;
    }
    
    let ans = if  count5==2 && count7==1  { "YES" } else { "NO" };
    println!("{}",ans);
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] a = new String[n];
        for(int i=n-1; i>=0; i--){
            a[i] = sc.next(); 
        }
        System.out.println(String.join(" ", a));
    }
}



Measured memory_bytes: 26260
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#define INF INT_MAX
using namespace std;

int N;
int F[110];
int P[110][10];
int ans = -INF;

int cntBit(int bit){
	int res = 0;
	for (int i = 0; i < 10; i++){
		if ((bit >> i) & 1)res++;
	}
	return res;
}

int main(){
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 9; j >= 0; j--) {
			int f;
			cin >> f;
			F[i] += f*(1 << j);
		}
	}
	for (int i = 0; i < N; i++){
		for (int j = 0; j <= 10; j++){
			cin >> P[i][j];
		}
	}
	for (int i = 1; i < (1 << 10); i++){
		int sum = 0;
		for (int j = 0; j < N; j++){
			int c = cntBit(F[j] & i);
			sum += P[j][c];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    L,R,d=mis()
    print(sum(i%d==0 for i in range(L,R+1)))









main()



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

int h, w;
vector<string> v;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool f = true;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> h >> w;
	for(int i=0; i<h; ++i){
		string s;
		cin >> s;
		v.push_back(s);
	}
	for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j){
			if(v[i][j] == '.') continue;
			bool t = false;
			for(int k=0; k<4; ++k){
				int x = i + dx[k];
				int y = j + dy[k];
				if(0 <= x && x < h && 0 <= y && y < w && v[x][y] == '#')
					t = true;
			}
			if(!t) f = false;
		}
	cout << (f ? "Yes\n" : "No\n");
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }

    int i = 0;
    int ans = 0;
    int cnt = 0;


    while(1){
        int i = 0;
        bool con = false;
        while(i < N){
            int c = 0;
            while(i < N && h[i] > 0){
                con = true;
                h[i]--;
                i++;
                c++;
            }
            if (c) cnt++;
            i++;
        }
        if (!con){
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

#define rep(i,n) for (int i=0; i<(n); i++)
const ll INF =2*1e9+2;
const ll BIG = 1e9+7;
const double PI = 3.141592653589793;

int main(){
    int k;
    cin >> k;
    ll f_n = 7 % k;
    bool check = false;
    rep(i, pow(10, 7)){
        if(f_n == 0){
            cout << (i+1) << endl;
            check = true;
            break;
        }else{
            f_n = ((f_n * 10) + 7)%k;
        }
    }
    if(!check) cout << "-1" << endl;
    return 0;
}

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


int main() {
  int n ;
  cin >> n ;
  
  int c=0;
  int x=1;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
      cin >> vec.at(i);
    if(vec.at(i)==x){
      x++;
    }
    else{
      c++;
    }
    
  }
  if(c==n){
    cout << -1 << endl;
  }
  else {
    
  cout << c << endl;
  }
}
  

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
flg = True
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            pass
        else:
            flg = False
            break

if flg:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long
#define sz(x) (int)x.size()
const int mx = 1000 * 100 + 5;
vector < int > ad[mx], ans;
bool mark[mx];
void dfs(int v){
	mark[v] = true;
	for(auto u : ad[v])
		if(!mark[u]){
			ans.pb(u);
			dfs(u);
			return;
		}
	return;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n, m, u, v;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		u--, v--;
		ad[u].pb(v);
		ad[v].pb(u);
	}
	mark[v] = 1;
	dfs(u);
	reverse(ans.begin(), ans.end());
//	for(auto k : ans)
//		cout << k << endl;
	ans.pb(u);
	ans.pb(v);
	dfs(v);
	cout << sz(ans) << endl;
	for(auto k : ans)
		cout << k + 1 << " ";
	return 0;
}


Measured memory_bytes: 9844
#include<bits/stdc++.h>
#define S second
#define F first
#define EPS (1e-7)
#define INF (1e9)
#define N 31
using namespace std;
typedef pair<double,int> P;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
typedef pair<P,P1> P3;
typedef pair<P3,int> P4;

vector<P2> G[N];
int n,m,s,g;

double dijkstra(){
  P d[N][N][N];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<N;k++)
	d[i][j][k]=P(INF,INF);
  priority_queue<P4,vector<P4>,greater<P4> > q;
  for(int i=0;i<G[s].size();i++){
    int nx=G[s][i].first,cost=G[s][i].second.first;
    d[s][nx][1]=P(cost,cost);
    q.push(P4(P3(P(cost,cost),P1(s,nx)),1));
  }
  while(!q.empty()){
    P4 t=q.top(); q.pop();
    int px=t.F.S.F,x=t.F.S.S,v=t.S,sum=t.F.F.S;
    double cost=t.F.F.F;
    if(d[px][x][v].F+EPS<cost)continue;
    if(abs(cost-d[px][x][v].F)<EPS)
      if(d[px][x][v].S<sum)continue;
    if(x==g&&v==1)return cost;
    for(int i=0;i<G[x].size();i++){
      int nx=G[x][i].F,cost2=G[x][i].S.F;
      int lim=G[x][i].S.S;
      if(nx==px)continue;
      for(int j=-1;j<=1;j++){
	int nv=v+j;
	if(nv<1||30<nv||nv>lim)continue;
	double ncost=cost+1.0*cost2/nv;
	if(d[x][nx][nv].F>ncost+EPS){
	  d[x][nx][nv]=P(ncost,sum+cost);
	  q.push(P4(P3(P(ncost,sum+cost),P1(x,nx)),nv));
	}
	if(abs(d[x][nx][nv].F-ncost)<EPS)
	  if(d[x][nx][nv].S>sum+cost){
	    d[x][nx][nv]=P(ncost,sum+cost);
	    q.push(P4(P3(P(ncost,sum+cost),P1(x,nx)),nv));
	  }
      }
    }
  }
  return -1;
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    cin>>s>>g;
    s--,g--;
    int a,b,c,d;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>d;
      a--,b--;
      G[a].push_back(P2(b,P1(c,d)));
      G[b].push_back(P2(a,P1(c,d)));
    }
    double r=dijkstra();
    if(r==-1)cout<<"unreachable"<<endl;
    else printf("%.5f\n",r);
    for(int i=0;i<n;i++)G[i].clear();
  }
  return 0;
}

Measured memory_bytes: 4160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = null;
		while (sc.hasNext()) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0) {
				sc.close();
				break;
			}
			for (int i=0; i < H; i++) {
				for (int j=0; j < W; j++) {
					s = i == 0 || i == H-1 ? "#" : j == 0 || j == W-1 ? "#" : ".";
					System.out.print(s);
					if (j == W-1)
						System.out.println();
				}
				if (i == H-1)
					System.out.println();
			}
		}
	}
}

Measured memory_bytes: 24632
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.util.Collections.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// Strange Currency System
// 2012/12/15
public class Main{
	Scanner sc=new Scanner(System.in);

	int n;
	int[] a;

	void run(){
		n=sc.nextInt();
		a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		sort(a);
		long sum=0;
		for(int i=0; i<=n; i++){
			if(i==n||a[i]>sum+1){
				println(sum+1+"");
				break;
			}
			sum+=a[i];
		}
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 13000
x, y = [int(x) for x in input().split()]
a = b = 0
flag = False
for i in range(x + 1 // 2):
    a = x - i
    b = x - a
    if 4 * a + 2 * b == y or 4 * b + 2 * a == y:
        flag = True
        break
print("Yes" if flag else "No")

Measured memory_bytes: 9188
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef long long ll;
ll comp(const void *a,const void *b)
{
  return *(ll *)b-*(ll *)a;
}
int main(void)
{
  int n=0,m=0,i=0,flag=0;
  char str[101];
  scanf("%s",str);
  while(str[i]!='\0') i++;
  for(int j=0;j<(i-1)/2;j++){
    if(str[j]!=str[i-1-j]) n++;
  }
  int k;
  k=(i+3)/2;
  for(int j=0;j<(i-1)/2;j++){
    if(str[j]!=str[k+j-1]) m++;
  }
  //printf("%d %d",n,m);
  if((n==0)&&(m==0)) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N;
    long long ans;
    cin >> N;

    ans=N/11 * 2;
    if(N%11 > 6){
        ans+=2;
    } else if(N%11>0){
        ans++;
    }

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



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Keyence_2020
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[][] lrs = new long[n][];
            for(int i = 0; i < n; i++)
            {
                long[] xl = ReadLongs();
                lrs[i] = new long[2] { xl[0] - xl[1], xl[0] + xl[1] };
            }
            Array.Sort(lrs, (a, b) => a[1].CompareTo(b[1]));
            int res = 1;
            long now = lrs[0][1];
            for(int i = 1; i < n; i++)
            {
                if (lrs[i][0] < now) continue;
                now = lrs[i][1];
                res++;
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 22336
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define ff first 
#define endl "\n"
#define ss second 
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int,int>
#define vii vector<pair<int,int> >
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom  pair<int,pair<int,int> >
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
#define mod 1000000007
ll dp[3001][3001];
ll solve(int* arr,int i,int j){
    if(i>j){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    ll op1=arr[i]+min(solve(arr,i+1,j-1),solve(arr,i+2,j));
    ll op2=arr[j]+min(solve(arr,i,j-2),solve(arr,i+1,j-1));
    return dp[i][j]=max(op1,op2);
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int arr[n];
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    memset(dp,-1,sizeof dp);
    ll bak=solve(arr,0,n-1);
    ll sak=sum-bak;
    cout<<bak-sak;
    return 0;
}

Measured memory_bytes: 74112
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main() {
    char a[100];
    fgets(a, 100, stdin);
    int n = strlen(a) - 1;
    char b[100];
    int j = -1;
    for(int i = 0; i < n; i++) {
        if(a[i] == '0')
            b[++j] = '0';
        if(a[i] == '1')
            b[++j] = '1';
        if(a[i] == 'B') {
            if(j == -1)
                continue;
            else
                j--;
        }
    }
        for(int i = 0; i <= j; i++)
            printf("%c", b[i]);
        printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <limits>
#include <queue>
#include <tuple>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

template <class Monoid>
struct segment_tree {
    typedef Monoid monoid_type;
    typedef typename Monoid::underlying_type underlying_type;
    int n;
    vector<underlying_type> a;
    Monoid mon;
    segment_tree() = default;
    segment_tree(int a_n, underlying_type initial_value = Monoid().unit(), Monoid const & a_mon = Monoid()) : mon(a_mon) {
        n = 1; while (n < a_n) n *= 2;
        a.resize(2*n-1, mon.unit());
        fill(a.begin() + (n-1), a.begin() + (n-1 + a_n), initial_value); // set initial values
        repeat_reverse (i, n-1) a[i] = mon.append(a[2*i+1], a[2*i+2]); // propagate initial values
    }
    void point_set(int i, underlying_type z) { // 0-based
        a[i+n-1] = z;
        for (i = (i+n)/2; i > 0; i /= 2) { // 1-based
            a[i-1] = mon.append(a[2*i-1], a[2*i]);
        }
    }
    underlying_type range_concat(int l, int r) { // 0-based, [l, r)
        underlying_type lacc = mon.unit(), racc = mon.unit();
        for (l += n, r += n; l < r; l /= 2, r /= 2) { // 1-based loop, 2x faster than recursion
            if (l % 2 == 1) lacc = mon.append(lacc, a[(l ++) - 1]);
            if (r % 2 == 1) racc = mon.append(a[(-- r) - 1], racc);
        }
        return mon.append(lacc, racc);
    }
};
template <typename T>
struct min_indexed_t {
    typedef pair<T, int> underlying_type;
    underlying_type unit() const { return make_pair(numeric_limits<T>::max(), -1); }
    underlying_type append(underlying_type a, underlying_type b) const { return min(a, b); }
};

int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> p(n); repeat (i, n) scanf("%d", &p[i]);
    assert (n % 2 == 0);

    // solve
    segment_tree<min_indexed_t<int> > even(n), odd(n);
    repeat (i, n) {
        auto & segtree = (i % 2 == 0 ? even : odd);
        segtree.point_set(i, make_pair(p[i], i));
    }
    reversed_priority_queue<tuple<int, int, int> > que;
    auto push = [&](int l, int r) {
        if (l == r) return;
        auto & left  = (l % 2 == 0 ? even : odd);
        int x = left.range_concat(l, r - 1).first;
        que.emplace(x, l, r);
    };
    push(0, n);
    vector<int> result;
    while (not que.empty()) {
        int l, r; tie(ignore, l, r) = que.top(); que.pop();
        auto & left  = (l % 2 == 0 ? even : odd);
        auto & right = (l % 2 == 0 ? odd : even);
        int m1 = left.range_concat(l, r - 1).second;
        int m2 = right.range_concat(m1 + 1, r).second;
        result.push_back(p[m1]);
        result.push_back(p[m2]);
        push(l, m1);
        push(m1 + 1, m2);
        push(m2 + 1, r);
    }

    // output
    repeat (i, n) {
        printf("%d%c", result[i], i < n - 1 ? ' ' : '\n');
    }
    return 0;
}


Measured memory_bytes: 11916
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int k = sc.nextInt();
		double total = 0;
		int cnt, tmp;
		for (int i = 1; i <= n; i++) {
			cnt = 0;
			tmp = i;
			while (tmp <= k - 1) {
				tmp = tmp * 2;
				cnt++;
			}
			total += 1.0 / n * Math.pow(0.5, cnt);
		}
		System.out.println(total);
	}
}


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

int main() {
    string s;
    cin >> s;
    if(s.length() != 6) {
        cout << "No\n";
    } else if(s[2] == s[3] && s[4] == s[5]) {
        puts("Yes");
    } else puts("No");
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;
#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
//1-indexedなので注意！！！！
//＄１には頂点数＋３くらいをいれるといい
vector<vector<ll>> graph(100003, vector<ll>(0));  // DAG
vector<ll> order(0);  // トポロジカルソートされた頂点を格納
vector<bool> used(100003,0);  // 訪問済みフラグ

// 辿れるところまで辿る深さ優先探索
void dfs(ll u){
    if(used[u]) return;
    used[u] = true;
    for(ll v : graph[u]) dfs(v);
    order.emplace_back(u);     // 帰りがけ順で頂点を入れていく
}

// トポロジカルソート
//Nは頂点数
void tsort(ll N){
    for(ll v = 1; v <= N; v++) dfs(v);
    reverse(order.begin(), order.end());
}
//1-indexedなので注意！！！！
//1-indexedなので注意！！！！
//1-indexedなので注意！！！！
//1-indexedなので注意！！！！
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> a(N+1,0);
    for(ll i=2;i<=N;++i)cin>>a[i];
    for(ll i=2;i<=N;++i){graph[a[i]].emplace_back(i);}
    tsort(N);
    vector<ll> dp(N+1,0);
    for(ll i=N-1;i>=0;--i){
        vl vec={};
        for(auto p: graph[order[i]])vec.emplace_back(dp[p]+1);
        ll n=vec.size();
        sort(vec.rbegin(), vec.rend());
        for(ll j=0;j<n;++j){
            chmax(dp[order[i]],j+vec[j]);
        }
    }
    prt(dp[1]);

    return 0;
}



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

int main(int argc, char *argv[])
{
    vector<int> v;
    int buff;
    while (1)
    {
        cin >> buff;
        if (buff == 0)
            break;
        v.push_back(buff);
    }

    // ???????????????????????????
    // int count = 1;
    // for_each(v.begin(), v.end(), [&count](int x) { cout << "Case " << count << ": " << x << endl; count++; });
    for (int i = 0; i < v.size(); i++)
    {
        cout << "Case " << i + 1 << ": " << v[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >>N;
  long long int a,af,b,bf;
  af=1;
  bf=1;
  for(int i=0;i<N;i++){
    cin >> a>> b;
    long long int j=max(af/a,bf/b);
    while(a*j < af || b*j < bf){
      j++;
    }
        af = a*j;
        bf = b*j;
  }
  cout << af+bf << endl;
}


Measured memory_bytes: 256
import bisect
import operator
import os
import sys
from functools import reduce


class SegmentTree:
    # http://codeforces.com/blog/entry/18051
    def __init__(self, values, op=operator.add):
        """
        :param list values:
        :param callable op: 結合律を満たす二項演算
        """
        self._size = len(values)
        self._op = op
        tree = [None] * self._size * 2
        tree[self._size:] = values[:]
        for i in reversed(range(1, self._size)):
            tree[i] = self._op(tree[i << 1], tree[i << 1 | 1])
        self._tree = tree

    def set(self, i, value):
        """
        values[i] = value
        :param int i:
        :param value:
        """
        i += self._size
        self._tree[i] = value
        i >>= 1
        while i > 0:
            self._tree[i] = self._op(self._tree[i << 1], self._tree[i << 1 | 1])
            i >>= 1

    def add(self, i, value):
        """
        values[i] = values[i]・value
        :param int i:
        :param value:
        """
        new_value = self._op(self._tree[self._size + i], value)
        self.set(i, new_value)

    def get(self, l, r=None):
        """
        [l, r) に op を順番に適用した値
        :param int l:
        :param int|None r:
        """
        if r is None:
            return self._tree[self._size + l]
        ret_l = []
        ret_r = []
        l += self._size
        r += self._size
        while l < r:
            if l & 1:
                ret_l.append(self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret_r.append(self._tree[r])
            l >>= 1
            r >>= 1
        return reduce(self._op, ret_l + ret_r)

    def __len__(self):
        return self._size


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

N = int(sys.stdin.buffer.readline())
XD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

XD.sort()
X = [x for x, d in XD]
D = [d for x, d in XD]

# R[i]: i 番目のロボットがどこまで行くか
st = SegmentTree(list(range(N)), op=max)
for i, (x, d) in reversed(list(enumerate(XD))):
    ri = bisect.bisect_left(X, x + d) - 1
    st.set(i, st.get(i, ri + 1))
R = [st.get(i) for i in range(N)]

# dp[i]: ロボット i からロボット N - 1 までを使うときの組み合わせの数
dp = [0] * (N + 1)
dp[-1] = 1
for i, r in reversed(list(enumerate(R))):
    # 使わない場合
    dp[i] += dp[i + 1]
    # 使う場合
    dp[i] += dp[r + 1]
    dp[i] %= MOD
# print(dp)
print(dp[0])


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int a, b; cin >> a >> b;
  if (a + b == 15) cout << "+\n";
  else if (a * b == 15) cout << "*\n";
  else cout << "x\n";
}


Measured memory_bytes: 256
#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
const ll INF = 1LL << 60;
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()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    cin >>N>>M;
    vector<ll>m(N+5);

    rep(i,M){
        ll l,r;
        cin>>l>>r;
        m[l]++;
        m[r+1]--;
    }
    ll ans =0;
    rep(i,N+4){
        m[i+1]+=m[i];
        if(m[i+1]==M){
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define pi acos(-1)
#define maxn 200001
using namespace std;
typedef long long ll;
const int mx=100005;
//void init(int node, int b, int e)
//{
//    if (b == e) {
//        tree[node] = a[b];
//        return;
//    }
//    int Left = node * 2;
//    int Right = node * 2 + 1;
//    int mid = (b + e) / 2;
//    init(Left, b, mid);
//    init(Right, mid + 1, e);
//    tree[node] = __gcd(tree[Left],tree[Right]);
//}
//int query(int node, int b, int e, int i, int j)
//{
//    if (i > e || j < b)
//        return 0;
//    if (b >= i && e <= j)
//        return tree[node];
//    int Left = node * 2;
//    int Right = node * 2 + 1;
//    int mid = (b + e) / 2;
//    int p1 = query(Left, b, mid, i, j);
//    int p2 = query(Right, mid + 1, e, i, j);
//    return __gcd(p1,p2);
//}
//void update(int node, int b, int e, int i, int newvalue)
//{
//    if (i > e || i < b)
//        return;
//    if (b >= i && e <= i) {
//        tree[node] = newvalue;
//        return;
//    }
//    int Left = node * 2;
//    int Right = node * 2 + 1;
//    int mid = (b + e) / 2;
//    update(Left, b, mid, i, newvalue);
//    update(Right, mid + 1, e, i, newvalue);
//    tree[node] = __gcd(tree[Left] , tree[Right]);
//}

int main(){

    string s;
    cin>>s;
    int cnt=0;
    for(int i=1;i<s.size();i++){
        if(s[i-1]=='h' && s[i]=='i')cnt+=2;
    }
    if(cnt==s.size()){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    print("YES" if len([a for a in a_list if a % 2 != 0]) % 2 == 0 else "NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14744
import java.util.*;


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

		int N = sc.nextInt();
		int A[] = new int[N];
		List<Integer> list = new ArrayList<>();
		
		for(int i=0; i<N; i++) {
			A[i]= sc.nextInt();
			list.add(A[i]);
		}
		
		Collections.sort(list);
		
		for(int i=0; i<N; i++) {
			if(A[i]==list.get(N-1)) {
				System.out.println(list.get(N-2));
			}else {
				System.out.println(list.get(N-1));
			}
		}
	}
}

Measured memory_bytes: 66160
#include<stdio.h>
int main()
{
	int a,b,c,i;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){i=a; a=b; b=i;}
	if(b>c){i=b; b=c; c=i;}
	if(a>b){i=a; a=b; b=i;}
	i=b-a+c-b;
	printf("%d\n",i);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true)
    {
        c -= b;
        if (c<=0) break;
        a -= d;
        if (a<=0) break;
    }
    if (a<=0) nout("No");
    else nout("Yes");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
#define f first
#define s second
int main()
{
	int x,n,ans=2000,m,p;
	cin>>x>>n;
	int vis[102]={0};
	for(int i=0;i<n;i++)
	{
		cin>>p;
		vis[p]=1;
		
	}
	for(int i=0;i<=101;i++)
	{
		if(vis[i]==0)
		{
			if(abs(x-i)<ans)
		{
			ans=abs(x-i);
			m=i;
		}
		else if(abs(x-i)==ans&&i<m)
		m=i;
		}
	}
	cout<<m;
	return 0;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		while (!(line = br.readLine()).equals("0")) {
            int n = Integer.parseInt(line);
            int i, L = 0, R  = 0;
            int[] a = new int[n];
            for (i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
			L = R = a[0];
			for(i = 1; i < n; i++){
				if( L >= R ) ; else L = R;
				if( R + a[i] < a[i] ) R = a[i]; else R = R + a[i];
			}
			if( L > R) {
				System.out.println(L);
			}else {
				System.out.println(R);
			}
		}


	}

}



Measured memory_bytes: 25260