akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline


N,Q=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(N-1)]
PLUS=[list(map(int,input().split())) for i in range(Q)]

SCORE=[0]*(N+1)
for p,x in PLUS:
    SCORE[p]+=x

ELIST=[[] for i in range(N+1)]

for x,y in EDGE:
    ELIST[x].append(y)
    ELIST[y].append(x)
#print(ELIST)

from collections import deque
Q=deque([1])

USED=[0]*(N+1)
USED[1]=1
#USED = [0, 1, 0, 0, 0] Ex1
#SCORE = [0, 100, 10, 1, 0] Ex1
#ELIST = [[], [2], [1, 3, 4], [2], [2]] Ex1

while Q:
    x=Q.pop()

    for to in ELIST[x]:
        if USED[to]==0:
            USED[to]=1
            SCORE[to]+=SCORE[x]
            Q.append(to)

print(*SCORE[1:])


Measured memory_bytes: 124508
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,k = inpl()
value = [[0 for _ in range(m)] for i in range(n)]
for _ in range(k):
    a,b,c = inpl()
    value[a-1][b-1] = c
dp = [0] * (4*(m+1)*(n+1))
def ind(i,j,k): 
    return 4*(m+1)*i + 4*j + k
for i in range(n):
    for j in range(m):
        for k in range(3)[::-1]:
            dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j])
        for k in range(4):
            dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)])
            dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)])
# print(dp)
mx = 0
for k in range(4):
    mx = max(mx, dp[ind(n-1,m-1,k)])
print(mx)

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

#ifndef _WIN32
    #define getchar getchar_unlocked
#endif

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
//#define int LLI
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define F1(i,n) FOR(i,1,n)

typedef long long LLI;
typedef unsigned long long LLU;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LLI, LLI> pll;
typedef vector<int> vi;

#ifdef ONLINE_JUDGE
ostream cnull(NULL);
#define cerr cnull
#endif

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr<<*sdbg++;
  cerr<<"="<<h<<",";
  _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define dbgV(R) {cerr << #R << "=["; for(int e : R) cerr << e << ", "; cerr << "E]\n";}
#define dbgA(R, n) {cerr << #R << "=["; for(int i = 0; i <= n; ++i) cerr << R[i] << ", "; cerr << "E]\n";}
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MX = 1e6 + 7;
int n;
string s;
int ileD[MX], ileM[MX];

LLI solve(int k){
	LLI ans = 0;
	LLI pary = 0;
	for(int i = 1; i < k; ++i){
		if(s[i - 1] == 'M') pary += ileD[i];
		if(s[i - 1] == 'C') ans += pary;
	}
	for(int i = k; i <= n; ++i){
		if(s[i - 1] == 'C') ans += pary;
		if(s[i - k] == 'D') pary -= (ileM[i] - ileM[i - k]);
		if(s[i - 1] == 'M') pary += (ileD[i] - ileD[i - k]);
	}
	return ans;
}

int32_t main()
{
    boost;
    int k;
    cin >> n >> s >> k;
    for(int i = 1; i <= n; ++i){
		ileD[i] = ileD[i - 1] + (s[i - 1] == 'D');
		ileM[i] = ileM[i - 1] + (s[i - 1] == 'M');
	}
    F1(i, k){
		int q; cin >> q;
		cout << solve(q) << '\n';
	}
}


Measured memory_bytes: 9244
#include <stdio.h>
#include <stdlib.h>
#define N 10001
int c[N];
int main(){
    for(int i = 0; i <= N; i++) c[i] = 0;
    int n;
    scanf("%d", &n);
    int a[n+1];
    int b[n+1];

    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        c[a[i]]++;
    }
    for(int i = 1; i <= N; i++) c[i] += c[i-1];

    for(int j = n-1; j >= 0; j--){
        b[c[a[j]]] = a[j];
        c[a[j]] --;
    }

    for(int j = 1; j <= n; j++){
        if(j != n) printf("%d ", b[j]);
        else printf("%d\n", b[j]);
    }
    return 0;
}


Measured memory_bytes: 17356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ull a;cin >> a;
    string b;cin >> b;
    ull sum=0;
    ull c,d;
    if(b.size()==4){
        c=b[0]-'0';
        d=(b[2]-'0')*10+b[3]-'0';
    }
    else{
        c=(b[0]-'0')*10+b[1]-'0';
        d=(b[3]-'0')*10+b[4]-'0';
    }
    ull ans=a*c+a*d/100;
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, Q;
char S[200011];
char T[200011];
char D[200011];

