akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    static ArrayList<Long> l=new ArrayList<>();
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=Long.parseLong(sc.next());
        long po=n;
        long ans=0;
       Map<Long,Integer> map=new HashMap<>();
       
        for(long i=2;i*i<=n;i++){
            while(n%i==0){
                if(map.containsKey(new Long(i))){
                    map.put(i,map.get(i)+1);
                }
                else {
                    map.put(i,1);
                }
                n/=i;
            }
        }
        if(n!=1)map.put(n,1);
        long aa[]=new long[map.size()];
        int index=0;
        for(Long key:map.keySet()){
            aa[index++]=key;
            //System.out.println(aa[index-1]);
        }
        popo(map,aa,map.size()-1,1);
        
        
        /*int count=0;
        for(Long key:map.keySet()){
            System.out.println(key+" "+map.get(key));
            count+=map.get(key);
        }
        long[]array=new long[count];
        int index=0;
        for(Long key:map.keySet()){
            for(int i=0;i<map.get(key);i++){
                array[index++]=key;
            }
        }*/
        
        //for(int i=0;i<count;i++)System.out.println(array[i]);
        //System.out.println(count);
        Collections.sort(l);
        for(int i=0;i<l.size()/2;i++){
            long a=Long.parseLong(l.get(l.size()-1-i)+"")-1;
            //System.out.println(a);
            if(po%a==po/a)ans+=a;
        }
        System.out.println(ans);
    }
    public static void popo(Map map,long[]aa,int size,long value){
        if(size<0){
            //System.out.println(value);
            l.add(value);
        }
        else{
            for(int i=0;i<Integer.parseInt(map.get(aa[size])+"");i++){
            if(i==0){
                popo(map,aa,size-1,value);
            }
            popo(map,aa,size-1,value*aa[size]);
            value*=aa[size];
        }
        }
    }
}


