akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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;
}

const long long INF = 1LL << 60;

const double PI = acos(-1.0);

// long long積のオーバーフロー検出
bool detect_mul_overflow(ll a, ll b)
{
    return a >= LONG_MAX / b;
}

int lcm(int a, int b)
{
    //最小公倍数
    return a / __gcd(a, b) * b;
}

struct edge
{
    int from, to, cost;
};

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));
int k;

int main()
{
    cin >> k;

    ll mod7 = 7 % k;
    ll mod10 = 1;
    ll res = 7 % k;
    if (k == 1 || k == 7)
    {
        cout << 1 << endl;
        return 0;
    }
    loop(i, 1, 1000000)
    {
        mod10 = mod10 * (10 % k);
        mod10%=k;
        res = (res + mod7 * mod10) % k;
        if (res == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


 int main(){
   int N, Q, ans;
   cin >> N >> Q;
   string S;
   cin >> S;
   int cnt[N+1] = {0};
   int l, r;
   rep(i, N-1){
     if(S[i] == 'A' && S[i+1] == 'C')
       cnt[i+2] = cnt[i+1] + 1;
     else cnt[i+2] = cnt[i+1];
   }
   rep(i, Q){
     cin >> l >> r;
     ans = cnt[r] - cnt[l-1];
     if(l!=1){
       if(S[l-1] == 'C' && S[l-2] == 'A') ans--;
     }
     cout << ans << endl;
   }
       
     
   
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll a[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,x;cin>>n>>x;
    for(ll i=1;i<=n;i++)cin>>a[i];
    ll ans = 0;
    for(ll i=2;i<=n;i++){
        ll cur=a[i]+a[i-1];
        ll rmv = max(0ll , cur - x);
        ll tmp = min(a[i],rmv);
        a[i] = a[i] - tmp;
        ans+=tmp;
        rmv-=tmp;
        tmp=min(a[i-1],rmv);
        a[i-1] = a[i-1] - tmp;
        ans+=tmp;
    }
    cout<<ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,d,e,f,g,h,i;
    cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
    if(a-b==d-e&&d-e==g-h&&b-c==e-f&&e-f==h-i&&a-d==b-e&&b-e==c-f&&d-g==e-h&&e-h==f-i) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
}


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

class Program
{
    static void Main(string[] args)
    {
        var S = new Dictionary<Char, String>()
        {
            { 'A',Console.ReadLine().ToUpper() },
            { 'B',Console.ReadLine().ToUpper() },
            { 'C',Console.ReadLine().ToUpper() },
        };
        var next = 'A';
        while (S[next].Length > 0)
        {
            var tmp = S[next].First();
            S[next] = S[next].Substring(1);
            next = tmp;
        }
        Console.WriteLine(next);
    }
}


Measured memory_bytes: 3416
n = int(input())
A = [int(i) for i in input().split()]

l = -2
r = 2 * 10 ** 9 + 2

def f(m):
    C = A[:]
    C[0] -= m // 2
    C[-1] -= m // 2
    for i in range(n - 1):
        C[i + 1] -= C[i]
        C[i] = 0
        if C[i + 1] < 0:
            return i % 2 == 1
    if C[-1] == 0:
        return True
    return False
    
while abs(r - l) > 2:
    m = (l + r) // 2
    if m % 2 == 1:
        m -= 1
    if f(m):
        r = m
    else:
        l = m

C = A[:]
C[0] -= r // 2
C[-1] -= r // 2
ans = [r]
for i in range(n - 1):
    ans.append(2 * C[i])
    C[i + 1] -= C[i]

print(*ans)


Measured memory_bytes: 83812
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
ll sumofdigit(long ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}
ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); }
ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive
 ***/

template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}

void solve()
{	
	ld n,x,t;
	cin>>n>>x>>t;

	ld z=ceil(n/x);
	// cout<<z;
	cout<<int(z*t);
}


int main()
{

#ifndef ONLINE_JUDGE
	freopen("C:/Users/91731/Documents/input.txt", "r", stdin);
	freopen("C:/Users/91731/Documents/output.txt", "w", stdout);
	freopen("C:/Users/91731/Documents/error.txt", "w", stderr);
#endif

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	solve();
}


Measured memory_bytes: 3740
<?php
$stdinNum = trim(fgets(STDIN));
$stdinStr = trim(fgets(STDIN));

if($stdinNum % 2 == 0){
    $num = $stdinNum / 2;
    $strFirst = substr($stdinStr, 0,$num);
    $strSecond = substr($stdinStr, $num ,strlen($stdinStr));
    if($strFirst == $strSecond){
        echo "Yes"."\n";
    }else{
        echo "No"."\n";
    }
}else{
    echo "No"."\n";
}
?>

Measured memory_bytes: 3700
n = int(input())
s = input()

a = ""

stack = []

for i in range(len(s)):
    if s[i] == "(":
        stack.append("(")
        a += "("
    elif s[i] == ")" and len(stack) == 0:
        stack.append(")")
        a += ")"
    elif s[i] == ")" and stack[-1] == ")":
        stack.append(")")
        a += ")"
    else:  # s[i] == ")" and stack[-1] == "("
        stack.pop(-1)
        a += ")"

while len(stack) > 0:
    if stack[len(stack) - 1] == ")":
        e = len(stack) - 1
        s = e
        while s - 1 >= 0 and stack[s - 1] == ")":
            s -= 1
        a = "(" * (e - s + 1) + a
        stack = stack[:s]
    elif stack[len(stack) - 1] == "(":
        e = len(stack) - 1
        s = e
        while s - 1 >= 0 and stack[s - 1] == "(":
            s -= 1
        a = a + ")" * (e - s + 1)
        stack = stack[:s]

print(a)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		
		ll n;
		cin>>n;
		vector<ll> freq(100005,0);
		vector<ll> a;
		ll sum = 0;
		for(ll i=0; i<n; i++) {
			ll x;
			cin>>x;
			freq[x]++;
			sum += x;
			a.push_back(x);
		}

		ll q;
		cin>>q;

		while(q--) {
			ll b,c;
			cin>>b>>c;
			sum = sum - freq[b]*(b-c);
			freq[c] += freq[b];
			freq[b] = 0;
			cout<<sum<<endl;
		}

		return 0;
	}