int GO(int pos) {
    REP (i, Q) {
	if (pos < 0 || N <= pos) return pos;
	if (S[pos] == T[i]) {
	    if (D[i] == 'L') pos--;
	    else pos++;
	}
    }
    return pos;
}

int LEFT() {
    int lo = -1, hi = N;
    while (hi - lo > 1) {
	int mid = (hi + lo) / 2;
	if (GO(mid) == -1) lo = mid;
	else hi = mid;
    }
    return hi;
}

int RIGHT() {
    int lo = -1, hi = N;
    while (hi - lo > 1) {
	int mid = (hi + lo) / 2;
	if (GO(mid) == N) hi = mid;
	else lo = mid;
    }
    return lo;
}

void MAIN() {
    scanf("%d%d%s", &N, &Q, S);
    REP (i, Q) scanf("%s%s", T+i, D+i);

    int l = LEFT();
    int r = RIGHT();

    int ans = r - l + 1;

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

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <tuple>
#include <set>
#include <functional> 
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll > pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	string s;
	int ans = 0;
	while (cin >> s && s != "\0"){
		cin.ignore();
		int digit = 10;
		int tmp = 0;
		FOR(i, s.size()){
			if (s[i] - '0' >= 0 && s[i] - '0' <= 9){
				tmp *= digit;
				tmp += s[i] - '0';
			}
			else{
				ans += tmp;
				tmp = 0;
			}
		}
		if (tmp > 0) ans += tmp;
	}
	cout << ans << endl;
}

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

