akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PLL> VP;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "

int main()
{
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    ll count=0;
    int mina=R;
    mina=min(mina,G);
    mina=min(mina,B);
    for(int i=0; i<=N/mina; i++){
        for(int j=0; j<=N/mina; j++){
            if((N-(i*R)-(j*G))%B==0 && (N-(i*R)-(j*G))>=0){
                count++;
            }
        }
    }
    cout << count << endl;
}

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

using ll = long long;

struct S {
    int a, b;
};

ll f(ll x, vector<S> v) {
    v.erase(remove_if(v.begin(), v.end(),
        [](S s) { return s.a >= s.b; }
    ), v.end());

    if (v.empty())
        return x;

    int a = v[0].a, b = v[0].b;
    v.erase(v.begin());

    if (v.empty())
        return (x / a) * b + x % a;

    ll res = 0;
    for (ll i = 0; i * a <= x; i++)
        res = max(res, i * b + f(x - i * a, v));

    return res;
}

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

    vector<S> v(3);
    for (int i = 0; i < 3; i++)
        cin >> v[i].a;
    for (int i = 0; i < 3; i++)
        cin >> v[i].b;

    vector<S> vr(3);
    for (int i = 0; i < 3; i++)
        vr[i] = {v[i].b, v[i].a};

    cout << f(f(n, v), vr) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<cstdlib>
using namespace std;

bool cmp(const string& a,const string b)
{
  if(a.size() != b.size())
    return a.size() < b.size();
  if(a != b)
    return (atoi)(a.c_str()) < (atoi)(b.c_str());
  return false;
}

int main()
{
  int n;
  vector<string> vec;
  cin >> n; 
  vec.resize(n);

  int men = 100000000;  
  int Size[6];
  for(int i=0;i<6;i++)
    Size[i] = 0;
  for(int i=0;i<n;i++)
    cin >> vec[i],Size[vec[i].size()]++,men = min(men,(int)vec[i].size());

  sort(vec.begin(),vec.end(),cmp);
    
  if(Size[men] >= 4)
      cout << vec[0] << vec[3] << endl;
  else if(Size[men] == 3)
    cout << vec[1] << vec[0] << endl;
  else if(Size[men] == 2)
    {
      string a,b;
      a = vec[0]+vec[2];
      b = vec[2]+vec[0];
      //cout << min((atoi)(b.c_str()),(atoi)(a.c_str())) << endl;
      cout << a << endl;
    }
  else if(Size[men] == 1)
    {
      vector<string> ans;
      for(int i=0;i<4;i++)
	for(int j=0;j<4;j++)
	  if(i != j)
	    ans.push_back(vec[i]+vec[j]);
      sort(ans.begin(),ans.end(),cmp);
      cout << ans[2] << endl;
    }

  return 0;
}

Measured memory_bytes: 1656
#include<iostream>
#include<algorithm>
#include<vector>
 
