akhauriyash/Code-Regression huggingface dataset:
count = 0


def merge_sort(n, nums):
    global count
    if n == 1:
        return nums
    left_n = n // 2  # 左側が小さい
    left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1]  # 番兵
    right_n = n - left_n
    right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1]  # 番兵
    left_idx = 0
    right_idx = 0
    idx = 0
    sorted_list = [0] * n
    while idx < n:
        if left_sorted[left_idx] <= right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]  # 反転したとき
            if left_sorted[left_idx] <= 10**9 and right_sorted[right_idx] <= 10**9:
                count += left_n - left_idx
            right_idx += 1
        idx += 1
    return sorted_list


def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    merge_sort(n, nums)
    print(count)


if __name__ == "__main__":
    main()



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

int main() {
  int N,M;
  cin >> N >> M;
  int x=0,y=100010;
  for (int i=0;i<M;i++){
    int L,R;
    cin >> L >> R;
    x=max(x,L);
    y=min(y,R);
  }
  int ans=y-x+1;
  if (ans>0){
    cout << ans << endl;
  }
  else {
    cout << 0 << endl;
  }
}

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

#define int long long
const long long INF = (long long)1e18;

const int MAX_V = 31;
	
void dijkstra(int s, vector<vector<vector<double>>> &d, vector<vector<vector<vector<pair<pair<int,pair<int,int>>, double>>>>> &G){
	priority_queue<pair<double,pair<int,pair<int,int>>>,vector<pair<double,pair<int,pair<int,int>>>>,greater<pair<double,pair<int,pair<int,int>>>>> q;
	
	int n = G.size();
	
	d.resize(n, vector<vector<double>>(n+1, vector<double>(MAX_V, INF+10)));
	
	d[s][n][0] = 0;
	
	q.push(make_pair(0,make_pair(s,make_pair(n,0))));
	
	while(!q.empty()){
		pair<double,pair<int,pair<int,int>>> p = q.top();q.pop();
		pair<int,pair<int,int>> pp = p.second;
		int v1 = pp.first;
		int v2 = pp.second.first;
		int v3 = pp.second.second;
		
		if(d[v1][v2][v3] < p.first) continue;
		
		// for()
		
		for(pair<pair<int,pair<int,int>>,double> e : G[v1][v2][v3]){
			int e1 = e.first.first;
			int e2 = e.first.second.first;
			int e3 = e.first.second.second;
			
			if(d[e1][e2][e3] > d[v1][v2][v3] + e.second){
				d[e1][e2][e3] = d[v1][v2][v3] + e.second;
				q.push(make_pair(d[e1][e2][e3], e.first));
			}
		}
	}	
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	while(true){
		int n, m;
		int s, g;
		double ans = INF + 10;
		vector<vector<vector<double>>> d;
		vector<vector<pair<int,pair<int,int>>>> F;
		vector<vector<vector<vector<pair<pair<int,pair<int,int>>, double>>>>> G;
		cin>>n>>m;
		
		if(!n && !m) break;
		
		cin>>s>>g;
		
		s--, g--;
		
		F.resize(n);
		G.resize(n, vector<vector<vector<pair<pair<int,pair<int,int>>,double>>>>(n+1, vector<vector<pair<pair<int,pair<int,int>>,double>>>(MAX_V)));
		
		for(int i = 0; i < m; i++){
			int x, y, d, c;
			
			cin>>x>>y>>d>>c;
			
			x--, y--;
			
			F[x].push_back({y, {c, d}});
			F[y].push_back({x, {c, d}});
		}
		
		for(int i = 0; i < n; i++){
			for(int o = 0; o <= n; o++) {
				for(int j = 0; j < F[i].size(); j++){
					for(int k = 0; k < MAX_V; k++){
						for(int l = -1; l <= 1; l++){
							if(k+l <= 0 || k+l > F[i][j].second.first) continue;
							if(o == F[i][j].first) continue;
							
							if(n == o && k+l != 1) continue;
							
							G[i][o][k].push_back({{F[i][j].first,{i,k+l}}, (double)F[i][j].second.second/(k+l)});
						}
					}
				}
			}
		}
		
		dijkstra(s, d, G);
		
		for(int i = 0; i < d[g].size(); i++){
				ans = min(ans, d[g][i][1]);
		}
		
		if(ans >= INF) cout<<"unreachable"<<endl;
		else cout<<ans<<endl;
		
	}
	return 0;
}



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