int gcd(int a, int b){
    while(b != 0){
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main(){
    int n, sx, x;
    cin >> n >> sx >> x;
    int ans = abs(x - sx);
    sx = x;
    for(int i = 1; i < n; i++){
        cin >> x;
        ans = gcd(ans, abs(x - sx));
        sx = x;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

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

    int n; cin >> n;
    string str; cin >> str;
    for (int i = 0; i < 2; i++){
        for (int j = 0; j < 2; j++){
            vi v(n+1);
            v[0] = i;
            v[1] = j;
            for (int k = 1; k < n; k++){
                if (v[k] == 0){ // sheep
                    if (str[k] == 'o') {
                        v[k+1] = v[k-1];
                    } else {
                        v[k+1] = 1 - v[k-1];
                    }
                } else {
                    if (str[k] == 'x') {
                        v[k+1] = v[k-1];
                    } else {
                        v[k+1] = 1 - v[k-1];
                    }
                }
            }
            int fin;
            if (i == 0) {
                if (str[0] == 'o'){
                    fin = j;
                } else
                    fin = 1-j;
            } else {
                if (str[0] == 'x'){
                    fin = j;
                } else
                    fin = 1-j;
            }
            if (v[n] == v[0] && v[n-1] == fin) {
                for (int x = 0; x < n; x++){
                    cout << "SW"[v[x]];
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 924
a = sorted(list(map(int,input().split())))
a[1] = a[1]-a[0]
a[2] = a[2]-a[0]
a[0] = 0
b = a[2]-a[1]
a[0] = b
if (max(a)-b) % 2 == 0:
    print(b+((max(a)-b)//2))
else:
    print(b+((max(a)-b)//2)+2)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long

int c[10][10];

signed main(){
	int h,w;
	cin>>h>>w;
	vector<int> cnt(10,0);
	for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
	cin>>c[i][j];
}}
	for(int i=0;i<h*w;i++){
		int x;cin>>x;
		if(x>=0)cnt[x]++;
	}	
	for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
	for(int k=0;k<10;k++){
		c[j][k]=min(c[j][k],c[j][i]+c[i][k]);
}}}
	int ans=0;
	for(int i=0;i<10;i++){
	ans+=c[i][1]*cnt[i];
}
cout<<ans<<endl;

}


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

#define Rep(i,n) for(int i=0;i<(n);i++)
#define For(i,n1,n2) for(int i=(n1);i<(n2);i++)
#define REP(i,n) for(ll i=0;i<(n);i++)
#define RREP(i,n) for(ll i=(n-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(n1);i<(n2);i++)
#define put(a) cout<<(a)<<"\n";
#define all(a)  (a).begin(),(a).end();
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}


string s;
int n;

int main() {
    cin >> n >> s;
    string t = s;
    bool flag = true;
    while(flag){
        flag = false;
        REP(i,t.size()){
            if(t[i]=='('&&t[i+1]==')'){
                t.erase(i,2);
                flag = true;
            }
        }
    }
    int cntl = 0;
    int cntr = 0;
    REP(i,t.size()){
        if(t[i]==')'){
            cntr++;
        }else{
            cntl++;
        }
    }
    string res = "";
    REP(i,cntr){
        res += '(';
    }
    res += s;
    REP(i,cntl){
        res += ')';
    }
    put(res);
    return 0;
}



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

const int INF=1e9+5;

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	vector<int> dp(n,INF);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=(i+k);j++){
			if(j<n){
				dp[j]=min(dp[j],(dp[i]+abs(h[i]-h[j])));
			}	
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define INF (int)1e15
int x, y, z, K;
int a[1111], b[1111], c[1111];
vector<int>v;
signed main() {
	cin >> x >> y >> z >> K;
	rep(i, x)cin >> a[i];
	rep(i, y)cin >> b[i];
	rep(i, z)cin >> c[i];
	sort(a, a + x, greater<int>());
	sort(b, b + y, greater<int>());
	sort(c, c + z, greater<int>());
	rep(i, x) {
		rep(j, y) {
			rep(k, z) {
				if ((i + 1) * (j + 1) * (k + 1) > K)break;
				v.push_back(a[i] + b[j] + c[k]);
			}
		}
	}
	sort(v.begin(), v.end(),greater<int>());
	rep(i, K)cout << v[i] << endl;
	return 0;
}

Measured memory_bytes: 1400
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=100001;

int main(){
  int n;
  int a[maxn];
  cin>>n;
  priority_queue<int> q;
  for(int i=0;i<n;i++){
    cin>>a[i];
    q.push(a[i]);
  }
  int count=0;
  int bef=-1;
  ll res=1LL;
  int now=0;
  while(q.size()!=0){
    int tmp=q.top();
    q.pop();
    if(tmp!=bef){
      count=1;
      bef=tmp;
    }
    else count++;
    if(count==2){
      res*=(ll)bef;
      count=0;
      now++;
    }
    if(now==2){
      cout<<res<<endl;
      return 0; 
    }

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


Measured memory_bytes: 1148
#include<iostream>
#include<algorithm>//fill、begin,endに必要
using namespace std;

int p[100010];//0なら素数でない、1なら素数
int acc[100010];//計算の高速化のため累積和を用いる
//ここより上に書くと配列内が自動的に0になる
int main(){
	int q,r, l;

		fill(begin(p), end(p), 1);//ｐの0から最後まで1で初期化
		p[0] = p[1] = 0;//別途0に書き直し

		for (int i = 2; i*i <= 100010; i++)
		{
			if (p[i] == 1)
			{
				for (int j = 2; i*j <= 100000; j++)
				{
					p[i*j] = 0;//素数の倍数の配列を0に書き換え
				}
			}
		}

		for (int i = 1; i < 100010; i++)
		{
			acc[i] = acc[i - 1];
			if (i % 2 == 1 && p[i] == 1 && p[(i + 1) / 2] == 1)
			{
				acc[i]++;
			}
		}

cin >> q;
	for (int k = 0; k < q; k++)
	{
cin >> l >> r;
cout <<acc[r] - acc[l - 1] << endl;
		
	}
		 
		
	
return 0;

}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ').Select(txt => int.Parse(txt)).ToList();
        var X = inputs[0];
        var N = inputs[1];

        HashSet<int> candidates = new HashSet<int>();
        if (N == 0)
        {
            candidates.Add(X);
        }
        else
        {
            var Ps = Console.ReadLine().Split(' ').Select(txt => int.Parse(txt)).ToList();
            var pmin = Ps.Min() - 1;
            var pmax = Ps.Max() + 1;
            for (int i = pmin; i <= pmax; i++)
            {
                if (Ps.Contains(i)) continue;
                candidates.Add(i);
            }

            if (X < pmin || pmax < X)
            {
                candidates.Add(X);
            }
        }

        var diff = int.MaxValue;
        var ans = int.MaxValue;
        foreach (var c in candidates.OrderBy(n => n).ToList())
        {
            var d = Math.Abs(X - c);
            if (d < diff)
            {
                diff = d;
                ans = c;
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28532
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define P pair<int, int>

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  bool yes = false;
  if (a == b)
  {
    if (c != a)
    {
      yes = true;
    }
  }
  else if (a == c)
  {
    if (b != a)
    {
      yes = true;
    }
  }
  else if (b == c)
  {
    if (a != b)
    {
      yes = true;
    }
  }

  if (yes)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	while(1){
		int r,c;
		int a[12][10002];
		
		scanf("%d%d",&r,&c); if( r == 0 && c == 0 )break;
		rep(i,r){
			rep(j,c){
				scanf("%d",&a[i][j]);
			}
		}
		
		int ret = 0;
		
		rep(s,1 << r){
			rep(i,r){
				if((s >> i)&1){
					rep(j,c){
						a[i][j] = 1-a[i][j];
					}
				}
			}
			int sum = 0;
			rep(j,c){
				int cnt = 0;
				rep(i,r){
					cnt += a[i][j];
				}
				sum += max ( cnt , r-cnt );
			}
			ret = max ( ret , sum );
			rep(i,r){
				if((s >> i)&1){
					rep(j,c){
						a[i][j] = 1-a[i][j];
					}
				}
			}
		}
		
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1572
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()){
            double a = sc.nextDouble(), b = sc.nextDouble(), c = sc.nextDouble();
            double d = sc.nextDouble(), e = sc.nextDouble(), f = sc.nextDouble();
            double y = (a*f-c*d) / (a*e-b*d);
            double x = (c-b*y) / a;
            System.out.printf("%.3f %.3f\n", x, y);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 20556
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, 0, N) cin >> A[i];
    B[0] = A[0];
    rep(i, 1, N) B[i] = B[i - 1] + A[i];

    int l = 0, r = 2;
    ll best = INFl;
    for (int m = 1; m < N - 1; m++) {
        //lを増やす
        while (B[l] < B[m] - B[l] && l + 1 < m) {
            l++;
        }
        if (B[l] > B[m] - B[l]) {
            if (l > 0 && B[l] - (B[m] - B[l]) > abs(B[l - 1] - (B[m] - B[l - 1]))) {
                l--;
            }
        }
        //rを増やす
        while (B[r] - B[m] < B[N - 1] - B[r] || (r <= m && r < N - 1)) {
            r++;
        }
        if (B[r] - B[m] > B[N - 1] - B[r]) {
            if (r > m + 1 && B[r] - B[m] - (B[N - 1] - B[r]) > abs(B[r - 1] - B[m] - (B[N - 1] - B[r - 1]))) {
                r--;
            }
        }
        vector<ll> seqs(4);
        seqs[0] = B[l];
        seqs[1] = B[m] - B[l];
        seqs[2] = B[r] - B[m];
        seqs[3] = B[N - 1] - B[r];
        sort(all(seqs));
        best = min(best, seqs[3] - seqs[0]);
    }

    cout << best << endl;


    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0)
#define endl '\n'
using namespace std;
ll dp[1000004];
int main()
{
    ll n;
    cin>>n;
    dp[0]=1;
    dp[1]=n;
    dp[2]=n*n;
    dp[2]%=mod;
    ll g=n-1;
    g=g*g;g=g%mod;
    ll sum=dp[1]+dp[2];
    sum%=mod;
    for(int i=3;i<=n;i++)
    {
        ll g=i-3;
        ll o=n-1;
        g=g*(o);
        g=g%mod;
        ll p=n-i+2LL;
        o++;
        p=p*o;p=p%mod;
        dp[i]=g+sum-dp[i-2]+p+mod;
        dp[i]%=mod;
        sum+=dp[i];
        sum%=mod;
    }
    cout<<dp[n]<<endl;



}




Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
double PHI = 1.6180339;
#define endl "\n"    
typedef long long ll;
#define int long long
//#define int unsigned long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    vector<int>v;
    int a[n+10];
    int b[n+10];
    int c[n+10];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    cin>>b[i];
    for(int i=1;i<n;i++)
    cin>>c[i];
  
    int res=0;
    for(int i=1;i<=n;i++)
    {
        res+=b[a[i]];
        v.push_back(a[i]);
    }
    for(int j=0;j<v.size();j++)
    {
        if(v[j]==v[j+1]-1)
        {
            res+=c[v[j]];
        }
    }
    cout<<res<<endl;

    
}
 

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j  in range(i,n):
        if a[i] > a[j]:
                b[i][1] += 1
        elif a[i] < a[j]:
        		b[i][0] +=1


b[i][0]=b[i][0]%mod		
b[i][1]=b[i][1]%mod	
ans = 0
sigmakp = ((k * (k+1) ) // 2) % mod
sigmakp = int(sigmakp)
sigmakn = ((k * (k-1)) // 2) % mod
sigmakn = int(sigmakn)
for i in range(n):
    mae = int(sigmakn * b[i][0]) % mod
    ushiro = int(sigmakp * b[i][1]) % mod
    ans = int((mae + ushiro) + ans) % mod 
print(ans)


Measured memory_bytes: 3324
#include <stdio.h>

int main (int argc, char* argv[])
{
  int i, j;

  for (i=1; i<=9; i++) {
    for (j=1; j<=9; j++) {
      printf("%dx%d=%d\n", i, j, i*j);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
struct var
{
    int s,t,x;
};
vector<var> v;
bool cmp(var a, var b)
{
    if(a.s==b.s) return a.t<b.t;
    return a.s<b.s;
}
typedef pair<int,int> pii;
int main()
{
    //freopen("inp","r",stdin);
    //freopen("out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,q;
    cin>>n>>q;
    v.resize(n);
    for(int i=0;i<n;++i)
    {
        int x,y;
        cin>>x>>y>>v[i].x;
        v[i].s=max(x-v[i].x,0);
        v[i].t=max(y-v[i].x,0);
    }
    sort(v.begin(),v.end(),cmp);
    priority_queue< pii, vector<pii> , greater<pii> >Q;
    int j=0;
    for(int i=0;i<q;++i)
    {
        int r;
        cin>>r;
        while(j<n&&v[j].s<=r)  Q.push(make_pair(v[j].x,v[j].t)),++j;
        while(!Q.empty())
        {
            pii t=Q.top();
            if(t.second<=r)
            {
                Q.pop();
                continue;
            }
            //cout<<t.first<<endl;
            printf("%d\n",t.first);
            break;
        }
        if(Q.empty())  printf("-1\n");
    }
    return 0;
}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    int a;
    cin >> a;

    cout << a + a * a + a * a * a << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 300005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll N,A,B;

int dp[SIZE],a[SIZE];

/*
void solve(){
	int l,r;
	fill(dp,dp+N,INF);
	for(int i=0;i<N;i++){
		*lower_bound(dp,dp+N,a[i]) = a[i];
	}
	l = lower_bound(dp,dp+N,INF) - dp;
	reverse(a,a+N);
	fill(dp,dp+N,INF);
	for(int i=0;i<N;i++){
		*lower_bound(dp,dp+N,a[i]) = a[i];
	}
	r = lower_bound(dp,dp+N,INF) - dp;
	reverse(a,a+N);
	cout << l << " " << r << endl;
}
*/

vector<ll> G[SIZE];

int main(){
	cin >> N >> A >> B;
	if(N < A+B-1 or N > A*B){
		cout << -1 << endl;
		return 0;
	}
	rep(i,0,B){
		G[i].push_back(N-i);
	}
	ll t = N-B+1LL;
	ll u = 1LL;
	rep(i,0,B){
		rep(j,0,(int)A-1){
			G[(int)B-i-1].push_back(u);
			u++;
			if(u == t)break;
		}
		if(u == t)break;
	}
	int s = 0;
	rep(i,0,B){
		sort(G[i].begin(),G[i].end());
		rep(j,0,G[i].size()){
			if(!(i==0 and j == 0)) cout << " ";
			cout << G[i][j];
			a[s++] = G[i][j];
		}
	}
	cout << endl;
	//solve();
	return 0;
}


Measured memory_bytes: 17024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll N,X;cin>>N>>X;
  ll L[N];
  ll i,j,k;
  rep(i,N) cin>>L[i];
  ll tmp=0,cnt=0;
  rep(i,N){
    if(tmp<=X) cnt++;
    tmp+=L[i];
  }
  if(tmp<=X) cnt++;
  cout<<cnt<<endl;
}


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

const int mod = 1e9+7;

long long int sum[1000001],dp[1000001];


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long int N,H,D;
	long long int facsum=0,fac=1;
	cin>>N>>H>>D;
	for(int i=1;i<=N;i++){
		fac=fac*i%mod;
		facsum+=fac;
	}
	facsum%=mod;
	dp[0]=1;
	sum[0]=dp[0];
	for(int i=1;i<=H;i++){
		long long int here = sum[i-1]-(i-D-1>=0?sum[i-1-D]:0);
		dp[i]=here%mod*facsum%mod;
		sum[i]=sum[i-1]+dp[i];
		if(i==H)
			cout<<here%mod*fac%mod<<endl;
	}
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, K; cin >> A >> B >> K;
for (int i = min(A, B); i >= 1; --i) {
if (A % i == 0 && B % i == 0) { --K;
if (K == 0) {
cout << i << endl; return 0;
} }
}
assert(false); }

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

int main() {
  int K,A,B;
  cin >> K >> A >> B;
  for (int i=0;; i++) {
if (A <= i*K && i*K <= B) {
      cout << "OK" << endl;
      break; 
    }
else if(i*K > B){
     cout << "NG" << endl;
  break;
}
  }

}



Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;



int main() {
	string s; cin >> s;
	int n = s.length();
	if (n == 2) {
		cout << s << endl;
	}
	else {
		cout << s[2] << s[1] << s[0];
	}
}




Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l


if sys.platform =='ios':
	if input_method==input_methods[0]:
		ic=input_clipboard()
		input = lambda : ic.__next__()
	elif input_method==input_methods[1]:
		sys.stdin=open('inputFile.txt')
	else:
		pass
	isTest=True
else:
	pass
	#input = sys.stdin.readline

#####segfunc######
def segfunc(x,y):
   return min(x,y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
#num =2**(n-1).bit_length()
#seg=[ide_ele]*2*num


n, k = tin()
#al = [int(input()) for _ in range(n)]
v_max = 300000
mmv = [0] * (v_max+1)
num=2**(v_max-1).bit_length()
seg = [ide_ele]*2*num

#init(mmv)
for value_i in range(n):
	value_i=int(input())
	r = query(max(value_i-k,0), min(value_i+1+k,v_max+1))
	update(value_i, r-1)
v = -query(0, num)
print(v)

	


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

#define      ll     long long int

int main()
{
    ll x, y, c = 0;
    cin >> x >> y;
    while (x <= y) {
        c++;
        x = x * 2;
    }
    cout << c << '\n';
    return 0;
}


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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];

        int[] x = new int[m];
        int[] y = new int[m];
        for (int i = 0; i < m; i++)
        {
            int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            x[i] = tmp[0];
            y[i] = tmp[1];
        }

        int[] pos = new int[n];
        pos[0] = 1;
        int[] box = new int[n];
        for (int i = 0; i < n; i++)
        {
            box[i] = 1;
        }

        for (int i = 0; i < m; i++)
        {
            box[x[i]-1] -= 1;
            box[y[i]-1] += 1;

            if (pos[x[i]-1] == 1)
            {
                pos[y[i]-1] = 1;
                if (box[x[i]-1] == 0)
                {
                    pos[x[i]-1] = 0;
                }
            }
        }

        var ans = pos.Where(value => value > 0).Count();

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 16704
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        sc.close();
        int[] a = new int[4];
        Arrays.fill(a,0);
        for (int i = 0; i < n; i++) {
            if (s[i].equals("AC")) a[0]++;
            else if (s[i].equals("WA")) a[1]++;
            else if (s[i].equals("TLE")) a[2]++;
            else if (s[i].equals("RE")) a[3]++;
        }
        
        System.out.println("AC x " + a[0]);
        System.out.println("WA x " + a[1]);
        System.out.println("TLE x " + a[2]);
        System.out.println("RE x " + a[3]);
    }
}



Measured memory_bytes: 64900
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

void ssolve(std::istream& in, std::ostream& out){
    int N, W;
    s2(N, W);

    vi dp(W + 1, 0);
    vi newdp(W + 1, 0);
    int w, vl;
    f(i, 0, N){
        s2(w, vl);
        f(j, 0, W - w + 1){
            newdp[j + w] = max(dp[j + w], dp[j] + vl);
        }
        dp = newdp;
    }

    int ans = *max_element(dp.begin(), dp.end());
    p(ans);
    return;
}

class DKnapsack1 {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    DKnapsack1 solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 4788
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a,b,c,d,n;
  while(cin>>n&&n){
    c=d=0;
    for(i=0;i<n;i++){
      cin>>a>>b;
      if(a>b)
	c+=a+b;
      else if(a<b)
	d+=a+b;
      else{
	c+=a;
	d+=b;
      }
    }
    cout<<c<<" "<<d<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair <int,ii>
#define iil pair<ll,ll>
#define iiil pair<ll,iil>
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define s(v) sort(v.begin(),v.end())
#define pf printf
#define sf scanf
#define MIN INT_MIN
#define MAX INT_MAX
#define accepted 0
using namespace std;
//long long int factorial(long long int n){if (n == 0)return 1;return n * factorial(n - 1);}
//
//bool prime[n];
//vector<int> v;
//void sieve(){
//    prime[0]=prime[1]=1;
//    for(int i=2;i*i<=n;i++){
//        if(prime[i]==0){
//            for(ll j = i*i;j<=n;j+=i){
//                prime[j]=true;
//            }
//        }
//    }
//    for(int i=2;i<=n;i++){
//        if(prime[i]==0)v.push_back(i);
//    }
//}
//
//bool ispalindrome(string s){
//
//    for(int i=0,j=s.size()-1;i<s.size();i++,j--){
//        if(s[i]!=s[j])
//            return false;
//    }
//    return true;
//}


int main(){
    int tst,value;    cin>>tst;
    bool flag = 1;
    vector<int> v;
        while(tst--){
            cin>>value;
            if(value%2==0){
                if(value%3!=0 && value%5!=0)flag = 0;
            }
          //  v.push_back(value);
        }
        if(flag)cout<< "APPROVED" <<endl;
        else cout<< "DENIED" <<endl;


    return accepted;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define y0    lol
#define y1    lool
#define yn    loool
#define prev  looool
#define next  loooool
#define read  looooool
#define tm    loooooool
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#ifdef LOCAL
#define rall(x,a) for(x : a)
#define LL "%lld"
#else
#define rall(x,a) for(auto x : a)
#define LL "%I64d"
#endif
#define rng(a) a.begin(), a.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 22;
int c[N], v[N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n) {
        cin >> v[i];
    }
    rep(i, 1, n) {
        cin >> c[i];
    }
    int ans = -1e4;
    rep(mask, 0, (1 << n) - 1) {
        int x = 0, y = 0;
        rep(i, 1, n) {
            if(mask & (1 << (i - 1))) {
                x += v[i];
                y += c[i];
            }
        }
        ans = max(ans, x - y);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
struct node
{
    int id,y;
    int res;
    bool operator<(const node&rhs)const
    {
        if(id == rhs.id)return y < rhs.y;

        return id < rhs.id;
    }
}d[maxn];
vector<int>s[maxn];
int judge(int x)
{
    int ans = 0;
    while(x)
    {
        ans++;
        x /= 10;
    }
    return 6 - ans;
}
int main()
{
     int n,m;
     while(cin>>n>>m)
     {
         for(int i = 0; i <= m; ++i)s[i].clear();
         for(int i = 0; i < m; ++i)
         {
             cin>>d[i].id>>d[i].y;
             int nd = judge(d[i].id);
             //cout<<nd<<endl;
             for(int j = 0; j < nd; ++j)
                s[i].pb(0);

             s[i].pb(d[i].id);
             d[i].res = i;
         }

         sort(d,d+m);

         int now = d[0].id;
         int can = 1;
         for(int i = 0; i < 5; ++i)s[d[0].res].pb(0);
         s[d[0].res].pb(1);

         for(int i = 1; i < m; ++i)
         {
             //cout<<d[i].id<<"  "<<now<<endl;
             if(d[i].id == now)
             {
                 can++;
                 for(int j = 0; j < judge(can); ++j)
                    s[d[i].res].pb(0);
                 s[d[i].res].pb(can);
             }
             else
             {
                 can = 1;
                 for(int j = 0; j < judge(can); ++j)
                    s[d[i].res].pb(0);
                 s[d[i].res].pb(can);
                 now = d[i].id;
             }
         }
         for(int i = 0; i < m; ++i)
         {
             for(int j = 0; j < s[i].size(); ++j)
                cout<<s[i][j];
             cout<<endl;
         }
     }
}












Measured memory_bytes: 36096
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    d =[0] *201

    for i in range(1,201):
        for k in range(1,201):
            if k%i==0 and k%2==1:
                d[k] +=1



    N = int(input())

    print(d[:N+1].count(8))


if __name__ == "__main__":
    main()


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

ll find_max_profit_momo(int v[],int w[],int wt,int n){
            // cout<<wt<<" "<<n<<endl;
           //  return 1;
      ll    int dp[n+1][wt+1];
            for(int i=0; i<=n; i++){
				for(int j=0; j<=wt; j++){
					//cout<<i<<" "<<j<<endl;
					if(i==0||j==0){
			     	if(j==0)
					 dp[i][j]=0;
					 else
					 dp[i][j]=0;
				     }
					 else{
					  if(j>=w[i-1])
				       dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
					  else
					    dp[i][j]= dp[i-1][j];
	 				 }
	                   //  cout<<dp[i][j]<<endl;	
	              
				}
				//cout<<endl;
			}
			return dp[n][wt];
			
     
}

int main() {
	 ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0); 
	// your code goes here
	 int n;
          cin>>n;
          int weight;
            cin>>weight;
          int w[n],v[n];
          for(int i=0; i<n; i++)
            cin>>w[i]>>v[i];
             
         //  cout<<find_max_profit(v,w,weight,n)<<endl;
          cout<<find_max_profit_momo(v,w,weight,n)<<endl;

	return 0;
}

Measured memory_bytes: 79232
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

typedef struct node node;
typedef struct edge{
    node* target;
    struct edge* next;
}edge;
typedef struct node{
    int col;
    int len;
    edge* fst;
    edge* lst;
}node;
void initNodeArray(node* p, int n){
    for(int i=0; i<n; i++){
        (p+i)->col = 0;
        (p+i)->len = 100002;
        (p+i)->fst = NULL;
        (p+i)->lst = NULL;
    }
}
void addEdge(node* p, node* target){
    if(p->fst == NULL){
        p->fst = (edge*)malloc(sizeof(edge));
        p->lst = p->fst;
    }else{
        p->lst->next = (edge*)malloc(sizeof(edge));
        p->lst = p->lst->next;
    }
    p->lst->target = target;
    p->lst->next = NULL;
}

void func(node* p, int len, node* pre, int col){
    p->col = col;
    p->len = len;
    edge* e = p->fst;
    while (e != NULL){
        if(len + 1 < e->target->len){
            func(e->target, len+1, p, col);
        }
        e = e->next;
    }
}

int main(){
    int n;
    scanf("%d", &n);
    node a[n+1];
    initNodeArray(a, n+1);
    rep(i, 1, n){
        int x, y;
        scanf("%d %d", &x, &y);
        addEdge(&a[x], &a[y]);
        addEdge(&a[y], &a[x]);
    }
    a[1].col = 1;
    a[n].col = 2;
    a[1].len = 0;
    a[n].len = 0;
    func(&a[1], 0, &a[1], 1);
    func(&a[n], 0, &a[n], 2);
    int f = 0, s = 0;
    rep(i, 1, n+1){
        if(a[i].col == 1){
            f++;
        }else{
            s++;
        }
    }
    printf(f > s ? "Fennec" : "Snuke");

    return 0;
}

Measured memory_bytes: 13440
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int  i, j;
	int c = 1, d = 0; //dは桁数

	cin >> i >> j;
	while(c < i){
		c = c * j;
		d++;
	

	}

	if (c == i) {
		d++;
	}
	cout << d;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int main(){
  long long int A, B, K;
  scanf("%lld%lld%lld", &A, &B, &K);

  std::cerr << "Answer: " << std::endl;
  if(K <= A){
    std::cout << A-K << " " << B << std::endl;
  }
  else if(K <= A+B){
    std::cout << 0 << " " << A+B-K << std::endl;
  }
  else{
    std::cout << "0 0" << std::endl;
  }

  return 0;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
typedef unsigned long long INT;
INT a, b;

INT A(LL i) {
	if (i < a)return i;
	else return i + 1;
}
INT B(LL i) {
	if (i < b)return i;
	else return i + 1;
}

bool check(INT x) {
	if (x < 110) {
		for (int i : range(1,x+1)) {
			int j = x - i + 1;
			if (A(i)*B(j) >= a*b)return false;
		}
	}
	else {
		for (int d : range(-50, 51)) {
			LL i = x / 2 + d;
			LL j = x - i + 1;
			if (A(i)*B(j) >= a*b)return false;
		}
	}
	return true;
}
int main() {
	int Q;
	cin >> Q;
	while (Q--) {
		cin >> a >> b;
		INT lb = 0;
		INT ub = (4 * 1e9)+10;
		while (ub - lb > 1) {
			const INT mid = (lb + ub) / 2;
			(check(mid)? lb : ub) = mid;
		}
		cout << lb << endl;
	}

	return 0;
}


Measured memory_bytes: 256