int main(){
  int n;
  std::cin >> n;
  
  std::vector<int> a(n),b(n),c(n);
  for(int i = 0; i < n; i++) std::cin >> a[i];
  for(int i = 0; i < n; i++) std::cin >> b[i];
  for(int i = 0; i < n; i++) std::cin >> c[i];
  
  std::sort(a.begin(),a.end());
  std::sort(b.begin(),b.end());
  std::sort(c.begin(),c.end());
  
  
  long long ans = 0;
  
  for(int i = 0; i < n; i++){
  	long long number_of_upper_parts = std::lower_bound(a.begin(),a.end(),b[i]) - a.begin();
    long long number_of_lower_parts = c.end() - std::upper_bound(c.begin(),c.end(),b[i]);
    ans += number_of_upper_parts * number_of_lower_parts;
  }
  std::cout << ans << std::endl;
}

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

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

    long long l, r;
    cin >> l >> r;
    if(l <= 2019 and 2019 <= r){
        cout << 0 << endl;
        return 0;
    }
    if((r / 2019 - l / 2019) >= 1){
        cout << 0 << endl;
        return 0;
    };

    long long ans = 1e18;
    for(long long i = l; i < r; i++){
        for(long long j = i + 1; j <= r; j++){
            ans = min((long long)ans, (long long)(i * j) % 2019);
        }
    }
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
const int maxn=505;
int a[maxn];
int pre[maxn];
int main(){
  int N,M,n,m;
  scanf("%d%d%d%d",&N,&M,&n,&m);
  if(N%n==0&&M%m==0){
    printf("No\n");
  }else{
    printf("Yes\n");
    if(N%n!=0){
      pre[0]=0;
      for(int i=1;i<n;++i)pre[i]=10000;
      for(int i=n;i<=N;++i)pre[i]=pre[i-n]-1;
      for(int i=1;i<=N;++i){
	for(int j=1;j<=M;++j)printf("%d%c",pre[i]-pre[i-1],(j==M)?'\n':' ');
      }
    }else{
      pre[0]=0;for(int i=1;i<m;++i)pre[i]=10000;
      for(int i=m;i<=M;++i)pre[i]=pre[i-m]-1;
      for(int i=1;i<=N;++i){
	for(int j=1;j<=M;++j)printf("%d%c",pre[j]-pre[j-1],(j==M)?'\n':' ');
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1792
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let S: String = read();
    let Q: usize = read();
    let mut is_reverse = false;
    let mut before_string = "".to_string();
    let mut after_string = "".to_string();
    for _ in 0..Q {
        let T: usize = read();
        if T == 1 {
            is_reverse = !is_reverse;
        } else {
            let F: i32 = read();
            // 1だったら2に、2だったら1に
            let F = if is_reverse { -(F - 2) + 1 } else { F };
            let C: String = read();
            let C = C.chars().next().unwrap();
            if F == 1 {
                before_string.push(C);
            } else {
                after_string.push(C);
            }
        }
    }
    before_string = before_string.chars().rev().collect();
    let msg = before_string + &S + &after_string;
    let msg = if is_reverse {
        msg.chars().rev().collect()
    } else {
        msg
    };
    println!("{}", msg);
}


Measured memory_bytes: 4732
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		if(k == 1){
			ans = 0;
		}else{
			ans = n - k;
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B;
  cin>>N>>A>>B;
  
  int plan1=0,plan2=0;
  plan1=A*N;
  plan2=B;
  
  if(plan1<plan2)cout<<plan1<<endl;
  else cout<<plan2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
string s,s1;
ll ar[250007],cr[200098],a,b, test, sum,t,x=0,p,q,y,i,j,k=0,l,cnteven=0,w=0,cnt,br[200008];
int main()
{
    ll test;
ll m=9999999999;
cin>>a;
cnt=0;
for(i=1;i<=a;i++)
{cin>>ar[i];}
sort(ar+1,ar+a+1);


for(i=2;i<=a;i++)
   {m=min(m,__gcd(ar[1],ar[i]));
   }
cout<<m;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef int64_t Int;

int main() {
  Int N;
  cin >> N;
  vector<Int> v(N);
  for(int i = 0; i<N; i++) {
    cin >> v[i];
  }
  
  sort(v.begin(),v.end());
  
  double ans = (double)v[0];
  
  for(int i = 1; i<N; i++) {
    ans = (ans + (double)v[i]) / 2.0;
  }
  
  cout << setprecision(10);
  cout << ans << endl;
}

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

int main(){
  vector<char> vc(15);
  for(int i=0;i<12;i++){
    if(i<4)cin >> vc[i];
    else cin >> vc[i+1];
  }
  vc[4]=' ';
  for(int i=0;i<13;i++){
    cout << vc[i];
  }
  cout << endl;
  
  return 0;
}





Measured memory_bytes: 256
k = int(input())

n = [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]

print(n[k-1])

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n,k;
double f[N],pre[N];
int main(){
	cin>>n>>k;
	double x;
	for(int i=1;i<=n;i++){
		read(x);
		f[i]=(1+x)*x/2/x;
		pre[i]=pre[i-1]+f[i];
	}
	double ans=0;
	for(int r=k;r<=n;r++){
		int l=r-k+1;
		ans=max(ans,pre[r]-pre[l-1]);
	}
	printf("%lf\n",ans);
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 998244353;

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

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

  int l = 1,r = n;

  vector<pii> ret;

  if(n%2 == 1){
    while(l < r){
      ret.push_back(make_pair(l,r));
      l++;r--;
    }
  }else{
    while(l+n-r < r-l){
      ret.push_back(make_pair(l,r));
      l++;r--;
    }
    l++;
    while(l < r){
      ret.push_back(make_pair(l,r));
      l++;r--;
    }
  }

  rep(i,m){
    cout << ret[i].first << " " << ret[i].second << endl;
  }
}

Measured memory_bytes: 4256
#include <stdio.h>
int main (void)
{
           int a[5],i,j,b;
           for(i=0;i<5;i++)
           {
                 scanf("%d",&a[i]);
           }
           for(j=0;j<100;j++)
           {
                 for(i=0;i<4;i++)
                 {
                            if(a[i]<a[i+1])
                            {
                            b=a[i];
                            a[i]=a[i+1];
                            a[i+1]=b;
                            }
                 }
           }
           printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
           return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		//入力表示

		long N = sc.nextLong();
		long K = sc.nextLong();

		long a = N % K;
		System.out.println(Math.min(a, K - a));

	}
}

Measured memory_bytes: 27028
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;

vector<int> v[10000];

int main(){
	int aN,bN,R;
	while(cin >> aN >> bN >> R , aN){	
		for(int i = 0 ; i < 10000 ; i++) v[i].clear();
		for(int i = 0 ; i < aN ; i++){
			int x,y;
			cin >> x >> y;
			v[y].push_back(x);
		}
		for(int i = 0 ; i < 10000 ; i++)
			sort(v[i].begin(),v[i].end());
		int D = 4 * R , ans = 0	;
		for(int i = 0 ; i < bN ; i++){
			int x,y;
			cin >> x >> y;
			for(int p = -D ; p <= D ; p++){
				if(y+p < 0 || y+p >= 10000) continue;
				int m = sqrt( D*D - p*p );
				ans += upper_bound(v[y+p].begin(),v[y+p].end(),x+m) -
					   lower_bound(v[y+p].begin(),v[y+p].end(),x-m);
			}
		}
		cout << ans << endl;
	}
}

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

int n;
vector<string> v;
template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	readVector(n, v);
	int a = 0, b = 0;
	for(int i=0; i<n; ++i){
		if(v[i] == "A") ++a;
		else ++b;
	}
	if(a != b){
		cout << "NO\n";
		return 0;
	}
	int t = 0;
	for(int i=0; i<n; ++i)
		if(v[i] == "A"){
			if(t < i){
				cout << "NO\n";
				return 0;
			}
			while(v[t] == "A")
				++t;
			if(t >= n){
				cout << "NO\n";
				return 0;
			}
			++t;
		}
	cout << "YES\n";
}


Measured memory_bytes: 3160
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n>100){
            System.exit(-1);
        }
        int[] list = new int[n];
        for(int i=0; i<n; i++){
            list[i] = sc.nextInt();
        }
        for(int i=n-1; i>0; i--){
            System.out.print(list[i] + " ");
        }
        System.out.println(list[0]);
    }
}

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