Measured memory_bytes: 5068
N,M=map(x->parse(Int,x),split(readline()))
A=ones(N)
for i=1:M
	A[parse(Int,readline())]=0
end
dp=zeros(Int,N+1)
dp[1]=1
for i=1:N
	dp[i]%=10^9+7
	dp[i+1]+=dp[i]*A[i]
	if i<N
		dp[i+2]+=dp[i]*A[i+1]
	end
end
println(dp[N+1]%(10^9+7))


Measured memory_bytes: 148824
#include <iostream>
using namespace std;
 
int main()
{
    int a, b;
     
    cin >> a >> b;
    if (a < b)
        cout << "a < b" << endl;
    else
    if (a > b)
        cout << "a > b" << endl;
    else
    if (a == b)
        cout << "a == b" << endl;
 
     
     
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
 
int main(){
	int n;
	int v[20];
	int c[20];
	int vc[20];
	std::cin>>n;
	for(int i=0;i<n;i++){
	    std::cin>>v[i];
	}
	for(int i=0;i<n;i++){
	    std::cin>>c[i];
	    vc[i]= v[i]-c[i];
	}
	int maxVc =0;
	for(int i=0;i<n;i++){
	    maxVc += (vc[i]>0)?(vc[i]):(0);
	}
  	std::cout<<maxVc;
  	return 0;
}

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

cnt = 0
ans1 = 0
for i in range(n):
    cnt += a[i]
    if i % 2 == 1:
        if cnt >= 0:
            ans1 += cnt + 1
            cnt = -1
    else:
        if cnt <= 0:
            ans1 += 1 - cnt
            cnt = 1

cnt = 0
ans2 = 0
for i in range(n):
    cnt += a[i]
    if i % 2 == 1:
        if cnt <= 0:
            ans2 += 1 - cnt
            cnt = 1
    else:
        if cnt >= 0:
            ans2 += cnt + 1
            cnt = -1
            
print(min(ans1,ans2))

Measured memory_bytes: 20004
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<pair<ll,int>> p(n);
  vector<int> q(n);
  rep(i,n){
    cin>>p[i].fi;
    p[i].se=i;
  }

  sort(all(p));

  rep(i,n){
    q[p[i].se]=i;
  }

  int ans=0;
  rep(i,n){
    if((i+q[i])%2) ans++;
  }

  cout << ans/2 << endl;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>

using namespace std;

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

    int data[3];
    data[0] = A;
    data[1] = B;
    data[2] = C;

    int ans = 0;

    if(data[0]%2 == data[1]%2 && data[0]%2 == data[2]%2);
    else {
        if((data[0] + data[1])%2 == 0){
            data[0]++;
            data[1]++;
        }
        else if((data[0] + data[2])%2 == 0){
            data[0]++;
            data[2]++;
        }
        else{
            data[1]++;
            data[2]++;
        }
        ans++;
    }
    sort(data, data+3, greater<int>());
    
    if((data[0] - data[2])%2 == 0){
        ans += (data[0] - data[2])/2;
    }
    else {
        ans += (data[0] - data[2])/2 + 1;
        data[1]++;
    }
    ans += (data[0] - data[1])/2;

    cout << ans << endl;

}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll x,y,z;
    cin >> x >> y >> z;
    rep(i,x){
        if(x - (z*(i+1)) - (y*i) < 0){
            cout << i-1 << endl;
            return 0;
        }
    }
    return 0;
}

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

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

