akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
#define rep(i,n) for(int i=0;i<(n);i++)

ll N,M;

bool C(ll x){
	if(M/2>=x && N+(M-2*x)/2>=x) return true;
  else return false;
}

int main(){
cin>>N>>M;
ll ub=INF;
ll lb=0;
ll mid;
while(ub-lb>1){
	mid=(ub+lb)/2;
  if(C(mid))lb=mid;
  else ub=mid;
}
cout << lb << endl;
  return 0;
}

Measured memory_bytes: 256
r, g, b, n = map(int,input().split())

ans = 0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        if r*i+g*j > n:
            break
        if (n-r*i-g*j)%b == 0:
            ans += 1
print(ans)

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

int main()
{
    char S[10];

    gets(S);

    if(strcmp(S, "Sunny")==0)printf("Cloudy");
    if(strcmp(S, "Cloudy")==0)printf("Rainy");
    if(strcmp(S, "Rainy")==0)printf("Sunny");

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
main(){
  int n, i, j, e, sum;
  int P[MAX],D[MAX],C[MAX],M[MAX][MAX],key,u;
  
  scanf("%d", &n);
  
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
  
  for(i = 0; i < n; i++){
    C[i] = INFTY;
    P[i] = -1;
    D[i] = 0;
  }
  
  C[0] = 0;

  while(1){
    key = INFTY;
    u = -1;
    
    for(i = 0; i < n; i++){
      if(key > C[i] && D[i] == 0){
	u = i;
	key = C[i];
      }
    }

    if(u == -1){
      break;
    }
    
    D[u] = 1;
    for(j = 0; j < n; j++){
      if(M[u][j] < C[j] && D[j] == 0){
	P[j] = u;
	C[j] = M[u][j];
      }
    }
  }
  sum = 0;
  
  for ( i = 0; i < n; i++ ){
    if ( P[i] != -1 ) sum += M[i][P[i]];
  }
  
  printf("%d\n", sum);
  
  return 0;
}

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

int main(){
  int n, m;
  cin >> n;
  vector<string> blue(n);
  for(int i=0;i<n;++i){
    cin >> blue.at(i);
  }
  
  cin >> m;
  vector<string> red(m);
  for(int i=0;i<m;++i){
    cin >> red.at(i);
  }
  
 int max=0;
 for(int i=0;i<n;++i){
   int count=1;
   if(blue.at(i)=="") continue;
    for(int j=i+1;j<n;++j){
      if(blue.at(i)==blue.at(j)){
        count++;
        blue.at(j) = "";
      }
    }
   
   for(int j=0;j<m;++j){
     if(blue.at(i)==red.at(j)){
       count--;
     }
  }
   if(count>max) max=count;
 }
   cout << max << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <math.h>
#include <algorithm>
#include<queue>
#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)

main(){
    int P, Q, R, d;
    int a, b, c;
    cin >> P >> Q >> R;
    a = min(P,Q);
    b = min(Q,R);
    c = min(P,R);
    
    if(a==b){cout << c + b << endl;}
    else if (b==c){cout << a + c << endl;}
    else {cout << b+c <<endl; }
}

Measured memory_bytes: 256
from collections import defaultdict as dd

dic = dd(int)
N = int(input())
a = list(map(int,input().split()))
for i in range(N):
    dic[str(a[i])] += 1

res = 0
# まずN個出す
for v in dic.values():
    res += v*(v-1)//2

res2 = [0]*N
for i in range(N):
    tmp = dic[str(a[i])]
    print(res-(tmp-1))




Measured memory_bytes: 27724
#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
#define int long long
using namespace std;
typedef pair<int,int> pii;

int a;

signed main()
{
    cin >> a;
    cout << fixed << setprecision(6) << (double)(a*a*a)/27 << '\n';
}

Measured memory_bytes: 3784
a,b,c = map(int,input().split())
same_count = 0
if a == b:
	same_count += 1
if a == c:
	same_count += 1
if b == c:
	same_count += 1
	
if same_count == 0:
	print(3)
elif same_count == 1:
	print(2)
else:
	print(1)

Measured memory_bytes: 3060
import sys
# -*- coding: utf-8 -*-

def multiple(target,count):
    length = len(target)
    result = []
    if length == 1:
        return count
    for i in range(1,length):
        prefix = int(target[:i])
        suffix = int(target[i:])
        result.append(prefix*suffix)
    return multiple(str(max(result)), count+1)

count=int(input())
for i in range(count):
    print(multiple(input(),0))



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 1e5, M = 7 + 1e9;
int n, k, a[100], dp[N+1];
bool cal(int sum){
	if(sum < a[0])
		return 0;
	int &ret = dp[sum];
	if(~ret)
		return ret;
	ret = 0;
	f(i, 0, n)
		if(sum >= a[i])
			ret |= !cal(sum-a[i]);
	return ret;
}
int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n >> k;
	f(i, 0, n)
		cin >> a[i];
	cout << (cal(k) ? "First" : "Second");

}

Measured memory_bytes: 5376
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import itertools
import sys


UNDET_POINT = (-1, -1)


class RecursiveDepthFirstSearch(object):

    def __init__(self, width, height, tiles):
        self.width = width
        self.height = height
        self.tiles = tiles
        self.reached = [array.array(
            "B", (False for j in range(height))) for i in range(width)]
        self.start_tile = UNDET_POINT
        for x, y in itertools.product(range(width), range(height)):
            if tiles[x][y] == "@":
                self.start_tile = (x, y)
                break

    def search(self, x, y):
        if x < 0 or self.width <= x or y < 0 or self.height <= y:
            pass
        elif self.tiles[x][y] == "#":
            pass
        elif self.reached[x][y]:
            pass
        else:
            self.reached[x][y] = True
            self.search(x + 1, y)
            self.search(x - 1, y)
            self.search(x, y + 1)
            self.search(x, y - 1)

    def count_reachable_tiles(self):
        self.search(*self.start_tile)
        reachable_tiles = sum([self.reached[x][y] for x, y in itertools.product(
            range(self.width), range(self.height))])
        return reachable_tiles


if __name__ == "__main__":
    sys.setrecursionlimit(10000)
    while True:
        width, height = map(int, input().split())
        if width == 0 and height == 0:
            break
        else:
            tiles = [x for x in zip(*[input() for y in range(height)])]
            dfs = RecursiveDepthFirstSearch(width, height, tiles)
            print(dfs.count_reachable_tiles())

Measured memory_bytes: 7940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;

int n, X, Y;
stack<int> s;
vector<pair<int, int> > v[4];

bool check(int x, int y)
{
	return x == 0 || x == X || y == 0 || y == Y;
}
void put(int x, int y, int id)
{
	if(x == 0 && y <= Y - 1) v[0].push_back(make_pair(y, id));
	if(y == Y && x <= X - 1) v[1].push_back(make_pair(x, id));
	if(x == X && y >= 1) v[2].push_back(make_pair(-y, id));
	if(y == 0 && x >= 1) v[3].push_back(make_pair(-x, id));
}



int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> X >> Y >> n;
	for(int i = 1; i <= n; i++)
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if(check(x1, y1) && check(x2, y2))
			put(x1, y1, i), put(x2, y2, i);
	}
	for(int i = 0; i < 4; i++)
		sort(v[i].begin(), v[i].end());
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < v[i].size(); j++)
		{
			int id = v[i][j].second;
			if(!s.empty() && s.top() == id)
				s.pop();
			else
				s.push(id);
		}
	if(s.empty())
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 2520
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

