akhauriyash/Code-Regression huggingface dataset:
using System;
 
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int EvenN = 0;int OddN = 0;
			for (int i = 0; i<N;i++){
            	if (i % 2 == 0){
                  EvenN++;
                }
              	else{
                  OddN++;
              	} 
            }
          	
 
            int result = EvenN * OddN;
 
            Console.WriteLine(result);
        }
    }
}

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

const double eps = 1e-9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define FORD(i,a,b) for (int i = int(b)-1; i >= (a); i--)
#define FORIT(i,c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define mp make_pair
#define pb push_back
#define mscanf(...) if(0 == scanf(__VA_ARGS__)){fprintf(stderr, "Could not parse arguments\n");}

int main(){
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    cout << (N+K-3) / (K-1) << endl;
	return 0;
}


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

int main() {
  int N, a, ans = 1, minA=100000; cin >> N;
  vector<int> A(100000, 0);
  for (int i = 0; i<N; i++) {
    cin >> a;
    A[a]++;
    minA = min(minA, a);
  }
  for (int i = minA-1; i<N-2; i++) ans = max(ans, A[i]+A[i+1]+A[i+2]);
  cout << ans << "\n";
}

Measured memory_bytes: 640
from collections import deque


H,W = map(int, input().split())

S = [input() for _ in range(H)]


"""
移動先の色が同じであれば、その部分は一回の操作でひっくり返せるので、黒から黒へ連続で移動していても操作回数は一回でOK

"""
INF = float("inf")
costs = [[INF for _ in range(W)] for _ in range(H)]

costs[0][0] = 0 if S[0][0] == "." else 1

q = deque()
q.append((costs[0][0], 0, 0))

while q:
    curr_cost, y, x = q.popleft()
    for dy, dx in [(1,0), (0,1)]:
        if y + dy >= H or x + dx >= W:
            continue
        nxt_cost = curr_cost if S[y][x] == S[y+dy][x+dx] else curr_cost + 1
        if nxt_cost < costs[y+dy][x+dx]:
            costs[y+dy][x+dx] = nxt_cost
            q.append((nxt_cost, y+dy, x+dx))


