akhauriyash/Code-Regression huggingface dataset:
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber
// 19 04 2020

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define    pi    acos(-1.0)

void task()
{
    int n, x;

    cin >> n;
    vector<int> boss(n+1);

    for(int K=1; K<n; K++){
        cin >> x;

        boss[x]++;
    }

    for(int K=1; K<=n; K++) cout << boss[K] << "\n";
}

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

    //clock_t tStart = clock();

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    //printf("Time taken: %.3fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);

    return 0;
}



Measured memory_bytes: 3992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


   String st = br.readLine();

   int n = Integer.parseInt( st );
   double[] abs = new double[n];
   String[] x = br.readLine().split(" ");
   String[] y = br.readLine().split(" ");

   double p1 = 0;
   for(int i = 0 ;i < n; i++){

	   abs[i] = Math.abs( Double.parseDouble(x[i]) - Double.parseDouble(y[i]) );
	   p1 += abs[i];

   }
   System.out.println(p1);

   double sum = 0;
   for(int i = 0 ;i < n; i++){

	   sum += Math.pow(Math.abs( Double.parseDouble(x[i]) - Double.parseDouble(y[i]) ) , 2);

   }
   double p2 = Math.sqrt(sum);
   System.out.println(p2);

   double sum2 = 0;
   for(int i = 0 ;i < n; i++){

	   sum2 += Math.pow(Math.abs( Double.parseDouble(x[i]) - Double.parseDouble(y[i]) ) , 3);

   }

  double triple = 1/3;
   double p3 = Math.pow(sum2 , 1.0 / 3.0);
   System.out.println(p3);


   double Ch = abs[0];
   for(int j = 0 ;j < n; j++){
     if(Ch < abs[j]){
       Ch = abs[j];
     }
   }
   System.out.println(Ch);

  }
}

Measured memory_bytes: 24748
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    S = "".join(list(sorted(input())))
    if S == "abc":
        print(Yes)
    else:
        print(No)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
import java.io.*;

public class Main {