int main()
{
	int a , b , c , d;
	cin >> a >> b >> c ;
	d = c-a;
	if (d <= b)
	{
		if ( d < 0) cout << 0 <<endl ;
		else cout <<d << endl ;
	}
	else cout <<"NA"<<endl;
	return 0 ;
}



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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N + 2, 0);
  vector<int> diff(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  long long sum = 0;
  for (int i = 1; i <= N + 1; i++) {
    diff[i - 1] = abs(A[i] - A[i - 1]);
    sum += diff[i - 1];
  }

  for (int i = 0; i < N; i++) {
    cout << sum - (diff[i] + diff[i + 1]) + abs(A[i + 2] - A[i]) << endl;
  }
  return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  int total=0;
  if (N>=2){
    total += N*(N-1)/2;
  }
  if (M>=2){
    total+= M*(M-1)/2;
  }
  cout << total;
}

Measured memory_bytes: 256
/*
 * 2590.cc: Unknown Switches
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 36;
const int MAX_M = 1000;

/* typedef */

typedef long long ll;

/* global variables */

ll bs[MAX_M];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n, m, q;
    cin >> n >> m >> q;
    if (n == 0) break;

    ll nbits = (1LL << n) - 1;
    for (int i = 0; i < m; i++) bs[i] = nbits;

    ll sb(0);

    while (q--) {
      string sw, bl;
      cin >> sw >> bl;

      for (int i = 0; i < n; i++)
	if (sw[i] == '1') sb ^= (1LL << i);

      for (int i = 0; i < m; i++) {
	if (bl[i] == '0') bs[i] &= ~sb;
	else bs[i] &= sb;
      }
    }

    for (int i = 0; i < m; i++) {
      int k = -1, bn = 0;
      for (int j = 0; j < n; j++)
	if (bs[i] & (1LL << j)) k = j, bn++;

      if (bn > 1) putchar('?');
      else if (k < 10) putchar('0' + k);
      else putchar('A' + k - 10);
    }
    putchar('\n');
  }
  
  return 0;
}