print((costs[-1][-1] + 1) // 2)


Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

int main(){
	while(true){
		int N, M;
		cin >> N >> M;
		if(N == 0 && M == 0){ break; }
		vector<pii> r(N);
		for(int i = 0; i < N; ++i){
			cin >> r[i].second >> r[i].first;
		}
		sort(r.begin(), r.end());
		ll answer = 0;
		for(int i = N - 1; i >= 0; --i){
			if(r[i].second <= M){
				M -= r[i].second;
			}else{
				answer += (r[i].second - M) * r[i].first;
				M = 0;
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1476
def sieve(x):
  p=[]
  b=[1]*x
  for i in range(2,x):
    if b[i]:
      p+=[i]
      for j in range(2*i,x,i): b[j]=0
  return p
p=sieve(10**5+1)
s=set(i for i in p if i<5e4)
l=[0]*(10**5)
for i in p[1:]:
  if i//2+1 in s:
    l[i]=1
from itertools import *
S=[*accumulate(l)]
q=int(input())
for _ in range(q):
  l,r=map(int,input().split())
  print(S[r]-S[l-1])

Measured memory_bytes: 13708
n = int(input())
a = list(map(int, input().split()))
a.sort()

res = 0
cnt = 1
for i in range(1, n) :
    if a[i-1] == a[i] :
        cnt += 1
    elif cnt >= a[i-1] :
        res += cnt - a[i-1]
        cnt = 1
    else :
        res += cnt
        cnt = 1
else :
    if cnt >= a[-1] :
        res += cnt - a[-1]
    else :
        res += cnt
    print(res)

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

namespace AtCoder.Abcdef
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //Input integer
            int n = int.Parse(Console.ReadLine());

            var dic = new Dictionary<string, int>();
            dic["AC"] = 0;
            dic["WA"] = 0;
            dic["TLE"] = 0;
            dic["RE"] = 0;

            //Input string
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();

                dic[s]++;
            }

            foreach (var item in dic) 
            {
                Console.WriteLine($"{item.Key} x {item.Value}");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 30956
/**Bismillahir Rahmanir Raheem
    Author:Refat(BSMRSTU)**/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}
int main() {
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;ll n,sum=0;
    ///scanf("%d",&test);
    for(int cs=1; cs<=test; cs++) {
        scanf("%lld",&n);
        for(int i=1;i<=n;i++){
            if(i%3==0||i%5==0){
                continue;
            }
            else{
                sum+=i;
            }
        }
        printf("%lld\n",sum);
    }
    return 0;
}



Measured memory_bytes: 3812
n = int(input()[-1])

if (n == 2 or n== 4 or n== 5 or n== 7 or n== 9):
    print("hon")
elif (n == 0 or n == 1 or n == 6 or n== 8):
    print("pon")
elif (n == 3):
    print("bon")

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int n, q;
char t[200005];
int d[200005];
string s;

int isOut(int k) {
    if(k <  0) return -1;
    if(k >= n) return +1;
    int now = k;
    inc(i, 0, q){
        if(s[now] == t[i]){
            now += d[i];
        }
        if(now <  0) return -1;
        if(now >= n) return +1;
    }
    return 0;
}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    cin >> n >> q;
    cin >> s;
    inc(i, 0, q){
        char dd;
        cin >> t[i] >> dd;
        if(dd == 'L'){
            d[i] = -1;
        }else{
            d[i] = +1;
        }
    }

    if(n == 1){
        if(isOut(0) == 0){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }

    int ok = -1;
    int ng = n;
    while(ng-ok>1){
        int c = (ok+ng)/2;
        if(isOut(c) == -1){
            ok = c;
        }else{
            ng = c;
        }
    }
    int l = ok;

    ok = n;
    ng = -1;
    while(ok-ng>1){
        int c = (ok+ng)/2;
        if(isOut(c) == +1){
            ok = c;
        }else{
            ng = c;
        }
    }
    int r = ok;
//    inc(i, 0, n){
//        cout << isOut(i) << endl;
//    }
//    cout << l << " " << r << endl;
    cout << r-l-1 << endl;

    return 0;
}


Measured memory_bytes: 1616
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int N, x, a;
  cin >> N >> x;
  int ans = 0;
  vector<int> vec(N);

  for (int i = 0; i < N; i++){
    cin >> a;
    vec.at(i) = a;
  }
  sort(vec.begin(), vec.end());

  for (int i = 0; i < N; i++) {
    x -= vec.at(i);
    if(x < 0){
      cout << ans << endl;
      return 0;
    } else if (i != N-1 && x > 0){
      ans++;
    } else if(x == 0){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int ple=sc.nextInt();
    int ans=ple;
    int cur;
    for(int i=1;i<n;i++){
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
import std.stdio, std.string, std.array, std.conv;

struct Stack {
    int[] x;

    void push(int y) {
        x ~= y;
    }

    int pop() {
        int result = x[$-1];
        --x.length;
        return result;
    }
}

void main() {
    Stack s;
    string[] c = readln.chomp.split.to!(string[]);
    int a, b;
    foreach (x; c) {
        if (x == "+") {
            a = s.pop;
            b = s.pop;
            s.push(b+a);
        } else if (x == "-") {
            a = s.pop;
            b = s.pop;
            s.push(b-a);
        } else if (x == "*") {
            a = s.pop;
            b = s.pop;
            s.push(b*a);
        } else {
            s.push(x.to!int);
        }
    }
    s.pop.writeln;
}


Measured memory_bytes: 2488
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    x,y,z = LI()
    print(z,x,y)
main()

Measured memory_bytes: 74556
#include<stdio.h>
#include<string.h>
#define min(a,b) (a<(b)?a:(b))
#define INF 20000000
int g[16][16],i,j,k,v,t,dp[1<<17];

int main()
{
	for(;~scanf("%d",&v),v;)
	{
		for(i=0;i<(1<<v);i++)
			dp[i]=INF;
		dp[0]=0;
		for(i=0;i<v;i++)
			for(j=0;j<=v;j++)
			{
				scanf("%d",&t);
				if(j==0)
					g[i][i]=t;
				else if(j-1!=i)
					g[i][j-1]=t;
			}
		for(i=0;i<=1<<v;i++)
			for(j=0;j<v;j++)
			{
				if(i>>j&1)continue;
				t=g[j][j];
				for(k=0;k<v;k++)
					t=min(t,i>>k&1?g[j][k]:INF);
				dp[i|1<<j]=min(dp[i|1<<j],dp[i]+t);
			}

		printf("%d\n",dp[(1<<v)-1]);
	}
	return 0;
}

Measured memory_bytes: 880
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n, tmp;
    cin >> n;
    map<ll, ll> mp;
    rep(n){
        cin >> tmp;
        mp[tmp]++;
    }

    vector<ll> rec;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        if(itr->second >= 2){
            rec.pb(itr->first);
        }
    }

    
    if((int)rec.size()== 0){
        printf("0");
    }else{
        sort(rall(rec));
        if((int)rec.size() == 1){
            if(mp[rec[0]] >= 4){
                printf("%lld", rec[0]*rec[0]);
            }else{
                printf("0");
            }
        }else{
            if(mp[rec[0]] >= 4){
                printf("%lld", rec[0]*rec[0]);
            }else{
                printf("%lld", rec[0]*rec[1]);
            }
        }
    }
  
}


Measured memory_bytes: 6528
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int ninzu,saishonoishi,wannnoishi;
        
        ninzu = sc.nextInt();
        saishonoishi = sc.nextInt();
        wannnoishi = saishonoishi;
        while(ninzu != 0){

            int[] kouhosha = new int[ninzu];
            
            for(int i=0; i< kouhosha.length ; i++){
                kouhosha[i]=0;
            }
            
            for(int i=0 ;;i++){
                if(i == ninzu){
                    i = 0;
                }
                if(wannnoishi != 0){
                    kouhosha[i] += 1;
                    wannnoishi -= 1;
                    
                } else if(wannnoishi ==0){
                    int checker = 0;
                    for(int j = 0; j < kouhosha.length; j++){
                        if(kouhosha[j] != 0)
                            checker += 1;
                        if(checker > 1){
                            wannnoishi = kouhosha[i];
                            kouhosha[i] = 0;
                            break;
                        }
                        
                    }
                    if (checker == 1){
                        if(i == 0){
                            System.out.println(ninzu - 1);
                            break;
                        }else{
                            System.out.println(i-1);
                            break;
                        }
                    }
                }
            }
          ninzu = sc.nextInt();
          saishonoishi = sc.nextInt();
          wannnoishi = saishonoishi;
            
            
        }
        
    }
}

Measured memory_bytes: 20556
from collections import *
h,w,n = map(int,input().split())
dic = defaultdict(int)
for _ in range(n):
  a,b = map(int,input().split())
  for i in range(9):
    dic[a - i //3,b - i % 3] += 1
ans =[0]*10
for i, j in dic:
  ans[dic[i,j]] += h-1 > i > 0 < j < w -1
ans[0] = (h -2)*(w-2) - sum(ans)
for item in ans:
  print(item)

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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    int n;
    cin>>n;
    if(n%1000==0)
        cout<<0<<nl;
    else cout<<1000-n%1000<<nl;
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b) {
    //a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
    }
  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
  bool prime[10000000];
void Sieve(ll int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Function to find gcd of array of 
// numbers 
int find(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 


//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
void reverse(string& str) 
{ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 

string fun(string s)
{
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='O' || s[i]=='o')
        {
            s[i]='0';
        }
        else if(s[i]=='l' || s[i]=='I' || s[i]=='L' || s[i]=='i')
        {
            s[i]='1';
        }
        else if(isupper(s[i]))
        {
            s[i]=tolower(s[i]);
        }
    }
    return s;
}
  
int main() {
    ios;
  ll int n;
  cin>>n;
  map<int,int>mp;
  for(int i=1;i<=100;i++)
  {
     for(int j=1;j<=100;j++)
     {
         for(int k=1;k<=100;k++)
         {
             ll int p=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(i*k);
             /*if(i==j && j==k)
             {
                 mp[p]+=1;
             }
             else if(i==j || j==k || k==i)
             {
                 mp[p]+=3;
             }
             else
             {
                 mp[p]+=6;
             }*/
             mp[p]++;
         }
         }
     }
  for(int i=1;i<=n;i++)
  {
      cout<<mp[i]<<endl;
  }
}


Measured memory_bytes: 5448
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0; i<N; i++)
#define lint long long
#define square_vector(name,N,M) vector<vector<lint>>name(N,vector<lint>(M,0))
#define sort(V) sort(V.begin(),V.end())

int main() {
  lint N;
  cin >> N;
  vector<string> s(N);
  vector<lint> t(N);
  rep(i,N) {
    cin >> s[i] >> t[i];
  }
  string X;
  cin >> X;
  lint ans = 0;
  bool ppp = false;
  rep (i,N) {
    if (ppp) {
      ans += t[i];
    }
    if (X == s[i]) {
      ppp = true;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC141
{
    class A
    {
        static void Main(string[] args)
        {

            string S = Console.ReadLine();

            if (S[0] == 'S') { Console.WriteLine("Cloudy"); }
            if (S[0] == 'C') { Console.WriteLine("Rainy"); }
            if (S[0] == 'R') { Console.WriteLine("Sunny"); }

        }
    }
}


Measured memory_bytes: 11092
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
use num::integer::gcd;
use proconio::fastout;
use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::f64::consts::PI;
use std::mem::swap;

type Pi = (i32, i32);

fn pri<T: std::fmt::Display>(x: T) {
    println!("{}", x);
}

#[fastout]
fn main() {
    input! {
        n: f64,
    }
    pri(2. * n * std::f64::consts::PI);
}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a,Zero,One,TwoOrMore;

main() {
    cin >> n;
    rep(i,n) {
        cin >> a;
        if (!(a%4)) TwoOrMore++;
        else if (!(a%2)) One++;
        else Zero++;
    }
    if (!One) Zero--;
    if (TwoOrMore>=Zero) ct("Yes")
    else ct("No")
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        if(a>=30){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35644
# -*- coding: utf-8 -*-
import collections


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

    a = []
    for i in range(N):
        tmp = list(map(int, input().split()))
        a += tmp[1:]

    c = collections.Counter(a)
    ans = 0
    for val in c.values():
        if val == N:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

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

struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

    vector<vector<mint>> dp(C + 5, vector<mint>(D + 5));
    rep(i, C + 5) rep(j, D + 5) dp[i][j] = 0;
    dp[A][B] = 1;

    reps(i, A, C + 1) {
        reps(j, B, D + 1) {
            if (i == A && j == B) continue;

            if (i == A)
                dp[i][j] = dp[i][j - 1] * i;
            else if (j == B)
                dp[i][j] = dp[i - 1][j] * j;
            else
                dp[i][j] = dp[i - 1][j] * j + dp[i][j - 1] * i -
                           dp[i - 1][j - 1] * (i - 1) * (j - 1);
        }
    }

    cout << dp[C][D] << endl;

    return 0;
}

Measured memory_bytes: 73924
#include <stdio.h>
#include <string.h>
#define R register
typedef long long ll;
#define MN 300005
#define P 998244353
int n;
ll A,B,k,fac[MN]={1},inv[MN],ans;
inline ll pw(ll x,int k=P-2){
	R ll res=1;
	for (; k; k>>=1,x=x*x%P) 
		if (k&1) res=res*x%P;
	return res;
}
inline ll C(ll n,ll m){return fac[n]*inv[m]%P*inv[n-m]%P;}
int main(){
	scanf("%d%lld%lld%lld",&n,&A,&B,&k);
	for (R int i=1; i<=n; ++i) fac[i]=fac[i-1]*i%P;
	inv[n]=pw(fac[n]);
	for (R int i=n; i--; ) inv[i]=inv[i+1]*(i+1)%P;
	for (R int i=0; i<=n&&A*i<=k; ++i)
		if ((k-A*i)%B==0){
			R ll t=(k-A*i)/B;
			if (t>n) continue;
			ans+=C(n,i)*C(n,t)%P;
			ans%=P;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
N,L = list(map(int,input().split()))


i = 1
taste = []

while i <= N:
        taste.append(L + i - 1)
        i += 1


if L > 0 :
        print(sum(taste[1:N]))
elif L <= 0 and N + L < 0:
        print(sum(taste[0:N-1]))
elif L <= 0 and N + L > 0:
        print(sum(taste[0:N]))
elif L <= 0 and N + L == 0:
        print(sum(taste[0:N-1]))

   

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int h,w,i,j; cin >>h>>w;
    vs s(h+2);
    rep2(i, 1, h+1) cin >> s[i];

    bool can = true;
    rep2(i, 1, h+1){
        rep(j, w){
            if(s[i][j] == '#'){
                if(s[i-1][j] !='#' && s[i+1][j] != '#' && s[i][j-1] != '#' && s[i][j+1] != '#'){
                    can = false;
                    break;
                }
            }
        }
    }
    cout << (can ? "Yes" : "No") <<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int main(){
	int n,m;
	while(scanf("%d%d", &n, &m), n||m){
		Vi h(n), w(m);
		map<int,int> ma;
		ll ans = 0;
		rep(i,n) scanf("%d", &h[i]);
		rep(i,m) scanf("%d", &w[i]);
		rep(i,n){
			int cnt = 0;
			for(int j = i; j < n; j++){
				cnt += h[j];
				ma[cnt]++;
			}
		}
		rep(i,m){
			int cnt = 0;
			for(int j = i; j < m; j++){
				cnt += w[j];
				ans += ma[cnt];
			}
		}
		printf("%lld\n", ans);
	}
}

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

int main(){
  int K;
  cin >> K;
  
  int count = 0;
  queue<long long> Q;
  for(int i=1;i<10;i++) Q.push(i);
  while(true){
    long long x = Q.front();
    Q.pop();
    count++;
    if(count==K){
      cout << x << endl;
      return 0;
    }
    
    for(int i=-1;i<=1;i++){
      int a = x%10;
      if(a+i<0 || a+i>9) continue;
      Q.push(x*10+a+i);
    }
  }
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>


int main(void)
{
	int totalValue=0;
	int commonPart,Apart,Bpart;
	int priceA,priceB,priceMix;
	scanf("%d%d%d",&priceA,&priceB,&priceMix);
	scanf("%d%d",&Apart,&Bpart);
	commonPart=(Apart<Bpart?Apart:Bpart);
	if(2*priceMix<priceA+priceB)
		totalValue=priceMix*2*commonPart;
	else
		totalValue=commonPart*(priceA+priceB);
	if((Apart-commonPart)*priceA+(Bpart-commonPart)*priceB<(Apart-commonPart+Bpart-commonPart)*priceMix*2)
		totalValue+=(Apart-commonPart)*priceA+(Bpart-commonPart)*priceB;
	else
		totalValue+=(Apart-commonPart+Bpart-commonPart)*priceMix*2;

	printf("%d\n",totalValue);
	return 0;
	

}

Measured memory_bytes: 128
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (C - A - B >= 0) {
		if (4 * A * B < (C - A - B) * (C - A - B))
			cout << "Yes";
		else
			cout << "No";
	}
	else
		cout << "No";
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            long X = in.Int();
            long Y = in.Int();
            if (X % Y == 0) {
                out.println(-1);
                return;
            }
            long x = X * 2;
            while (x % Y == 0) {
                if (1e18 < x) {
                    out.println(-1);
                    return;
                }
                x += X;
            }
            out.println(x);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23380
try:
    N = int(input())
    A = list(map(int,input().split()))
except ValueError:
    print('数値以外が入力されました')

times_swap =0
for i in range(len(A)):
    for j in range(len(A)-1,i,-1):  
            # reversed(A)で配列の要素を逆順で取り出せる 
            #　配列はスライスでも逆順にできる 
            # list[start:end:stop] 
            # 逆順　list[::-1] （後ろ向きに1個ずつ止まる）
            
        if A[j] < A[j-1]:
            times_swap += 1
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp

print(*A)
print(str(times_swap))



Measured memory_bytes: 5604
from sys import stdin

n,l = [int(x) for x in stdin.readline().rstrip().split()]
li = []
abss = []
for i in range(1,n+1):
    aji = l + i - 1
    li.append(aji)
    abss.append(abs(aji))
li.pop(abss.index(min(abss)))
print(sum(li))

Measured memory_bytes: 3060
S=input()
T=input()


def judge():
    
    Sletters=list("abcdefghijklmnopqrstuvwxyz")
    Tletters=[0]*26

    for i in range(len(S)):
        if Tletters[Sletters.index(S[i])]!=0 and Tletters[Sletters.index(S[i])]!=T[i]:
            return "No"
        else: Tletters[Sletters.index(S[i])]=T[i]
    
    
    Tletters=list("abcdefghijklmnopqrstuvwxyz")
    Sletters=[0]*26
    
    for i in range(len(T)):
        if Sletters[Tletters.index(T[i])]!=0 and Sletters[Tletters.index(T[i])]!=S[i]:
            return "No"
        else: Sletters[Tletters.index(T[i])]=S[i]
        
    return "Yes"
    
print(judge())

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

struct P {
  int x, y;
  P(int a, int b) {x=a;y=b;}
  P() {}
  friend ostream &operator<<(ostream &stream, P ob) {stream << "(" << ob.x << ", " << ob.y << ")";}
};

P start, end;
int w, h;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int mn;

void f(int mat[][20], P now, int n)
{
  if (n >= 10)
    return;

  for (int i = 0; i < 4; i++) {
    int x = now.x, y = now.y;
    bool saisyo = false;
    while (1) {
      int xx = x+dx[i], yy = y+dy[i];
      if (end.x == xx && end.y == yy)
        mn = min(mn, n+1);
      if ((xx < 0 || xx >= w) || (yy < 0 || yy >= h))
        break;
      if (mat[xx][yy]) {
        if (saisyo) {
          mat[xx][yy] = 0;
          f(mat, P(x,y), n+1);
          mat[xx][yy] = 1;
        }
        break;
      }
      saisyo = true;
      x += dx[i];
      y += dy[i];
    }
  }
}

int main()
{
  while (cin >> w >> h && (w||h)) {
    int mat[w][20];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) {
        cin >> mat[j][i];
        if (mat[j][i] == 2) {
          start = P(j, i);
          mat[j][i] = 0;
        } else if (mat[j][i] == 3) {
          end = P(j, i);
          mat[j][i] = 0;
        }
      }
    mn = 1000;
    f(mat, start, 0);
    if (mn && mn <= 10)
      cout << mn << endl;
    else
      cout << -1 << endl;
  }
}

Measured memory_bytes: 868
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

X=int(input())
if X>=1800:
    print(1)
elif X>=1600:
    print(2)
elif X>=1400:
    print(3)
elif X>=1200:
    print(4)
elif X>=1000:
    print(5)
elif X>=800:
    print(6)
elif X>=600:
    print(7)
elif X>=400:
    print(8)

Measured memory_bytes: 61936
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long long int h,w,k;
vector<vector<char>> grid;
vector<vector<long long int>> ans;
void saiki(long long int h1,long long int h2,long long int w1,long long int w2){
  long long int k2=0;
  pair<long long int,long long int> one={-1,-1};
  pair<long long int,long long int> two={-1,-1};
  for(long long int i=h1; i<=h2; i++){
    for(long long int j=w1; j<=w2; j++){
      if(grid.at(i).at(j)=='#') {
        k2++;
        if(one.first==-1){
          one.first=i;
          one.second=j;
        }else if(two.first==-1){
          two.first=i;
          two.second=j;
        }
      }
    }
  }
  if(k2==1){
    for(long long int i=h1; i<=h2; i++){
      for(long long int j=w1; j<=w2; j++){
        ans.at(i).at(j)=k;
      }
    }
    k--;
    return;
  }

  if(one.first!=two.first){
    saiki(h1,one.first,w1,w2);
    saiki(one.first+1,h2,w1,w2);
  }else{
    saiki(h1,h2,w1,one.second);
    saiki(h1,h2,one.second+1,w2);
  }
}
int main(void){
  cin>>h>>w>>k;
  grid.resize(h);
  ans=vector<vector<long long int>>(h,vector<long long int>(w));
  for(long long int i=0; i<h; i++){
    for(long long int j=0; j<w; j++){
      char c;
      cin>>c;
      grid.at(i).push_back(c);
    }
  }
  saiki(0,h-1,0,w-1);
  for(long long int i=0; i<h; i++){
    for(long long int j=0; j<w; j++){
      cout<<ans.at(i).at(j);
      if(j!=w-1){
        cout<<" ";
      }else{
        cout<<endl;
      }
    }
  }
}

Measured memory_bytes: 4492
#include<bits/stdc++.h> 
using namespace std; 
int main() { 

int a,b,c,d,a1,a2; 

scanf("%d%d%d%d " , &a,&b,&c,&d) ; 


a1= a*b; 
a2=c*d; 

if ( a1 >= a2 ) { 
 printf("%d" , a1 ) ;
 
} 
else { 
printf("%d" , a2) ;
}


return 0;
}

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

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

  int ans = 0;
  int sum = 1;
  while (sum < B) {
    sum = sum + A - 1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>

using namespace std;

template <class T> class SegTree {
    int n;                          // 葉の数
    vector<T> data;                 // データを格納するvector
    T def;                          // 初期値かつ単位元
    function<T(T, T)> operation;    // 区間クエリで使う処理
    function<T(T, T)> update;       // 点更新で使う処理

    // 区間[a,b)の総和。ノードk=[l,r)に着目している。
    T _query(int a, int b, int k, int l, int r){
        // 交差しない場合
        if(r <= a || b <= l) return def; 
        //// a,l,r,bの順で完全に含まれる
        if (a <= l && r <= b){
            return data[k]; 
        }else{
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
            return operation(c1, c2);
        }
    }
    public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    //コンストラクタ
    SegTree(size_t _n, T _def, 
                    function<T(T, T)> _operation, 
                    function<T(T, T)> _update)
                    :def(_def), operation(_operation), update(_update){
        n=1;
        while(n < _n){
            n *= 2;
        }
        data = vector<T>(2*n -1, def);
    }

    //区間クエリ[a, b)
    T query(int a, int b){
        return _query(a, b, 0, 0, n);
    }

    //更新クエリ:場所i(0-indexed)の値をxで更新
    void change(int i, T x){
        i += n -1;
        data[i] = update(data[i], x);
        while(i > 0){
            i = (i-1)/2;
            data[i] = operation(data[i*2+1], data[i*2+2]);
        }
    }

    // 添字でアクセス
    T operator[](int i){
        return data[i + n -1];
    }
};

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

    vector<long long> alphabet_unit(26); 

    auto operate = [&](vector<long long> a, vector<long long> b){
        vector<long long> ans(26);
        for(int i=0; i<26; ++i){
            ans[i] = a[i] + b[i];
        }
        return ans;
    };

    auto update = [&](vector<long long> a, vector<long long> b){
        return b;
    };

    bool alphabet[26];

    // 要素数N・long long型・区間min・点更新
    SegTree< vector<long long> > st(N, alphabet_unit, operate, update);

    string s; cin >> s; 
    for(int i=0; i<s.size(); ++i){
        int idx = s[i] - '0' - 49;
        vector<long long> alphabet(26);
        alphabet[idx] = 1;
        st.change(i, alphabet);
    }

    int Q; cin >> Q;
    for(int i=0; i<Q; ++i){
        int query_type; cin >> query_type;
        if(query_type == 1){
            int leave_id; cin >> leave_id;
            leave_id--;
            char c; cin >> c;
            vector<long long> alphabet(26);
            int idx = c - '0' - 49;
            alphabet[idx] = 1;
            st.change( leave_id, alphabet);
        }else{
            int l, r; cin >> l >> r;
            l--;
            if(l ==r) r++;
            vector<long long> res = st.query(l, r);

            long long ans = 0;
            for(int i=0; i<26; ++i){
                if(res[i] > 0) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
template<class T> using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-10;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }


int n;
ll a[200005];
bool check(ll x) {
    vector<pair<ll, ll>> d;
    reps(i, n) {
        if (a[i] - a[i - 1] > 0) d.emplace_back(0, a[i] - a[i - 1]);
        else {
            ll cnt = -(a[i] - a[i - 1]);
            while (d.back().second < cnt) {
                cnt -= d.back().second;
                d.pop_back();
            }
            d.back().second -= cnt;
            if (d.back().second == 0) d.pop_back();

            ll res = 0;
            while (d.back().first >= x - 1) {
                res += d.back().second;
                d.pop_back();
                if (d.empty()) return false;
            }

            if (d.back().second != 1) {
                d.back().second -= 1;
                d.emplace_back(d.back().first + 1, 1);
            }
            else d.back().first += 1;

            if (res != 0) d.emplace_back(0, res);
        }
    }
    return true;
}

void solve() {
    cin >> n;
    reps(i, n) cin >> a[i];
    ll l = 0, r = inf + 1;
    while (r - l > 1) {
        auto mid = (l + r) / 2;
        if (!check(mid)) l = mid;
        else r = mid;
    }
    cout << r << endl;
}

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


Measured memory_bytes: 9232
import java.util.*;
public class Main {
	int xpos;
	int ypos;
	int w;
	int h;

	private boolean checkUpper(int pos, String state){
		if(state.equals("y")){
			if(pos > h){
				return false;
			}
			else{
				return true;
			}
		}
		else{
			if(pos > w){
				return false;
			}
			else{
				return true;
			}
		}
	}

	private boolean checkLower(int pos, String state){
		if(state.equals("y")){
			if(pos <= 0){
				return false;
			}
			else{
				return true;
			}
		}
		else{
			if(pos <= 0){
				return false;
			}
			else{
				return true;
			}
		}
	}

	private void operate(int dis, int dir){
		switch(dir){
		case 0:
			if(! checkUpper(ypos+dis, "y")){
				ypos = h;
			}
			else{
				ypos += dis;
			}
			break;

		case 1:
			if(! checkUpper(xpos+dis, "x")){
				xpos = w;
			}
			else{
				xpos += dis;
			}
			break;

		case 2:
			if(! checkLower(ypos-dis, "y")){
				ypos = 1;
			}
			else{
				ypos -= dis;
			}
			break;

		case 3:
			if(! checkLower(xpos-dis, "x")){
				xpos = 1;
			}
			else{
				xpos -= dis;
			}
			break;
		}
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if(w == 0 && h == 0)
				break;
			int dir = 0;
			xpos = 1;
			ypos = 1;
			int [][] map = new int[w+1][h+1];
			while(true){
				String str = sc.next();
				if(str.equals("STOP")){
					break;
				}
				else if(str.equals("RIGHT")){
					dir = (dir + 1) % 4;
				}
				else if(str.equals("LEFT")){
					dir = (dir + 3) %4;
				}
				else if(str.equals("FORWARD")){
					int dis = sc.nextInt();
					operate(dis, dir);
				}
				else if(str.equals("BACKWARD")){
					int dis = sc.nextInt();
					operate(dis, (dir + 2) % 4);
				}
			}
			System.out.println(xpos + " " + ypos);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,s[123456]={},a,b,ans;
  cin>>n;
  while(n--){
    cin>>a>>b;
    s[a-1]++,s[b]--;
  }
  for(int i=0;i<100001;s[++i]+=s[i-1])
    if(i<=s[i])ans=i;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<queue>
#include<tuple>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

int main() {

	double A, B, H, M;
	cin >> A >> B >> H >> M;

	double minutes = H * 60 + M;
	double jisin_x = A * sin(2 * acos(-1) * minutes / (12 * 60.0));
	double jisin_y = A * cos(2 * acos(-1) * minutes / (12 * 60.0));
	double hunsin_x = B * sin(2 * acos(-1) * M / (60.0));
	double hunsin_y = B * cos(2 * acos(-1) * M / (60.0));

	cout << setprecision(11) << sqrt(pow(jisin_x - hunsin_x, 2) + pow(jisin_y - hunsin_y, 2)) << endl;

	return 0;
}

Measured memory_bytes: 4104
import sys
 
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
 
#WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
 
 
dp = [[0]*(N+1) for j in range(W+1)]
 
for i in range(1, W+1):
        for j in range(1, N+1):
                if i - w[j-1]>=0:
                #if i - WV[j-1][0]>=0:
                        dp[i][j] = max(dp[i-w[j-1]][j-1]+v[j-1], dp[i][j-1])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = dp[i][j-1]
 
print(dp[W][N])

Measured memory_bytes: 131036
#include <iostream>
#include <string>

using namespace std;

int main(){
	int S;
	cin >> S;
	int h, m, s;
	
	s = S % 60;
	S = S / 60;
	
	m = S % 60;
	h = S / 60;
	
	cout << h << ":" << m << ":" << s << "\n";
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    for(int i = 0; i < s.size(); ++i) {
        int x = s[i] - 'A';
        x = (x+n)%26;
        putchar('A' + x);
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <cmath> 
using namespace std;   
int main()  
{ 
     int a,b,c,x,ans;
     cin>>a>>b>>c>>x;
     for(int i=0;i<=c;i++){
          for(int j=0;j<=b;j++){
               for(int k=0;k<=a;k++){
                   if(50*i+100*j+500*k==x)ans++;}}}
          cout<<ans;
    system("pause");
    return 0;
}

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

int main() {
  int n, k, x, y;
  int sum;
  
  cin >> n >> k >> x >> y;
  
  if (n <= k) {
    sum = x*n;
  } else {
    sum = x*k + y*(n-k);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256