Measured memory_bytes: 30544
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    ll k;
    cin >> k;   

    int n = s.length();

    ll res = 0;
    ll sum0 = 1;
    ll sum1 = 1;
    bool ok1 = true;
    rep(i, n - 1) {
        if (ok1) {
            if (s[i] == s[i + 1]) {
               sum0++;
               continue;
            }
            else {
                ok1 = false;
            }
        }

        if (s[i] == s[i + 1]) {
            sum1++;
            continue;
        }
        res += sum1 / 2;
        sum1 = 1;
    }
    
    res *= k;

    if (sum0 == n) {
        cout << sum0 * k / 2 << endl;
        return 0;
    }

    if (s[0] == s[n-1]) {
        res += sum0 / 2 + (sum0 + sum1) / 2 * (k - 1) + sum1 / 2;
    }
    else {
        res += (sum0 / 2 + sum1 / 2) * k;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void ABC60(void);
void ABC61(void);
void ABC62(void);
void ABC63(void);
void ABC64(void);
void ABC65(void);
void ABC66(void);
void ABC67(void);
void ABC68(void);
void ABC69(void);

int main(void){
    ABC69();
}

void ABC69(void){
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
bool seen[100000];
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

//input



//processing
int ans = 0;



//dpTable
//int dp[100050];
int main(){
    string S,T;
    cin >> S >> T;
    rep (i,S.size()) {
        if (S.at(i) != T.at(i)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    int N; cin>>N;
    vector<ll> a(5,0);
    string S;
    for(int i=0;i<N;i++){
        cin>>S;
        if(S[0]=='M')a[0]++;
        else if(S[0]=='A')a[1]++;
        else if(S[0]=='R')a[2]++;
        else if(S[0]=='C')a[3]++;
        else if(S[0]=='H')a[4]++;
    }
    ll ans=0;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ans+=a[i]*a[j]*a[k];
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  bool ex = true;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    if(a[i] != 0)ex = false;
  }
  sort(a.begin(),a.end());
  if(a[0] == 0 && a[n-1] == 0)cout << "Yes" << endl;
  else if(n % 3 == 0){
    if(a[0] == 0 && a[n/3-1] == 0 && a[n/3] == a[n-1])cout << "Yes" << endl;
    else if(a[0] == a[n/3-1] && a[n/3] == a[2*n/3-1] 
            && a[2*n/3] == a[n-1] && (a[0]^a[n/3]^a[n-1]) == 0)cout << "Yes" << endl;
    else cout << "No" << endl; 
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

const int MAXW = 17, E = 0, S = 1;
int dx[] = {1,0};
int dy[] = {0,1};

bool mat[MAXW][MAXW][2];
int dp[MAXW][MAXW];

int main()
{
    int gx, gy, p, n; cin >> n;
    rep(k,n)
    {
        memset(dp, 0, sizeof(dp)); dp[0][0] = 1;
        memset(mat, 0, sizeof(mat));

        cin >> gx >> gy >> p;
        int x1, x2, y1, y2;
        REP(p)
        {
            cin >> x1 >> y1 >> x2 >> y2;
            if(x1 == x2) mat[x1][min(y1, y2)][S] = 1;
            else mat[min(x1, x2)][y1][E] = 1;
        }

        rep(j, gy + 1)rep(i, gx + 1)
        {
            if(!mat[i][j][E]) dp[i + 1][j] += dp[i][j];
            if(!mat[i][j][S]) dp[i][j + 1] += dp[i][j];
        }

        if(dp[gx][gy] == 0) cout << "Miserable Hokusai!" << endl;
        else cout << dp[gx][gy] << endl;

    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000000;

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

  vector<int> h = vector<int>(n);

  REP(i,n){
    cin >> h[i];
  }

  int ans = 0;

  while (true) {
    int start = -1;
    REP(i,n){
      if (h[i] != 0) {
        start = i;
        break;
      }
    }

    if (start == -1) {
      break;
    }

    for(int i = start; i < n;i++){
      if (h[i] == 0) {
        ans++;
        break;
      }
      if (i == n-1) {
        ans++;
        h[i]--;
        break;
      }
      h[i]--;
    }
  }

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

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

int main(){
long long int t;
cin>>t;
long long int arr[t];
long long int arr1[t],arr3[t-1];


for(int i=1;i<=t;i++)
{
cin>>arr[i];
}
for(int i=1;i<=t;i++)
{
cin>>arr1[i];
}
for(int i=1;i<=t-1;i++)
{
cin>>arr3[i];
}



long long int sum=0;
sum+=arr1[arr[1]];
for(int i=2;i<=t;i++)
{
if(arr[i]-arr[i-1]!=1)
{
sum+=arr1[arr[i]];
}
else{
sum+=arr1[arr[i]]+arr3[arr[i]-1];
}

    
}

cout<<sum<<endl;

return 0;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	bool c=false, f=false;
	rep(i,s.size()){
		if(!c){
			if(s[i]=='C') c=true;
		}else{
			if(s[i]=='F') f=true;
		}
	}
	if(c&&f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(){
    
    
    int a,b;
    cin >> a >> b;
    string A,B;
    
    A = to_string(a);
    B = to_string(b);
    
    string str = A+B;
    long num = atoi(str.c_str());
    
    long suu = num;
    
    suu = sqrt(suu);
    
    suu*=suu;
    
    if(num==suu) cout << "Yes";
    else cout << "No";
    
    
    
    return 0;
}

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

int dps(vector<vector<int>> &winners, int N, int i) {
    if (winners[i].size() == 0) {
    return 0;
  }
  vector<int> depth;
  for (auto v : winners[i]) {
    depth.push_back(dps(winners, N, v));
  }
  sort(depth.begin(), depth.end(), greater<int>());
  int j = 1;
  for (auto &item : depth) {
    item += j;
    j++;
  }
  return *max_element(depth.begin(), depth.end());
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> winners(N + 1);
  for (int i = 2; i < N + 1; ++i) {
    int winner;
    cin >> winner;
    winners[winner].push_back(i);
  }
  cout << dps(winners, N, 1) << endl;
}


Measured memory_bytes: 15104
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>
#include <regex>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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


  // string s("hello william and me");
  // s.replace(s.find("william"), sizeof("william") - 1, "Somename");
  // cout << s << endl;

  int a, b;
  cin >> a >> b;
  cout << a * b << endl;






  return 0;
}


Measured memory_bytes: 3644
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces
 
Compile: g++  -o E.exe E.cpp 
Execute: ./E
*/ 
 
#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
#include <algorithm> 
using namespace std;
 
int main() { 	
	int n, x, y; 
	
	cin >> n; 
	int r[n], s[n];
	for(int i = 0; i < n; i++) {
		cin >> x >> y; 
		r[i] = (x+y); 
		s[i] = (x-y); 
	}
	
	int min_value_r = *min_element(r, r+n), 
		max_value_r = *max_element(r, r+n),
		min_value_s = *min_element(s, s+n), 
		max_value_s = *max_element(s, s+n);
	
	cout << max(max_value_r - min_value_r, max_value_s - min_value_s) << endl; 
	
	return 0; 
} 

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

int main () {
    int N,X,remX,Ans;
    int sumX = 0;
    cin >> N >> X;

    vector<int> M(N);
    for (int i=0; i < N; i++) {
        cin >> M[i];
        sumX += M[i];
    }
    
    remX = X-sumX;
    sort(M.begin(), M.end());
    Ans = N+remX/M[0];
    cout << Ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll A(3 * N);
  REP(i, 0, 3 * N) {
    ll a;
    cin >> a;
    A[i] = a;
  }
  sort(A.begin(), A.end(), greater<>());

  ll ans = 0;
  REP(i, 1, N+1) {
    ans += A[i * 2 - 1];
  }
  cout << ans << endl;

  return 0;
}


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

#define FOR(i,m,M) for(int i = m;i<M;i++)

int main()
{
	long long N,m = 1,n;
	bool flag = false;
	cin >> N;
	
	for(long long i = (long long)sqrt(N);i>0;i--)
	{
		if (N % i == 0)
		{
			m = i;
			break;
		}
	}
	n = N / m;
	cout << n + m - 2;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
long long box[20001];
int main(void)
{
	int n,a[20001],m,k,i,j,MIN,MAX;
	scanf("%d %d %d",&n,&m,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		box[i]=0;
	}
	box[0]=0;
	for(i=1;i<=n;i++){
		MIN=1000000001;
		MAX=0;
		for(j=0;j<m;j++){
			if(i+j>n){
				break;
			}
			MIN=min(MIN,a[i+j]);
			MAX=max(MAX,a[i+j]);
			box[i+j]=min(box[i+j],(long long)(MAX-MIN)*(j+1)+k+box[i-1]);
			if(box[i+j]==0){
				box[i+j]=(long long)(MAX-MIN)*(j+1)+k+box[i-1];
			}
		}
	}
	printf("%lld\n",box[n]);
	return 0;
}


Measured memory_bytes: 2944
import java.util.*;


public class Main{
	static int[] dp=new int[1000001];
	
	static int solve(int[] arr,int n,int k,int i)
	{
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=Integer.MAX_VALUE;
		for(int it=1;it<=k;it++)
		{
			if(i+it>=n)
			{
				break;
			}
			ans=Math.min(ans,solve(arr,n,k,i+it)+Math.abs(arr[i+it]-arr[i]));
			
		}
		return dp[i]=ans;
		
	}
	
	
	
	public static void main(String[] args) {
		Arrays.fill(dp,0,1000000,-1);
		Scanner sc=new Scanner(System.in);
		int n,k;
		n=sc.nextInt();
		k=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
		}
		System.out.println(solve(arr, n, k, 0));
		
		
		
		sc.close();

	}

}


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

int main(){
  int l,n;
  vector<string>list;
  string s;
  cin >> n >> l;
  for(int i=0;i < n;i++){
    cin >> s;
    list.push_back(s);
  }
  sort(list.begin(),list.end());
  for(int i=0;i<n;i++){
    cout << list[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define mo 1000000007
using namespace std;
long long n,k,i,j,a[2005],ans;
long long read(){
	char ch=getchar();
	long long xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
void pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
	return;
}
int main(){
	n=read();k=read();
	for(i=1;i<=n;i++)
		a[i]=read();
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(a[i]>a[j]){
				if(i<j){
					ans=ans+(1LL+k)*k/2;
				}
				else{
					ans=ans+(k-1LL)*k/2;
				}
				ans%=mo;
			}
	cout<<ans<<endl;
	return 0;
}

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

void print_vec(vector<ll> vec) {
    for (int a = 0; a < vec.size(); ++a){
        cout << vec[a] << " ";
    }
    cout << endl;
}

int main() {
    ll n, k, v, vs[101];

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

    ll res = LONG_MIN;

    for(int m = 0; m <= min(k, n); ++m) {
        for(int i = n - m; i <= n; ++i) {
            vector<ll> a = vector<ll>();
            for(int j = 0; j < m; ++j) {
                a.push_back(vs[i + j]);
            }
            sort(a.begin(), a.end());

            int l = -1;
            for(int j = 0; j < m; ++j) {
                if (a[j] >= 0) {
                    break;
                } else {
                    l += 1;
                }
            }
            for(int j = 0; j <= min(ll(l), k-m-1); ++j) {
                a[j] = 0;
            }
            res = max(res, accumulate(a.begin(), a.end(), 0LL));
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

uint lps(const vector<vector<uint>>& E, vector<uint>& LP, const uint v) {
	if(LP[v] > 0) return LP[v];

	uint d = 0;
	for(auto nv : E[v]) {
		d = max(d, lps(E, LP, nv) + 1);
	}
	
	LP[v] = d;
	return d;
}

int main() {
	uint N, M;
	cin >> N >> M;

	vector<vector<uint>> E(N, vector<uint>());
	for(uint i=0; i<M; i++) {
		uint x, y;
		cin >> x >> y;
		E[x-1].emplace_back(y-1);
	}

	vector<uint> V(N);

	uint ans = 0;
	for(uint i=0; i<N; i++) { // start node
		ans = max(ans, lps(E, V, i));
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vvi A(2,vi(N));
  cin >> A;

  vvi B(2,vi(N));
  B[0][0] = A[0][0];
  rep(i,1,N){
    B[0][i] = B[0][i-1]+A[0][i];
  }
  B[1][N-1] = A[1][N-1];
  rrep(i,N-2,-1){
    B[1][i] = B[1][i+1]+A[1][i];
  }

  vi C(N);

  rep(i,N) C[i] = B[0][i] + B[1][i];

  cout << *max_element(rng(C)) << "\n";



}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 256
#include <cstdio>
#define NIL -1
#define MAX 10000

struct Node {
    int parent, left, right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if(u==NIL) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u) {
    int h1=0, h2=0;
    if(T[u].left != NIL)  h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
    
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void preorder(int u) {
    if(u == NIL) return;
    printf(" %d", u);
    preorder(T[u].left);
    preorder(T[u].right);
}

void inorder(int u) {
    if(u == NIL) return;
    inorder(T[u].left);
    printf(" %d", u);
    inorder(T[u].right);
}

void postorder(int u) {
    if(u == NIL) return;
    postorder(T[u].left);
    postorder(T[u].right);
    printf(" %d", u);
}

int main() {
    int v, l, r, root=0;
    scanf("%d", &n);
    
    for (int i=0; i<n; i++) T[i].parent = NIL;
    
    for (int i=0; i<n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }
    
    for (int i=0; i<n; i++) if(T[i].parent == NIL) root = i;
    
    setDepth(root, 0);
    setHeight(root);
    
    printf("Preorder\n");
    preorder(root);
    printf("\nInorder\n");
    inorder(root);
    printf("\nPostorder\n");
    postorder(root);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 2752
import math

def solve(n,a,b):
  diff = b - a
  if diff % 2 == 0:
    return (diff + 1) // 2
  
  # foward to "1" table and A stay 1 round
  root_a = a
  # A kicks back to B
  root_a += diff // 2
  # foward to "N" table B stay 1 round
  root_b = n - b + 1
  # B kicks back to A
  root_b += diff // 2
  
  return min(root_a, root_b)

n, a, b = map(int,input().split())
ans = solve(n,a,b)
print(ans)

Measured memory_bytes: 9196
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getMaxEffectiveBit(ull a)
{
	ll index = -1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

inline ll getSpecifiedBit(ull a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

ll val(ll a, ll c, ll d)
{
	ll m = c / getGcd(c, d) * d;
	return a - a / c - a / d + a / m;
}

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

	ll n;
	cin >> n;

	vector<ll> ps(n);
	for (ll i = 0; i < ps.size(); ++i)
	{
		cin >> ps[i];
	}

	ll res = 0;
	for (ll i = 0; i + 2 < n; ++i)
	{
		vector<ll> tmp = { ps[i], ps[i + 1], ps[i + 2] };
		sort(tmp.begin(), tmp.end());
		if (tmp[1] == ps[i + 1])
		{
			++res;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')

//------------------------------------------------------------------------------
const int UF_SIZE = 100000;

int par[UF_SIZE];
int rnk[UF_SIZE];

void union_find_init(int n) {
  REP(i, n) {
    par[i] = i;
    rnk[i] = 0;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

//------------------------------------------------------------------------------
const int N_MAX = 100000;
const int M_MAX = 100000;

int N, M;
int p[N_MAX];
int x[M_MAX];
int y[M_MAX];

void solve() {
  union_find_init(N);
  REP(i, M) unite(x[i], y[i]);
  int ans = 0;
  REP(i, N) {
    if (find(i) == find(p[i])) ans++;
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, N) {
    scanf("%d", p + i);
    --p[i];
  }
  REP(i, M) {
    scanf("%d%d", x + i, y + i);
    --x[i];
    --y[i];
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int N, M, a[364364];
long long int r;

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(int &x){int k;x=0;for(;;){k=gc();if(48<=k&&k<=57){x=k-48;break;}}for(;;){k=gc();if(k<48||k>57)break;x=x*10+k-48;}}

int main(){
    read(N);
    M = N + (N << 1);
    for(int i = 0; i ^ M; ++i){
        read(a[i]);
    }
    sort(a, a + M, greater<int>());
    for(int i = 0; i ^ N; ++i){
        r += a[i * 2 + 1];
    }
    printf("%lld", r);
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    while(cin >> s) {
        int n = s.size(), ok = 0, a = -1, b = -1;
        for(int i = 0; i < n && !ok; i++) {
            if(i+1 < n && s[i] == s[i+1]) {
                ok = 1; a = i+1; b = i+2;
            } else if (i+2 < n && s[i] == s[i+2]) {
                ok = 1; a = i+1; b = i+3;
            }
        }
        cout << a << " " << b << '\n';
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    int A,B,C;
    cin >> A >> B >> C;
    swap(A,B);
    swap(A,C);
    cout << A csp B csp C << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main()
{
	ll a;
	ld b;
	cin >> a >> b;
	//int c = b * 100;
	ll sum = a * b;
	//sum /= 100;
	cout << sum << endl;
	/*
	ld ddddddddddd = a * b;
	cout << ddddddddddd << endl;
	*/
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }


int main(){
    ll n;
    cin >> n;
    ll a[n] = {};
    vector<ll> vec(n);
    ll memo = 0;

    rep(i,0,n){
        ll a;
        cin >> a;

        ll ok = memo, ng = -1;
        while(abs(ok-ng) > 1){
            ll mid = (ok+ng)/2;
            if(vec[mid] < a) ok = mid;
            else ng = mid;
        }

        if(ok == memo) vec[memo++] = a;
        else vec[ok] = a;
    }
    
    cout << memo << endl;
    return 0;
}


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

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  bool d=0;
  
  for(int i=a;i<=b;i++){
    if(i%k==0){
      d+=1;
      break;
    }
  }
  if(d==1){
    cout<<"OK"<<endl;
  }
  else
    cout<<"NG"<<endl;
}
      

Measured memory_bytes: 3620
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
const val YES = "Yes"
const val NO = "No"
fun solve(N: Int){
    for (i in 0..N/4){
        for (j in 0..N/7){
            if (4*i + 7*j == N){
                println(YES)
                return
            }
        }
    }
                println(NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    solve(N)
}



Measured memory_bytes: 29600
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD =  1000000007;
const int INF = 1e11;
using Graph = vector<vector<int>>;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

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

  int ans = 0;
  vector<int> cnt(K+1); //cnt[i]:iがgcdであるような配列の個数
  for( int i = K; i >= 1; i-- ){
    cnt[i] = modpow(K/i, N, MOD);
    for( int j = 2; i*j <= K; j++ ) cnt[i] -= cnt[i*j];
    while( cnt[i] < 0 ) cnt[i] += MOD;
    ans += cnt[i]*i;
    ans %= MOD;
  }
  cout << ans << endl;

}


Measured memory_bytes: 3948
N,K = map(int,input().split())
a=[int(x) for x in range(N)]
for i in range(N):#1の場所を探す。他の数字は関係ない。
  if a[i]==1:
    p=i
L = p#1の左にある個数
R = N-p-1#1の右にある個数
count=L//(K-1)+R//(K-1)#一回の作業で(K-1)個変換できる
L_=L%(K-1)
R_=R%(K-1)#左右の端数を最初に処理したい。
if 0<L_+R_<=(K-1):
  count +=1
elif L_+R_>=K:
  count +=2
print(count)

Measured memory_bytes: 7088
#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 100000000;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= 10) { print("error"); }
	else { print(a + b); }
	return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n,k; scanf("%d%d",&n,&k);
   vector<int> a(n);
   rep(i,0,n)scanf("%d",&a[i]);
   sort(ALL(a));
   ll res=0;
   rep(i,0,n-k)res+=a[i];
   printf("%lld\n",res);
   return 0;
}

Measured memory_bytes: 1024
from collections import deque

n, u, v = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

d_1 = deque()
d_1.append(u-1)
dist_1 = [-1] * n
dist_1[u-1] = 0
while d_1:
    node = d_1.popleft()
    for next_node in edge[node]:
        if dist_1[next_node] < 0:
            dist_1[next_node] = dist_1[node] + 1
            d_1.append(next_node)

d_2 = deque()
d_2.append(v-1)
dist_2 = [-1] * n
dist_2[v-1] = 0
while d_2:
    node = d_2.popleft()
    for next_node in edge[node]:
        if dist_2[next_node] < 0:
            dist_2[next_node] = dist_2[node] + 1
            d_2.append(next_node)

res = 0
for i in range(n):
    if dist_1[i] < dist_2[i]:
        res = max(res, dist_2[i]-1)
print(res)

Measured memory_bytes: 64748
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int N;
	List<int> c, d;
	void Solve()
	{
		N = F;
		var a = G;
		var b = G;
		var s = 0;
		for (var i = 29; i >= 0; i--)
		{
			int n = 1 << i, m = n << 1, t = 0, l1 = 0, l2 = 0, r1 = 0, r2 = 0, k = m - 1;
			if (i == 29)
			{
				c = new List<int>(a);
				d = new List<int>(b);
				c.Sort();
				d.Sort();
			}
			else
			{
				c = Sort(c, k);
				d = Sort(d, k);
				//for (var j = 0; j < N; j++) c[j] &= k;
				//for (var j = 0; j < N; j++) d[j] &= k;
			}
			for (var j = N - 1; j >= 0; j--)
			{
				var x = d[j];
				l1 = Incr(l1, n - x);
				r1 = Incr(r1, m - x);
				l2 = Incr(l2, n + m - x);
				r2 = Incr(r2, 2 * m - x);
				t += r1 - l1;
				t += r2 - l2;
				t %= 2;
			}
			if (t > 0) s ^= 1 << i;
		}
		WriteLine(s);
	}
	int Incr(int i, int v)
	{
		while (i < N && c[i] < v) i++;
		return i;
	}
	List<int> Sort(List<int> x, int mask)
	{
		var m = 0;
		while (m < N && x[m] <= mask) m++;
		for (var i = 0; i < N; i++) x[i] &= mask;
		if (m == 0 || m == N) return x;
		return Merge(x, m);
	}
	// x[0, m) , x[m, N) => sort
	List<int> Merge(List<int> x, int m)
	{
		var y = new List<int>();
		int l1 = 0, r1 = m;
		while (true)
		{
			if (x[l1] <= x[r1]) y.Add(x[l1++]);
			else y.Add(x[r1++]);
			if (l1 == m || r1 == N) break;
		}
		while (l1 < m) y.Add(x[l1++]);
		while (r1 < N) y.Add(x[r1++]);
		return y;
	}
}


Measured memory_bytes: 46544
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n*n];
    for(int row = 0; row < n; row++){
        for(int clm = 0; clm < n; clm ++){
            scanf("%d",&arr[row*n + clm]);
        }
    }
    int S[(n+1)*(n+1)];
    for(int i = 0; i < n+1; i++){
        S[i] = 0;
        S[i*(n+1)] = 0;
    }
    for(int row = 1; row < n+1; row++){
        for(int clm = 1; clm < n+1; clm ++){
            S[row*(n+1) + clm] = S[row*(n+1) + clm-1] + S[(row-1)*(n+1) + clm] - S[(row-1)*(n+1) + clm-1] + arr[(row-1)*n + clm-1];
        }
    }
    /*
    for(int i = 0; i < (n+1)*(n+1); i++){
        if(i % (n+1) == 0){
            printf("\n");
        }
        printf("%d ",S[i]);
    }
    printf("\n");
    */
    int maxs = S[n+2],maxe;
    for(int rowf = 1; rowf < n+1; rowf++){
        for(int clmf = 1; clmf < n+1; clmf++){
            for(int rowt = rowf; rowt < n+1; rowt++){
                for(int clmt = clmf; clmt < n+1; clmt++){
                    if(rowf == rowt && clmf == clmt){
                        maxe = S[rowt*(n+1) + clmt] - S[rowt*(n+1) + clmf-1] - S[(rowf-1)*(n+1) + clmt] + S[(rowf-1)*(n+1) + clmf-1];
                    }else{
                        maxe = max(maxe,S[rowt*(n+1) + clmt] - S[rowt*(n+1) + clmf-1] - S[(rowf-1)*(n+1) + clmt] + S[(rowf-1)*(n+1) + clmf-1]);
                    }
                    maxs = max(maxs,maxe);
                    //printf("maxe %d\n",maxe);
                    //printf("maxs %d\n",maxs);
                }
            }
        }
    }
    printf("%d\n",maxs);
}

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

typedef struct {
  int n;
  int A;
} st;

int f(const void *a,const void *b){
  return ((st*)a)->A-((st*)b)->A;
}

int main(){
  int N;
  st S[100002];
  scanf("%d",&N);
  int T;
  for(int i=0;i<N;i++){
    scanf("%d",&T);
    S[i].n=i+1;
    S[i].A=T;
  }
  qsort(S,N,sizeof(st),f);
  for(int i=0;i<N;i++){
    printf("%d",S[i].n);
    if(i<N-1) printf(" ");
    else printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3044
#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
    char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
    in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
    in ll read()
    {
        ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
        x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
    }
    in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
    in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
    in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
    in void flush() {if(C>1<<22) ot();}
    template <typename T>
    in void write(T x,char t)
    {
        int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
        if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
    }
    in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=85;
int n,m,a[N][N];bitset<25605>f[N][N];
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=abs(a[i][j]-read());
	f[1][1][a[1][1]+12800]=1;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		if(i^n) f[i+1][j]|=f[i][j]<<a[i+1][j],f[i+1][j]|=f[i][j]>>a[i+1][j];
		if(j^m) f[i][j+1]|=f[i][j]<<a[i][j+1],f[i][j+1]|=f[i][j]>>a[i][j+1];
	}
	for(int i=12800;i<=25600;i++) if(f[n][m][i]) return write(i-12800,'\n'),ot(),0;
}
//Author: disangan233
//In my dream's scene,I can see the everything that in Cyaegha.

Measured memory_bytes: 24448
#include<iostream>
#include<vector>
#include<numeric>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iterator>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  for(int i = 0; i < n; i++) cin >> w.at(i);
  int ans = accumulate(w.begin(), w.end(), 0);
  for(int i = 0; i < n; i++){
    int s1 = accumulate(w.begin(), w.begin() + i + 1, 0);
    int s2 = accumulate(w.begin() + i + 1, w.end(), 0);
    int test = abs(s1-s2);
    if(test < ans){
      ans = test;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
 int n,k ;
   string s;
   cin >> n >> k;
   cin >> s;
   if(s.at(k-1)=='A')
     s.at(k-1)='a';
   if(s.at(k-1)=='B')
     s.at(k-1)='b';
   if(s.at(k-1)=='C')
     s.at(k-1)='c';
   cout << s << endl; }


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

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

int dp[100005];
int main(){
    int n; cin >> n;
    rep(i,100005) dp[i] = 2000000000;
    dp[0] = 0;
    vector<int> h(n); rep(i,n) cin >> h[i];
    for(int i=0;i<n;i++){
        if(i+1 < n) dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        if(i+1 < n) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));

    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

typedef struct {
	int up;
	int left;
	int right;
	int front;
	int back;
	int down;
} dice_t;

void init(dice_t* dice) {
	dice->up=1;
	dice->left=4;
	dice->right=3;
	dice->front=2;
	dice->back=5;
	dice->down=6;
}

void North(dice_t* dice) {
	int temp;
	temp=dice->up;
	dice->up=dice->front;
	dice->front=dice->down;
	dice->down=dice->back;
	dice->back=temp;
}

void East(dice_t* dice) {
	int temp;
	temp=dice->up;
	dice->up=dice->left;
	dice->left=dice->down;
	dice->down=dice->right;
	dice->right=temp;
}

void West(dice_t* dice) {
	int temp;
	temp=dice->up;
	dice->up=dice->right;
	dice->right=dice->down;
	dice->down=dice->left;
	dice->left=temp;
}

void South(dice_t* dice) {
	int temp;
	temp=dice->up;
	dice->up=dice->back;
	dice->back=dice->down;
	dice->down=dice->front;
	dice->front=temp;
}

void Right(dice_t* dice) {
	int temp;
	temp=dice->front;
	dice->front=dice->right;
	dice->right=dice->back;
	dice->back=dice->left;
	dice->left=temp;
}

void Left(dice_t* dice) {
	int temp;
	temp=dice->front;
	dice->front=dice->left;
	dice->left=dice->back;
	dice->back=dice->right;
	dice->right=temp;
}

int main(void) {
	char sizi[10];
	int i,n;
	int sum;
	dice_t dice;
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		init(&dice);
		sum=1;
		for(i=0;i<n;i++) {
			scanf("%s",sizi);
			switch(sizi[0]) {
				case 'N':
					North(&dice);
					break;
				case 'E':
					East(&dice);
					break;
				case 'W':
					West(&dice);
					break;
				case 'S':
					South(&dice);
					break;
				case 'R':
					Right(&dice);
					break;
				case 'L':
					Left(&dice);
					break;
			}
			sum+=dice.up;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#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 pb(a) push_back(a)
using namespace std;
typedef long long ll;

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

    cout << min(A * N, B) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int n;
int a[200005];
int p[200005],q[200005];
map<ll,int>m;
int main(void){
	cin>>n;
	REP(i,n)cin>>a[i];
	REP(i,n)p[i]=a[i]+i;
	REP(i,n)q[i]=a[i]-i;
	REP(i,n)m[p[i]]++;
	ll ans=0;
	REP(i,n)ans+=m[-q[i]];
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 28688
//コード整形版２ 遅くなる？
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

int n, l[2020];

int main(){
  cin >> n;
  rep(i, n) cin >> l[i];
  sort(l, l + n);
  int sum = 0;
  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      auto ub = upper_bound(l + j + 1, l + n, l[i] + l[j] - 1);
      sum += (int)(ub - (l + j + 1));
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>

using namespace std;
#define LL long long
#define LLBIG 1999999999999999999
#define INTBIG 1000000000
#define VI vector<int>
#define VVI vector<vector<int>>

int N, ans[103];
VI a;
bool flg = false;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	for (int i = 0; i < N; i++) {
		for (int j = N - 1 - i; j >= 0; j--) {
			if (a[j] == j + 1) {
				ans[N - 1 - i] = a[j];
				a.erase(a.begin() + j);
				break;
			}
			if (!j) {//不可能
				j = -1; i = N; flg = true;
			}
		}
	}
	if (flg) 
		cout << "-1" << endl;
	else 
		for (int i = 0; i < N; i++)
			cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for(int i=0; i<T; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int sum=0;
    for(int i=0; i<T-1; i++){
        sum+=a[i];
    }
    if(sum>=a[T-1]-1){
        cout << 0;
    }else{
        cout << a[T-1]-sum-1;
    }
}

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

int main(){
    int n;
    int H[4][3][10];
    cin >> n;
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                H[i][j][k] = 0;
            }
        }
    }
    for(int i=0; i<n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        H[b-1][f-1][r-1] += v;
    }
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                cout << " " << H[i][j][k];
            }
            cout << endl;
        }
        if(i != 3) cout << "####################" << endl;
    }
    
    
    return 0;
}

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

//C++14 (GCC 5.4.1)
int main() {
    int N,K;
    cin >>N>>K;

    //-----------------------------------
    int Ans=0;
    if(N%K!=0){
        Ans=1;
    }

    cout << Ans <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> d(n);
  for (int i = 0; i < n; ++i)
    std::cin >> d.at(i);

  std::sort(d.begin(), d.end());
  int dm = d.at(n / 2);
  std::cout << dm - d.at(n / 2 - 1) << std::endl;
}


Measured memory_bytes: 640