int main() {
  int N;
  cin >> N;
  cout << pow(N,3);
}

Measured memory_bytes: 4276
num = int(input())
ls_value = [ int(x) for x in input().split(' ') ]
ls_cost = [ int(y) for y in input().split(' ') ]
profit = 0
for x, y in zip(ls_value, ls_cost):
    if (x - y) > 0:
        profit += (x - y)

print(profit)

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

int main() {
    int n;
    while (cin >> n, n) {
        int found = -1;
        char ma1 = '@', ma2 = '@';
        vector<int> cnt(128);
        for (int i = 1; i <= n; i++) {
            char c; cin >> c;
            if (~found) continue;
            if (++cnt[c] > cnt[ma2] && c != ma1) ma2 = c;
            if (cnt[ma2] > cnt[ma1]) swap(ma2, ma1);
            if (cnt[ma1] > cnt[ma2] + n - i) found = i;
        }
        if (~found) cout << ma1 << " " << found << endl;
        else cout << "TIE" << endl;
    }
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

ll gcd(ll a, ll b){return b==0 ? a : gcd(b, a%b);}
ll lcm(ll a, ll b){return a / gcd(a,b) * b;}

int main()
{
  ll n; cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) cin>>a[i]>>b[i];
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());

  ll ans = 0;
  rep(i, n) {
    ll m = (a[i]+ans)%b[i];
    if (m == 0) continue;
    ll t = b[i] - m;
    ans += t;
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    pqi q;
    int a;
    rep(i,n){
        cin >> a;
        q.push(a);
    }
    rep(i,m){
        a=q.top();
        q.pop();
        a/=2;
        q.push(a);
    }
    ll ans = 0;
    rep(i,n){
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}


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

using vi = vector<int>;
using ii = pair<int, int>;

int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);

  long long int d, t, s;

  cin >> d >> t >> s;

  cout << (s * t < d ? "No" : "Yes") << endl;

  return 0;
}


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

#define ll long long int

double hi[3005], ti[3005], dp[3005][3005];

double f(ll i, ll j){

    if(j == 0) return 1.0;

    if(i == 0) return 0.0;

    if(dp[i][j] >= 0.0) return dp[i][j];

    return dp[i][j] = hi[i] * f(i-1,j-1) + ti[i] * f(i-1,j);
}

int main() {

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    ll n;
    cin>>n;

    for(ll z=1;z<=n;z++) cin>>hi[z], ti[z] = 1.0 - hi[z];

    memset(dp, -1, sizeof dp);

    cout<<fixed<<setprecision(10)<<f(n, (n+1)/2);

    return 0;
}

Measured memory_bytes: 74524
#include <stdio.h>

int main(void) {
	int H,W;
	int i,j;
	while(1)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) {
			break;
		}
		for (i = 0; i < H; ++i) {
			for (j = 0; j < W; ++j) {
				if ((i + j) % 2) {
					printf(".");
				} else {
					printf("#");
				}
 			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
  
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define Jrep(j,n) for(int j=0;j<(n);j++)
#define Jreps(j,n) for(int j=1;j<=(n);j++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
  
using namespace std;    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int bord=n/1.08;
    int s=bord*1.08;
    if((int)s==n) cout<<(int)bord<<'\n';
    else if((int)((bord+1)*1.08)==n) cout<<(int)bord+1<<'\n';
    else cout<<":("<<'\n';
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

int sum[101];

int main(){
	sum[0] = 0;
	int n, m;
	int l;
	while(cin >> m >> n && (n || m)){
		rep(i, n){
			cin >> l;
			sum[i+1] = sum[i] + l;
		}
		int ub = INF;
		int lb = 0;
		while(ub - lb > 1){
			int mb = (ub + lb) / 2;
			int pos = 0;
			rep(i, m){
				rep2(j, pos+1, n + 1){
					if(sum[j] - sum[pos] > mb){
						pos = j-1;
						break;
					}
					if(j == n) pos = n;
				}
			}
			if(pos == n) ub = mb;
			else lb = mb;
		}
		cout << ub << endl;
	}
	return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   int N, M;
   cin >> N >> M;
   int ans[N+1] = {};
   for(int i = 0; i < M; i++)
   {
      int a, b; cin >> a >> b;
      ans[a]++;
      ans[b]++;
   }
   for(int i = 1; i <= N; i++)
      cout << ans[i] << nl;
   return 0;

}


Measured memory_bytes: 3600
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c))
#define     M             32000
int main()
{


 ll m,n,s=0;
 cin>>m>>n;
 ll a[n];
 for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n;i++)
    {
        s+=a[i];
    }
    ll y = m-s;
    if(y>=0) cout<<y<<endl;
    else cout<<"-1"<<endl;


}


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