int main(){
	int D;
	cin >> D;
	
	vector<int> c(26);
	rep(i, 26) cin >> c[i];
	
	vector<vector<int>> s(D, vector<int> (26));
	rep(d, D) {
		rep(i, 26) {
			cin >> s[d][i];
		}
	}
	
	vector<int> t(D);
	rep(d, D) cin >> t[d];
	
	vector<int> last(26, 0);
	
	int v = 0;
	rep(d, D) {
		v += s[d][t[d]-1];
//      cout << v << endl;
		rep(i, 26) {
			if (i == t[d]-1) {
				last[i] = d + 1;
			}
			v -= c[i] * (d+1 - last[i]);
		}
		cout << v << endl;
	}
}


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

    int A=0,B=0,C=0,D=0;
    int sum=0;
    cin>>A>>B>>C>>D;

    if(A>B){
        sum=B;
    }else{
        sum=A;
    }

    if(C>D){
        sum=sum+D;
    }else{
        sum=sum+C;
    }

    cout<<sum<<endl;

}

Measured memory_bytes: 256
# frozen_string_literal: true

def otoshidama(n, y)
  (0..n).each {|i|
    (0..(n - i)).each {|j|
      k = n - i - j
      if 10000 * i + 5000 * j + 1000 * k == y
        return [i, j, k]
      end
    }
  }

  [-1, -1, -1]
end

n, y =* gets.split(" ").map(&:to_i)
puts otoshidama(n, y).join(" ")


Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  // 1回ずつ最適な変更をすればいいわけではない。
  //
  //   *
  //  ***
  // *****
  //
  // たとえばこの例だと、1回の操作では中央を1減らすのが良いが、
  // 3回の操作をするなら全部1段になるのがベストなので、中央は2減らさないといけない。

  // K == N の場合、全てを0にすれば良い。
  // K < N のとき、HiはHjに変更する、と考える。
  // このとき、変更する区間とHjは必ず隣接する。（隣と高さを合わせることで、操作数を減らすことができるから）
  // 変更する部分が孤立しているとき、Hjはその左右どちらかであるし、
  // 変更する部分が複数隣接する場合は、Hjはその区間の左右どちらかになる。

  // K 回以下の変更で、操作回数を可能な限り削減せよ。

  // 操作回数の数え方。O(N)

  //    *
  //  * *
  //  *** *
  // **** *
  // **** *  *
  // ****** **
  // *********
  //
  // この操作回数は13回。
  // 全てのHiに対し、一つ前のHiとの差の数列にし、そのうち正の数のみの合計を取る。
  // ただしH0は0とする
  //
  // 上の例だと、数列は
  // 4,2,-1,2,-5,3,-4,1,1
  // 正の数のみ足すと、操作回数の13が得られる。 

  // 1回（1区間）の変更で、どれだけ操作回数が削減できるか？
  // 上の例で、左右をのぞいた中全てを変更すると考える。
  // すると操作回数は4回にできる。
  //
  // ********
  // *********
  // *********
  // *********
  //
  // 操作回数の観点でいえば、変更された部分が存在しないと考えても同じである。
  // つまり、変更された部分は削除され、以下になると考える。
  //
  // *
  // **
  // **
  // **
  
  // よって、問題はこうなる。
  // 「K列消して、操作回数を最小にせよ。」

  i64 result = 0;

  int N, K;
  cin >> N >> K;
  vector<int> hs(N+2);
  F0R(i, N) {
    cin >> hs[i+1];
    result += max(hs[i + 1] - hs[i], 0);
  }

  // dp[i][j] := i列目までを、K列消したときの、減らせる操作回数の最大値
  vector<vector<i64>> dp(N + 1, vector<i64>(K + 1));

  FOR(i, 1, N+1) { // 消し始める列

    FOR(j, 1, min(i + 1, K+1)) {
      chmax(dp[i][j], dp[i - 1][j]);
    }

    i64 sum = max(hs[i] - hs[i-1], 0);

    // i列から連続で消す数-1
    F0R(j, min(K, N - i + 1)) {
      sum += max(hs[i + j + 1] - hs[i + j], 0);
      i64 score = sum - max(hs[i + j + 1] - hs[i - 1], 0);
      //debug(score);

      if (i >= 2) {
        F0R(k, K - j) {
          chmax(dp[i + j][j + 1 + k], score + dp[i - 2][k]);
        }
      }
      else {
        chmax(dp[i + j][j + 1], score);
      }
    }
    //Print(dp[i]);
  }

  result -= dp[N][K];

  cout << result;
}
#endif


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;
#define int long long


signed main()
{
	fastio();
	int a, b, c;
	cin >> a >> b >> c;
	cout << min({ abs(a - b) + abs(b - c), abs(c - a) + abs(a - b) , abs(b - c) + abs(c - a) });
	system("pause");
}

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

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	
	if (a < 0) { cout << (0-a)*c + d + ((b - 0)*e) << endl; }
	else { cout << (b - a)*e << endl; }
	return 0;
}