Measured memory_bytes: 1180
N, K, Q = map(int, input().split())
a_list = [int(input()) for _ in range(Q)]

win = [True] * N

from collections import defaultdict

cnt = defaultdict(int)

for a in a_list:
    cnt[a] += 1
#print(cnt)
for i in range(N):
    w = K - Q
    if (i + 1) in cnt:
        w += cnt[i + 1]
    # print(i+1, w)
    if w > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 12688
#include <bits/stdc++.h>
#include <map>
 #define rep(i,n) for(int i=0;i<(n);i++)
 using namespace std;
  int main(){
      int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h)cin >> s[i];
    int ans=0;
    rep(is,1<<h)rep(js,1<<w){
        int cnt =0;
        rep(i,h)rep(j,w){
        if(is>>i&1)continue;         
        if(js>>j&1)continue;
        if(s[i][j]=='#')cnt++;
        }
        if(cnt==k){
        ans++;
        }
    }
cout << ans << endl;
   return 0;   
  }

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int ContestCount = 26;
int d;
vector<int> c;
vector<vector<int>> s;

int calcMinus(int dd, vector<int> &last) {
  dd++;
  int res = 0;
  rep(i, ContestCount) {
    res += c.at(i) * (dd - last.at(i));
  }
  return res;
}

int calcScore(int dd, int contest, vector<int> &last) {
  int score = 0;
  int plus = s.at(dd).at(contest);
  score += plus;
  last.at(contest) = dd + 1;
  // マイナス分の計算
  int minus = calcMinus(dd, last);
  score -= minus;
  return score;
}

int main() {
  // 入力処理
  cin >> d;
  c.resize(ContestCount);
  rep(i, ContestCount) cin >> c.at(i);
  s.resize(d, vector<int>(ContestCount));
  rep(i, d) {
    rep(j, ContestCount) {
      cin >> s.at(i).at(j);
    }
  }

  // lastデータ
  vector<int> last = vector<int>(ContestCount, 0);
  // スコアデータ
  vector<int> v(d, 0);
  // コンテスト開催データ
  vector<int> t(d);
  rep(dd, d) {
    // 元スコア
    int score;
    if (dd == 0) {
      score = 0;
    } else {
      score = v.at(dd - 1);
    }
    // コンテスト開催
    // 総当たり
    int scoreMax = INT_MIN;
    int scoreMaxContest = 0;
    for (int contest = 0; contest < ContestCount; contest++) {
      vector<int> tmpLast(last);
      int tmpScore = calcScore(dd, contest, tmpLast);
      if (tmpScore > scoreMax) {
        scoreMax = tmpScore;
        scoreMaxContest = contest;
      }
    }
    score += calcScore(dd, scoreMaxContest, last);
    t.at(dd) = scoreMaxContest;
    v.at(dd) = score;
  }
  rep(i, d) {
    cout << t.at(i) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3696
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long mod = (long)Math.Pow(10, 9) + 7;

        long power = 1;

        for (int i = 0; i < n; i++)
        {
            power = (power * (i + 1)) % mod;
        }

        Console.WriteLine(power);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef long long ll;
int main(void)
{
	ll k;
	scanf("%lld",&k);
	ll a=0;
	for(ll i=0;i<2000000;i++)
	{
		a=a*10+7;
		a%=k;
		if(a==0)
		{
			printf("%lld\n",i+1);
			return 0;
		}
	}
	printf("-1");
}

Measured memory_bytes: 3820
#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;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using BS = bitset<2000*2000+1>;
BS can;
int N;
int main(){
	cin>>N;
	int sum = 0;
	can.set(0);
	rep(i,N){
		int a;
		cin>>a;
		sum += a;
		can = can | (can<<a);
	}
	for(int i = (sum+1)/2;i<=sum;i++) if(can[i]){
		cout<<i<<endl;
		return 0;
	}
	assert(0);
}


Measured memory_bytes: 2304
#include <stdio.h>
int main()
{
	int h,n;
	scanf("%i%i",&h,&n);
	int a[n+1],b[n+1],mn=1e9,maks=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%i%i",&a[i],&b[i]);
		if(a[i]<mn)	mn=a[i];
		if(a[i]>maks)	maks=a[i];
	}
	int dp[h+maks+1];
	dp[0]=0;
	int inf=1e9;
	for(int i=1;i<=mn;i++)
	{
		dp[i]=inf;
	}
	int mndp=1e9,mnp=0;
	for(int i=mn;i<=h+maks-1;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i>=a[j])
			{
				if(dp[i-a[j]]+b[j]<mndp)
				{
					mndp=dp[i-a[j]]+b[j];
				}
			}
		}
		dp[i]=mndp;
		mndp=1e9;
	}
	int mnr=1e9;
	for(int i=h;i<=h+maks-1;i++)
	{
		if(dp[i]<mnr)	mnr=dp[i];
	}
	printf("%i",mnr);
}