int main() {
    int N;
    cin >> N;
    vector<pair<ll, int>> C(2*N);
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        C[i] = {A, 1};
    }
    for (int i = 0; i < N; i++) {
        int B;
        cin >> B;
        C[i+N] = {B, -1};
    }
    sort(C.begin(), C.end());
    
    ll mod = 1e9+7;
    ll ans = 1;
    ll cnt = 0;
    for (int i = 0; i < 2*N; i++) {
        if (cnt*C[i].second < 0) {
            ans *= abs(cnt);
            ans %= mod;
        }
        cnt += C[i].second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6424
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long n;

long long dfs(string s) {
	long long cnt = 0;
	if (stoll(s) > n) {
		return 0;
	}
	char st[11];
	for (int i = 0; i < s.length(); i++) {
		st[i] = s[i];
	}
	if (count(st, st + s.length(), '7') > 0) {
		if (count(st, st + s.length(), '5') > 0) {
			if (count(st, st+s.length(), '3') > 0) {
				cnt++;
			}
		}
	}
	cnt += dfs(to_string(stoll(s) * 10 + 7));
	cnt += dfs(to_string(stoll(s) * 10 + 5));
	cnt += dfs(to_string(stoll(s) * 10 + 3));
	return cnt;
}

int main() {
	cin >> n;
	cout << dfs(to_string(0)) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N,num=0;
		N=sc.nextInt();
		int[] A=new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		for(int i=0;i<N-1;i++){
			for(int j=N-1;j>i;j--){
				if(A[j]<A[j-1]){
					int tmp=A[j];
					A[j]=A[j-1];
					A[j-1]=tmp;
					num++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}
			else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(num);
	}
}


Measured memory_bytes: 26272
#include <iostream>
#include <vector>

int main() {
    int n; std::cin >> n;
    int m = 0;
    int c = 0;
    int p = 0;
    for (int i = 0; i < n; i++) {
        int h; std::cin >> h;
        if (p < h) {
            m = std::max(m, c);
            c = 0;
        } else {
            c++;
        }
        p = h;
    }
    m = std::max(m, c);

    std::cout << m << std::endl;

    return 0;
}

Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 179 (https://atcoder.jp/contests/abc179)
// Problem: E: Sequence Sum (https://atcoder.jp/contests/abc179/tasks/abc179_e)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    ll n; int x, m; cin >> n >> x >> m;
    vi next(m);
    rep(i, m)
        next[i] = (ll)i * i % m;

    vi seen(m, -1), path = {x};
    seen[x] = 0;
    while (seen[next[path.back()]] == -1)
        seen[next[path.back()]] = sz(path), path.push_back(next[path.back()]);

    int start = seen[next[path.back()]];
    int cyclen = sz(path) - start;

    ll res = 0;
    rep(i, start)
        res += path[i];

    ll cycsum = 0;
    reps(i, start, sz(path))
        cycsum += path[i];

    ll cyccnt = (n - start) / cyclen;
    res += cycsum * cyccnt;

    rep(i, (n - start) % cyclen)
        res += path[start + i];

    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string a;
  cin >> a;
  //白白...黒黒...
  vector<int> b(n+1);
  vector<int> w(n+1);
  for(int i = 1;i <= n;i++){
    if(a[i-1] == '.'){
      w[i] = w[i-1]+1;
      b[i] = b[i-1];
    }else{
      w[i] = w[i-1];
      b[i] = b[i-1]+1;
    }
  }
  int ans,cnt;
  ans = 200000;
  for(int i = 0;i <= n;i++){
    cnt = b[i] - w[i] + w[n];
    if(cnt < ans)ans =cnt;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	int n = s.size();

	string x;
	for (int i = 0; i < n; i+=2) {
		x = s[i];
		cout << x;
	}
}

Measured memory_bytes: 592
main :: IO ()
main = do
    [a, b, k] <- fmap (map read . words) getLine :: IO [Int]
    print $ solve a b k

solve :: Int -> Int -> Int -> Int
solve a b k =
    [ i | i <- [100, 99 .. 1], a `mod` i == 0, b `mod` i == 0 ] !! (k - 1)


Measured memory_bytes: 508
s = input()
c = s.count('R')
if c==3:
  print(c)
elif c==1:
  print(c)
elif c==2:
  if (s[0]=='R' and s[0]==s[1]) or (s[1]=='R' and s[1]==s[2]):
    print(c)
  else:
    print("1")
else:
  print(0)

Measured memory_bytes: 9112
from operator import itemgetter
Dishes = [[0 for n in range(2)] for m in range(5)]
result = 0
most_loss = 0

for i in range(5):
    k = input()
    loss = 0  if int(k) % 10 == 0 else 10 - (int(k) % 10)
    Dishes[i][0] = int(k)
    Dishes[i][1] = loss
    if most_loss < loss:
        most_loss = loss
    result = int(k) + loss + result
    
result = result - most_loss
    
print(result)


Measured memory_bytes: 3188
#include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 1000000
int ans;
int a,d,n;
bool prime[MAX];
using namespace std;
void era();
int main() {
  while(true){
    era();
    cin >> a >> d >> n;
    if(a==0&&d==0&&n==0) return 0;
    int i;
    for(i = a;n>0;i+=d){
      if(prime[i]) n--;
    }
    cout << i-d << endl;
  }
  return 0;
}

void era(){
  rep(i,MAX) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  for(int i = 4;i<MAX;i+=2) prime[i] = false;
  rep(i,MAX){
    if(prime[i])
      for(int j = 3*i;j<MAX;j+=2*i){
        prime[j] = false;
      }
  }
}

Measured memory_bytes: 2136
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    static const long double pi = 3.141592653589793;
    
    
    ld A,B,H,M;
    cin >> A >> B >> H >> M;
    
    ld angle_long = M / 60.0  * 360;
    ld angle_short = ((H + (M/60.0)) /12.0) * 360;

    
    //cout << angle_long << "::" << angle_short << endl;;
    ld angle = abs(angle_long - angle_short)/180.0 * pi;
    
    ld ans = A * A + B * B - 2.0 * A * B * cos(angle);
    ans = sqrt(ans);

    cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 4136
#include<stdio.h>
int main(){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if(A==5&&B==5&&C==7||A==5&&B==7&&C==5||A==7&&B==5&&C==5) {printf("YES");}
    else {printf("NO");}
    

    return 0;
}

Measured memory_bytes: 128
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,k = readline() |> split |> parseMap
	s = chomp(readline())
	a = Int[]
	b = Int[0]
	f = s[1]=='0'?0:1
	t = 1
	for i in 2:n
		if s[i-1] != s[i]
			push!(a,f)
			f = f==0?1:0
			push!(b,t+b[length(b)])
			t = 1
		else
			t += 1
		end
	end
	if t != 0
		push!(a,f)
		push!(b,t+b[length(b)])
	end
	l = length(a)
	if l == 1
		println(n)
	else
		m = 0
		for i in 1:l
			if k%2+a[i] == 1
				x = b[min(i+k+1,l+1)]-b[max(i-k,1)]
				m = max(m,x)
			end
		end
		println(m)
	end
end
main()


Measured memory_bytes: 117840
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <cstring>
#define MAX_N 1000 + 16
 
using namespace std;
 
int N, H, W;
int X1[MAX_N], X2[MAX_N], Y1[MAX_N], Y2[MAX_N];
int fld[2 * MAX_N][2 * MAX_N], // 填充遍历用，代表坐标(i, j)处是否空白（压缩后）
dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 };
 
// 压缩坐标，将坐标的值变成“这是第几种值”，返回一共有几种坐标
int compress(int *x1, int *x2, int w)
{
	vector<int>xs;
 
	for (int i = 0; i < N; ++i)
	{
		int tx1 = x1[i], tx2 = x2[i];
		if (1 <= tx1 && tx1 < w) xs.push_back(tx1);
		if (1 <= tx2 && tx2 < w) xs.push_back(tx2);
	}
	xs.push_back(0);
	xs.push_back(w);
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for (int i = 0; i < N; ++i)
	{
		x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
		x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
	}
	return xs.size() - 1;
}
 
int bfs()
{
	int ans = 0;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if (fld[i][j]) continue;
			++ans;
			queue<pair<int, int> >que;
			que.push(make_pair(j, i));
			while (!que.empty())
			{
				int nx = que.front().first, ny = que.front().second;
				que.pop();
 
				for (int i = 0; i < 4; ++i)
				{
					int tx = nx + dx[i], ty = ny + dy[i];
					if (tx < 0 || W < tx || ty < 0 || H< ty || fld[ty][tx] > 0) continue;
					que.push(make_pair(tx, ty));
					fld[ty][tx] = 1;
				}
			}
		}
	}
	return ans;
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
	while (cin >> W >> H, W | H)
	{
		cin >> N;
		for (int i = 0; i < N; ++i)
		{
			cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
		}
 
		memset(fld, 0, sizeof(fld));
 
		W = compress(X1, X2, W);
		H = compress(Y1, Y2, H);
 
		// imos-法
		for (int i = 0; i < N; i++)
		{
			fld[Y1[i]][X1[i]]++;
			fld[Y1[i]][X2[i]]--;
			fld[Y2[i]][X1[i]]--;
			fld[Y2[i]][X2[i]]++;
		}
		// 横向累积
		for (int i = 0; i < H; i++)
		{
			for (int j = 1; j < W; j++)
			{
				fld[i][j] += fld[i][j - 1];
			}
		}
		// 纵向累积
		for (int i = 1; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				fld[i][j] += fld[i - 1][j];
			}
		}// 累积完后，fld中非0部分表示有挡板
		cout << bfs() << endl;
	}
	return 0;
}


