akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

template<class Abel> struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, Abel SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, Abel w) {
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	UnionFind<int> uf(N);
	for (int i = 0; i < M; ++i) {
		int l, r, d;
		cin >> l >> r >> d;
		--l, --r;
		if (uf.issame(l, r)) {
			if (d != uf.diff(l, r)) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			uf.merge(l, r, d);
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1408
import math
a, b = map(int, input().split())
row_a = max(1, math.ceil((a - 1) / 50) * 2)
row_b = max(1, math.ceil((b - 1) / 50) * 2)

print("{} {}".format((row_a + row_b), 100))

rest = a - 1
for i in range(row_a):
  temp = ""
  if i % 2 == 0:
    for j in range(50):
      if rest != 0:
        temp += "#."
        rest -= 1
      else:
        temp += "##"
  else:
    for j in range(50):
      temp += "##"
  print(temp)
rest = b - 1
for i in range(row_b):
  temp = ""
  if i % 2 != 0:
    for j in range(50):
      if rest != 0:
        temp += ".#"
        rest -= 1
      else:
        temp += ".."
  else:
    for j in range(50):
      temp += ".."
  print(temp)


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int mozi[26];
    FOR(i, 0, 26) mozi[i] = 0;
    string s;
    cin>>s;
    FOR(i, 0, s.length()) mozi[s[i]-'a']++;
    FOR(i, 0, 26){
        if(mozi[i]%2==1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 13 21:30:21 2020

@author: NEC-PCuser
"""


A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())


dis = abs(A - B)
soutai_v = V - W

if dis == 0:
    print("YES")
elif soutai_v <= 0:
    print("NO")
else:
    amari = dis % soutai_v
    shou = dis // soutai_v

    if shou > T or (shou == T and amari != 0):
        print("NO")
    else:
        print("YES")



Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
  ll n;
  cin >> n;
  ll mn = LLONG_MAX;
  for(ll i = 1; i * i <= n; i++){
    if(n % i == 0){
      ll a = i - 1, b = n / i - 1;
      mn = min(mn , a + b);
    }
  }
  cout << mn << endl;
  return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

#define LL long long int

LL N,M;
LL A[100000];

LL ans = 0;
 
void solve(){
	priority_queue<LL> q;
	for(int i=0;i<N;i++){
		q.push(A[i]);
	}
	for(int i=0;i<M;i++){
		LL num = q.top();
		q.pop();
		q.push(num/2);
	}
	while(!q.empty()){
		ans += q.top();
		q.pop();
	}
}
 
int main(){
	cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}

	solve();

	cout<<ans;
	return 0;
}

Measured memory_bytes: 2168
if __name__ == '__main__':
	a = [int(input()) for _ in range(5)]
	k = int(input())
	a.sort(reverse=True)
	for i in range(4):
		j = i+1
		for j in range(5):
			if(a[i]-a[j]>k):
				print(":(")
				exit()
	print("Yay!")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PP pop_back()
#define set(x,y) memset(x,y,sizeof(x))
#define MIN3(x,y,z) min(min(x,y),z)
#define MAX3(x,y,z) max(max(x,y),z)
#define ALL(x) x.begin(),x.end()
#define sz(x) (int) x.size()
#define sag(x) 2*x+1
#define sol(x) 2*x
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define ROF(i,j,k) for(int i=j;i>=k;i--)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pii pair<int,int>
#define st first
#define nd second
#define ll long long
#define llu long long unsigned
#define lf double
#define orta (bas+son)/2
#define MOD 1000000007
#define inf 1000000000
#define N 200005
using namespace std;
int main() {
    int cev=1,n,k;
    scanf("%d %d",&n,&k);
    FOR(i,2,n) cev*=k-1;
    printf("%d",cev*k);
}


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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x;
  cin >> x;
  for (ll a = -1000; a <= 1000; a++) {
    for (ll b = -1000; b <= 1000; b++) {
      ll left = a * a * a * a * a - b * b * b * b * b;
      if (left == x) {
        cout << a << ' ' << b << '\n';
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n;cin >> n;
    vl a(n),p(n),b(n);
    rep(i,n){
        a[i]=30000*i+1;
    }
    rep(i,n)cin >> p[i],p[i]--;
    b[p[0]]=0;
    rep(i,n-1){
        b[p[i+1]]=a[p[i]]+b[p[i]]-a[p[i+1]]+1;
    }
    if(b[n-1]<=0){
        rep(i,n)b[i]+=-(b[n-1])+1;
    }
    rep(i,n)cout << a[i] <<" ";
    cout <<endl;
    rep(i,n)cout << b[i] <<" ";
    cout << endl;
} 

Measured memory_bytes: 1152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize
    }
    let mut ans = 0;
    let mut k = 1;
    while k * (k + 1) < n {
        if n % k == 0 {
            ans += n / k - 1;
        }
        k += 1
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;

struct Edge{
	int y,nxt;
} E[N*2];
int las[N],A[N];
int n,k,ans,cnt;

void Add_Edge(int x,int y){
	E[cnt]=(Edge){y,las[x]};las[x]=cnt++;
}
int dfs(int x,int fa){
	int d=0;
	for (int i=las[x],y;~i;i=E[i].nxt){
		y=E[i].y;
		d=max(d,dfs(y,x)+1);
	}
	if (d>=k-1&&fa!=1){
		ans++;
		return -1;
	} else{
		return d;
	}
}

int main(){
	memset(las,-1,sizeof(las));
	n=IN(),k=IN();
	For(i,1,n+1) A[i]=IN();
	if (A[1]!=1) ans++;
	For(i,2,n+1) Add_Edge(A[i],i);
	dfs(1,1);
	printf("%d\n",ans);
}

Measured memory_bytes: 6528
n, m = gets.split.map(&:to_i)
a = m.times.map {gets.split}.map! {|a| [a[0].to_i, a[1].chomp] }

c = {}
p = Array.new(n)
ans, pen = 0, 0

a.each do |v|
  if v[1] == 'WA'
    if p[v[0]].nil?
      p[v[0]] = {p: 1, s: nil}
    elsif p[v[0]][:s].nil?
      p[v[0]][:p] += 1
    end
  else
    if p[v[0]].nil?
      p[v[0]] = {p: 0, s: 1}
    else
      p[v[0]][:s] = 1
    end
  end
end

p.compact.each do |v|
  unless v[:s].nil?
    ans += 1
    pen += v[:p]
  end
end
puts "#{ans} #{pen}"

Measured memory_bytes: 52220
require 'bigdecimal'
 
N, K = gets.chop.split.map(&:to_i)
 
@sum = 0
 
(1..N).to_a.each do |i|
  now = i
  probability = Rational(1, N)
  while now < K do
    now *= 2
    probability *= Rational(1, 2)
  end
  @sum += probability
end
 
puts @sum.to_f

Measured memory_bytes: 2684
#include"bits/stdc++.h"
using namespace std;
set<string> sub_set;
int k;
void PSS(string str,int n)
{
	int i,j;
	for(i=0;i<n;i++)
		for(j=0;j<n-i;j++)
			sub_set.insert(str.substr(j,i+1));
}
int main()
{
	int i,j;
	string str,s1,minstr;
	cin>>str>>k;
	minstr=str;
	if(str.length()>=k)
	{
		for(i=0;i<str.length()-k;i++)
		{
			s1=str.substr(i,k);
			if(s1<minstr)
			{
				minstr=s1;
				PSS(s1,k);
			}
		}
		PSS(str.substr(str.length()-k,k),k);
	}
	else
		PSS(str,str.length());
	set<string>::iterator it=sub_set.begin();
	for(i=0;i<k-1;i++)
	{
		it++;
	}
	cout<<*it;
	
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = in.nextInt();
        int W = in.nextInt();
        int [][] arr = new int[H][W];
        for (int i = 0; i < H; i++) Arrays.fill(arr[i], 0);
        int h = in.nextInt();
        int w = in.nextInt();
        for (int row = 0; row < h; row++){
            Arrays.fill(arr[row], 1);
        }
        for (int i = 0; i < w; i++){
            for (int j = 0; j < H; j++){
                arr[j][i] = 1;
            }
        }
        int ans = 0;
        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                //System.out.print(arr[i][j] + " ");
                if (arr[i][j] == 0) ans++;
            }
            //System.out.println();
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
[x,n] = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
ls = []
for i in range(-101,202):
    if i not in p:
        ls.append(i)
diff = 1000
ans = -400
for i in ls:
    if abs(x-i) < diff:
        diff = abs(x-i)
        ans = i
print(ans)


Measured memory_bytes: 61788
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1e+6;
pair<int ,int> a[101];
int dp[101][N+1];
main()
{
    int n,w,goal=0;
    scanf("%lld%lld",&n,&w);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&a[i].S,&a[i].F);
    }
    sort(a+1,a+n+1);
    for(int i=0;i<=n;i++){
        for(int j=1;j<=N;j++){
            dp[i][j]=100000000000;
        }
    }
    for(int i=1;i<=n;i++){
        goal+=a[i].F;
        for(int j=1;j<=goal;j++){
            if(a[i].F>=j){
                dp[i][j]=min(a[i].S,dp[i-1][j]);
            }
            else{
                dp[i][j]=min(a[i].S+dp[i-1][j-a[i].F],dp[i-1][j]);
            }
        }
    }
    int it=0;
    while(dp[n][it]<=w&&it<=N){
        //cout<<dp[n][it]<<" ";
        it++;
    }
    cout<<it-1;
}


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

using namespace std;

int main(void) {
  int N; cin >> N;
  int ans = 0;
  int s[10][10];
  memset(s, 0, sizeof(s));

  for (int a = 1; a <= N; a++) {
    int h = a, t = a % 10;
    while(h/10 != 0) h /= 10;
    s[h][t]++;
  }
  
  for (int h = 1; h < 10; h++) {
    for (int l = 1; l < 10; l++) {
      ans += s[h][l] * s[l][h];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def solve_L():
    X = input()
    Y = input()
  
    a = len(X)
    b = len(Y)
    c1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = X[i]
        c2 = c1+[]
        for j in range(b):
            if e1 == Y[j]:
                c1[j+1] = c2[j] + 1
            elif c1[j+1] < c1[j]:
                c1[j+1] = c1[j]
    return c1[-1]
  
n = int(input())
ans = [[] for i in range(n)]
for i in range(n):
    ans[i] = solve_L()
for i in range(n):
  print(ans[i])

Measured memory_bytes: 7764
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
int main(){
    int a,b,c;
    cin >> a;
    if(a==1)
        cout << "Hello World" << endl;
    else{
        cin >> b >> c;
        cout << b+c << endl;
    }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n, k;
li a[100100];

int main() {
    cin >> n >> k;
    rin{
        cin >> a[i];
    }

    li res = (n - 1) / (k - 1);
    if ((n - 1) % (k - 1) > 0)++res;

    cout << res << endl;


    return 0;
}

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

const ll Q = 1000000007;

ll fact_list[100005];

ll pow_q (ll x, ll y){
    if ( y == 0 ) return 1;
    ll ans = 1;
    ll z = x;
    ll s = 0;
    while ( y >> s > 0){
        if ( (y >> s) % 2) ans *= z;
        ans %= Q;
        ++s;
        z *= z;
        z %= Q;
    }
    return ans;
}

void set_fact(){
    fact_list[0] = 1;
    for ( ll i = 1; i < 100005; i++ ){
        fact_list[i] = i * fact_list[i-1];
        fact_list[i] %= Q;
    }
}

ll combi_q(ll x, ll y){
    if ( x < y ) return 0;
    return ( ( ( fact_list[x] * pow_q( fact_list[y], Q - 2 ) ) % Q) * pow_q( fact_list[x-y], Q - 2) ) % Q;
}

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, k;
    cin >> n >> k;
    
    set_fact();
    
    for ( int i = 0; i < k; i++ )
    cout << combi_q( n - k + 1, i + 1) * combi_q( k - 1, i ) % Q << endl;
    
    return 0;
}


Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc127/tasks/abc127_c
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int no_of_cards, no_of_gates;
    cin >> no_of_cards >> no_of_gates;
    int max_left = INT_MIN, min_right = INT_MAX;
    for (int i = 0; i < no_of_gates; i++)
    {
        int left, right;
        cin >> left >> right;
        max_left = max(max_left, left);
        min_right = min(min_right, right);
    }
    if (max_left > min_right)
        cout << 0 << endl;
    else
        cout << min_right - max_left + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
def solve(N, xy, M, diredist):
    now = (10, 10)
    field = [[0]*21 for i in range(21)]
    field[now[0]][now[1]] = 1
    direction = {"N":(1, 0), "W":(0,-1), "S":(-1, 0), "E":(0, 1)}
    for i in range(M):
        dire = direction[diredist[i][0]]
        dist = int(diredist[i][1])
        for j in range(dist):
            field[now[0]+dire[0]][now[1]+dire[1]] = 1
            now = (now[0]+dire[0], now[1]+dire[1])
        
    for xi, yi in xy:
        if field[yi][xi]:
            continue
        else:
            return False
    
    return True
    

def main():
    ans = []
    while True:
        N = int(input())
        if (not N):
            break
        xy = [list(map(int, input().split())) for i in range(N)]
        M = int(input())
        diredist = [input().split() for i in range(M)]
        ans.append(solve(N, xy, M, diredist))
    
    for i in ans:
        print("Yes" if i else "No")


main()



Measured memory_bytes: 5648
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat May 26 17:48:59 2018
//
package main

import (
	"fmt"
)

var K, T int

func main() {
	fmt.Scan(&K, &T)
	a := make([]int, T)
	max := 0
	for i := range a {
		fmt.Scan(&a[i])
		if max < a[i] {
			max = a[i]
		}
	}

	n := max - 1
	if 0 < n-(K-max) {
		fmt.Println(n - (K - max))
	} else {
		fmt.Println(0)
	}

}


Measured memory_bytes: 512
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
ll dp[100005][2];
vector<ll>grp[100005];
void dfs(ll node,ll parent){
	// cout<<node<<" "<<parent<<endl;
	for(ll i=0;i<grp[node].size();i++){
		if(grp[node][i]!=parent){
			dfs(grp[node][i],node);
			dp[node][0]*=(dp[grp[node][i]][0]+dp[grp[node][i]][1])%MOD;
			dp[node][0]%=MOD;
			dp[node][1]*=dp[grp[node][i]][0]%MOD;
			dp[node][1]%=MOD;
		}
	}
	return ;
}
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n;
		cin>>n;
		for(int i=0;i<=n;i++){
			dp[i][0]=dp[i][1]=1;
		}
		for(int i=0;i<n-1;i++){
			ll u,v;
			cin>>u>>v;
			grp[u].pb(v);
			grp[v].pb(u);
		}
		dfs(1,-1);
		ll res=(dp[1][0]+dp[1][1])%MOD;
		cout<<res<<endl;
	}
}

Measured memory_bytes: 14208
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  string s,t;
  cin>>s>>t;
  int n=s.size();
  bool ans=false;
  for(int j=0;j<n;j++){
    bool ans=true;
    for(int i=0;i<n;i++){
      if(s[i]!=t[(i+j)%n])ans=false;
    }
    if(ans){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
	fastio;
	ll ar[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k=0;
	cin>>k;
	cout<<ar[--k];
return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

# dp[l][r]: 区間[l,r)のときのX-Y
dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

# 終局から遡る
# tは系列の長さ
for t in range(1, N+1):
    for l in range(N-t+1):
        r = t + l
        # 減った石の個数が偶数のとき、先手
        if (N - t) % 2 == 0:
            # 先手は直前の状態が大きい方
            # +X する
            dp[l][r] = max(dp[l + 1][r] + A[l], dp[l][r - 1] + A[r-1])
        else:
            # 先手は直前の状態が小さい方
            # -Y する
            dp[l][r] = min(dp[l + 1][r] - A[l], dp[l][r - 1] - A[r-1])

print(dp[0][N])

Measured memory_bytes: 120668
def main():
	N = int(input())
	A = list(map(int, input().split()))
	for i in range(N):
		A[i] -= i+1
	A.sort()

	mid = A[N//2]
	ans = 0
	for i in range(N):
		ans += abs(A[i] - mid)

	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 26832
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

struct elem
{
    int reward;
    int days;
};

bool operator < (const elem& a, const elem& b)
{
    if(a.reward == b.reward)
        return a.days > b.days;

    return a.reward > b.reward;
}

int main()
{
    int n, m;
    cin >> n >> m;

    vector<elem> v(n);

    for(int i = 0; i < n; ++i)
        cin >> v[i].days >> v[i].reward;

    sort(v.begin(), v.end());
    set<int> days;

    for(int i = 0; i < m; ++i)
        days.insert(i);

    ll out = 0;

    for(int i = 0; i < n; ++i) {
        int d = m - v[i].days;
        auto it = days.upper_bound(d);
        if(it == days.begin())
            continue;

        --it;
        days.erase(it);
        out += v[i].reward;
    }

    cout << out << endl;

    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e5;
const int size=1e5;
const int inf=1e9;
int main(){
	long X,K,D; cin>>X>>K>>D;
	X = abs(X);
	if(X > 0 && X / D >= K) cout<<X - K * D<<endl;
	else{
		if((X / D) % 2 == K % 2) cout<<X % D<<endl;
		else cout<<D - X % D<<endl;
	}
}

Measured memory_bytes: 3628
n = int(input())
l = sorted(map(int, input().split()))
cnt = 0
m = n-1
g = []
for i in range(n):
  for j in range(i):
    g.append(l[i]+l[j])
g = sorted(g,reverse = True)
for i in g:
  while l[m] >= i:
    m-=1
  cnt += n-m-1
print(n*(n-1)*(n-2)//6-cnt)

Measured memory_bytes: 109536
import math
pi = math.atan(1) * 4
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    if x == y == 0: continue
    if x == 0:
        r = pi/2 if y > 0 else -pi/2
    else:
        r = math.atan(y/x)
        if x < 0: r += pi
    X.append((x, y, r))

X = sorted(X, key = lambda x: x[2]) * 2
M = len(X)
ma = 0
for i in range(M):
    sx, sy = 0, 0
    for j in range(i+1, min(i+M//2+1, M)):
        sx += X[j][0]
        sy += X[j][1]
        d = sx ** 2 + sy ** 2
        ma = max(ma, d)

print(ma**0.5)

Measured memory_bytes: 3188
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n,q = m()

count = [0 for i in range(n)]

root = [[] for i in range(n)]

for i in range(n-1):
    a,b = m()
    a -= 1
    b -= 1
    root[a].append(b)

for i in range(q):
    a,b = m()
    a -= 1
    count[a] += b
de = cl.deque()

for i in range(len(root[0])):
    count[root[0][i]] += count[0]
    de.append(root[0][i])
while de:
    k = de.popleft()
    for i in range(len(root[k])):
        count[root[k][i]] += count[k]
        de.append(root[k][i])
print(jo(count))




Measured memory_bytes: 134880
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)
	fmt.Println(360 * x / lcm(x, 360) / x)
}

func lcm(a, b int) int {
	if a == 0 {
		return b
	}
	if a > b {
		return lcm(a-b, a)
	}
	return lcm(b-a, a)
}


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

int n;
std::vector<char> cs(100);
std::map<char, int> map;
int main() {
    char c;
    while(std::cin >> n, n != 0) {
        for(int i=0; i<n; ++i) {
            std::cin >> cs[i];
        }

        bool f = true;
        map.clear();
        for(int i=0; i<n; ++i) {
            c = cs[i];
            if(map.count(c) == 0) {
                map.insert({c, 0});
            }
            map[c] = map[c] + 1;

            int fst = 0, snd = 0;
            char fstc;
            for(auto it: map) {
                if(fst < it.second) {
                    fst = it.second;
                    fstc = it.first;
                }
            }
            for(auto it: map) {
                if(fstc != it.first && snd < it.second) {
                    snd = it.second;
                }
            }

            int rest = n - i -1;
            if(fst > snd + rest) {
                std::cout << fstc << " " << i+1 << std::endl;
                f = false;
                break;
            }
        }
        if(f) {
            std::cout << "TIE" << std::endl;
        }
    }
}


Measured memory_bytes: 3100
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

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

    int x;

    cin>>x;
    cout<<(!x)<<endl;

    return 0;
}


Measured memory_bytes: 3628
CHARACTER(200) S,T
READ*,S,T
DO I=1,LEN_TRIM(S)
  IF (S==T)THEN
    PRINT"(A)","Yes"
    STOP
  ENDIF
  S=TRIM(S(2:))//S(1:1)
END DO
PRINT"(A)","No"
END 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N, K; cin >> N >> K;
    bool B[10]; for (int i = 0; i < 10; i++) B[i] = true;
    for(int i = 0; i < K; i++){
        int x; cin >> x; B[x] = false;
    }
    for(int i = N; i < 100000; i++){
        int num = i;
        if(!B[num%10]) continue;
        bool flag = true;
        //cout << num%10 << endl;
        while(num/10!=0){
            num /= 10;
            //cout << num%10 << endl;
            if(!B[num%10]) {
                flag = false;
                break;
            }
        }
        if(flag){
            cout << i << endl;
            return 0;
        }
    }
}

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

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    int st = -1, ed = -1;
    for(int i = 0; i < SZ(s); i++){
        if(s[i] == 'A'){
            st = i;
            break;
        }
    }
    for(int i = SZ(s) - 1; i >= 0; i--){
        if(s[i] == 'Z'){
            ed = i;
            break;
        }
    }
    cout << SZ(s.substr(st, ed - st + 1));
    return 0;
}
/*
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 788
n = int(input())
ans = [0] * (n + 1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            d = x * x + y * y + z * z + x * y + y * z + z * x
            if n >= d:
                ans[d] += 1
            else:
                break

print('\n'.join(map(str, ans[1:])))


Measured memory_bytes: 9468
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
// #define MOD 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const ll B = 20, N = 300010, M = 2000000;
ll a, b, res = MAX;
int solve()
{
    cin >> a >> b;
    for (int i = 1; i <= 10000; i++)
    {
        if ((ll)(i * .08) == a && (ll)(i * 0.1) == b)
        {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    return solve();
}

Measured memory_bytes: 3752
# -*- coding: utf-8 -*-

N = int(input())

dict = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s in dict:
        dict[s] += 1
    else:
        dict[s] = 1


sum = 0
list1 = list(dict.values())
for i in list1:
    sum += int(i * (i-1) / 2)

print(sum)


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

using namespace std;

int main()
{
	int n;
	int a[20];
	int b[20];
	int c[20];

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n-1; i++)
		cin >> c[i];

	int preID = -10;
	int satisfaction = 0;

	for (int i = 0; i < n; i++)
	{
		satisfaction += b[a[i] - 1];

		// 連続コンボチェック
		if (a[i] - 1 == preID)
		{
			satisfaction += c[a[i - 1] - 1];
		}

		preID = a[i];
	}

	cout << satisfaction;

	return 0;
}


Measured memory_bytes: 256
s = gets.chomp
if s=='SUN'
  puts 7
elsif s =='MON'
  puts 6
elsif s == 'TUE'
  puts 5
elsif s == 'WED'
  puts 4
elsif s == 'THU'
  puts 3
elsif s == 'FRI'
  puts 2
elsif s == 'SAT'
  puts 1
end

Measured memory_bytes: 1788
function main(input){
    ab=input.split(' ')
    a=parseInt(ab[0],10)
    b=parseInt(ab[1],10)
    if (b%a==0){
        console.log(a+b)

    }else{
        console.log(b-a)

    }


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
fn parse() -> Vec<u8> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim_right().into()
}

fn calculate(ts: &[u8]) -> usize {
    let comp = ['0' as u8, '1' as u8];

    let count = ts
        .iter()
        .zip(comp.iter().cycle())
        .filter(|&(&a, &b)| a == b)
        .count();

    if count < ts.len() - count {
        count
    } else {
        ts.len() - count
    }
}

fn main() {
    let ts = parse();
    println!("{}", calculate(&ts));
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<set>
#include<algorithm>
#define ll long long
using namespace std;

int c[100000]{};
int f[100000]{};
int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	for (int d = 0; d < b; d++) {
		int e;
		scanf("%d",&e);
		f[d] = e;
	}
	for (int g = 0; g < b - 1; g++) {
		c[min(f[g], f[g + 1])-1]++;
		c[max(f[g], f[g + 1])-1]--;
	}
	int s = 0;
	ll p = 0;
	for (int h = 0; h < a - 1; h++) {
		s += c[h];
		ll x, y, z;
		scanf("%lld%lld%lld", &x, &y, &z);
		ll o= min(z + y*s, x*s);
		p += o;
	}
	cout << p << endl;
}

Measured memory_bytes: 3908
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main(){
	int N, ans = 0;
	int A[100001];
	scanf("%d", &N);
	A[0] = 0;
	int six = 1, nine = 1;
	FOR(i, 1, N + 1){
		if (i == six * 6){
			six *= 6;
		}
		if (i == nine * 9){
			nine *= 9;
		}
		A[i] = min(A[i - six], A[i - nine]);
		A[i] = min(A[i], A[i - 1]) + 1;
	}

	printf("%d\n", A[N]);
	return 0;
}

Measured memory_bytes: 640
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N; cin>>N;
    ll arr[N];
    ll sum = 0;
    
    for(ll i=0;i<N;++i)
    {
        cin>>arr[i];
        sum += arr[i];
    }
    
    ll dp[N][N][2];
    memset(dp,0,sizeof(dp));
    
    for(ll diff = 0;diff<N;++diff)
    {
        for(ll i=0;i<N;++i)
        {
            ll j = i + diff;
            
            if(j >= N)
                continue;
            
            if(diff == 0) //base case
            {
                dp[i][j][0] = arr[i];
                dp[i][j][1] = 0;
                continue;
            }
            
            dp[i][j][0] = max(dp[i + 1][j][1] + arr[i],dp[i][j - 1][1] + arr[j]);
            dp[i][j][1] = min(dp[i + 1][j][0],dp[i][j - 1][0]);
        }
    }

    
    cout<<(2LL*dp[0][N - 1][0] - sum)<<endl;
}

Measured memory_bytes: 144304
from collections import deque

N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]


def norm(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


q = deque()

P.sort(key=lambda x: -x[2])
x0, y0, h0 = P[0]
x1, y1, h1 = P[1]
for cx in range(0, 101):
    for cy in range(0, 101):
        norm0 = norm((x0, y0), (cx, cy))
        norm1 = norm((x1, y1), (cx, cy))
        if h0 - h1 == -norm0 + norm1:
            q.append((cx, cy))

t = 2
# print("22: print(len(q)) {}".format(len(q)))
while len(q) > 1:
    x0, y0, h0 = P[t - 1]
    x1, y1, h1 = P[t]
    for i in range(len(q)):
        cx, cy = q.popleft()
        norm0 = norm((x0, y0), (cx, cy))
        norm1 = norm((x1, y1), (cx, cy))
        if h0 - h1 == -norm0 + norm1:
            q.append((cx, cy))
    t += 1
    # print(t)

cx, cy = q.popleft()
x, y, h = P[0]
H = h + abs(x - cx) + abs(y - cy)

print(*[cx, cy, H])


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;i++)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const int mod = 1e9 + 7;
const ll INF = (ll)1e17;
const int N = 1e5 + 10;


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

  //freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);


  int n, k; cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = INF;
  for (int i = 0; i + k - 1 < n; i++) {
    int j = i + k - 1;
    if (a[j] <= 0) ans = min(ans, -(ll)a[i]);
    else if (a[i] >= 0) ans = min(ans, (ll)a[j]);
    else {
      ans = min(ans, 2ll * (-a[i]) + a[j]);
      ans = min(ans, 2ll * (a[j]) - a[i]);
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 640
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


#隣接リスト 1-order
def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    N = NI()
    A = []
    B = []
    for i in range(N):
        a, b = NMI()
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()

    if N%2:
        l = A[(N+1)//2-1]
        r = B[(N+1)//2-1]
        print(r-l+1)
        exit()

    ll = A[N//2-1]
    lr = A[N//2]
    rl = B[N//2-1]
    rr = B[N//2]
    l = (ll+lr)/2
    r = (rl+rr)/2
    gap = r-l
    print(int(gap*2+1))



if __name__ == "__main__":
    main()

Measured memory_bytes: 25752
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]

dp = [[0,0,0] for i in range(N)]
dp[0] = L[0]

for i in range(1,N):
  for j in range(3):
    dp[i][j] = max(dp[i - 1][(j + 1) % 3],dp[i - 1][(j + 2) % 3]) + L[i][j]
    
print(max(dp[-1]))

Measured memory_bytes: 47384
N = int(input())

ans = 0
n = int(N ** 0.5) + 1
for i in range(1,n):
    if N % i != 0 or i ** 2 == N:
        continue
    if i == (N % (N // i - 1)):
        ans += N // i - 1

print(ans)
    

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

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


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

    // 面倒くさいので R, G, B を 0, 1, 2 に置き換える
    string T;
    REP(i, N){
        if(S[i] == 'R') T += '0';
        if(S[i] == 'G') T += '1';
        if(S[i] == 'B') T += '2';
    }
    // R, G, B の累積個数を後ろから数える
    vector<vector<int>> num(3, vector<int>(N+1));
    for(int i = N-1; i >= 0; --i){
        REP(j, 3) num[j][i] = num[j][i+1];
        ++num[int(T[i]-'0')][i];
    }

    long long ans = 0;
    REP(i, N){
        FOR(j, i+1, N-1){
            if(T[i] == T[j]) continue;
            int tmp = 3-int(T[i]-'0')-int(T[j]-'0');
            ans += num[tmp][j+1];
            if(2*j-i < N and T[2*j-i] == char('0'+tmp)) --ans;
        }
    }
    cout << ans << endl;
    

    return 0;
}

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

const int MAX_N = 300000;

int main() {
    vector<bool> isprime(MAX_N + 1, false);
    for(int i = 6; i <= MAX_N; i += 7) isprime[i] = true;
    for(int i = 8; i <= MAX_N; i += 7) isprime[i] = true;

    vector<int> li;
    for(int i = 0; i <= MAX_N; i++) {
        if(isprime[i]) {
            li.push_back(i);
            for(int j = 2 * i; j <= MAX_N; j += i) isprime[j] = false;
        }
    }

    for(int N; cin >> N, N != 1; ) {
        vector<int> res;
        for(int i = 0; i < (int)li.size(); i++) {
            if(N % li[i] == 0) {
                res.push_back(li[i]);
            }
        }
        cout << N << ": ";
        for(int i = 0; i < (int)res.size(); i++) {
            cout << res[i] << " \n"[i == res.size() - 1];
        }
    }
}

Measured memory_bytes: 1384
x = int(input())
if x < 600:
    print(8)
elif x < 800:
    print(7)
elif x < 1000:
    print(6)
elif x < 1200:
    print(5)
elif x < 1400:
    print(4)
elif x < 1600:
    print(3)
elif x < 1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 9096
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    double T, A;
    cin >> T >> A;
    double odl = 1000000000.0;
    int nr;
    for (int i = 0; i < n; ++i)
    {
        double t;
        cin >> t;
        if (abs(A - (T - t * 0.006)) < odl)
        {
            odl = abs(A - (T - t * 0.006));
            nr = i;
        }
    }
    cout << nr + 1;
    return 0;
}


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

typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pi;
typedef unsigned long long int ull;

ll lsone(ll p){return(p & -p);}

int main(){
    std::ios::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n, d[100100];
    map<int, int> deg;
    ll ans, prev_num, cur_num, md;
    md = 998244353;
    vi dis;
    dis.clear();
    cin >> n;
    cin >> d[1];
    if (d[1] != 0){
        cout << 0;
        return 0;
    }
    for (int i=2;i<=n;i++){
        cin >> d[i];
        dis.push_back(d[i]);
    }
    sort(dis.begin(), dis.end());
    int i = 0;
    int prev = 0;
    prev_num = 1;
    ans = 1;
    while (i < dis.size()){
        int cur = dis[i];
        int ii = i;
        if (cur - prev != 1){
            cout << 0;
            return 0;
        }
        while (i < dis.size() && dis[i] == cur){
            i++;
        }
        cur_num = i - ii;
        for (int j=0;j<cur_num;j++){
            ans = (ans * prev_num) % md;
        }
        prev = cur;
        prev_num = cur_num;
    }
    cout << ans;
}

Measured memory_bytes: 1148