Measured memory_bytes: 256
import sys

class Dsu:
	def __init__(self, n):
		self.n = n
		self.par = [i for i in range(n)]
	def root(self, x):
		path = []
		while self.par[x] != x:
			path.append(x)
			x = self.par[x]
		for i in path:
			self.par[i] = x
		return x
	def join(self, x, y):
		x = self.root(x)
		y = self.root(y)
		if x != y:
			self.par[x] = self.par[y]

input = sys.stdin.readline
n, k, l = map(int, input().split())
road = Dsu(n)
rail = Dsu(n)
for i in range(k):
	p, q = map(int, input().split())
	road.join(p - 1, q - 1)
for i in range(l):
	p, q = map(int, input().split())
	rail.join(p - 1, q - 1)
d = dict()
res = []
for i in range(n):
	d[road.root(i), rail.root(i)] = d.get((road.root(i), rail.root(i)), 0) + 1
for i in range(n):
	res.append(d[road.root(i), rail.root(i)])
print(' '.join(map(str, res)))


Measured memory_bytes: 108072
import heapq

n = int(input())
A = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(A)

while len(A) > 1:
    Amax1 = heapq.heappop(A) * (-1)
    Amax2 = heapq.heappop(A) * (-1)
    pushA = Amax1 % Amax2
    if pushA == 0:
        heapq.heappush(A, Amax2 * (-1))
    else:
        heapq.heappush(A, pushA * (-1))
        heapq.heappush(A, Amax2 * (-1))

print(A[0] * (-1))