Measured memory_bytes: 19064
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    
    reverse(S.begin(), S.end());
    vector<int> ans;
    int now = 0;
    while (true) {
        if (N - now <= M) {
            ans.push_back(N - now);
            break;
        }
        bool susumu = false;
        for (int i = M; i > 0; --i) {
            if (S[now + i] == '0') {
                ans.push_back(i);
                now += i;
                susumu = true;
                break;
            }
        }
        if (!susumu) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    rep(i, ans.size() - 1) cout << ans[i] << " ";
    cout << ans[ans.size() - 1] << endl;
    return 0;
}


Measured memory_bytes: 1144
import java.util.* ;
public class Main {
	public static void main(String[] args) {
		Scanner S = new Scanner( System.in ) ;
		int n = S.nextInt() ;
		int[] arr = new int[n] ;
		int result = 0 ;
		for( int i=0;i<n;i++ ) {
			arr[i] = S.nextInt() ;
			result ^= arr[i] ;
		}
		for( int i=0;i<n;i++ ) {
			System.out.print( ( result^arr[i] )+" " ) ;
		}
	}
}

Measured memory_bytes: 61912
#include<stdio.h>
#include<string.h>
char c[201];
char table[]="abcdefghijklmnopqrstuvwxyz.?! ";
char ret[101];
int main(){
	while(~scanf("%s",c)){
		int v=strlen(c);
		if(v%2){
			printf("NA\n");
			continue;
		}
		bool na=false;
		int now=0;
		for(int i=0;i<v/2;i++){
			if(c[i*2]>'6'||c[i*2]<'1'||c[i*2+1]>'5'||c[i*2+1]<'1'){
				na=true;
				break;
			}
			else{
				ret[now++]=table[(c[i*2]-'1')*5+(c[i*2+1]-'1')];
			}
		}
		ret[now]='\0';
		if(na)printf("NA\n");
		else printf("%s\n",ret);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=405;
const int MOD=998244353;
int n;
int h[N];
long long Pw[N];
long long C[N][N];
void init(int n=400)
{
	for(int i=0;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=n;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
	}
	Pw[0]=1;
	for(int i=1;i<=n;i++)
		Pw[i]=Pw[i-1]*2%MOD;
	return;
}
long long f[N][N],g[N][N];
void dfs(int d,int l,int r)
{
	static long long tmpf[N],tmpg[N];
	for(int i=0;i<=r-l+1;i++)
		f[d][i]=g[d][i]=0;
	f[d][0]=g[d][0]=1;
	int pre=l,s=0;
	for(int i=l;i<=r;i++)
		if(h[i]==d)
		{
			if(pre<=i-1)
			{
				dfs(d+1,pre,i-1);
				int len=i-1-pre+1;
				for(int j=0;j<=s;j++)
					for(int k=0;k<=len;k++)
						tmpf[j+k]=(tmpf[j+k]+f[d][j]*f[d+1][k]%MOD)%MOD;
				for(int j=0;j<=s+len;j++)
					f[d][j]=tmpf[j],tmpf[j]=0;
				for(int j=0;j<=s;j++)
					for(int k=0;k<=len;k++)
						tmpg[j+k]=(tmpg[j+k]+g[d][j]*g[d+1][k]%MOD)%MOD;
				for(int j=0;j<=s+len;j++)
					g[d][j]=tmpg[j],tmpg[j]=0;;
				s+=len;
			}
			pre=i+1;
		}
	if(pre<=r)
	{
		dfs(d+1,pre,r);
		int len=r-pre+1;
		for(int j=0;j<=s;j++)
			for(int k=0;k<=len;k++)
				tmpf[j+k]=(tmpf[j+k]+f[d][j]*f[d+1][k]%MOD)%MOD;
		for(int j=0;j<=s+len;j++)
			f[d][j]=tmpf[j],tmpf[j]=0;
		for(int j=0;j<=s;j++)
			for(int k=0;k<=len;k++)
				tmpg[j+k]=(tmpg[j+k]+g[d][j]*g[d+1][k]%MOD)%MOD;
		for(int j=0;j<=s+len;j++)
			g[d][j]=tmpg[j],tmpg[j]=0;;
		s+=len;
	}
	int len=r-l+1,t=len-s;
	for(int i=0;i<=s;i++)
	{
		for(int j=0;j<=s-i;j++)
			tmpf[i+t+j]=(tmpf[i+t+j]+C[s-i][j]*(j?Pw[i+t]:(Pw[i+t]-1))%MOD*f[d][i]%MOD)%MOD;
		tmpf[i]=(tmpf[i]+g[d][i])%MOD;
		for(int j=0;j<=len-i;j++)
			tmpg[i+j]=(tmpg[i+j]+C[len-i][j]*Pw[i]%MOD*g[d][i]%MOD)%MOD;
	}
	for(int i=0;i<=len;i++)
	{
		f[d][i]=tmpf[i],tmpf[i]=0;
		g[d][i]=tmpg[i],tmpg[i]=0;
	}
	return;
}
int main()
{
	init();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	dfs(1,1,n);
	printf("%lld",f[1][n]);
	return 0;
}

Measured memory_bytes: 7696
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int n;
double dp[100005][35];

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		
		for(int i = n-1; i >= 0; i--){
			for(int j = 0; j < 35; j++){
				double p = pow(2, -j);
				dp[i][j] = (1-p) * dp[i+1][0];
				if(j+1 < 35) dp[i][j] += p * (dp[i+1][j+1]+1);
			}
		}
		printf("%.11f\n", dp[0][0]);
	}
	
	return 0;
}