Measured memory_bytes: 3088
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    if N == 1:
        print(1)
        sys.exit()
    div = defaultdict(int)
    for n in range(1, N + 1):
        for i in range(2, int(n ** 0.5) + 1):
            while n % i == 0:
                n //= i
                div[i] += 1
        if n != 1:
            div[n] += 1

    ans = 1
    for Value in div.values():
        ans *= (Value+1) % MOD
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


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

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 1000000007
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;

using namespace std;

const int mx=2e6+5;

int main()
{
    DeltaCube23
	int t=1;
	//cin>>t;
	while(t--)
	{
	    lli x,k,d,q,q1,q2,di;
	    cin>>x>>k>>d;
	    q1=x%d;
	    q1=abs(q1);
	    q2=(q1-d)%d;
	    if(q1==0)
	    q2=d;
	    q2=abs(q2);
	    q=min(q1,q2);
	    lli a=q;
	    lli b=max(q1,q2);
	    if((x-q)%d==0)
	    di=(x-q)/d;
	    else
	    di=(x+q)/d;
	    di=abs(di);
	    lli ans;
	    if(k<di)
	    {
	        lli y=abs(x-d*k);
	        lli z=abs(x+d*k);
	        ans=min(y,z);
	        cout<<ans;
	    }
	    else
	    {
	        lli left=k-di;
	        if(left&1)
	        cout<<b;
	        else
	        cout<<a;
	    }
	}
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define reg register
#define maxn 4101
#define M 1000000007
using namespace std;
int n, a[200001], b[200001], c[maxn][maxn], f[maxn][maxn], fac[200001], ans;
int ksm(int u, int v){
	int s = 1;
	for(int i = v; i; i >>= 1){
		if(i & 1) s = 1ll * s * u % M;
		u = 1ll * u * u % M;
	}
	return s;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d%d", &a[i], &b[i]);
		c[2001 - a[i]][2001 - b[i]]++; 
		c[a[i] + 2001][b[i] + 2001]++;
	}
	for(int i = 1; i <= 4002; i++)
		for(int j = 1; j <= 4002; j++)
		{
			if(i <= 2001 && j <= 2001) f[i][j] = (f[i - 1][j] + f[i][j - 1] + c[i][j]) % M;
			else f[i][j] = (f[i - 1][j] + f[i][j - 1]) % M, ans = (ans + 1ll * c[i][j] * f[i][j] % M) % M;
		}
	fac[0] = 1;
	for(int i = 1; i <= 10002; i++) fac[i] = 1ll * fac[i - 1] * i % M;
	for(int i = 1; i <= n; i++)
	{
		int p = a[i], q = b[i];
		ans = ans + M - 1ll * fac[(p + q) * 2] * ksm(fac[p * 2], M - 2) % M * ksm(fac[q * 2], M - 2) % M;
		if(ans > M) ans -= M;
	}
	
	ans = 1ll * ans * ksm(2, M - 2) % M;
	cout << ans;
	return 0;
}

Measured memory_bytes: 133248
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
total_time = 0

for i in range(n):
    total_time += ab[i][0]

    if total_time > ab[i][1]:
        print('No')
        exit()

print('Yes')


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


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

    int A[N][N];
    rep(i, N) rep(j, N) cin >> A[i][j];

    bool possible = true;
    rep(k, N) rep(i, N) rep(j, N) {
        if (A[i][j] > A[i][k] + A[k][j]) possible = false;
    }

    ll ans = -1;
    if (possible) {
        ans = 0;
        rep(k, N) rep(i, N) rep(j, N) {
            if (A[i][j] == A[i][k] + A[k][j] && A[i][k] > 0 && A[k][j] > 0) A[i][j] = 0;
        }

        for (int i=0; i<N; i++) for (int j=i; j<N; j++) ans += A[i][j];
    }

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



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int a,sum;
  sum=1000000000;
  vector<int> v;
  cin>>a;
  for(int i=0;i<a;i++){
  	int tmp;
  	cin>>tmp;
  	v.push_back(tmp);
  }
  int tmp_sum=0;
  for(int i=0;i<100;i++){
  	for(int j=0;j<a;j++){
  		tmp_sum+=(v[j]-(i+1))*(v[j]-(i+1));
  	}
  	if(tmp_sum<sum){
  		sum=tmp_sum;
  		tmp_sum=0;
  	}else{
  		tmp_sum=0;
  	}
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
N, X = map(int, input().split())
mLst = [0] * N
total = 0
for i in range(N):
    mLst[i] = int(input())
    total += mLst[i]
mLst.sort()
tmp = X - total
mMin = mLst[0]
ans = N
ans += tmp // mMin
print(ans)

Measured memory_bytes: 3060
n = gets.to_i
ary = []
n.times do
  ary << gets.chomp.to_i
end

ary = ary.group_by(&:itself).map{ |key, value| [key, value.count] }

cnt = 0

ary.each do |x|
  if x[1].odd?
    cnt += 1
  end
end

puts cnt


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

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

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll D) {
  string str = "Christmas";
  while(D < 25) {
    str += " Eve";
    ++D;
  }
  cout << str << endl;
}