Measured memory_bytes: 14184
#include<cstdio>
#define Re register long long
long long n,K;
int main(){
	scanf("%lld%lld",&n,&K);
	if(!n){puts("1");return 0;}
	for(Re i=1,j=1;i<=31;++i){
		if(j>n){
			printf("%lld\n",i-1);
			return 0;
		}
		j*=K;
	}
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int main()
{
	ll n,m;
	scanf("%lld%lld",&n,&m);
	ll a,b;
	ll sum=0;
	if(n*2<=m)
	{
		sum+=n;
		a=m-n*2;
		sum+=a/4;
	}
	else
	{
		sum=m/2;
		
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 128
program kadai
	implicit none

	integer  ::  a,b,c
    integer  ::  flag1,flag2
    character(len=4)  ::  Q,X
    character(len=2)  ::  W
    character(len=9)  ::  Z
    flag1=0
    flag2=0
    
    read(*,*) a
    
    b=a/100
    c=a-b*100
    
    X="YYMM"
    Q="MMYY"
    Z="AMBIGUOUS"
    W="NA"
    if (0<c .and. c<13) then
    	flag1=1  !YYMM
    end if
    
    if (0<b .and. b<13) then
    	flag2=1  !MMYY
    end if
    
    if (flag1==0) then
    	if(flag2==1) then
        	write(*,'(a)') trim(Q)
        else
        	write(*,'(a)') trim(W)
        end if
    end if
    
    if (flag1==1) then
    	if(flag2==0) then
        	write(*,'(a)') trim(X)
        else
         	write(*,'(a)') trim(Z)
        end if
     end if
    
    
end program kadai

Measured memory_bytes: 256
r, c = gets.split.map(&:to_i)
arr = Array.new(r+1).map{ Array.new(c+1, 0) }

for i in 0..r-1 do
    arr[i] = gets.split.map(&:to_i)
    arr[i][c] = 0
end

for i in 0..r-1 do
    for j in 0..c-1  do
        arr[i][c] += arr[i][j]
end
end

for i in 0..c do
    for j in 0..r-1 do
        arr[r][i] += arr[j][i] 
    end
end

for i in 0..r do
    puts arr[i].join(" ")
end



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

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

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


int x, y, z;

void solve()
{
    cin >> x >> y >> z;
    sout(z); sout(x); nout(y);
}

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

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main()
{
string x,y;
cin>>x>>y;

int c=x.length();
for(int i=0;i<c;i++){
if(x==y){
cout<<"Yes"<<endl;
break;
}

char z;
z=x[x.length()-1];
x.erase(x.end()-1);
x.insert(x.begin(),z);
if(i+1==c){cout<<"No"<<endl;}
}


    return 0;
}

Measured memory_bytes: 3588
N=int(input())
c=input()
j_L=0
j_R=len(c)-1
ans=0
while True:
    while j_L<len(c) and c[j_L]=="R":j_L+=1
    while j_R>=0 and c[j_R]=="W":j_R-=1
    if j_L>=j_R:
        print(ans)
        exit()
    else:
        ans+=1
        j_L+=1
        j_R-=1




Measured memory_bytes: 9364
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll

using namespace std;
using Graph = vector<vector<int> >;

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);
  }

  // root(y) と root(x) を merge する
  // その際に weight(y) - weight(x) = w を満たすようにする.
  bool merge(int x, int y, int 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;
    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)) {
      int diff = uf.diff(l, r);
      if (diff != d) {
        cout << "No" << endl;
        return 0;
      }
    } else {
      uf.merge(l, r, d);
    }
  }
  cout << "Yes" << endl;
}

  


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI 3.141592653589793


int main() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int s1 = 0, s2 = 0;
	s1 = h1 * 60 + m1;
	s2 = h2 * 60 + m2;
	int hikizan = s2 - s1;
	cout << hikizan - k;
	return 0;

}

Measured memory_bytes: 3596
#14:20
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
  if a[i] < 0:
    cnt += 1
    a[i] *= -1
a.sort()
if cnt % 2 == 0:
  print(sum(a))
else:
  print(sum(a)-2*a[0])

Measured memory_bytes: 14284
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


// a aa c ca c a b a ab a b c
int main() {
	string S;
	cin >> S;
	int ans = 1;
	string tmp = S.substr(0,1);
	for (int i = 1; i < S.size(); i++) {
		if (tmp.size() == 1) {
			if (tmp[0] == S[i]) {
				if (i != S.size() - 1) {
					tmp = S.substr(i, 2);
					ans++;
					i++;
				}
				else {
					break;
				}
			}
			else {
				tmp = S.substr(i, 1);
				ans++;
			}
		}
		else {
			tmp = S.substr(i, 1);
			ans++;
		}
	}
	cout << ans << endl;
}

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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    lint sum[200001];
    map<lint,lint> cnt;
    sum[0]=0LL;

    lint N;
    cin >> N;
    ulint ans=0;

    cnt[0]=1;
    for(int i=1;i<=N;i++){
        lint A;
        cin >> A;
        sum[i]=sum[i-1]+A;
        cnt[sum[i]]++;
    }
    for(auto it=cnt.begin();it!=cnt.end();++it){
        if(it->second<=1) continue;
        ans+=(it->second-1)*(it->second)/2;
    }

    cout << ans << endl;

    return 0;
}

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

const int N = 1e6 + 5;