int main()
{
	INT a, b;
	cin >> a >> b;

	if (a >= 13)
	{
		cout << b << endl;
	}
	else if (a >= 6)
	{
		cout << b / 2 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int a[N];
int cmp(int a,int b){
    return a>b;
}
typedef long long ll;
int main(){

    ll a,b;
    cin>>a>>b;
    cout<<min(a%b,abs(a%b-b));
}


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

int main(){
    string s;
    cin >> s;
    int count = 0;
    int ans = 0;
    for(int i =0;i < s.size();i++){
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            count += 1;
            ans = max(ans,count);
    }else{
        count = 0;
    }
}
cout << ans << endl;
}

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

typedef pair<int,int> pii;
#define f first
#define s second
#define mp make_pair
#define sz(x) ((int)x.size())

const int N = 1e5 + 5;

map<int,int> maps[2];

vector<pii> v[2];

int main() {
  int n;
  scanf("%d",&n);

  for(int i = 1; i <= n; i++) {
    int x;
    scanf("%d",&x);
    maps[i%2][x]+=1;
  }

  for(int j = 0; j < 2; j++) {
    for(pii cur : maps[j]) {
      v[j].push_back(mp(cur.s, cur.f));
    }
    v[j].push_back(mp(0,0));
    sort(v[j].begin(), v[j].end());
  }

  int ans = 1e9;
  for(int i=sz(v[0])-1; i>=sz(v[0])-2; i--) {
    for(int j=sz(v[1])-1; j>=sz(v[1])-2; j--) {
      if (v[0][i].second != v[1][j].second) {
        ans = min(ans, n-v[0][i].first-v[1][j].first);
      }
    } 
  }

  printf("%d\n",ans);

  return 0;
}

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

using ll = long long;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> K(Q); cin >> K;

    vector<int> sumd(N), summ(N), ic;
    vector<ll> sumdm(N);
    sumd[0] = S[0] == 'D';
    summ[0] = S[0] == 'M';
    sumdm[0] = 0;
    for (int i = 1; i < N; i++) {
        char ch = S[i];
        sumd[i] = sumd[i-1] + (ch == 'D');
        summ[i] = summ[i-1] + (ch == 'M');
        sumdm[i] = sumdm[i-1] + (ch == 'M' ? sumd[i] : 0);
        if (ch == 'C') ic.push_back(i);
    }

    for (const int& k : K) {
        ll ans = 0;
        for (const int& i : ic) {
            ll dm = sumdm[i];
            int p = i-k;
            if (p >= 0) {
                dm -= sumdm[p];
                dm -= (ll)sumd[p] * (summ[i] - summ[p]);
            }
            ans += dm;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 24088
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

ll modPow(ll base, ll ex, ll m) {
	ll ret = 1;
	while(ex){
		if(ex & 1){
			ret = ret * base % m;
		}
		ex >>= 1;
		base = base * base % m;
	}
	return ret;
}
vector<ll> mFacts, mInvFacts;
ll modFact(int n){ return mFacts[n]; }
ll modInvFact(int n){ return mInvFacts[n]; }
ll modInv(int n, ll m){ return modPow(n, m - 2, m); }
ll modC(int n, int k, ll m){ return modFact(n) * modInvFact(k) % m * modInvFact(n - k) % m; }
void init(int n, ll m){
    mFacts.resize(n + 1);
    mInvFacts.resize(n + 1);
    mFacts[0] = 1;
    for(int i = 1; i <= n; i++){
        mFacts[i] = mFacts[i - 1] * i % m;
    }
    mInvFacts[n] = modInv(mFacts[n], m);
    for(int i = n - 1; i >= 0; i--){
        mInvFacts[i] = mInvFacts[i + 1] * (i + 1) % m;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    init(2e5, M);
    int n, m;
    cin >> n >> m;
    map<int, int> fs;
    for(int i = 2; i <= sqrt(m); i++){
        while(m % i == 0){
            fs[i]++;
            m /= i;
        }
    }
    if(m > 1){
        fs[m]++;
    }
    printde(fs);
    ll ans = 1;
    for(auto& p : fs){
        ans = ans * modC(n - 1 + p.second, p.second, M) % M;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3328
n = input()
l = len(n)
n = int(n)
b = n
a = [0]*l
for i in range(l-1,-1,-1):
    a[i] = n // 10**i
    n = n - a[i]*10**i
s = sum(a)
if b % s == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
    int Y, M, D;
    scanf("%4d/%2d/%2d", &Y, &M, &D);
    if (Y < 2019 || (Y == 2019 && M <= 4)) printf("Heisei\n");
    else printf("TBD\n");

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int get() { int r; cin >> r; return r; }
signed main() {
	double x0, y0, r; int q;
	cin >> x0 >> y0 >> r >> q;
	for1(i, q) {
		double x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		double p = ((y2 - y1) * (x0 - x1) - (x2 - x1) * (y0 - y1)) / ((x2 - x1) * (x1 - x2) + (y2 - y1) * (y1 - y2));
		p = -p;
		double x4 = x0 + p * (y1 - y2), y4 = y0 - p * (x1 - x2);
		double k = sqrt(r * r - (x0 - x4) * (x0 - x4) - (y0 - y4) * (y0 - y4)) / sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
		if (x1 < x2) { swap(x1, x2); swap(y1, y2); }
		else if (x1 == x2 && y1 < y2) { swap(x1, x2); swap(y1, y2); }
		printf("%.10f %.10f %.10f %.10f\n", x4 - k * (x1 - x2), y4 - k * (y1 - y2), x4 + k * (x1 - x2), y4 + k * (y1 - y2));
	}
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N,K;
  cin >>N>>K;
  vector<int> h(N);
  rep (i, N) cin >> h[i];//h[i]は足場i+1の高さ。
  vector<int> dp(N,1000000000);
  //vector dp[i]には、足場i+1まで到達した場合の最小コストを記入する。
  dp[0]=0;//足場1にいるとき(i=0)、コストは0
  rep(i,N){
      for(int j=1;j<=K;j++){//足場2以上のとき(i>=1)、i-1, i-2...i-Kの時を調べる
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
      }
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<climits>
 
using namespace std;
 
const int MAX_N=1<<17; 
int n,bit[MAX_N+1];
 
int sum(int i){
  int s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}
 
void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}
 
int main(void){
 
  int q,com,a,b;
 
  cin >> n >> q;
  n++;
  while(q--){
    cin >> com >> a >> b;
    if(com)cout << sum(b+1)-sum(a) << endl;
    else add(a+1,b);
  }
}


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

MOD = 2019  # type: int

def solve(L: int, R: int):
    if(R-L >= 2019):
        print(0)
    else:
        m = 2020
        for i in range(L,R+1):
            for j in range(i+1,R+1):
                m = min(m,(i*j)%2019)
        print(m)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(L, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long ld;
typedef pair<ld,ld> mp;
#define inf 1e9
typedef pair<ld,mp> mmp;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}

int main(){
	int n,k;
	cin>>n>>k;
	vector<mp> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
	}
	bool f = false;
	
	for(int i=0;i<n;i++){
		map<mp,int> st;
		if(!f) for(int j=i+1;j<n;j++){
		    	if(i==j)continue;
		    	ld dx = a[i].first-a[j].first;
			ld dy = a[i].second-a[j].second ;
			int d = 1;
			if(dx==0)dy=1;
			else if(dy==0)dx=1;
			else{
				if(dx<0){
					dx*=-1;
					dy*=-1;
				}	
				 d = gcd(abs((int)dx),abs((int)dy ));
				 dx/=d;
				 dy/=d;
			}
			if(++st[{dx,dy}]>=k-1){
				f= true;
				break;
			}
			
		}
	}
	if(f)cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}



Measured memory_bytes: 3340
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ii pair<int,int>
#define setin set.insert
using namespace std;

void solve()
{
   ll n,ans=0;
   cin >> n;
   for(int i=1;i<=n;i++)
       ans+=((n/i)*((n/i)+1)*i)/2;
   cout << ans << endl;
}

int main()
{

    solve();

    return 0;
}


Measured memory_bytes: 3588
from collections import  deque
import sys
import bisect
# import math
import itertools
from queue import deque
# from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

# def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
A = [0 for _ in range(N)]
xx = [[] for _ in range(N)]
yy = [[] for _ in range(N)]

for i in range(N):
    A[i] = inp()
    for _ in range(A[i]):
        x, y = inp_list()
        xx[i].append(x)
        yy[i].append(y)

# ↑ inputs
# ↓ main process

# {0, 1, ..., N-1} の集合の bit 全探索
ans = 0
for bit in range(1 << N):
    """
        例： bit == 10 のとき、2進数では 001010 
            右から人 1, 2, ..., 6 と対応させる。
    """
    is_inconsistent = False
    # 整数 bit を２進数表示し、右から 1/0 を True/False に置換
    is_honest = [(bit >> i) & 1 for i in range(N)]
    for i in range(N):
        if not is_honest[i]: continue
        for (x, y) in zip(xx[i], yy[i]):
            if is_honest[x - 1] != y:
                is_inconsistent = True # 矛盾
    if not is_inconsistent:
        ans = max(ans, sum(is_honest))
print(ans)


Measured memory_bytes: 3944
n, m, q = map(int, input().split())

abcd = [list(map(int, input().split())) for _ in range(q)]
from itertools import combinations_with_replacement as cwr
AList = list(cwr(range(1, m+1), n))


maxPoint = 0
for A in AList:
  point = 0
  for abc in abcd:
    a = abc[0]
    b = abc[1]
    c = abc[2]
    d = abc[3]
    if A[b-1] - A[a-1] == c:
      point += d
  if point > maxPoint:
    maxPoint = point
print(maxPoint)

Measured memory_bytes: 21484
#include<iostream>
#include<vector>
using namespace std;
int main() {
    string s, res;
    int k;
    cin >> s;
    cin >> k;
    for (char c = 'a'; c <= 'z' && k > 0; ++c) {
        vector<int> v;
        for (int i = 0; i < s.size(); ++i) if (s[i] == c) v.push_back(i);
        if (v.size() == 0) continue;
        else if (k == 1) {
            cout << c << endl;
            return 0;
        }
        res = c, --k;
        for (int j = 1; k > 0; ++j, --k) {
            char min = 'z';
            vector<int> _v;
            for (auto itr = v.begin(); itr != v.end(); ++itr) {
                if (*itr+j >= s.size()) continue;
                char _c = s[*itr+j];
                if (_c == min) _v.push_back(*itr);
                else if (_c < min) {
                    min = _c;
                    _v = {*itr};
                }
            }
            if (_v.size() == 0) break;
            else {
                res += min;
                v = _v;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
import  java.util.*;
import java.math.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int m, money, years, n, tanri_or_fukuri, charge;
	static double rate;
	static int result;
	public static void main(String[] args) {
		m = sc.nextInt();
		for(int i = 0; i < m; i++){
			result = 0;
			read();
			System.out.println(result);
		}
	}
	static void read(){
		money = sc.nextInt();
		years = sc.nextInt();
		n = sc.nextInt();
		for(int i = 0; i < n; i++){
			tanri_or_fukuri = sc.nextInt();
			rate = sc.nextDouble();
			charge = sc.nextInt();
			solve();
		}
	}
	static void solve(){
		int A = money;
		int B = (int)(double)(money*rate);
		int C = 0;
		int res = 0;
		if(tanri_or_fukuri == 0){//P
			for(int i = 0; i < years; i++){
				res = A - charge;
				C = C + B;
				A = res;
				B = (int)(double)(A *rate);
			}
		}else{//¡
			for(int i = 0; i < years; i++){
				res = A + B - charge;
				A = res;
				B = (int)(double)(A *rate);
			}
		}
		result = Math.max(result, res+C);
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <cmath>
#include <limits>
#include <stack>
#define ll long long
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int ans=1000000000,sum=0;
    for(int i=-100;i<=100;i++){
        for(int j=0;j<N;j++){
            sum = sum + (i-a[j])*(i-a[j]);
        }
        ans = min(ans,sum);
        sum = 0;
    }
    cout << ans << endl;
}

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

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

    //formatcheck
    int A,B;
    A = (S[0] - 0x30)*10 + (S[1] - 0x30);
    B = (S[2] - 0x30)*10 + (S[3] - 0x30);

    while(1){
        //AMBIGUOUS ?
        if((A > 0 && A <= 12) && (B > 0 && B <= 12)) {
            cout << "AMBIGUOUS" << endl;
            break;
        }
        //YYMM?
        if(B > 0 && B <= 12){
            cout << "YYMM" << endl;
            break;
        }
        //MMYY?
        if(A > 0 && A <= 12){
            cout << "MMYY" << endl;
            break;
        }
        //NA
        cout << "NA" << endl;
        break;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

long long kaidan[10000000];

void kaical(long long n){
	kaidan[0] = 1;
	for(long long i = 1; i < n; i++){
		kaidan[i] = kaidan[i-1] * i;
		kaidan[i] %= DIV;
	}
}

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= DIV;
		}
		ori *= ori;
		ori %= DIV;
		po >>= 1;
	}
	return res;
}

//nCk
long long combination(long long n, long long k){
	if(n == 0 && k == 0)return 1;
	if(n < k || n < 0)return 0;
	long long n_kai = kaidan[n];
	long long k_kai = kaidan[k];
	long long nmk_kai = kaidan[n-k];

	long long ans = n_kai * modpow(k_kai, DIV - 2);
	ans %= DIV;
	ans *= modpow(nmk_kai, DIV-2);
	ans %= DIV;
	return ans;
}

int main(){
	ll N, K;
	cin >> N >> K;

	kaical(N + 5);


	for(ll i = 1; i <= K; i++) {
			cout << (combination(N-K+1, i) * combination(K-1, i -1)) %DIV << endl;
	}
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int a,b;

int main(){
	cin>>a>>b;
	if(a<=0&&b>=0){
		cout<<"Zero"<<endl;
		return 0;
	}
	if(a>0||(b-a)%2==1){
		cout<<"Positive"<<endl;
		return 0;
		
	}
	cout<<"Negative"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  if(x + y == 15)
    cout << '+' << endl;
  else if (x * y == 15)
    cout << '*' << endl;
  else
    cout << 'x' << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    int a[100];
    
    int sum = 0;
    int diff_min = 200;
    int min_index;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
    
    for(int i = 0; i < N; i++){
        if(diff_min > abs(sum - N*a[i])){
            diff_min = abs(sum - N*a[i]);
            min_index = i;
        }
    }
    cout << min_index << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
typedef double dbl;
dbl x[3], y[3], A, mx, my, ansx, ansy;
char c;

int main() {
	while (cin >> x[0] >> c >> y[0]) {
		for (int i = 1; i <= 2; i++) {
			cin >> c >> x[i] >> c >> y[i];
		}
		if (x[1] == x[0]) {
			ansx = (-1) * x[2];
			ansy = y[2];
		}
		else {
			A = (y[1] - y[0]) / (x[1] - x[0]);
			mx = (A*A*x[0] + x[2] + A*(y[2] - y[0])) / (A*A + 1);
			my = A*(mx - x[0]) + y[0];
			ansx = 2 * mx - x[2];
			ansy = 2 * my - y[2];
		}
		printf("%.6f %.6f\n", ansx, ansy);
	}
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    cout << min( A * N, B ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000

void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c;
  cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0) cout<<0<<endl;
  else {
    cout<<min(a*b,min(b*c,a*c))<<endl;
  }
}
int main(){
  solve();
  return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for (int i=0;i<n;++i) cin >> a[i];
  reverse(a.begin(),a.end());  
  vector<int> lab;
  int num=1;
  lab.push_back(a[0]);
  for (int i=1;i<n;++i) {
    if (lab[num-1]<=a[i]) {
      lab.push_back(a[i]);
      num+=1;
    } else if (lab[0]>a[i]) {
      lab[0]=a[i];
    } else {
      int j=0;
      while(a[i]>=lab[j]){
        j+=1;
      }
      lab[j]=a[i];
    }
  }
  cout<<num<<endl;
}



Measured memory_bytes: 1276
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_3_C-in10.txt"));
		// while (scan.hasNext()) {
		boolean[] d = new boolean[(int) Math.pow(4, 13)];

		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			String s = scan.next();
			if (s.equals("insert"))
				d[idxno(scan.next())] = true;
			if (s.equals("find"))
				if (d[idxno(scan.next())])
					System.out.println("yes");
				else
					System.out.println("no");
		}

		scan.close();
		System.exit(0);
	}

	private static int idxno(String s) {
		int r = 1;
		for (int i = 0; i < s.length(); i++) {
			r <<= 2;
			switch (s.charAt(i)) {
			case ('A'):
				break;
			case ('C'):
				r |= 1;
				break;
			case ('G'):
				r |= 2;
				break;
			case ('T'):
				r |= 3;
				break;
			}
		}
		return r;
	}
}

Measured memory_bytes: 231012
#include <cstdio>
#include <iostream>
using namespace std;
using i64 = int64_t;

int main() {
	i64 a, b, c;
	scanf("%I64ld %I64ld.%I64ld", &a, &b, &c);
	i64 d = a * b * 100 + a * c;
	printf("%I64ld", d / 100);
	return 0;
}


Measured memory_bytes: 3796
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 1000000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

//try thinking from a different angle after spending some time
//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
    
	speed
	//global var
	int x, y;cin>>x>>y;
	if(y%2){cout<<"No";return 0;}
	y/=2;
	int b=y-x;
	int a=x-b;
	if(a>=0 and b>=0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define rep(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

int N, A[3][3], b[10];
bool appear[3][3];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) cin >> A[i][j];
	}
	cin >> N;
	for (int i = 0; i < N; i++) cin >> b[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			appear[i][j] = false;
			for (int k = 0; k < N; k++) {
				if (A[i][j] == b[k]) appear[i][j] = true;
			}
		}
	}
	string ANS = "No";
	for (int i = 0; i < 3; i++) {
		if (appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
	}
	for (int i = 0; i < 3; i++) {
		if (appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
	}
	if (appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes";
	if (appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes";
	cout << ANS << endl;
	return 0;

}

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

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

using namespace std;

set<ui> brokenFloors{};
vector<ll> answers{};
constexpr ll MOD = 1000000007;

ll recursion(ui floor)
{
	if (brokenFloors.find(floor) != brokenFloors.end())
	{
		answers[floor] = 0;
	}
	else if (floor == 1
		|| floor == 0)
	{
		answers[floor] = 1;
	}
	else if (answers[floor] == -1)
	{
		answers[floor] = (recursion(floor - 1) + recursion(floor - 2)) % MOD;
	}

	return answers[floor];
}

ull solve(void)
{
	ui N{}, M{};
	cin >> N >> M;

	for (ui i = 0; i < M; ++i)
	{
		ui floor;
		cin >> floor;
		brokenFloors.insert(floor);
	}

	answers.resize(N + 1, -1);

	return recursion(N);
}

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);

	auto ans = solve();
	cout << ans << endl;

	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    sort(ALL(A));
    cout << A[N-1] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 3596
import math
k = int(input())
a = (k+1)*k/2
b = 0
for i in range(1,k-1):
    for j in range(i+1,k):
        for l in range(j+1,k+1):
            b += math.gcd(math.gcd(i,j),l)
b = b*6
c = 0
for i in range(1,k):
    for j in range(i+1,k+1):
        c += math.gcd(i,j)
c = c*6
print(int(a+b+c))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int imax = INT_MAX;
int imin = INT_MIN;
ll llmax = LLONG_MAX;
ll llmin = LLONG_MIN;

int main()
{
	int mi(imax);
	int w, a, b;
	cin >> w >> a >> b;
	if ((b >= a && b <= a + w) || (b + w >= a && b + w <= a + w))
		cout << 0 << endl;
	else if ((a >= b && a <= b + w) || (a + w >= b && a + w <= b + w))
		cout << 0 << endl;
	else{
		mi = min(abs(b - a), mi);
		mi = min(abs(b - a - w), mi);
		mi = min(abs(a - b - w), mi);
		cout << mi << endl;
	}
	return 0;
}

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


int main(){
  int n,i;
  cin >> n;
  vector<long long> a(n);
  vector<long long> s(n+1,0);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  for(i=0;i<n;++i){
    s[i+1]=s[i]+a[i];
  }
  map<long long,long long> mp;
  for(i=0;i<n+1;i++){
    mp[s[i]]++;
  }
  long long ans=0;
  for(auto p : mp){
    long long num=p.second;
    ans=ans+(num*(num-1))/2;
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 15872
# -*- coding: utf-8 -*-
def is_kaibun(s):
    r = list(s)
    r.reverse()
    str_r = "".join(r)
    if s == str_r:
        return True
    else:
        False

str_s = input()
n = len(str_s)
part_str_a = str_s[0:(n-1)//2]
part_str_b = str_s[(n+3)//2-1:n]
result = True


if not is_kaibun(str_s):
    result = False
if not is_kaibun(part_str_a):
    result = False
if not is_kaibun(part_str_b):
    result = False

if result:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	int cnt = 0, sz = (int)s.size();
	for (int i = 0; i < sz - i - 1; i++) {
		cnt += (s[i] != s[sz - i - 1]);
	}

	cout << cnt << "\n";

	return 0;
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
  int n,d[100],i,cnt=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
   scanf("%d",&d[i]);
  }
  qsort(d,n,sizeof(int),compare_int);
  for(i=0;i<n-1;i++){
   if(d[i]!=d[i+1]) ++cnt;
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,i,j,ans;
  cin>>N;
  ans=1000000000;
  vector<int>X(N);
  for(i=0;i<N;i++)
    cin>>X[i];
  sort(X.begin(),X.end());
  for(j=X[0];j<=X[N-1];j++){
    int sum=0;
    for(i=0;i<N;i++){
      sum+=(X[i]-j)*(X[i]-j);
    }
    if(sum<=ans)
    ans=sum;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){
  int N; cin >> N;
  cout << N * N * N << endl;
  

  return 0;
}


Measured memory_bytes: 256
/*
Á·Ï°Ìâ£ºBall_AOJ 0033
*/
#include <cstdio>
#include <cstring>
using namespace std;

int a[15];
int mark[15];
int count;

void dfs(int x)
{
	mark[x] = 1;
	if(x==9)
	{
		count++;
		return ;
	}
	for(int i=x+1; i<=9; i++)
		if(a[x]<a[i]&&mark[i]==0)
		{
			return dfs(i);
		}
		else
		{
			if(i==9)
				count++;
			continue;
		}
	return ;
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		count=0;
		bool flag=false;
		memset(mark, 0, sizeof(mark));
		for(int i=0; i<10; i++)
			scanf("%d", &a[i]);
		for(int i=0; i<10; i++)
		{
			if(mark[i]==0)
				dfs(i);
		}
		if(count<=2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    
    x -= a;
    int num(x/b);
    if(num==0)  cout << x << endl;
    else{
        cout << x - num*b << endl;
    }

    return 0;
}

Measured memory_bytes: 3536
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit()
#include <stdbool.h>

#define MAX_V 10000
#define MAX_E 100000

typedef struct list_tbl
{
	int t;
	int next;
} list_t;

int V;
int G[MAX_V];
list_t list[MAX_E];
bool visited[MAX_V];
int out[MAX_V];
int ix;

void
cleanup(int ecode)
{
	exit(ecode);
}

void
dfs(int v)
{
	visited[v] = true;
	for (int l = G[v]; l != -1; l = list[l].next)
	{
		int u = list[l].t;
		if (!visited[u])
			dfs(u);
	}

	out[--ix] = v;
}

void
tsort()
{
	for (int v = 0; v < V; ++v)
		visited[v] = false;

	for (int v = 0; v < V; ++v)
	{
		if (!visited[v])
			dfs(v);
	}
}

int
main(int argc, char** argv)
{
	scanf("%d", &V);
	for (int i = 0; i < V; ++i)
		G[i] = -1;

	int E;
	scanf("%d", &E);


	int nl = 0;
	for (int i = 0; i < E; ++i)
	{
		int s, t;
		scanf("%d %d", &s, &t);
		if (nl >= MAX_E)
		{
			fprintf(stderr, "graph area overflow. size:%d\n", MAX_E);
			cleanup(1);
		}

		list[nl].t = t;
		list[nl].next = G[s];
		G[s] = nl++;
	}

	ix = V;
	tsort();

	for (; ix < V; ++ix)
		printf("%d\n", out[ix]);

	return 0;
}

Measured memory_bytes: 2088
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

ll n, a[3010], dp[3010][3010];
bool used[3010][3010];

ll dfs(ll l, ll r) {
  if(l+r == n) return 0;
  if(used[l][r]) return dp[l][r];
  ll ret;
  if((l+r)%2) {
    ret = LLINF;
    chmin(ret, dfs(l+1, r) - a[l]);
    chmin(ret, dfs(l, r+1) - a[n-1-r]);
  } 
  // 先手
  else {
    ret = -LLINF;
    chmax(ret, dfs(l+1, r) + a[l]);
    chmax(ret, dfs(l, r+1) + a[n-1-r]);
  }
  used[l][r] = true;
  return dp[l][r] = ret;
}

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

  cin >> n;
  REP(i, n) cin >> a[i];

  cout << dfs(0, 0) << endl;

  return 0;
}


Measured memory_bytes: 78464
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,a[N],vis[N],ans,k,b[N];
vector<int>s[N];
void dfs(int x)
{
	int tmp=1;
	for (int i=0;i<s[x].size();i++)
	{
		dfs(s[x][i]);
		tmp=max(tmp,b[s[x][i]]+1);
	}
	if (tmp==k&&a[x]!=1)
	{
		//cout<<x<<endl;
		b[x]=0;
		ans++;
	}
	else b[x]=tmp;
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (i!=1) s[a[i]].push_back(i);
	}
	if (a[1]!=1) a[1]=1,ans++;
	dfs(1);
	printf("%d\n",ans);
}	

Measured memory_bytes: 11136
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

int main()
{
	int r,g,b,n;
	cin >> r >> g >> b >> n;
	long long count=0;

	for(int i=0;i<=n/r;i++)
		for(int j=0;j<=n/g;j++)
			if((n-i*r-j*g)%b==0 and n-i*r-j*g>=0)
					count++;
	cout << count << endl;


}


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

B = []

for i in range(len(A)):
    if i == 0:
        B.append(A[i])
    else:
        if A[i] < B[i-1]:
            B.append(B[i-1])
        else:
            B.append(A[i])

diff = map(lambda a,b: a - b, B,A)
print(sum(list(diff)))

Measured memory_bytes: 32380
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int n, k, q; cin >> n >> k >> q;
	vector<int> a(n+1);
	rep(i, 0, n) cin >> a[i];
	a[n] = -1; int ans = inf;
	rep(i, 0, n) {
		vector<int> b, c;
		rep(j, 0, n+1) {
			if (a[j] < a[i]) {
				sort(b.begin(), b.end());
				rep(l, 0, (int)b.size() - k + 1) c.push_back(b[l]);
				b = {};
			}
			else b.push_back(a[j]);
		}
		if (c.size() < q) continue;
		sort(c.begin(), c.end());
		ans = min(ans, c[q - 1] - c[0]);
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;int main(){int a,b,t=0,c[2][1010]={0};string s;while(getline(cin,s)){if(s=="")t++;a=0,b=0;while(s[b]>45)a*=10,a+=s[b]-48,b++;c[t][a]++;}for(t=0;t<1010;t++){a=c[0][t],b=c[1][t];if(a&&b)cout<<t<<" "<<a+b<<endl;}return 0;}

Measured memory_bytes: 2980
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<int,int> pii;
map<string,int>M;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint n;
    cin>>n;
    vector<lint> V(n);
    for(lint i=0;i<n;i++) cin>>V[i];
    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    lint sum=V[0];
    lint pos=2;
    for(lint i=1;i<n;i++){
        if(pos!=n){
            sum+=V[i];
            pos++;
        }
        if(pos!=n){
            sum+=V[i];
            pos++;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 4788
#include <stdio.h>
#include <string.h>
#include <ctype.h>

char table[8][10] = {
	{ '*', '*', '*', '*', '*', ' ', ' ', ' ', ' ', ' ' },
	{ ' ', ' ', ' ', ' ', ' ', '*', '*', '*', '*', '*' },
	{ '=', '=', '=', '=', '=', '=', '=', '=', '=', '=' },
	{ ' ', '*', '*', '*', '*', ' ', '*', '*', '*', '*' },
	{ '*', ' ', '*', '*', '*', '*', ' ', '*', '*', '*' },
	{ '*', '*', ' ', '*', '*', '*', '*', ' ', '*', '*' },
	{ '*', '*', '*', ' ', '*', '*', '*', '*', ' ', '*' },
	{ '*', '*', '*', '*', ' ', '*', '*', '*', '*', ' ' },
};

int main()
{
	char str[7], *p;
	int tmp[7];
	int i = 0, j = 0, len, mid = 0, flg = 0;

	while ( fgets( str, sizeof( str ), stdin ) ) {
		p = str; i = j = 0;
		if ( flg == 0 ) {
			flg = 1;
		} else {
			printf( "\n" );
		}

		for ( i = 0 ; i < strlen( str )-1 ; i++ ) {
			if ( isdigit( *p ) ) {
				tmp[i] = *p - '0'; 
				p++;
			}
		}

		len = strlen( str ) - 1; mid = 5 - len;
		for ( i = 0 ; i < 8 ; i++ ) {
			for ( j = 0 ; j < mid ; j++ ) {
				printf( "%c", table[i][0]  );	
			}
			for ( j = 0 ; j < len ; j++ ) {
				printf( "%c", table[i][tmp[j]] );
			}
			printf( "\n" );
		}
	}
	return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<long long> ans(n,0);
  for(int i=0; i<n-1; ++i){
    int c, s, f;
    cin >> c >> s >> f;
    for(int j=0; j<=i; ++j){
      ans[j] = max(ans[j], (long long)s);
      if(ans[j] % f >0){
        ans[j] /= f;
        ++ans[j];
        ans[j] *= f;
      }
      ans[j] += c;
    }
  }
  for(int i=0; i<n; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    ll n;cin >>n;
    vector<ll> a(n);
    rep(i,n)cin >>a[i];
    vector<ll> s(n+1);
    rep(i,n){
        s[i+1] = s[i]+a[i];
    }
    ll dif = LINF;
    for(ll i = 1;i <n;i++){
        ll left = s[i];
        ll right = s[n]-s[i];
        ll tmp = abs(left-right);
        dif = min(tmp,dif);
    }
    cout <<dif<<endl;

}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd


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

    int2(n, k);
    vi data(n);
    rep(i, n) {
        cin >> data[i];
    }

    vi table(k+2, 0);
    table[k] = 1;
    rep(i, n) {
        vi nxt(k+2, 0);
        rep(j, k+1) {
            nxt[max(0ll, j - data[i])] += table[j];
            nxt[j+1] -= table[j];
        }
        Rep(j, nxt.size()) {
            nxt[j] += nxt[j-1];
        }
        rep(j, nxt.size()) {
            nxt[j] %= MOD;
        }
        table = nxt;
    }

    cout << table[0] << endl;

    return 0;
}


Measured memory_bytes: 1792