int main() {
  ll D;
  cin >> D;
  solve(D);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 w, h;
  while(cin >> w >> h, w && h) {
    vector<vector<i64>> fie(2 * h + 1, vector<i64>(2 * w + 1, -1));
    rep(i,0,h) rep(j,0,w) fie[i * 2 + 1][j * 2 + 1] = 0;

    rep(i, 1, 2 * h) {
      if(i & 1) {
        rep(j, 1, w) {
          i64 a;
          cin >> a;
          if(a == 1) fie[i][j * 2] = -1;
          else fie[i][j * 2] = 1;
        }
      }
      else {
        rep(j,0,w) {
          i64 a;
          cin >> a;
          if(a == 1) fie[i][j * 2 + 1] = -1;
          else fie[i][j * 2 + 1] = 1;
        }
      }
    }

    vector<vector<i64>> dist(2 * h + 1, vector<i64>(2 * w + 1, 1e18));
    using P = pair<i64, i64>;
    queue<P> que;
    que.push({1, 1});
    dist[1][1] = 0;

    vector<i64> d = {0, 1, 0, -1};
    
    while(!que.empty()) {
      i64 x = que.front().first;
      i64 y = que.front().second;
      que.pop();
      rep(q, 0, 4) {
        i64 xx = x + d[q];
        i64 yy = y + d[q ^ 1];
        if(fie[xx][yy] == -1) continue;
        if(dist[xx][yy] > dist[x][y] + fie[xx][yy]) {
          dist[xx][yy] = dist[x][y] + fie[xx][yy];
          que.push(P(xx, yy));
        }
      }
    }
    if(dist[h * 2 - 1][w * 2 - 1] == 1e18) { dist[h * 2 - 1][w * 2 - 1] = -1; }
    cout << dist[h * 2 - 1][w * 2 - 1] + 1 << endl;
  }
}



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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<vector<int>> hp, dp;
  Solver(LL n) : n(n), hp(n + 1, vector<int>(3)), dp(n + 1, vector<int>(3)){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 3; ++j) {
        cin >> hp[i + 1][j];
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 3; ++k) {
          if (j != k) {
            dp[i][j] = max(dp[i][j], dp[i - 1][k] + hp[i][j]);
          }
        }
      }
    }
    cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


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

using namespace std;

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

  int aa[n];
//  for(int i=0;i<n;i++){ cin>>aa[i]; }
  for(int i=0;i<n;i++){
    int c;
    cin>>c;
    aa[c-1]=i+1;
  }
  
  for(int i=0;i<n;i++){
    cout<<aa[i]<<' ';
  }
  cout<<endl;
}

Measured memory_bytes: 1152
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

auto dijkstra(Edge[][] adj, int s) {
    alias Pair = Tuple!(int, "num", long, "dist");

    int N = adj.length.to!int;

    auto dist = new long[](N);
    dist[] = infl;
    dist[s] = 0;

    auto q = BinaryHeap!(Array!Pair, "a.dist > b.dist")();
    q.insert(Pair(s, 0));

    int rep = N - 1;

    while (!q.empty && rep) {
        auto v = q.front;
        q.popFront();

        if (dist[v.num] < v.dist)
            continue;

        rep--;

        foreach (e; adj[v.num]) {
            if (dist[e.to] > dist[v.num] + e.cost) {
                dist[e.to] = dist[v.num] + e.cost;
                q.insert(Pair(e.to, dist[e.to]));
            }
        }
    }

    return dist;
}

alias Edge = Tuple!(int, "to", int, "cost");