Measured memory_bytes: 30592
n=int(input())
a=[int(i) for i in input().split()]
asum2=sum(a)/2
j,k=0,0
for i in range(n):
  j+=a[i]
  if j>=asum2:
    break
for i in range(n):
  k+=a[n-i-1]
  if k>=asum2:
    break
if j-asum2<k-asum2:
  print(int(2*j-2*asum2))
else:
  print(int(2*k-2*asum2))
 
  
 


Measured memory_bytes: 26220
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <cassert>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	
	deque<int> counts;
	int curr = 1;
	for (int i = 1; i != s.size(); ++i)
	{
		if (s[i] == s[i - 1])
			curr++;
		else
		{
			counts.push_back(curr + 1);
			curr = 1;
		}
	}
	counts.push_back(curr + 1);
	
	if (s.front() == '>')
		counts.push_front(1);
	if (s.back() == '<')
		counts.push_back(1);
	
	long long ans = 0;
	for (int i = 0; i != counts.size(); ++i)
		ans += 1LL * counts[i] * (counts[i] - 1) / 2;
	
	for (int i = 0; i != counts.size(); i += 2)
		ans -= min(counts[i], counts[i + 1]) - 1;
	
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 1820
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline long IN(void)
{
  long x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
//https://atcoder.jp/contests/acl1/submissions/16917558
static inline long GCD(long a,long b){return !b?a:GCD(b,a%b);}
//static inline long LCM(long a,long b){return a*b/GCD(a,b);}
static inline long Min(long a,long b){return a<b?a:b;}
static inline long Euclid(long a,long b,long &x,long &y)
{
  if(!b){x=1,y=0;return a;}long ret=Euclid(b,a%b,x,y),t=x;x=y,y=t-(a/b)*y;return ret;
}
static inline long Calc(long i,long j,long ref){long a,b;Euclid(i,j,b,a);b=(b%j+j)%j;return Min(ref,i*b-1);}
int main(void)
{
  long N=IN(),A=N-1;if(N==1){return puts("1"),0;}N*=2;
  for(long i=2;i*i<=N;i++)
  {
    if(N%i){continue;}if(GCD(i,N/i)>1){continue;}A=Calc(i,N/i,A);A=Calc(N/i,i,A);
  }
  return OUT(A),0;
}

Measured memory_bytes: 1532
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;

string grade[8] = { "NA", "E", "D", "C", "B", "A", "AA", "AAA" };
double t500[8] = { 70, 55, 50, 43, 40, 37.5, 35.5, 0 };
double t1000[8] = { 148, 116, 105, 89, 83, 77, 71, 0 };

bool AOJ0123()
{
	double t1, t2;
	if (!(cin >> t1 >> t2)) return false;
	
	REP(i, 8) {
		if (t1 >= t500[i] || t2 >= t1000[i]) {
			cout << grade[i] << endl;
			return true;
		}
	}

	return true;
}

int main()
{

	while (AOJ0123()) {

	}

	return 0;
}

Measured memory_bytes: 3220
n = int(input())
l1 = []
l2 = []
b = 0
ans = float('inf')

def keta(x):
    l = []
    while(x > 0):
        l.append(x%10)
        x //= 10
    return l

for a in range(1, n):
    b = n - a
    l1 = keta(a)
    l2 = keta(b)
    ans = min(ans, sum(l1, sum(l2)))

print(ans)


Measured memory_bytes: 9120
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
const int N = 16;
const int max_states = (1 << N);
int g[N][N];
int dp[max_states][N];
int n, m;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int solve() {
    int states = (1 << n);
    memset(dp, 0x3f3f3f, sizeof dp);
    dp[1][0] = 0; // start from vertex 0;
    for(int state = 0; state < states; state ++) {
        // ex: 110111
        for(int bit = 0; bit < n; bit ++) {
            if(((state >> bit) & 1) == 1) {
                //ex: 110111, bit = 2 => former state: 110011
                int mask = (1 << bit);
                int prev_state = (state ^ mask);
                for(int prev = 0; prev < n; prev ++) {
                    if(((prev_state >> prev) & 1) == 1) {
                        //prev state: 110011, prev: 4 => state: 110111, bit: 2
                        dp[state][bit] = min(dp[state][bit], dp[prev_state][prev] + g[prev][bit]);

                    }
                }
            }
        }
    }
    int res = INT_MAX;
    for(int final= 0; final < n; final ++) {
        res = min(res, dp[states-1][final] + g[final][0]);
    }
    if(res >= 0x3f3f3f) return -1;
    return res;
}

int main()
{
    quickread();
    memset(g, 0x3f3f3f, sizeof g);
    cin >> n >> m;
    int u, v, w;//u->v, weight = w
    for(int i = 0; i < m; i ++) {
        cin >> u >> v >> w;
        g[u][v] = w;
    }
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 7312
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long X;
    cin >> X;

    long long LIMIT = 1e18;

    vector<pair<long long, long long>> A;

    auto pow5 = [&](long long x) {
        return x * x * x * x * x;
    };

    {
        long long x = 0;
        while (true) {
            double p = pow(x, 5);
            if (p > LIMIT) {
                break;
            }
            auto y = pow5(x);
            A.emplace_back(y, x);
            A.emplace_back(-y, -x);
            ++x;
        }
    }

    sort(A.begin(), A.end());
    A.resize(unique(A.begin(), A.end()) - A.begin());

    for (auto& p : A) {
        long long a = p.second;
        long long t = p.first - X;
        auto it = lower_bound(A.begin(), A.end(), make_pair(t, -LIMIT));
        if (it != A.end() && it->first == t) {
            long long b = it->second;
            cout << a << " " << b << "\n";
            return 0;
        }
    }

    assert(0);
    cout << 0 << " " << 0 << "\n";

    return 0;
}

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

namespace Aizu_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputText = Console.ReadLine();
            double inputdata = double.Parse(inputText);

            double outputdata = inputdata * inputdata * inputdata;
            string outputText = outputdata.ToString();

            Console.WriteLine(outputText);
        }
    }
}