int n;
char s[N];
int sum[N], pmx[N], pmi[N];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  sum[0] = 0;
  pmx[0] = 0;
  pmi[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + 1 - 2 * (s[i] == '0');
    pmx[i] = max(pmx[i - 1], sum[i]);
    pmi[i] = min(pmi[i - 1], sum[i]);
  }
  int suf_mi = sum[n], suf_mx = sum[n];
  int ans = pmx[n] - pmi[n];
  for (int i = n; i; i--) {
    suf_mi = min(suf_mi, sum[i]);
    suf_mx = max(suf_mx, sum[i]);
    if (s[i] == '?') {
      if (pmx[i - 1] < suf_mx) {
        ans = min(ans, max(pmx[i - 1], suf_mx - 2) - min(pmi[i - 1], suf_mi - 2));
      }
      if (pmx[i - 1] + 1 < suf_mx) {
        suf_mx -= 2;
        suf_mi -= 2;
        ans = min(ans, max(pmx[i - 1], suf_mx) - min(pmi[i - 1], suf_mi));
      }
    }
  }
  suf_mi = sum[n], suf_mx = sum[n];
  bool found = false;
  for (int i = n; i; i--) {
    suf_mi = min(suf_mi, sum[i]);
    suf_mx = max(suf_mx, sum[i]);
    if (s[i] == '?') {
      if (pmx[i - 1] + 1 == suf_mx) {
        ans = min(ans, max(pmx[i - 1], suf_mx - 2) - min(pmi[i - 1], suf_mi - 2));
        if (!found) {
          suf_mi -= 2;
          suf_mx -= 2;
          found = true;
        }
      } else if (pmx[i - 1] + 1 < suf_mx) {
        suf_mx -= 2;
        suf_mi -= 2;
        ans = min(ans, max(pmx[i - 1], suf_mx) - min(pmi[i - 1], suf_mi));
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 16540
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	string S;cin >> S;
	int ans = 0;
	int tmp = 0;
	rep(i,3){
		if(S[i] == 'R')tmp++;
		else{
			ans = max(tmp,ans);
			tmp = 0;
		}
	}

	ans = max(tmp,ans);
	cout << ans << endl;
}	

Measured memory_bytes: 10932
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool endwith(string s, string t) {
  int tlen = t.size(), slen = s.size();
  if (tlen > slen) return false;
  int si = slen - 1;
  for (int ti = tlen - 1, si = slen - 1; ti >= 0; ti--, si--) {
    if (s[si] != t[ti]) return false;
  }
  return true;
}

void solve() {
  string s; cin >> s;
  vector<string> v = {"dream", "dreamer", "erase", "eraser"};
  while (s.size() > 0) {
    bool ok = false;
    for (int i = 0; i < 4; i++) {
      if (endwith(s, v[i])) {
        s = s.substr(0, s.size() - v[i].size());
        ok = true;
        break;
      }
    }
    if (!ok) {
      NO();
      return;
    }
  }
  YES();
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll n, k;

    cin >> n >> k;
    vector<int> a(n), visit(n, -1);
    rep(i, n)
    {
        cin >> a[i];
    }
    int now = 0;
    visit[0] = 0;
    ll ans = 0, i;
    for (i = 0; i < k; i++)
    {
        now = a[now] - 1;
        if (visit[now] != -1)
        {
            ll sub = i + 1 - visit[now];
            ll a = (k - i - 1) % sub;
            rep(j, n)
            {
                if (visit[j] == a + visit[now])
                {
                    ans = j + 1;
                    break;
                }
            }
            break;
        }
        else
        {
            visit[now] = i + 1;
        }
    }
    cout << (i < k ? ans : now + 1) << endl;
}

Measured memory_bytes: 4788
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, 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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      s: String,
    }
    if s <= "2019/04/30".to_string() {
        println!("{}", "Heisei");
    } else {
        println!("{}", "TBD");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl;
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    int n, r;
    cin >> n >> r;
    if(n < 10){
        r += (10-n)*100;
    }
    cout << r << endl;
    
}

Measured memory_bytes: 256
S = input()
T = input()
S_ =S
l = []
for i in range(len(S)-len(T)+1):
    h = [S[i+j] == T[j] or S[i] == '?' for j in range(len(T))]
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            h = False
    if h:
        S_ = S[:i] + T + S[i+len(T):]
        l.append(S_)
    h = True
    
if len(l) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(l)[0].replace('?','a'))


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

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

	string a,b,c;
	cin>>a>>b>>c;
	int x=a.size(),y=b.size(),z=c.size();
	if(a[x-1]==b[0]&&b[y-1]==c[0]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI A(N*3);
		REP(i, N*3) cin>>A[i];
		sort(ALLR(A));
//		DD(A);
		ll ans=0;
		REP(i, N) ans+=A[i*2+1];
		cout<<ans<<endl;
	}
	
	return 0;
}


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