void main() {
    int n, m, s;
    scan(n, m, s);

    const mn = 50 * n + 1;
    chmin(s, mn - 1);

    auto adj = new Edge[][](n * mn, 0);
    foreach (i; 0 .. m) {
        int ui, vi, ai, bi;
        scan(ui, vi, ai, bi);
        ui--, vi--;
        foreach (j; 0 .. mn) {
            if (j - ai >= 0) {
                assert(j * n + ui < n * mn);
                assert(j * n + vi < n * mn);
                assert((j - ai) * n + vi >= 0);
                assert((j - ai) * n + ui >= 0);
                adj[j * n + ui] ~= Edge((j - ai) * n + vi, bi);
                adj[j * n + vi] ~= Edge((j - ai) * n + ui, bi);
            }
        }
    }

    foreach (i; 0 .. n) {
        int ci, di;
        scan(ci, di);
        foreach (j; 0 .. mn) {
            if (j + ci >= mn) break;
            assert((j + ci) * n + i < n * mn);
            adj[j * n + i] ~= Edge((j + ci) * n + i, di);
        }
    }

    debug {
        // writefln("%(%s\n%)", adj);
    }

    auto dist = dijkstra(adj, s * n + 0);
    auto ans = new long[](n);
    ans[] = infl;
    foreach (i; 1 .. n) {
        foreach (j; 0 .. mn) {
            chmin(ans[i], dist[j * n + i]);
        }
    }
    writefln("%(%s\n%)", ans[1..$]);
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 17492
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
const int MAX = 1010101;

long long fac[MAX], finv[MAX], inv[MAX];

void binom_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long binom(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<int, int> prime_factor(int n) {
  map<int, int> mp;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ++mp[i];
    }
  }
  if (n != 1) {
    ++mp[n];
  }
  return mp;
}

int N, M;