Measured memory_bytes: 15912
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define chmax(x,y) x = max(x, y)

int main() {
    int n, W ;
    cin >> n >> W ;
    int dp[105][10005] ;
    int w [n] ;
    int v [n] ;
    rep(i, n){
        cin >> v[i] >> w[i] ;
    }
    rep(i, n){
        rep(j, W+1){
            if(j < w[i]){
                dp[i+1][j] = dp[i][j] ;
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]] + v[i])  ;
            }
        }
    }
    cout << dp[n][W] << endl ; 
} 


Measured memory_bytes: 7024
#include <iostream>
#include <cassert>
#include <fstream>
#include <sstream>
#include <math.h>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <deque>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

int N;
vi L;
ll minCost = 0x01 << 30;
int minValue = -1000;

ll cost(int v) {
	ll ret = 0;

	for (int i : L) {
		ret += POW(i - v);
	}

	if (minCost > ret) {
		minCost = ret;
		minValue = v;
	}

	return ret;
}

//二分探索、バイナリーサーチ
int binarySearch() {
	int left = -100;
	int right = 100;

	REP(i, 1000) {
		int mid = (left + right) / 2;

		ll l = cost(left);
		ll r = cost(right);

		if (l < r) {
			right = mid;
		}
		else {
			left = mid;
		}
	}

	return minCost;
}

int main() {
	cin >> N;

	L.resize(N);
	bool f = true;


	REP(i, N) {
		cin >> L[i];

		if (i != 0 && L[0] != L[i]) {
			f = false;
		}
	}
	
	if (f) {
		cout << "0" << endl;
	}
	else {
		cout << binarySearch() << endl;
	}

	return 0;
}


Measured memory_bytes: 256