int main() {
  int count[5] = {0};
  int temp = 0;
  for (int i = 0; i < 6; i++) {
    cin >> temp;
    count[temp]++;
  }
  
  string result = "YES";
  for (int i = 1; i < 5; i++) {
    if (count[i] >2) {
      result = "NO";
    }
  }
  
  cout << result << endl;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, t;
	cin >> n >> t;
	vector<P> kitaku(n);
	rep(i, n) {
		cin >> kitaku[i].second >> kitaku[i].first;
	}
	int ans = 1001;
	sort(kitaku.begin(), kitaku.end());
	rep(i, n) {
		if (kitaku[i].first <= t) ans = min(ans, kitaku[i].second);
	}
	if (ans != 1001)cout << ans << endl;
	else cout << "TLE" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=35000;
const int Mod=1e9+7;
struct gao{   int A,B;   }Edge[MAXN];
int Ans,End,n,m,Two[MAXN]={1},A[MAXN],B[MAXN],F[3][MAXN];
int main()
{   scanf("%d%d",&n,&m),End=(1<<n)-1;
	for(rg int i=1;i<=m;i++) scanf("%d%d",&Edge[i].A,&Edge[i].B);
	for(rg int i=1;i<=m;i++) Two[i]=(Two[i-1]<<1)%Mod;
	for(rg int i=1;i<=End;i++)
		for(rg int j=1;j<=m;j++)
		{	if((i&(1<<(Edge[j].A-1)))&&(i&(1<<(Edge[j].B-1)))) A[i]++;
			if((i&(1<<(Edge[j].A-1)))||(i&(1<<(Edge[j].B-1)))) B[i]++;
		}
	for(rg int S=1;S<=End;S++)
	{   F[1][S]=Two[A[S]]*(S&1),F[2][S]=Two[A[S]]*(S>>1&1);
		for(rg int T=(S-1)&S;T;T=(T-1)&S)
		{	if(T&1) F[1][S]=(F[1][S]-1ll*F[1][T]*Two[A[S^T]])%Mod;
			if(T&2) F[2][S]=(F[2][S]-1ll*F[2][T]*Two[A[S^T]])%Mod;
		}
	}
	for(rg int S=1;S<=End;S++)
		for(rg int T=(End^S);T;T=(T-1)&(End^S))
		{   if(A[S]+A[T]!=A[S|T]||~S&1||~T&2) continue ;
			Ans=(Ans-1ll*F[1][S]*F[2][T]%Mod*Two[A[End^S^T]])%Mod;
		}
	printf("%lld\n",(1ll*Ans+Two[m]+Mod)%Mod);
}


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

int main(){
  string s;
  cin >> s;
  int n = 0;
  for( int i = 0; i < 3; i++ ){
    if ( s[i] == 'o' ) n++;
  }
  cout << 700 + 100 * n << endl;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int dfs(int v, vector<vector<int>> &g) {
  dump(v);
  if (g[v].size() == 0)
    return 0;
  vector<int> a;
  int n = g[v].size();
  for (auto u : g[v]) {
    a.eb(dfs(u, g));
  }
  sort(all(a));
  dump(a);
  rep(i, 0, n) { a[i] += n - i; }
  return *max_element(all(a));
}
signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> p(N, -1);
  vector<vector<int>> g(N);
  rep(i, 1, N) {
    cin >> p[i];
    p[i]--;
    g[p[i]].eb(i);
  }
  cout << dfs(0, g) << endl;

  return 0;
}


Measured memory_bytes: 15872
N = int(input())
A = [int(input()) for _ in range(N)]

ans = 0
for i in range(N-1):
    ans += A[i]//2
    A[i] %= 2
    if A[i] <= A[i+1]:
        ans += A[i]
        A[i+1] -= A[i]
ans += A[N-1]//2

print(ans)

Measured memory_bytes: 7072