akhauriyash/Code-Regression huggingface dataset:
N,T=map(int,input().split())
li = [list(map(int,input().split())) for i in range(N)]
#print(li)
t_cost=[T - li[i][1] for i in range(N)]
#print(t_cost)
if(all(x < 0 for x in t_cost)):#時間内Tに帰宅不可能な場合
  print('TLE')
else:#時間内に帰宅できる場合に最小コストのものを出力
  t_cost_1=[]
  for i in range(N):
    if(t_cost[i]>=0):
      t_cost_1.append(i)
    else:continue
  #print(t_cost_1)
  print(min([li[t_cost_1[i]][0] for i in range(len(t_cost_1))]))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> line;
	int time,pro;
	cin >> time;
	for (int i = 0; i < time; ++i) {
		cin >> pro;
		line.push_back(pro);
	}
	int damy;
	vector<int>::iterator he;
	for (he = line.begin(); he != line.end()-1; ++he) {
		cout << *he << " ";
	}
	cout << *(line.end() - 1) << endl;
	int i2;
	for (int i = 1; i < time; ++i) {
		for (i2=0; *(line.begin()+i2) <*(line.begin()+i) ; ++i2) {
		}
		damy = *(line.begin() + i);
		line.erase(line.begin() + i);
		line.insert(line.begin()+i2, damy);
		for (he = line.begin(); he != line.end()-1; ++he) {
			cout << *he << " ";
		}
		cout << *(line.end() - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
-- B
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local N = read.n()
local tmp_sum = 0
for i=1,N do
    local a = read.n()
    tmp_sum = tmp_sum + 1.0 / a
end
local ans = 1 / tmp_sum
print(ans)

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

int main() {
	int n;
	while (cin >> n, n) {
		rep(i, n) {
			int p, q, r; cin >> p >> q >> r;
			if (p == 100 || q == 100 || r == 100)puts("A");
			else if (p + q >= 180)puts("A");
			else if (p + q + r >= 240)puts("A");
			else if (p + q + r >= 210)puts("B");
			else if (p + q + r >= 150 && (p >= 80 || q >= 80))puts("B");
			else puts("C");
		}
	}
	return 0;
}

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

int main() {
    int64_t N;
    std::cin >> N;

    int64_t cnt[N] = {0};
    int64_t A;
    for (int64_t i = 1; i < N; ++i) {
        std::cin >> A;
        --A;
        cnt[A] += 1;
    }

    for (int i = 0; i < N; ++i) {
        std::cout << cnt[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 5160
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string s;
    ll i, j, judge=1, ans=0;

    cin >> s;

    i = 0;
    j = s.size()-1;

    while(i < j){
        if(s[i] == s[j]){
            i++;
            j--;
        }
        else if(s[i]=='x'){
            ans++;
            i++;
        }
        else if(s[j]=='x'){
            ans++;
            j--;
        }
        else{
            judge = 0;
            break;
        }
    }

    if(judge==1) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll x;
int32_t main(){
CODE_START;
cin>>x;
cout<<(x^1)<<endl;
}



Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

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() {
    int n, k;
    cin >> n >> k;
    vector<int> mozi(n);
    rep(i, n) {
        int ai;
        cin >> ai;
        ai--;
        mozi[ai]++;
    }
    sort(mozi.begin(), mozi.end());

    int ans = 0;

    rep(i, n - k) {
        ans += mozi[i];
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3964
INF = 10 ** 10

N = int(input())
 
L = [tuple(map(int,input().split())) for _ in range(N)]
 
L.sort(key=lambda x:(-x[0], x[1]))
 
MAX_L = 0
MIN_R = INF
MAX = 0
a = 0
b = 0
 
for i in range(N):
    if MAX_L < L[i][0]:
        MAX_L = L[i][0]
        a = i
    if MIN_R > L[i][1]:
        MIN_R = L[i][1]
        b = i
    MAX = max(MAX, L[i][1] - L[i][0] + 1)
 
ans = MAX + max(0, MIN_R - MAX_L + 1)
 
p = INF
 
for i in range(N-1):
    p = min(p, L[i][1])
    ans = max(ans, max(0, p - L[a][0] + 1) + max(0, L[b][1] - L[i+1][0] + 1))
 
print(ans)

Measured memory_bytes: 33484
import sys
sys.setrecursionlimit(10000)
def bom(i,j):
    for s in range(-1,2):
        for d in range(-1,2):
            if i+s==-1 or i+s==h or j+d==-1 or j+d==w:
                continue
            if l[i+s][j+d]==1:
                l[i+s][j+d]=0
                bom_2(i+s,j+d)
                return 1
    return 0
def bom_2(i,j):
    for s in range(-1,2):
        for d in range(-1,2):
            if i+s==-1 or i+s==h or j+d==-1 or j+d==w:
                continue
            if l[i+s][j+d]==1:
                l[i+s][j+d]=0
                bom_2(i+s,j+d)                
while True:
    w,h=map(int,input().split())
    if w==0:break
    l=[list(map(int,input().split())) for _ in range(h)]
    ans=0
    for i in range(h):
        for j in range(w):
            if l[i][j]==1:
                ans+=bom(i,j)
    print(ans)


Measured memory_bytes: 8004
n = parse(Int,readline())

if n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 ==7 || n % 10 == 9
    println("hon")
elseif n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8
    println("pon")
else
    println("bon")
end


Measured memory_bytes: 152096
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    int N, R;
    cin >> N >> R;
    if (N >= 10) cout << R << endl;
    else cout << R + 100*(10-N) << endl;
}

Measured memory_bytes: 3576
from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
q = deque([0])
pre = [-1 for _ in range(n)]
while q:
    v = q.popleft()
    for t in g[v]:
        if pre[t] == -1:
            pre[t] = v
            q.append(t)
print('Yes')
for i in range(1, n):
    print(pre[i]+1)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector< vi > vii;
typedef vector<string> vs;
typedef pair<int,int> pii;

main(){
  int n,k;
  cin >> n >> k;
  int ans=1;
  rep(i,n){
    ans=min(ans*2,ans+k);
  }
  cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		try{
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String buf = br.readLine();
            StringTokenizer st=new StringTokenizer(buf," ");
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int c = Integer.parseInt(st.nextToken());
            int cnt=0;
            if(a <= b && 1<=a && 1<= b && 1<=c && a<=10000 && b<=10000 && c<=10000){
 
                for(int i=a; i <= b;i++){
                    if( (c/i) >=1 && (c%i)==0)   cnt++;
                }
                System.out.println(cnt);
            }
 
        } catch(IOException e) {
            System.err.println(e);
        }
		
	}

}

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

typedef long long ll;

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

    int a[4];
    for(int i=0;i<4;i++) cin >> a[i];
    sort(a,a+4);
    if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9) cout << "YES" << endl;
    else cout << "NO" << endl; 
    return 0;
}

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

void swap(int array[],int lo,int hi){
  int temp=array[lo];
  array[lo]=array[hi];
  array[hi]=temp;
}

void shuffle(int array[],int array2[],int size){
  for(int i=0;i<size;i++){
    int j=rand()%size;
    swap(array,i,j);
    swap(array2,i,j);
  }
}

int partition(int array[],int array2[],int low,int hig){
  int i=low;
  int j=hig+1;
  while(1){
    while(array[++i]<array[low]){
      if(i == hig) break;}
    while(array[low]<array[--j]){
      if(j==low) break;}
    if(i>=j) break;
    swap(array,i,j);
    swap(array2,i,j);
  }
  swap(array,low,j);
  swap(array2,low,j);
  return j;
}

void sort(int array[],int array2[],int lo,int hi){
  if(hi<=lo) return;
  int j=partition(array,array2,lo,hi);
  sort(array,array2,lo,j-1);
  sort(array,array2,j+1,hi);
}

void quicksort(int array[],int array2[],int size){
  shuffle(array,array2,size);
  sort(array,array2,0,size-1);
}

int main(){
  int n,d,a;
 scanf("%d%d%d",&n,&d,&a);
 int x[n+1];
 int h[n+1];
  for(int i=0;i<n;i++){
    scanf("%d%d",&x[i],&h[i]);}
  quicksort(x,h,n);

  int kaisu=0;
  long int sum=0;
  long int add[n+1];
  for(int i=0;i<n+1;i++){
    add[i]=0;}
  long int addreal=0;
  int right=0;
  
  for(int i=0;i<n;i++){
    //decrease hp
    addreal+=add[i];
    h[i]-=addreal;
    
    //if hp is equal to or less than 0, do continue
    if(h[i]<=0){
      if(i==right) right++;
      continue;}
    //if not, bomb until the fox is dead
    //kaisu=(h[i]-1)+1
    kaisu=h[i]/a;
    if(h[i]%a>0) kaisu++;
    sum+=kaisu;
    addreal+=a*kaisu;

    //calculate decrease hp
    while(x[i]+2*d >= x[right] && right<n+1){
      right++;}
    add[right]-=a*kaisu;
    /*
    for(int j=i+1;j<n;j++){
      if(x[i]+2*d >= x[j]){
	if(h[j]>0)
	  h[j]-=a*kaisu;}
      else{
	break;}
	}*/
    if(i==right){ right++;};

    //if i erase this, it doesnt work but with this, it works -> while(right<n+1) wo kakiwasureteta
    //printf("i=%d,h[i]=%d,addreal=%ld\n",i,h[i],addreal);
  }
  printf("%ld\n",sum);

  return 0;
}


Measured memory_bytes: 3328
s=input()
for i in [0]*int(input()):
    x=input().split()
    a=int(x[1])
    b=int(x[2])+1
    if x[0]=='print':
        print(s[a:b])
    elif x[0]=='replace':
        s=s[:a]+x[3]+s[b:]
    else:
        s=s[:a]+s[a:b][::-1]+s[b:]


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

int main(){
    int x,n; cin >> x >> n;
    vector<int> A(n);
    for(int i=0;i<n;++i) cin >> A[i];
    for(int a=0; ;++a){
        int l = x - a , r = x + a;
        bool lf = false , rf = false;
        for(int v : A){
            if(v == l) lf = true; 
            if(v == r) rf = true;
        }
        if(!lf){
            cout << l << endl;
            return 0;
        }
        else if(!rf){
            cout << r << endl;
            return 0;
        }
    }
    
    
    
}


Measured memory_bytes: 3596
function *main() {
  const N = +(yield);
  const A = (yield).split(" ").map(s => +s).sort((a, b) => b*b - a*a);
  let count = 0;
  const B = A.map(a => {
    if (a < 0) {
      count++;
      a = -a;
    }
   	return a;
  });
  
  if (count % 2 != 0) {
    B[B.length-1] *= -1;
  }
  
  const sum = B.reduce((a, b) => a + b);
  console.log(sum);
}

const iter = main();
iter.next();
require("readline").createInterface({input: process.stdin}).on("line", l => iter.next(l));

Measured memory_bytes: 56916
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if(a < b && a != 1)cout << "Bob" << endl;
    else if(b < a && b != 1)cout << "Alice" << endl;
    else if(a == b)cout << "Draw" << endl;
    else{
        if(a == 1)cout << "Alice" << endl;
        else cout << "Bob" << endl;
    }
}

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

ll n,k;

int main() {
  cin >> n >> k; 
  double ans=0;
  for(int i=1;i<=n;i++){
    int x=i; double p=1;
    while(x<k){
      p/=2; x*=2;
    }
    ans+=p/n;
  }
  printf("%.10f\n",ans);
}

Measured memory_bytes: 256
s = input()
k = int(input())
for i in range(len(s)):
    if s[i] != '1':
        print(s[i])
        exit()
    else:
        if i == len(s) - 1:
            print('1')
            exit()
        if i + 1 == k:
            print('1')
            exit()


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll H[100005];
ll dp[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, N) {
        cin >> H[i];
    }
    REP(i, N) {
        dp[i] = INF;
    }
    dp[0] = 0;
    REP(i, N) {
        REP(j, K) {
            ll nxt = i + j + 1;
            if (nxt >= N)
                break;
            dp[nxt] = std::min(dp[nxt], dp[i] + abs(H[nxt] - H[i]));
        }
    }
    cout << dp[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1792
R,C,K = gets.split.map &:to_i
RCV = K.times.map{ gets.split.map(&:to_i)}

V = Array.new(R){[]}
RCV.each do |r,c,v|
    V[r-1][c-1] = v
end

row = Array.new(C+1){[0] * 4}
row_up = Array.new(C+1){[0] * 4}
R.times do |r|
    C.times do |c|
        cell = row[c]
        v = V[r][c]
        if v then
            2.downto(0) do |i|
                cell[i+1] = [cell[i+1], cell[i] + v].max
            end
        end

        row_up[c][0] = cell.max
        right = row[c+1]
        right[0] = cell[0] if right[0] < cell[0]
        right[1] = cell[1]
        right[2] = cell[2]
        right[3] = cell[3]
    end

    row,row_up = row_up,row
end

p row[C-1][0]

Measured memory_bytes: 122048
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int x[100000], y[100000], tx[100000], ty[100000];
int sum1[100001], sum2[100001];
#define dist(x,y)(abs(i-x)+abs(j-y))
signed main() {
	int w, h, n; scanf("%lld%lld%lld", &w, &h, &n);
	rep(i, n) {
		scanf("%lld%lld", &x[i], &y[i]);
		tx[i] = x[i]; ty[i] = y[i];
	}
	sort(x, x + n); sort(y, y + n);
	rep(i, n) {
		sum1[i + 1] = sum1[i] + x[i];
		sum2[i + 1] = sum2[i] + y[i];
	}
	set<int>ax, ay;
	int mx = LLONG_MAX, my = LLONG_MAX;
	rep(i, n) {
		int a = ((x[i] * i - sum1[i]) + (sum1[n] - sum1[i] - x[i] * (n - i))) * 2;
		if (mx > a) {
			mx = a; ax.clear();
		}
		if (mx == a)ax.insert(x[i]);
		a = ((y[i] * i - sum2[i]) + (sum2[n] - sum2[i] - y[i] * (n - i))) * 2;
		if (my > a) {
			my = a; ay.clear();
		}
		if (my == a)ay.insert(y[i]);
	}
	int ansx, ansy, ans = LLONG_MAX;
	for (int i : ax)for (int j : ay)rep(k, n) {
		int d = mx + my - dist(tx[k], ty[k]);
		if (ans > d) {
			ans = d;
			ansx = i; ansy = j;
		}
	}
	printf("%lld\n%lld %lld\n", ans, ansx, ansy);
}

Measured memory_bytes: 7924
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)

Measured memory_bytes: 9060
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

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

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	int N;

	while(cin >> N, N) {
		vvi pieces(N+1, vi(2, 0));
		pieces[0][0] = 0;
		pieces[0][1] = 0;
		int min_x = 0, max_x = 0;
		int min_y = 0, max_y = 0;

		FOR(i, 1, N) {
			int n, d;
			cin >> n >> d;

			switch(d) {
			case 0:
				pieces[i][0] = pieces[n][0]-1;
				pieces[i][1] = pieces[n][1];
				break;
			case 1:
				pieces[i][0] = pieces[n][0];
				pieces[i][1] = pieces[n][1]-1;
				break;
			case 2:
				pieces[i][0] = pieces[n][0]+1;
				pieces[i][1] = pieces[n][1];
				break;
			case 3:
				pieces[i][0] = pieces[n][0];
				pieces[i][1] = pieces[n][1]+1;
				break;
			}

			if(min_x > pieces[i][0]) {
				min_x = pieces[i][0];
			}
			if(max_x < pieces[i][0]) {
				max_x = pieces[i][0];
			}
			if(min_y > pieces[i][1]) {
				min_y = pieces[i][1];
			}
			if(max_y < pieces[i][1]) {
				max_y = pieces[i][1];
			}
		}

		cout << max_x-min_x+1 << " " << max_y-min_y+1 << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

/**
 * Created by sd on 2016/11/22.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }


        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        for(int i=1; i<N; i++){
            int v = a[i], j=i-1;
            while(j>=0 && a[j]>v){
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = v;
            for(int ii=0; ii<N-1; ii++){
                System.out.print(a[ii]+" ");
            }
            System.out.println(a[N-1]);
        }
    }
}

Measured memory_bytes: 32488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    char boin[] =  {'a','e','i','o','u'};
    char c;
    cin >> c;
    for(char x : boin){
        if(x == c){
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
    return 0;
}

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

vector<int> graph[200001];
int counter[200001], n;

void dfs(int start){
	vector<bool> visited(n+1,false);

	stack<int> S;
	S.push(start);

	while(S.size()){
		int u=S.top();	S.pop();
		visited[u]=true;

		for(int v:graph[u]){
			if(visited[v])continue;
			counter[v]+=counter[u];
			S.push(v);
		}
	}

	return;
}

int main(){
	int q;	cin>>n>>q;
	for(int i=1;i<n;i++){
		int a,b;	cin>>a>>b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	for(int i=0;i<q;i++){
		int p,x;	cin>>p>>x;
		counter[p]+=x;
	}

	dfs(1);
	for(int i=1;i<=n;i++){
		if(i>1)cout<<" ";
		cout<<counter[i];
	}cout<<endl;

	return 0;
}


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

using namespace std;

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

#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define DOW(i,b,a) for (int i = (b); i >= (a); i--)
#define pb(a) push_back(a)
#define ALL(a) (a).begin(),(a).end()
#define fi first
#define se second

template<typename T>
void print_array(T* arr, int num) {
   FOR(i, 0, num) cout << arr[i] << ' ';
   cout << endl;
}

template<typename T> 
void print_vector(vector<T> vec) {
   FOR(i,0,vec.size()) cout << vec[i] << ' ';
   cout << endl;
}

int n, arr[100010];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("test.txt", "r", stdin);
    cin >> n;
    FOR(i,0,n) cin >> arr[i];
    ll sum = 0, ans = 0;
    FOR(i,0,n) {
        sum += arr[i];
        if (i % 2 == 0) {
            if (sum < 0) {
                ans += -(sum) + 1;
                sum = 1;
            } else if (sum == 0) {
                ans++;
                sum = 1;
            }
        } else {
            if (sum > 0) {
                ans += sum + 1;
                sum = -1;
            } else if (sum == 0) {
                ans++;
                sum = -1;
            }
        }
    }
    sum = 0;
    ll ans2 = 0;
    FOR(i,0,n) {
        sum += arr[i];
        if (i % 2) {
            if (sum < 0) {
                ans2 += -(sum) + 1;
                sum = 1;
            } else if (sum == 0) {
                ans2++;
                sum = 1;
            }
        } else {
            if (sum > 0) {
                ans2 += sum + 1;
                sum = -1;
            } else if (sum == 0) {
                ans2++;
                sum = -1;
            }
        }
    }
    cout << min(ans, ans2);
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#define INF (1e9)

string S;
ll MOD = 1e9 + 7;

int main() {
    cin >> S;
    int l = S.size();

    vvi DP(l + 1, vi(13, 0));
    DP[0][0] = 1;
    for (int i = 0; i < l; i++) {
        for (int n = 0; n < 10; n++) {
            if (S[i] != '?' && S[i] != n + '0') continue;
            for (int j = 0; j < 13; j++)
                DP[i + 1][(n + j * 10) % 13] += DP[i][j];
        }
        for (int j = 0; j < 13; j++)
            DP[i + 1][j] %= MOD;
    }
    cout << DP[l][5] << endl;
    return 0;
}


Measured memory_bytes: 13696
x,y=map(int,input().split())
if y==0:
  print(x)
else:
  l=set(list(map(int,input().split())))
  if x in l:
    i=1
    while True:
      if not x-i in l:
        print(x-i)
        quit()
      elif not x+i in l:
        print(x+i)
        quit()
      i+=1
  else:
    print(x)
    

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

int main(){
	int K,T;
	vector<int> a;
	cin >> K >> T;
	int input;
	while(cin >> input){
		a.push_back(input);
	}
	sort(a.begin(),a.end(),std::greater<int>());
	if(T == 1){
		cout << a[0] - 1;
	}else{
		int sum = 0;
		for(int i = 1;i < a.size();i++){
			sum += a[i];
		}
		if(sum > a[0]){
			cout << '0';
		}else{
			cout << a[0] - sum - 1;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define flush fflush(stdout)
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 3005
using namespace std;
typedef long long ll;
typedef pair<int ,int > pii;
string s1, s2;
int LCS[N][N];
int main(){
    #ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL); 
    cin >> s1 >> s2;
    for(int i = 0; i < s1.size(); i++){
        for(int j = 0; j < s2.size(); j++){
            if(s1[i] == s2[j]){
                LCS[i][j] = 1 + (j == 0 || i == 0 ? 0 : LCS[i - 1][j - 1]);
            }
            else {
                LCS[i][j] = max((i == 0 ? 0 : LCS[i - 1][j]), (j == 0 ? 0 : LCS[i][j - 1]));
            }
        }
    }
    int i = s1.size() - 1, j = s2.size() - 1;
    string ans = "";
    while(i != -1 && j != -1){
        if(s1[i] == s2[j]){
            ans += s1[i];
            i--;
            j--;
        }
        else if((i == 0 ? 0 : LCS[i - 1][j]) >(j == 0 ? 0 : LCS[i][j - 1]))i--;
        else j--;
    }
    reverse(all(ans));
    cout << ans;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
   ll n,a,b;cin>>n>>a>>b;
   vector<ll> h(n);
   rep(i,n) cin>>h[i];
   ll left=0,right=1e+9;
   while(right-left>1){
       ll mid=(right+left)/2;
       ll tot=0;
       rep(i,n){
           tot+=max((ll)0,h[i]-mid*b+a-b-1)/(a-b);
       }
       if(tot>mid)left=mid;
       else right=mid;
   }
   cout<<right<<endl;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
inline int sho(P p){
	int x=p.fs,y=p.sc;
	if(x>0&&y>=0) return 0;
	if(x<=0&&y>0) return 1;
	if(x<0&&y<=0) return 2;
	if(x>=0&&y<0) return 3;
	assert(false);
}
bool comp(const PP& pp,const PP& qq){
	P p=pp.fs,q=qq.fs;
	int s=sho(p),t=sho(q);
	if(s!=t) return s<t;
	ll a=p.fs,b=p.sc,c=q.fs,d=q.sc;
	return b*c<a*d;
}
int gcd(int x,int y){
	if(y==0) return abs(x);
	return gcd(y,x%y);
}
ll cro(P a,P b){
	return a.fs*b.sc-a.sc*b.fs;
}
inline P inv(P p){
	return P(-p.fs,-p.sc);
}
map<P,ll> mp;
vector<PP> vc;
ll inf=1e10;
ll solve(){
	ll ans=inf;
	int N=vc.size();
	{
		int j=1;
		ll mn=inf;
		while(j<N&&cro(vc[0].fs,vc[j].fs)>0) j++;
		int J=j;
		if(j<N&&cro(vc[0].fs,vc[j].fs)>=0) j++;
		j--;
//		show(J);
//		show(j);
		for(int i=1;i<J;i++){
			while(j<N-1&&cro(vc[i].fs,vc[j+1].fs)>0){
				chmin(mn,vc[j+1].sc);
				j++;
			}
			chmin(ans,vc[0].sc+vc[i].sc+mn);
		}
	}
	if(mp.count(inv(vc[0].fs))){
		for(int j=1;;j++){
			if(vc[j].fs==inv(vc[0].fs)) break;
			if(mp.count(inv(vc[j].fs))){
				chmin(ans,vc[0].sc+mp[inv(vc[0].fs)]+vc[j].sc+mp[inv(vc[j].fs)]);
			}
		}
	}
	return ans;
}
int main(){
	int N;
	cin>>N;
	ll mnc=inf;
	rep(i,N){
		ll a,b,c;
		cin>>a>>b>>c;
		if(a==0&&b==0) continue;
		int g=gcd(a,b);
		a/=g,b/=g;
		if(!mp.count(P(a,b))||mp[P(a,b)]>c){
			mp[P(a,b)]=c;
		}
		chmin(mnc,c);
	}
	for(auto pp:mp) vc.pb(PP(pp.fs,pp.sc));
	sort(all(vc),comp);
	N=vc.size();
	if(N<=2){
		puts("-1");
		return 0;
	}
	int id=-1;
	rep(i,N) if(vc[i].sc==mnc) id=i;
	rotate(vc.begin(),vc.begin()+id,vc.end());
//	rep(i,N) cout<<"("<<vc[i].fs.fs<<","<<vc[i].fs.sc<<")  "<<vc[i].sc<<endl;
	ll ans=inf;
	chmin(ans,solve());
	id=-1;
	ll mn=inf;
	rep1(i,N-1){
		if(mn>vc[i].sc) id=i,mn=vc[i].sc;
	}
	rotate(vc.begin(),vc.begin()+id,vc.end());
	chmin(ans,solve());
	if(ans==inf) ans=-1;
	cout<<ans<<endl;
}

Measured memory_bytes: 20896
import math
data = map(float, raw_input().split(" "))

rad = data[2]*math.pi/180

h = data[1]*math.sin(rad)
s = data[0]*h/2
l = data[0]+data[1]+math.sqrt((data[0]-data[1]*math.cos(rad))**2+h**2)

print "%f\n%f\n%f" % (s,l,h)

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec

void Main()
{
	string S="";
	cin>>S;
	int n=S.size();
	if(S[n-1]=='s') S+="es";
	else S+="s";

	cout<<S;
}


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


Measured memory_bytes: 3652
s = list(input())

ans = [0] * (len(s)+1)

for i in range(len(s)):
    if s[i] == '<':
        ans[i+1] += ans[i]+1

for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
        ans[i] = max(ans[i], ans[i+1]+1)

print(sum(ans))


Measured memory_bytes: 27056
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pll >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 

const ll mod = 1e9+7;
const ll inf=1e18+1e17;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}

const ll N =2e5 + 6;


void solve(){
	string s;
	cin>>s;
	if ( s=="ARC")
		cout<<"ABC\n";
	else
		cout<<"ARC\n";

}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif	*/
    ll t=1;
	//cin>>t;
    for (ll i=1;i<=t;i++){
    //	cout<<"Case #"<<i<<": ";
    	solve();
 	}
}

Measured memory_bytes: 3644
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdlib.h>
using namespace std;

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         input(a)       for(auto &it : a) cin>>it
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         vcl            vector<ll>
#define         vpl            vector<pair<ll,ll>>
#define         pb             push_back
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         ikarus_101     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){ikarus_101

    ll tc,n,m,a,b,c,d,x,y,i,j,k,ans,sum,tot,cnt,mx,mn,idx,tmp;

    cin>>n;
    ll aa[n+5];
    memset(aa , 0 , sizeof(aa));
    rep(i,n-1)
    {
        cin>>x;
        aa[x]++;
    }
    rep1(i,n)
        cout<<aa[i]<<nn;
    return 0;
}


Measured memory_bytes: 5220
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def gcd(a, b):
    if b>a:
        a, b = b, a
    while b>0:
        a, b = b, a%b
    return a

def solve(T: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):
    for i in range(T):
        a, b, c, d = A[i], B[i], C[i], D[i]
        if a<b or b>d:
            print('No')
            continue
        x = (c-a+1)%b
        g = gcd(b, d)
        print('No' if -(-x//g*g) - x + c+1 < b else 'Yes')


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = int(next(tokens))  # type: int
    A = [int()] * (T)  # type: "List[int]" 
    B = [int()] * (T)  # type: "List[int]" 
    C = [int()] * (T)  # type: "List[int]" 
    D = [int()] * (T)  # type: "List[int]" 
    for i in range(T):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(T, A, B, C, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

typedef long long ll;

using namespace std;

int main()
{ ll D, G; cin >> D >> G;
 
vector<ll> P(D), C(D); 
 for(ll i = 0; i < D; i++)
 {cin >> P[i] >> C[i];}
 
 vector<ll> ord(D);
 
 for(ll i = 0; i < D; i++)
 { ord[i] = i + 1;} //並び替え配列構成
 
 ll min_cnt = 1e5;
 
 do
 {
   ll cnt = 0; ll total = G;
  
  for(ll i = 0; i < D; i++){
    
    if(total <= ord[i]*100*P[ord[i] - 1])
        { //おまけ無し終了
      while(total > 0 ){
        total -= 100*ord[i];
        cnt++;}
        break;}
    else{
      total -= ord[i]*100*P[ord[i] - 1];
          cnt += P[ord[i]- 1];
         if(total > C[ord[i] - 1]){ total -= C[ord[i] - 1];}//おまけ有り続行
         else{break;}//おまけ有り終了
         }
                               }
   
   min_cnt = min(min_cnt,cnt);
 }while(next_permutation(ord.begin(),ord.end())) ;
 
 cout << min_cnt << endl;
 
 return 0;
}
      
      
                            
   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
string s;
int main(){
	cin>>n>>m;
	cin>>s;
	for(int i=0;i<n;i++){
		if(i==m-1){
			cout<<(char)(s[i]-('A'-'a'));
		}else{
			cout<<s[i];
		}
	}
	return 0;
} 

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

int main()
{
    int H, W;

    while (cin >> H >> W && H && W) {
        cout << string(W, '#') << endl;
        for (int i = 2; i < H; i++)
            cout << '#' << string(W - 2, '.') << '#' << endl;
        cout << string(W, '#') << endl;
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 2996
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;

int main()
{

    int n,m,q=0;
    scanf("%d %d",&n,&m);
    int a[m];

    for(int i=0;i<m;i++)
    {
        scanf("%d",&a[i]);
        q=q+a[i];
    }

    if(q>n)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d\n",n-q);
    }
    


    return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];

	vector<int> minv = A;
	for(int i = N-1; i > 0; i--) minv[i-1] = max(minv[i-1], minv[i]-1);
	for(int i = 0; i < N; i++) if(minv[i] > A[i]) {
		cout << "-1\n";
		return 0;
	}
	if(A[0] != 0) {
		cout << "-1\n";
		return 0;
	}

	vector<int> cnt_val(N, 0);
	vector<int> occ(N+1, 0);
	for(int i = N-1; i >= 0; i--) {
		if(A[i] == 0) continue;
		if(i == N-1) {
			cnt_val[N-1] = (A[N-1] == 0) ? 0 : 1;
			if(i-A[i] >= 0) occ[i-A[i]]++;
			continue;
		}
		cnt_val[i] = cnt_val[i+1];
		if(A[i] > A[i+1]-1) cnt_val[i]++;
		// subtract val. 0?
		if(occ[i]) cnt_val[i]--;
		if(i-A[i] >= 0) occ[i-A[i]]++;
	}

	cat ans = 0;
	for(int i = N-1; i >= 0; i--) ans += cnt_val[i];
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
const int mod=1e9+7;
ll dp[110][100010];
ll solve(ll b[],int n,int k){
	 if(k == 0) 
	 return 1;
    if(n == 0|| k < 0)
     return 0;
    if(dp[n][k] != -1) 
    return dp[n][k];
    ll res = solve (b,n - 1, k) % mod + solve (b,n, k - 1) % mod - solve(b,n - 1, k - b[n] - 1) + mod;
    return dp[n][k] = res % mod;
}
int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
       int n,k;
         cin>>n>>k;
        ll b[n+1]={0};
        for(int i=1; i<=n; i++)
         { cin>>b[i];  
			  }
			 
       memset(dp,-1,sizeof(dp));
        // cout<<solve(b,n,k); 
      for(int i=0; i<=k; i++)
        dp[0][i]=0;
       for(int i=0; i<=n; i++)
       dp[i][0]=1;
       for(int i=1; i<=n; i++)
        {
			for(int j=1; j<=k; j++){
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		    //  cout<<dp[i][j]<<" ";
				dp[i][j]=((dp[i][j]-(j-b[i]<=0?0:dp[i-1][max(j-b[i]-1,(ll)0)])%mod)+mod)%mod;
				//cout<<dp[i][j]<<" "<<(j-b[i]-1<=0?0:dp[i-1][max(j-b[i]-1,(ll)0)])<<" "<<j-b[i];

			}
			//cout<<endl;
		}
		cout<<dp[n][k]<<endl;  
         
         //   cout<<n<<" "<<k<<endl;
    }


Measured memory_bytes: 86144
#include <stdio.h>
#include <string.h>

int main() {
  int i, j, number_n, number_m, count, max_count = 0;
  scanf("%d", &number_n);
  char str_blue[number_n][11];
  for(i = 0; i < number_n; i++) {
    scanf("%s", str_blue[i]);
  }
  scanf("%d", &number_m);
  char str_red[number_m][11];
  for(i = 0; i < number_m; i++) {
    scanf("%s", str_red[i]);
  }
  for(i = 0; i < number_n; i++) {
    count = 0;
    for(j = 0; j < number_n; j++) {
      if(strcmp(str_blue[i], str_blue[j]) == 0) count++;
    }
    for(j = 0; j < number_m; j++) {
      if(strcmp(str_blue[i], str_red[j]) == 0) count--;
    }
    if(max_count < count) {
      max_count = count;
    }
  }
  printf("%d\n", max_count);
  return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

# 上限は1000
N = ri()
S = list(rs())
answer = set()
se1 = set()
for i in range(len(S)-2):
    x = S[i]
    if x in se1:
        continue
    se1.add(x)
    se2 = set()
    for j in range(i+1, len(S)-1):
        y = S[j]
        if y in se2:
            continue
        se2.add(y)
        se = set(S[j+1:])
        for z in se:
            answer.add((x, y, z))

print(len(answer))


Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int sab(int a[],int n){
    int ans=0;
    for (int i=0; i<n; i++) {
        int minj=i;
        for (int j=i+1; j<n; j++) {
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        if (a[i]!=a[minj]) {
            swap(a[i],a[minj]);
            ans++;
        }
    }
    return ans;
}
int main() {
    int A[100];
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    
    int ans= sab(A,N);
    
    for (int i=0;i<N-1;i++) {
        cout<<A[i]<<" ";
    }
    cout<<A[N-1]<<endl<<ans<<endl;
}

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

struct Group {
    vector<int> cities;
};

int main() {
    large n, k;
    cin >> n >> k;

    auto a = vector<int>(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    auto group = vector<int>();
    auto visited = vector<bool>(n);
    group.reserve(n);
    for (auto i = 0; !visited[i];) {
        group.emplace_back(i);
        visited[i] = true;
        i = a[i];
    }

    auto loop_start = a[group.back()];
    auto before_loops = 0;
    for (int i = 0; group[i] != loop_start; i++)
        ++before_loops;

    if (k < before_loops) {
        cout << (group[k] + 1) << "\n";
        return 0;
    }

    if (before_loops) {
        k -= before_loops;
        group.erase(group.begin(), group.begin() + before_loops);
    }

    auto index = k % group.size();

    cout << (group[index] + 1) << "\n";
    return 0;
}


Measured memory_bytes: 4688
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();

		List<Guide> guids = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			Guide g = new Guide();
			g.place = sc.next();
			g.score = sc.nextInt();
			g.index = i + 1;
			guids.add(g);
		}

		sc.close();

		guids.sort((g1 , g2) -> {
			int order = g1.place.compareTo(g2.place);

			if (order != 0) {
				 return order;
			} else {
				return Integer.compare(g2.score, g1.score);
			}
		});

		for (Guide guide : guids) {
//			System.out.println(guide.place);
//			System.out.println(guide.score);
			System.out.println(guide.index);
//			System.out.println();
		}
		// System.out.println(ans);
	}

	private static class Guide {
		String place;
		int score;
		int index;
	}

}


Measured memory_bytes: 28628
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
}

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

using namespace std;

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

void Main(){
    auto& fin = cin;
    int64_t n;
string s;
fin >> n >> s;
auto max_length_of_true_seq = [](const vector<bool>& v)->int64_t{
    int64_t ret = 0;
    int64_t tmp = 0;
    for(int64_t i = 0; i < v.size(); ++i){
        if(v[i]){
            tmp++;
        }else{
            ret=max(tmp, ret);
            tmp=0;
        }
    }
    ret=max(tmp, ret);
    return ret;
};
int64_t ans = 0;
for(int64_t i = 0; i < n; ++i){
    vector<bool> tmp(n-i);
    for(int64_t j = 0; j < n-i; ++j){
        tmp[j] = s[i+j]==s[j];
    }
    ans=max(ans, min(i, max_length_of_true_seq(tmp)));
}
cout << ans << endl;
}


Measured memory_bytes: 384