	public static void main(String[] args) {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line;
			while((line=r.readLine())!=null){
				String[] vars = line.split(" ");
				int res = Integer.valueOf(vars[0]) + Integer.valueOf(vars[1]);
				System.out.println(res);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 17180
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 30000
#define nmax_def_2 15000
#define Inf 2000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

vector<vector<vb>> DP;

int main() {
	int H, W;
	cin >> H >> W;
	vector<vi> A(H);
	vector<vi> B(H);
	vector<vi> difflist(H);
	rep(i, H) {
		difflist[i].resize(W);
		A[i].resize(W);
		B[i].resize(W);
	}
	rep(i, H) {
		rep(j, W) {
			cin >> A[i][j];
		}
	}
	rep(i, H) {
		rep(j, W) {
			cin >> B[i][j];
		}
	}
	rep(i, H) {
		rep(j, W) {
			difflist[i][j] = A[i][j] - B[i][j];
		}
	}
	
	DP.resize(H + 1);
	rep(i, H + 1) {
		DP[i].resize(W + 1);
		rep(j, W + 1) {
			DP[i][j].resize(nmax_def);
			rep(k, nmax_def) {
				DP[i][j][k] = false;
			}
		}
	}
	DP[1][1][difflist[0][0] + nmax_def_2] = true; // 左上が(1, 1)で差はdifflist[0][0]->(要素では)+=7500
	DP[1][1][-difflist[0][0] + nmax_def_2] = true; // 左上が(1, 1)で差は-difflist[0][0]->(要素では)+=7500
	rep(i, H) {
		rep(j, W) {
			rep(k, nmax_def) {
				if (DP[i + 1][j][k]) {
					DP[i + 1][j + 1][k + difflist[i][j]] = true;
					DP[i + 1][j + 1][k - difflist[i][j]] = true;
				}
				if (DP[i][j + 1][k]) {
					DP[i + 1][j + 1][k + difflist[i][j]] = true;
					DP[i + 1][j + 1][k - difflist[i][j]] = true;
				}
			}
		}
	}
	int ans = Inf;
	rep(k, nmax_def) {
		if (DP[H][W][k]) {
			int anstmp = abs(k - nmax_def_2);
			ans = min(ans, anstmp);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 24704
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;

int main(){
   int n;
   cin >>n;
   rep(i,10){
     rep(j,10){
       if(i*j == n) {cout << "Yes";return 0;}
     }
   }
   cout << "No";
}
   

Measured memory_bytes: 256
from math import factorial

n, k = list(map(int, input().split()))

memo = dict()
ans = []
d = 0
for i in range(1, k+1):
    nn = n - k + 1
    if i > nn:
        ans.append("0")
        continue
    k1 = i
    k2 = nn - k1
    nn2 = k - 1
    k3 = i - 1
    k4 = nn2 - k3
    if nn not in memo:
        memo[nn] = factorial(nn)
    if k1 not in memo:
        memo[k1] = factorial(k1)
    if k2 not in memo:
        memo[k2] = factorial(k2)
    if nn2 not in memo:
        memo[nn2] = factorial(nn2)
    if k3 not in memo:
        memo[k3] = factorial(k3)
    if k4 not in memo:
        memo[k4] = factorial(k4)
    c = ((memo[nn] // memo[k2] // memo[k1]) * (memo[nn2] // memo[k4] // memo[k3])) % 1000000007
    ans.append(str(c))
print("\n".join(ans))


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

int main (void)
{
    int A, B, C, D, E;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    cin >> E;
    int sec = 0;
    int l = 0;
    while (A < B)
    {
        if (A < 0)
        {
            A++;
            sec += C;
        }
        else if (A == 0 && l == 0)
        {
            sec += D;
            l++;
        }
        else
        {
            A++;
            sec += E;
        }
    }
    cout << sec << endl;
}



Measured memory_bytes: 3100
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for p in range(N):
    i = input()
    if i == 'AC':
        AC += 1
    elif i == 'WA':
        WA += 1
    elif i == 'TLE':
        TLE += 1
    else:
        RE += 1


print('AC x ', AC)
print('WA x ', WA)
print('TLE x ', TLE)
print('RE x ', RE)

Measured memory_bytes: 9172
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)






int main() {
    ll n;
    cin >> n;
    map<string, ll> mp;
    char t;
    REP(i, n){
        string w;
        cin >> w;
        if(mp[w]){
            cout << "No" << endl;
            return 0;
        }
        if(i == 0){
            mp[w]++;
            t = w[w.size() - 1];
        }
        else{
            if(w[0] != t){
                cout << "No" << endl;
                return 0;
            }
            mp[w]++;
            t = w[w.size() - 1];
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	stack<char>A;
	string S; cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S.at(i) == 'B') {
			if (!A.empty()) {
				A.pop();
			}
		}
		else A.push(S.at(i));
	}
	vector<char>ans(A.size());
	for (int i = A.size() - 1; i >= 0; i--) {
		ans.at(i) = A.top();
		A.pop();
	}
	for (int i = 0; i < ans.size(); i++) {
		cout << ans.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e+3+5;
const int L = 4005000;
const int mo = 1e+9+7;

int n,k;
LL js[L],ny[L],inv[L];
LL f[N][N];

LL calc(int n,int m){return js[n]*ny[m]%mo*ny[n-m]%mo;}

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();k=get();
	if (k==1)return printf("1\n"),0;
	k-=2;
	js[0]=ny[0]=inv[0]=js[1]=inv[1]=ny[1]=1;
	fo(i,2,4004000){
		js[i]=js[i-1]*i%mo;
		inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
		ny[i]=ny[i-1]*inv[i]%mo;
	}
	f[0][0]=1;
	fo(i,0,n)
		fo(j,0,n)
		if (f[i][j]){
			if (j>i)f[i+1][j]=add(f[i+1][j],f[i][j]);
			if (j<n)f[i][j+1]=add(f[i][j+1],f[i][j]*calc(k+i+j*(k+1),i+j*(k+1))%mo);
		}
	printf("%lld\n",f[n][n]*js[n]%mo);
	return 0;
}

Measured memory_bytes: 125568
/* A - Addition and Subtraction Easy */

#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(void) {
    io;
    long long a,b;
    char c;
    cin >> a >> c >> b;
    if (c == '+') {
        cout << (a+b)  << endl;
    } else {
        cout << (a-b) << endl;
    }
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

ll ncr(ll n, ll r){
  if(n < r) return 0;
  if(r > n-r) r = n-r;

  ll a = 1, b = 1;
  for(int i = 0; i < r; i++){
    a *= (n - i);
  }
  for(int i = 0; i < r; i++){
    b *= (i + 1);
  }
  return a/b;
}

int main(){
  ll N, M;
  cin >> N >> M;
  vll A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  vll sum(N+1, 0);
  for(int i = 0; i < N; i++){
    sum.at(i+1) = sum.at(i) + A.at(i); 
  }
  map<int, ll> ma;
  for(int i = 0; i < N+1; i++){
    int n = sum.at(i) % M;
    if(!ma.count(n)) ma[n] = 1LL;
    else ma.at(n)++;
  }
  ll ans = 0LL;
  for(auto ite = ma.begin(); ite != ma.end(); ite++){
    ll n = ite -> second;
    ans += ncr(n, 2LL);
  }
  cout << ans << endl;
}

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    lld N;
    string c;
    cin >> N;
    cin >> c;
    lld rc = 0;
    lld rw = 0;
    for (int i = 0; i < c.size(); i++) {
        if(c[i] == 'R'){
            rc++;
        } else {
            rw++;
        }
    }
    lld ans = 0;
    if(rc == 0 || rw == 0){
        cout << ans << endl;
    } else {
        ans = min(rc,rw);
        lld cnt = 0;
        for (int i = 0; i < rc; i++) {
            if(c[i] == 'W'){
                cnt++;
            }
        }
        ans = min(ans,cnt);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N;
int t[100010], x[100010], y[100010];

int main() {
	cin >> N;
	rep(i, N)cin >> t[i] >> x[i] >> y[i];
	int px = 0, py = 0, pt = 0;
	bool f = true;
	rep(i, N) {
		int nx = abs(x[i] - px);
		int ny = abs(y[i] - py);
		int nt = abs(t[i] - pt);
		px = x[i], py = y[i], pt = t[i];

		// printf("%d %d %d\n", nx, ny, nt);
		if (nt - (nx + ny) < 0) {
			f = false;
		}
		if ((nt - (nx + ny)) % 2) {
			f = false;
		}
	}
	if (f) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
int n;
cin>>n;
char c[n];
int W=0,E=0;
rep(i,n){
cin>>c[i];
if(c[i]=='E')
E++;
}
int M=1000000;
rep(i,n){
  int count;
if(c[i]=='E'){
  E--;
count=W+E;
}
else
{
  count=W+E;
  W++;
}
//cout<<count<<endl;
M=min(M,count);
}
cout<<M<<endl;
  return 0;
}


Measured memory_bytes: 512
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     LL a,b,c,d;
     cin>>a>>b>>c>>d;
     cout<<max({a*c,a*d,b*c,b*d})<<endl;
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 3660
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
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; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
ll GetDigit(ll num){ 
    ll digit=0; 
    while(num!=0){num/=10;digit++;} 
    return digit; 
} 


using namespace std;
//-------------------------------------------

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;cin>>s;
  ifYN(s[2]==s[3]&&s[4]==s[5]);
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)


if __name__ == "__main__":
    solve()


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

int main(){
  
  int N, M;
  cin >> N >> M;
  
  int X[M];
  for (int i = 0; i < M; i++) {
    cin >> X[i];
  }
  sort(X, X+M);
  int distance[M];
  distance[0]=0;
  for (int i = 1; i < M; i++) {
    distance[i]=X[i]-X[i-1];
  }
  sort(distance, distance+M, greater<int>());

  int ans = abs(X[M-1]-X[0]);
  for (int i = 2; i <= min(N,M); i++) {
    ans -= distance[i-2];
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>

int main(int argc, char* argv[])
{
    long n, t;
    scanf("%ld %ld", &n, &t);

	long min = 10000;
	long i;
	for(i=0; i<n; i++) {
		long cc, tt;
		scanf("%ld %ld", &cc, &tt);
		if(tt <= t) {
			if(min > cc)
    			min = cc;
		}
	}
	if(min==10000) {
		printf("TLE\n");
	}
	else {
		printf("%d\n", min);
	}
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <vector>

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

template <typename T>
class UnionFind {
 private:
  vector<T> parent;
  vector<T> group_size;

 public:
  UnionFind(T size_) : parent(size_), group_size(size_, 1) {
    iota(parent.begin(), parent.end(), 0);
  }

  void reset() {
    iota(parent.begin(), parent.end(), 0);
    fill(group_size.begin(), group_size.end(), 1);
  }
  
  T root(T x) { return parent[x] == x ? x : parent[x] = root(parent[x]); }

  void merge(T x, T y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (group_size[x] < group_size[y]) swap(x, y);
    group_size[x] += group_size[y];
    parent[y] = x;
  }

  bool same(T x, T y) { return root(x) == root(y); }
  T size(T x) { return group_size[root(x)]; }
};

int main() {
  int N, M, ans{};
  cin >> N >> M;
  vector<pair<int,int>> e(M);
  for (int i = 0; i != M; ++i) {
    cin >> e[i].first >> e[i].second;
  }

  UnionFind<int> u(N);
  for (int i = 0; i != M; ++i) {
    u.reset();
    for (int j = 0; j != M; ++j) {
      if (i == j) continue;
      u.merge(e[j].first-1, e[j].second-1);
    }
    if (u.size(0) < N) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);


//入力変数
int N=sc.nextInt();
int[][] A=new int[2][N];
for(int i=0;i<N;i++){
    A[0][i]=sc.nextInt();
}
for(int i=0;i<N;i++){
    A[1][i]=sc.nextInt();
}

//入力値変換

//出力変数
int ans;

//計算
int tempofans=0;
int num=0;

for(int k=0;k<N;k++){
    num=0;
    for(int j=0;j<N;j++){
        if(j<=k){
            num+=A[0][j];
        }
        if(j>=k){
            num+=A[1][j];
        }
    }
    if(num>tempofans){
        tempofans=num;
    }
}
ans = tempofans;

//出力
System.out.println(ans);

}}

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

using namespace std;

void print(int A[], int N) {
	for (int i = 0; i < N; ++i) {
		if (i != 0)
			cout << " " << A[i];
		else
			cout << A[i];
	}
	cout << endl;
}

void insertionSort(int A[], int N) {
	print(A, N);
	for (int i = 1; i < N; ++i) {
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			--j;
		}
		A[j + 1] = v;
		print(A, N);
	}
}

int main() {

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

	int A[n];
	for (int i = 0; i < n; ++i) {
		int v;
		scanf("%d", &v);
		A[i] = v;
	}

	insertionSort(A, n);

	return 0;
}

Measured memory_bytes: 3128
//arc077_c.cpp
//Fri Jun  8 22:33:38 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	int a[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
	}

	int b[n];
	int flag = 0;
	int num = 0;
	for (int i=n-1;i>=0;i--){
		b[num] = a[i];
		if (flag == 0){
			num = n-1-num;
			flag = 1;
		}else {
			num = n-1-num+1;
			flag = 0;
		}
	}

	for (int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	printf("\n");
}

Measured memory_bytes: 3712
K = int(input())
A, B = map(int, input().split())
list_ = [(i+A) for i in range(B-A+1)]
count = 0
for i in range(len(list_)):
  if list_[i] % K == 0:
    count += 1
    break

if count > 0:
  print('OK')
else:
  print('NG')

Measured memory_bytes: 9136
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 300 + 10;
int64 dp[N][N], sum[N][N];
int64 C[N][N];

int main() {
  int n, m, mod;
  scanf("%d%d%d", &n, &m, &mod);
  for (int i = 0; i < N; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
  }
  for (int j = 0; j <= m; ++j) dp[1][j] = 1;
  for (int j = m; j >= 0; --j) sum[1][j] = (sum[1][j + 1] + dp[1][j]) % mod;
  for (int i = 2; i <= n + 1; ++i) {
    for (int j = 0; j <= m; ++j) {
      for (int k = 1; k <= i - 1; ++k) {
        dp[i][j] += sum[k][j + 1] * dp[i - k][j] % mod * C[i - 2][k - 1] % mod;
        dp[i][j] %= mod;
      }
    }
    for (int j = m; j >= 0; --j) sum[i][j] = (sum[i][j + 1] + dp[i][j]) % mod;
  }
  printf("%lld\n", dp[n + 1][0]);
  return 0;
}


Measured memory_bytes: 2432
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int t[][] = new int[N][2];		
		for(int i=0;i<N;i++) {
			t[i][0]=sc.nextInt();//x
			t[i][1]=sc.nextInt();//y
		}
		sc.close();
		
		
		double d[][] = new double[N][N];
		for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				//iからjへの距離
				int tix = t[i][0];
				int tiy = t[i][1];
				
				int tjx = t[j][0];
				int tjy = t[j][1];
				
				double dist = Math.sqrt(Math.pow(tix-tjx,2)+Math.pow(tiy-tjy,2));
				
				d[i][j]=dist;
				d[j][i]=dist;
			}
		}
		
		double sum = 0;
		for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				sum += d[i][j];
			}
		}
		double ans = sum/N;
		
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<ll, ll> P;
int main()
{
    int n;
    cin >> n;
    vector<int> v(n + 1);
    int mx = 0;
    rep(i, n)
    {
        int x;
        cin >> x;
        mx = max(mx, x);
        v[x]++;
    }
    if (mx % 2)
    {
        for (int i = mx / 2 + 1; i <= mx; i++)
        {
            v[i] -= 2;
        }
        if (v[mx / 2 + 1] > 0)
        {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    else
    {
        for (int i = mx / 2; i <= mx; i++)
        {
            v[i] -= 2;
        }
        v[mx / 2]++;
        if (v[mx / 2] > 0)
        {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    rep(i, n + 1)
    {
        if (v[i] < 0)
        {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int k  = sc.nextInt();

		int a  = sc.nextInt();
		int b  = sc.nextInt();
		
		int di = a/k;
		int re = a%k;
		
		if( re != 0 ) di += 1;
		System.out.println( di*k <= b ? "OK" : "NG");
	}
	
	
}


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

vector< vector< int > > g;
vector< int > visited;
vector< int > tlist;

void dfs(int v){
	visited[v] = 1;
	
	for(vector< int >::iterator it = g[v].begin(); it != g[v].end(); ++it){
		if(visited[*it] == 0){
			dfs(*it);
		}
	}
	tlist.push_back(v);
	
}

int main(){
	int v, e, s, t;
	
	cin >> v >> e;
	
	g.resize(v);
	visited.resize(v);
	
	for(int i = 0; i < e; ++i){
		cin >> s >> t;
		g[s].push_back(t);
	}
	
	
	for(int i = 0; i < v; ++i){
		if(visited[i] == 0){
			dfs(i);
		}
	}
	
	reverse(tlist.begin(), tlist.end());
	
	for(vector< int >::iterator it = tlist.begin(); it != tlist.end(); ++it){
		cout << (*it) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1988
#include<stdio.h>

int main(void){
	int a, b, c, keta = 0;
	while(scanf("%d%d", &a, &b) != EOF){
		c = a + b;
		while(1){
			c = c / 10;		
			keta++;
			if(c == 0){
				break;
			}
		}
		printf("%d\n", keta);
		keta = 0;
	}
}

Measured memory_bytes: 1716
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################
H,W = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
M = list( list(input()) for _ in range(H) )

# if ch==dh and cw==dw:
#   print(0)
#   exit()

INF = 10**18

for h in range(H):
  for w in range(W):
    if M[h][w] == ".": M[h][w] = INF
    # if M[h][w] == "#": M[h][w] = -1

ch -= 1
cw -= 1
dh -= 1
dw -= 1

M[ch][cw] = 0
# M[dh][dw] = "G"

# _pa(M)


from collections import deque
Q = deque()
Q.append((ch,cw))

ans = INF

while Q:
  h,w = Q.popleft()

  for ih,iw in [(1,0), (-1,0), (0,1), (0,-1)]:
    nh = h + ih
    nw = w + iw
    if nh < 0 or H <= nh: continue
    if nw < 0 or W <= nw: continue
    if M[nh][nw] == "#": continue

    if nh == dh and nw == dw:
      M[nh][nw] = min(M[h][w], M[dh][dw])
      ans = min(ans, M[nh][nw])
      continue

    if M[h][w] < M[nh][nw]:
      M[nh][nw] = M[h][w]
      Q.appendleft((nh,nw))
      continue

    if M[h][w] > M[nh][nw]:
      M[h][w] = M[nh][nw]
      Q.appendleft((h,w))

  for ih,iw in [(1,1), (1,-1), (-1,1), (-1,-1), (2,0), (2,1), (2,2), (2,-1), (2,-2), (1,2), (1,-2), (0,2), (0,-2), (-1,2), (-1,-2), (-2,0), (-2,1), (-2,-2), (-2,-1), (-2,-2)]:
    nh = h + ih
    nw = w + iw
    if nh < 0 or H <= nh: continue
    if nw < 0 or W <= nw: continue
    if M[nh][nw] == "#": continue

    if nh == dh and nw == dw:
      M[nh][nw] = min(M[h][w]+1, M[dh][dw])
      ans = min(ans, M[nh][nw])
      continue

    if M[h][w]+1 < M[nh][nw]:
      M[nh][nw] = M[h][w]+1
      Q.append((nh,nw))
      continue

    if M[h][w] > M[nh][nw]+1:
      M[h][w] = M[nh][nw]+1
      Q.append((h,w))

# _pa(M)

if ans == INF: ans = -1
print(ans)






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

#define M_PI       3.14159265358979323846   // pi

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

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	string s;
	cin >> s;
	int n = s.size();
	const ll t = 13;
	vector<vector<ll>> dp(n + 1, vector<ll>(t, 0));
	dp[0][0] = 1;
	rep(i, n) {
		char c = s[i];
		if (c == '?') {
			rep(a, 10) {
				rep(j, t) {
					int m = (j * 10 + a) % t;
					dp[i + 1][m] += dp[i][j];
					dp[i + 1][m] %= mod;
				}
			}

		}
		else {
			int a = c - '0';
			rep(j, t) {
				int m = (j * 10 + a) % t;
				dp[i + 1][m] += dp[i][j];
				dp[i + 1][m] %= mod;
			}
		}
	}
	cout << dp[n][5] << endl;
	return 0;
}


Measured memory_bytes: 13696
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  int gc=0,ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='g') gc++;
    else gc--;
    if(gc>=s.size()-i-1){
      for(int j=i+1;j<s.size();j++){
        if(s[j]=='g') ans++;
      }
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define NOD(x) (x%2)
using namespace std;

int a, b, c, even, A, B, C, answer;
int main(){
 cin >> a >> b >> c;

 if(NOD(a) && NOD(b) && NOD(c) || !NOD(a) && !NOD(b) && !NOD(c)){
  while(a != max({a,b,c})) { a += 2; answer++; };
  while(b != max({a,b,c})) { b += 2; answer++; };
  while(c != max({a,b,c})) { c += 2; answer++; };
 }else{
  answer++;
  if(NOD(a)) { even++; A++; }
  if(NOD(b)) { even++; B++; }
  if(NOD(c)) { even++; C++; }
  if(even == 1){
	 if(!A)a++;
	 if(!B)b++;
	 if(!C)c++;
	}
	if(even != 1){
	 if(A)a++;
	 if(B)b++;
	 if(C)c++;
	}
  while(a != max({a,b,c})) { a += 2; answer++; };
  while(b != max({a,b,c})) { b += 2; answer++; };
  while(c != max({a,b,c})) { c += 2; answer++; };
 }
 cout << answer << endl; 
 return 0; 
};


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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=200009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


int cnt[M+2],x;
 main()

{
    fast
    int n;
    cin>>n;
    f(i,2,n)
    {
        cin>>x;
        cnt[x]++;
    }
    f(i,1,n)
    {
        cout<<cnt[i]<<" ";
    }
    cout<<endl;


















    return 0;

}













Measured memory_bytes: 5156
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

vector<ll> X;
vector<ll> V;
vector<ll> S;
vector<ll> pmax;
vector<ll> nmax;
ll n;
ll c;
int main() {
    cin >> n >> c;
    X.resize(n+1, 0);
    V.resize(n+1, 0);
    S.resize(n+1, 0);
    pmax.resize(n+1, 0);
    nmax.resize(n+1, 0);
    llrep(i, 0, n) {
        cin >> X[i+1] >> V[i+1];
    }

    ll ans = 0;
    llrep(i, 0, n) {
        S[i+1] = S[i] + V[i+1];
        ans = max(ans, S[i+1]-X[i+1]);
    }

    llrep(i, 0, n) {
        if ((S[pmax[i]] - X[pmax[i]]) < (S[i+1] - X[i+1])) {
            pmax[i+1] = i + 1;
        }else{
            pmax[i+1] = pmax[i];
        };

        if ((S[nmax[i]] - 2 * X[nmax[i]]) < (S[i+1] - 2 * X[i+1])) {
            nmax[i+1] = i + 1;
        }else{
            nmax[i+1] = nmax[i];
        };
    }
    llrrep(i, n, 0) {
        ans = max(ans, S[pmax[i-1]] + (S[n] - S[i-1]) - (X[pmax[i-1]] + 2 * (c - X[i])));
        ans = max(ans, S[nmax[i-1]] + (S[n] - S[i-1]) - (X[nmax[i-1]] * 2 + (c - X[i])));
    }
    cout << ans << endl;
}

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

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

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

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	int count=0;
	for(int i=0;i<n;++i)
	{
		if(a[i]%2!=0 && i%2==0)
			count++;
	}
	cout<<count<<"\n";
}

Measured memory_bytes: 3652
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
	int N,L;
	scanf("%d%d",&N,&L);
	int X[100002];
	X[0]=0;
	X[N+1]=0;
	int XW[100002];
	for(int i=1;i<=N;i++){
		scanf("%d",&X[i]);
	}
	int ans=0;
	vector<int>A,B;
	A.push_back(0);
	for(int i=1;i<=N;i++){
		if(X[i-1]<X[i]&&X[i]>X[i+1])B.push_back(i);
		else if(X[i-1]>X[i]&&X[i]<X[i+1])A.push_back(i);
	}
	A.push_back(N+1);
	for(int i=1;i<=N+2;i++){
		X[i-1]=L-X[i-1];
		if(i==1||i==N+2)X[i-1]=0;
		if(i==1)XW[i]=X[i-1];
		else XW[i]=XW[i-1]+X[i-1];
		//printf("%d\n",XW[i]);
	}
	XW[0]=0;
	for(int i=0;i<B.size();i++){
		ans=max(ans,max(XW[B[i]+1]-XW[A[i]],XW[A[i+1]+1]-XW[B[i]]));
		//printf("%d %d %d\n",A[i],B[i],XW[B[i]+1]-XW[A[i]]);
		//printf("%d %d %d\n",B[i],A[i+1],XW[A[i+1]+1]-XW[B[i]]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2268
N, M = map(int, input().split())
H = list(map(int, input().split()))
A_to_B = [0]*N
for _ in range(M):
    tmp = list(map(int, input().split()))
    if A_to_B[tmp[0]-1] < H[tmp[1]-1]:
        A_to_B[tmp[0]-1] = H[tmp[1]-1]

    if A_to_B[tmp[1]-1] < H[tmp[0]-1]:
        A_to_B[tmp[1]-1] = H[tmp[0]-1]

ans = 0
for i in range(N):
    if H[i] > A_to_B[i]:
        ans += 1
print(ans)


Measured memory_bytes: 20132
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int a[101][101];

int main() {
    int n, m;
    cin >> n >> m;
    REP(i,n) REP(j,m) cin >> a[i][j];
    REP(i,n) REP(j,m) a[i][m] += a[i][j];
    REP(j,m+1) REP(i,n) a[n][j] += a[i][j];
    REP(i,n+1){
        REP(j,m+1){
            cout << a[i][j];
            if (j < m) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long
	int q, h, s, d;
	cin >> q >> h >> s >> d;
	int n;
	cin >> n;
	if (h > 2*q) {
		h = 2 * q;
	}
	if (s > 2 * h) {
		s = 2 * h;
	}
	if (d > 2 * s) {
		d = 2 * s;
	}
	cout << (n / 2)*d + (n % 2)*s << endl;
	return 0;
}

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

int main(int argc, char const* argv[]) {
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int sum = 0;
		int num = i;
		while (num > 0) {
			sum += num % 10;
			num /= 10;
		}
		if (A <= sum && sum <= B) {
			ans += i;
		}
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 3764
#coding: utf-8
from fractions import gcd
import math

# GCDの約数を素因数分解する
def primeFactor(n):
    flg = 0
    count = 0
    tmp = math.sqrt(n)
    i = 2

    if n == 1:
        return 1

    while i <= tmp:
        # print(str(i)+str(',')+str(gcd_cnt))
        if n % i == 0:
            if flg == 0:
                flg = 1
                count += 1
            n = n // i
        else:
            flg = 0
            i += 1
    # if flg == 1:
    #     count += 1
    # print(str('素数=')+str(count)+str(' n=')+str(n)+str(' i=')+str(i))
    if n > 1:
        count += 1
    # 1を足す
    count += 1
    return count


# # print(len(div))
m,n = map(int,input().split())
p = gcd(m,n)
# print(str('gcd=')+ str(p))
ans = primeFactor(p)
print(ans)


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

template <typename T>
struct segtree {
	int n;
	vector<T> tree;
	
	segtree(int n_) {
		for (n = 1; n < n_; n *= 2) {
			
		}
		tree.assign(2 * n, 0);
	}
	
	void update(int a, int b, int index, int l, int r, T x) {
		if (r <= a || b <= l) {
			return;
		}
		if (a <= l && r <= b) {
			tree[index] += x;
			return;
		}
		update(a, b, 2 * index, l, (l + r) / 2, x);
		update(a, b, 2 * index + 1, (l + r) / 2, r, x);
	}
	
	void update(int l, int r, T x) {
		update(l, r, 1, 0, n, x);
	}
	
	T query(int a, int b, int index, int l, int r) {
		if (r <= a || b <= l) {
			return 0;
		}
		if (a <= l && r <= b) {
			return tree[index];
		}
		tree[2 * index] += tree[index];
		tree[2 * index + 1] += tree[index];
		tree[index] = 0;
		T puni = query(a, b, 2 * index, l, (l + r) / 2);
		T muni = query(a, b, 2 * index + 1, (l + r) / 2, r);
		return puni + muni;
	}
	
	T query(int l, int r) {
		return query(l, r, 1, 0, n);
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	segtree<int> seg(n);
	for (int i = 0; i < q; i++) {
		bool b;
		cin >> b;
		if (b) {
			int x;
			cin >> x;
			cout << seg.query(x - 1, x) << endl;
		} else {
			int s, t, x;
			cin >> s >> t >> x;
			seg.update(s - 1, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 3892
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=2e5+5,YL=1e9+7;
inline int MO(const int &x){return x>=YL?x-YL:x;}
inline int in(){int k;cin>>k;return k;}
int cnt[1<<18],a[1<<18],mp[1<<18],rev[1<<18],L[19],R[19];
inline int low(int x){return x&(-x);}
int n,A,B;
void calc(int a,int b,int c)
{
	if(cnt[c^((1<<n)-1)]==1)return printf("%d %d ",b,a^b),void();
	for(int i=0;i<n;++i)
		if(!(c&(1<<i))&&(a&(1<<i)))
			for(int j=0;j<n;++j)
				if(!(c&(1<<j))&&i!=j)
					return calc(1<<j,b,c|(1<<i)),
						calc(a^(1<<i)^(1<<j),b^(1<<i)^(1<<j),c^(1<<i));
}
int main()
{
	ios::sync_with_stdio(0);cin>>n>>A>>B;
	for(int i=0;i<1<<n;++i)cnt[i]=cnt[i>>1]+(i&1);
	if(cnt[A^B]&1)puts("YES"),calc(A^B,A,0),puts("");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 3072
from itertools import permutations
n=int(input())
l = list(permutations(range(1, n+1))) 
s1=[int(x) for x in input().split()]
s2=[int(x) for x in input().split()]
# print(l)
# print(s1)
# print(s2)
pos1=l.index(tuple(s1))
pos2=l.index(tuple(s2))
# print(pos1,pos2)
print(abs(pos1-pos2))

Measured memory_bytes: 8052
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for i in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(1,N+1):
    for w in range(W+1):
        if w-wv[i-1][0]>=0:
            dp[i][w] = max(dp[i-1][w-wv[i-1][0]]+wv[i-1][1],dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]
print(dp[N][W])


Measured memory_bytes: 120172
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n;
cin >> n;
ll a[n];
ll b[n];
for(ll i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i]-i;
}
sort(b,b+n);
ll best_b = b[n/2];
ll ans=0;
for(ll i=0;i<n;i++){
    ans+=abs(b[i]-best_b);
    }
    cout << ans << endl;
}


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

using namespace std;

string solve(){
	string s;
	string t;
	cin>>s;
	cin>>t;
	if(t.length() != s.length()+1)
		return "No";
	for(int i=0;i<s.length();i++)
		if(s[i]!=t[i])
			return "No";

	return "Yes";
}
int main(){
	
	cout<<solve();

	return 0;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);

		str = br.readLine().split(" ");

		long sum = 0;
		for (int i = 0; i < k; i++) {
			int a = Integer.parseInt(str[i]);

			sum += a;
		}
		if (n < sum) {
			System.out.println("-1");
		} else {
			System.out.println(n - sum);
		}
	}
}

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

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(),x.end());
  for (int i = 0; i < M; i++) {
    cin >> y.at(i);
  }
  sort(y.begin(),y.end());
  int Z=y.at(0);
  if(x.at(N-1)<Z && X<Z && Z<=Y) cout << "No War" << endl;
  else cout << "War" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
struct Node {int num, left, right; };
struct Node T[10000];
void pre(int a);
void in(int a);
void post(int a);

int main(void)
{
    int n, i, v, l, r, root;
    scanf("%d",&n);
    for(i = 0; i < n; i++)
    {
        T[i].num = -1;
    }
    for(i = 0; i < n; i++)
    {
        scanf("%d %d %d",&v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if(l != -1) T[l].num = v;
        if(r != -1) T[r].num = v;
    }
    for(i = 0; i < n; i++)
    {
        if(T[i].num == -1) root = i;
    }
    printf("Preorder\n");
    pre(root);
    printf("\nInorder\n");
    in(root);
    printf("\nPostorder\n");
    post(root);
    printf("\n");
    return 0;
}
void pre(int a)
{
    if(a == -1) return;
    
    printf(" %d",a);
    pre(T[a].left);
    pre(T[a].right);
}
void in(int a)
{
    if(a == -1) return;
    in(T[a].left);
    printf(" %d",a);
    in(T[a].right);
}
void post(int a)
{
    if(a == -1) return;
    post(T[a].left);
    post(T[a].right);
    printf(" %d",a);
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

int main(){
    int n; vector<int> v(3); cin >> n >> v[0] >> v[1] >> v[2];
    vector<P> c(n);
    rep(i,n){
        string s; cin >> s;
        c[i].first = s[0] - 'A';
        c[i].second = s[1] - 'A';
    }
    vector<char> ans;

    auto check = [&](int k){
        if(v[0] + v[1] + v[2] == 0) return false;

        int c1 = c[k].first, c2 = c[k].second;

        if(v[0] + v[1] + v[2] == 1){
            if(v[c1] + v[c2] == 0) return false;

            if(v[c1] == 0) {
                v[c1]++;
                v[c2]--;
                ans.pb('A' + c1);
            }
            else{
                v[c1]--;
                v[c2]++;
                ans.pb('A' + c2);
            }
        }
        else{
            if(v[c1] + v[c2] == 0) return false;

            if(v[0] + v[1] + v[2] == 2 && v[c1] == 1 && v[c2] == 1 && k != n-1 && c[k] != c[k+1]){
                int n1 = c[k+1].first, n2 = c[k+1].second;
                if(c1 == n1){
                    v[0]++; v[c2]--;
                    ans.pb('A');
                }
                else if(c2 == n2){
                    v[2]++; v[c1]--;
                    ans.pb('C');
                }
                else{
                    v[1]++;
                    if(c1 == 1) v[c2]--;
                    else v[c1]--;
                    ans.pb('B');
                }
            }

            else if(v[c1] <= v[c2]) {
                v[c1]++;
                v[c2]--;
                ans.pb('A' + c1);
            }
            else{
                v[c1]--;
                v[c2]++;
                ans.pb('A' + c2);
            }

        }
        return true;
    };

    rep(i,n){
        if(!check(i)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    rep(i,n){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 4396
import java.util.Scanner;

public class Main {

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

		Scanner scanner = new Scanner(System.in);

		//入力表示
		String N = scanner.next();
		String S = scanner.next();
		String T = scanner.next();

		//
		char[] a = S.toCharArray();
		char[] b = T.toCharArray();
		StringBuilder sb = new StringBuilder();
		
		for (int i = 0; i < Integer.parseInt(N); i++) {
			
			sb.append(a[i]);
			sb.append(b[i]);

		}
		
		String d = new String(sb);
		System.out.println(d);

		scanner.close();
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,f = 1;
  cin >> n;
  vector<pair<int,int>> p(n);
  ll s = 0;
  for(int i = 0;i<n;i++)
  {
      int a,b;
      cin >> a >> b;
      p[i] = make_pair(b,a);
  }
  sort(p.begin(),p.end());
  for(int i = 0;i<n;i++)
  {
    s += p[i].second;
    if(s > p[i].first)
    {
      f = 0;
      break;
    }
  }
  if(f) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 6e3+69;
const int mod = 1e9+7;
int m,n;
int t;
int x,y,z;
struct vl{
	int x,y;
	bool operator<(vl t)const {
		if(x==t.x)return y<t.y;
		return x<t.x;
	}
};
int dp[MAXN];
vl a[MAXN];
signed main(){																																																																																						ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>t;
	for(int i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		for(int j=MAXN-1;j>=0;j--){
			if(j>=a[i].x&&j-a[i].x<t){
				dp[j]=max(dp[j],dp[j-a[i].x]+a[i].y);
			}
			
			//cout<<dp[j]<<' ';
		}
		//cout<<endl;
	}
	int ans = 0;
	for(int i=0;i<MAXN;i++){
		//cout<<dp[i]<<' ';
		ans = max(ans,dp[i]);
	}
	cout<<ans;
}  
/*
3 5
5 7
3 4
4 4
*/

Measured memory_bytes: 3692