int main() {
  binom_init();
  cin >> N >> M;
  auto mp = prime_factor(M);
  ll ans = 1;
  for (auto e : mp) {
    int k = e.first;
    int v = e.second;
    ans *= binom(v + N - 1, v);
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m;
    cin >> n >> m;
    int res = 0;
    res += (n) * (n-1) / 2;
    res += m * (m-1) / 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import itertools

S=int(input())

def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans=0
for i in range(S//3):
  length=i+1
  a=S-length*3
  ans+=combinations_count(length+a-1,a)
  ans%=1000000007
  
print(ans)


Measured memory_bytes: 9204
#include <iostream>
#include <math.h>
using namespace std;

int getNum(int a, int b)
{
    int num = 0;
    while (a < b)
    {
        a = a * 2;
        num++;
    }
    return num;
}

int main()
{
    int N, K;

    double sum = 0;

    cin >> N >> K;

    for (int i = 1; i <= N; i++)
    {
        if (i >= K)
        {
            sum += (double)1 / (double)N;
        }
        else
        {
            sum += (double)1 / (double)N * (double)pow(0.5, getNum(i, K));
        }
    }

    printf("%.12f\n", sum);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n";
long long M = 1e9+7;
long long power(long long a, long long p)
{
    if(p==0) return 1;
    long long ans= power(a,p/2);
    ans =(ans * ans) % M;
    if(p%2) ans = (ans*a) % M;
    return ans;
}

bool isPrime(long long n)
{
    if (n <= 1)
        return false;
    for (long long i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}
long long SieveOfEratosthenes(long long n, long long a)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (long long p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (long long p=2; p<=n; p++)
       if (prime[p])
       {
           if(a%p==0)
           {
               return (a-p);
           }
       }
}
long long nCr(int n, int r)
{
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}
//int vis[51][51];
//int x[]={1,0,0,-1};
//int y[]={0,1,-1,0};
/* void dfs_visit(long long n,long long a, long long b)
{
    vis[a][b]=1;
    for(int i=0; i<4; i++)
    {

        int p=a+x[i];
        int q=b+y[i];
        if(p>=0 && p<n && q>=0 && q<n && vis[p][q]==0)
        {
           // cout<<p<<" "<<q<<endl;
            vis[p][q]=1;
            dfs_visit(n,p,q);
        }
    }
}
*/
long long fun(long long a)
{
    long long co=1,res=0;
    while(a>0)
    {
        if(a%2==0)
        {
            res=co;
        }
        a/=2;
        co++;
    }
    return res;
}

int main()
{
    IOS;
    long long a,b,c,d,e,h,l,n,t,f,m,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,arr1[100001]={0},sum=0,sum1=0,ma=0,ma1=0,mi=1000000000000000001;
    long long g,co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0,sum3=0,mu=1,mu1=1;
    long long a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,b6;
    double pi=2 * acos (0.0);
    string str,str1,str2,str3,str4,str5,str6;
    char ch,ch1;
    //vector<long long>v; //vector<long long> v(n+1);
    //vector<long long>v1;
   // vector<string>vs;
   // vector<string>vs1;
    //map<long long,long long>mp;
    //set<long long>s;
    //stack<long long> stk;
    //vector< pair<long long,long long> >v3;
    //map<long long,long long>::iterator it;
    //map<string,string>::iterator it;
   // vector<pair<char, pair<int,int> > > v3;
    //vector< pair<char,int > > v1;
    //int x[]={1,1,1,0,0,-1,-1,-1};
    //int y[]={0,1,-1,1,-1,1,-1,0};
    //int x[]={1,0,0,-1};
    //int y[]={0,1,-1,0};
    cin>>a>>b>>c;
    for(int i=b; i<=c; i++)
    {
        if(i%a==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    double a, b;
    cin >> a >> b;
    double x = (b - a) / 2.;

    // vector<double> v{x - 360, x - 180, x, x + 180, x + 360};
    // printV(v);
    double t = 1e10;
    for (int k = -100; k <= 100; ++k) {
        if (abs(t) > abs(x + k * 180.)) {
            t = x + k * 180.;
        }
    }
    double tmp = a + t;
    for (int k = -100; k <= 100; ++k) {
        double hoge = tmp + k * 360.;
        if (0 <= hoge && hoge < 360) {
            cout << fixed << setprecision(10) << hoge << endl;
            return 0;
        }
    }


}

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

const int maxn= 2e5+10;

int a[maxn];
typedef pair<int,int> II;
II b[maxn];


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = 0;
	int m = 0;
	cin >> n >> m;
	for(int i=0;i<n;i++) cin >> a[i];
	sort(a, a+n);
	for(int i = 0; i < m ; i++) {
		cin >> b[i].second >> b[i].first;
	}

	sort(b, b + m);
	reverse(b, b + m);
	int cur = 0;
	for(int i=0;i<m;i++) {
		//while (cur >=0 && a[cur] >= b[i].first) cur--;
		int cnt = b[i].second;
		while (cur < n && cnt > 0) {
			if (a[cur] <= b[i].first) a[cur] = b[i].first;
			else break;
			cur++;
			cnt--;
		}
	}

	long long res = 0;
	for(int i=0;i<n;i++) res += a[i];
	cout << res;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define rint register int
using namespace std;
int n,a[2005];
ll sum=0;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  sort(a+1,a+n+1);
  for(int i=n;i>=2;i--)
  {
  	int l=1,r=i-1;
  	while(l<r)
  	{
  	  if(a[l]+a[r]>a[i])
		{
		  sum+=r-l;	
		  r--;
		}	
	  else l++;
	}
  }
  printf("%lld\n",sum);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define MOD 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define for0(i, n) for (int i = 0; i < n; i++)
#define tc(t) int t; cin >> t; while (t--)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ps(x,y)         fixed<<setprecision(y)<<x
using namespace std;
int dp[100001];
int frog_jump(int arr[], int i, int n)
{
	if (i > n)
		return INT_MAX;
	if (i == n)
		return 0;
	int y = INT_MAX;
	if (dp[i] != -1)
		return dp[i];
	int x = abs(arr[i] - arr[i + 1]) + frog_jump(arr, i + 1, n);
	if (i + 2 <= n)
		y = abs(arr[i] - arr[i + 2]) + frog_jump(arr, i + 2, n);
	return dp[i] = min(x, y);
}
int main()
{
	IOS
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < 100001; i++)
		dp[i] = -1;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	ll res = frog_jump(arr, 0, n - 1);
	cout << res << endl;
}

Measured memory_bytes: 8832
N,K = gets.split.map &:to_i
Mod = 10**9 + 7

a = N
s = []
si = []
ss = []
while 0 < a do
  x = N/a
  b = (1...a).bsearch{ |y| N/y == x }
  s << x
  si << (b || a)
  ss << a
  a = (b || a) - 1
end

M = s.size
dp0 = (0...M).map{ |i| ss[i] - si[i] + 1 }
dpkk = (0...M).map{ |i| ss[i] - si[i] + 1 }
dpk = Array.new(M, 0)

(1...K).each{ |k|
  dpk = Array.new(M, 0)
  tt = [0]
  dpkk.reverse_each{ |x| tt << (tt[-1] + x) }
  dpk = tt[1..M]
  dpkk = (0...M).map{ |i| dpk[i] * dp0[i] % Mod }
}

p dpkk.reduce{ |a,b| a + b } % Mod


Measured memory_bytes: 76308
from collections import defaultdict
from fractions import Fraction
N = int(input())
A = [0 for  _ in range(N)]
B = [0 for  _ in range(N)]
for i in range(N):
    A[i], B[i] = [int(i) for i in input().split()]
A.sort()
B.sort()

if N%2 == 1:
    target = ((N+1)//2)-1
    print(B[target]-A[target]+1)
else:
    target1 = ((N)//2)-1
    target2 = (N)//2
    num1 = (A[target1]+A[target2])/2
    num2 = (B[target1]+B[target2])/2
    print(int(((num2-num1)/0.5)+1))

Measured memory_bytes: 99908
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
#include<cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,pii> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}

bool warp[5][5];
int maze[3010][3010];
int cnt[3010][3010];
int h,w;
vector<string> s;
int c;
void dfs(int y,int x){
    cnt[y][x]=c;
    for(int i=0;i<4;++i){
        int ny=y+dy[i],nx=x+dx[i];
        if(!(ny>=0&&ny<h&&nx>=0&&ny<w)) continue;
        if(s[ny][nx]=='#') continue;
        if(cnt[y][x]>0) continue;
        dfs(ny,nx);
    }
}
int main(){
    int d,t,s;cin>>d>>t>>s;
    cout<<(t*s>=d?"Yes":"No")<<endl;
}


Measured memory_bytes: 3556
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;



int main() {
	int n;
	string s;
	cin >> s >> n;
	string ans = "";
	for (int i = 0; i < s.size(); i += n) {
		ans += s[i];
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	int totalNum;
	cin >> totalNum;
	
	
	int pNum, wNum, gNum, yNum;
	
	for (int i = 0; i < totalNum; i++) {
	    string color;
	    cin >> color;
	    
	    if(color == "P")
	        pNum++;
        else if(color == "W")
            wNum++;
        else if(color == "G")
            gNum++;
        else if(color == "Y")
            yNum++;
        else
            cout << "no such hina-arare" << endl;
	}
	
	if(pNum * wNum * gNum * yNum == 0)
	    cout << "Three" << endl;
	else
	    cout << "Four" <<endl;
  
}

// P か W か G か Y

Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = nin(n)

i = 0
ans = 0
flag = True
while i != 1:
    if ans > n:
        flag = False
        break
    i = a[i] - 1
    ans += 1

print(ans if flag else -1)

Measured memory_bytes: 7080
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int X, Y;
    cin >> X >> Y;

    cout << X + Y / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    int a,b;
    while(cin >> a >> b){
    a+=b;
    b=1;
        for(int i=1; i<=7; i++){
            b=b*10;
            if(a < b){
                cout << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int x, y; cin >> x >> y;
    vector<int> A(13);
    A[1] = 1; A[3] = 1; A[5] = 1; A[7] = 1; A[8] = 1; A[10] = 1; A[12] = 1;
    A[4] = 2; A[6] = 2; A[9] = 2; A[11] = 2;
    A[2] = 3;
    if (A[x] == A[y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
n = int(input())
A = list(map(int, input().split()))
l = 1
r = 2*n
while l < r-1:
    mid = (l+r)//2
    B = []
    C = []
    for i in range(0,2*n-1):
        B.append(A[i] >= mid)
        C.append(0)
    for i in range(1,2*n-1):
        if B[i-1] == B[i]:
            C[i] = 1
    for i in range(0,2*n-2):
        if B[i+1] == B[i]:
            C[i] = 1
    mi = 2*n
    ans = False
    for i in range(0,2*n-1):
        if C[i] == 1:
            if abs(i-n+1) < mi:
                mi = abs(i-n+1)
                ans = B[i]
    if mi == 2*n:   #specialfall
        ans = ((n+1)%2)^B[n-1]
    if ans == True:
        l = mid
    else:
        r = mid
print(l)
        


Measured memory_bytes: 125632
n,m = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(m):
    bc = tuple(map(int,input().split()))
    BC.append(bc)

A.sort()
BC.sort(key = lambda tup: tup[1], reverse = True)

#print(BC)

Bflg = 0
j = 0
for i in range(n):
    if Bflg == BC[j][0]:
        j = j + 1
        Bflg = 0
    if j >= len(BC):
        break
    if A[i] > BC [j][1]:
        break
    else:
        A[i] = BC[j][1]
        Bflg = Bflg + 1

print(sum(A))


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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

int id[1001][1001];
vector<int> g[1001 * 1001];
int dp[1001 * 1001];
bool calc[1001 * 1001];

inline int get_id(int i, int j)
{
    if (i > j) swap(i, j);
    return id[i][j];
}

int dfs(int u)
{
    if (dp[u] != -1) return calc[u] ? dp[u] : -1;
    dp[u] = 1;
    for (auto &v: g[u]) {
        int res = dfs(v);
        if (res == -1) return -1;
        dp[u] = max(dp[u], res + 1);
    }
    calc[u] = true;
    return dp[u];
}

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

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

    int v = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) id[i][j] = v++;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 2; j++) {
            int from = get_id(i, a[i][j]);
            int to   = get_id(i, a[i][j + 1]);
            g[from].push_back(to);
        }
    }

    memset(dp, 0xff, sizeof(dp));

    int ans = 0;
    for (int i = 0; i < v; i++) {
        int res = dfs(i);
        if (res == -1) {
            cout << -1 << endl;
            return 0;
        }

        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51712
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int a,b,c;

int main(int argc, char const *argv[])
{
    cin>>a>>b>>c;
    cout<<min(a+b,min(b+c,a+c))<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
import java.io.*;
 
public class Main{
    
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int M = s.nextInt();

        String a = "";
        String b = "";
        for(int i = 0; i < M; i++){
            a = a + String.valueOf(N);
        }
        for(int i = 0; i < N; i++){
            b = b + String.valueOf(M);
        }
        if(a.compareTo(b) >= 0){
            System.out.println(b);
        }else{
            System.out.println(a);
        }
        
	}
} 

Measured memory_bytes: 22612
s = int(input())
s_12 = int(s / 100)
s_34 = s - s_12 * 100

if 1 <= s_12 <= 12:
    if 1 <= s_34 <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= s_34 <= 12:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

struct Bar{
  int x;
  int y;
};

int main(){
  int total_vertical_bars;
  int total_horizontal_bars;
  int max_height;
  int total_selected_bars;
  while(~scanf("%d %d %d %d",
	       &total_vertical_bars,
	       &total_horizontal_bars,
	       &max_height,
	       &total_selected_bars)){
    if(total_vertical_bars == 0
       && total_horizontal_bars == 0
       && max_height == 0
       && total_selected_bars == 0) break;

    int sum = 0;
    int points[1001];
    memset(points,0,sizeof(points));
    for(int i=0;i<total_vertical_bars;i++){
      scanf("%d",points + i);
    }
    vector<int> bars[1001];
    memset(bars,0,sizeof(bars));
    for(int i=0;i<total_horizontal_bars;i++){
      int x,y;
      scanf("%d %d",&x,&y);
      bars[y-1].push_back(x-1);
    }

    int matrix[1001];
    for(int i=0;i<total_vertical_bars;i++) matrix[i] = i;

    vector<P> change;
    vector<P> log;

    for(int height=0;height < max_height;height++){
      for(int i=0;i<bars[height].size();i++){
	int x = bars[height][i];
	change.push_back(P(matrix[x],matrix[x+1]));
	swap(matrix[x],matrix[x+1]);
      }
    }


    for(int height=max_height-1;height >= 0;height--){
      for(int i=bars[height].size()-1;i >= 0;i--){
	int x = bars[height][i];
	log.push_back(P(points[x],points[x+1]));
	swap(points[x],points[x+1]);
      }
    }

    reverse(log.begin(),log.end());

    int res = 0;
    for(int i=0;i<total_selected_bars;i++){
      res += points[i];
    }

    int base = res;
    int idx = 0;
    for(int height=0;height < max_height;height++){
      for(int i=0;i<bars[height].size();i++){
	if(change[idx].first >= total_selected_bars
	   && change[idx].second < total_selected_bars){
	  res = min(res,
		    base
		    - log[idx].first
		    + log[idx].second);
	}
	
	if(change[idx].first < total_selected_bars
	   && change[idx].second >= total_selected_bars){
	  res = min(res,
		    base
		    + log[idx].first
		    - log[idx].second);
	}
	idx++;
      }
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 4016
#coding:utf-8
def alchemy(x, y):
    val = (x+y)/2
    return val

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    ans = 0

    for i in range(n-1):
        v = sorted(v)
        new_item = alchemy(v[0], v[1])
        del v[0:2]
        v.append(new_item)
        #print(v_sort)

    print(v[0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

ll dp[2005][2005];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];
   vector<P> p;
   rep(i, 0, n) p.emplace_back(a[i], i);
   sort(p.rbegin(), p.rend());
   rep(i, 0, n) {
      int pi = p[i].second;
      rep(l, 0, i + 1) {
         int r = i - l;
         chmax(dp[i + 1][l + 1], dp[i][l] + ll(pi - l) * a[pi]);
         chmax(dp[i + 1][l], dp[i][l] + ll((n - r - 1) - pi) * a[pi]);
      }
   }
   ll ans = 0;
   rep(i, 0, n + 1) chmax(ans, dp[n][i]);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 26328
S = input()
m =  0
cnt = 0
for s in S:
    if s == 'A':
        cnt += 1
    elif s == 'C':
        cnt += 1
    elif s == 'G':
        cnt += 1
    elif s == 'T':
        cnt += 1
    else:
        cnt = 0
    m = max(m, cnt)
print(m)


Measured memory_bytes: 8972
#include <cstdio>
#include <iostream>

using namespace std;

int n, last;
int a[100100][4], f[4][100100];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= 3; ++ j)
			scanf("%d", &a[i][j]);
	for (int i = 1; i <= 3; ++ i)
		f[i][1] = a[1][i];
	for (int i = 2; i <= n; ++ i)
	{
		for (int j = 1; j <= 3; ++ j)
			for (int k = 1; k <= 3; ++ k)
				if (j != k)
					f[j][i] = max(f[j][i], f[k][i - 1] + a[i][j]);
	}
	printf("%d", max(f[1][n], max(f[2][n], f[3][n])));
	return 0;
}

Measured memory_bytes: 2944