akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate

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

c = [0] + list(accumulate(a))
d = [0] + list(accumulate(b))

ans = 0
i = 0
j = len(b)

while True:
    num = c[i] + d[j]
    if num > k and j >= 1:
        while True:
            j -= 1
            if j == 0 or c[i] + d[j] <= k:
                break
    if c[i] + d[j] <= k:
        ans = max(ans, i + j)
    if i == len(a):
        break
    while True:
        i += 1
        if i == len(a) or c[i] + d[j] > k:
            i -= 1
            break
    if c[i] + d[j] <= k:
        ans = max(ans, i + j)
    i += 1

print(ans)

Measured memory_bytes: 129940
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int a,b; cin >> a >> b;
    if(a < 10 && b < 10) cout << a*b << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>

using namespace std;
unsigned int* h;
unsigned int N;
unsigned int findMax() {
    unsigned max = 0;
    unsigned int found = N;
    for (unsigned int i = 0; i < N; i++) {
        if (max < h[i]) {
            max = h[i];
            found = i;
        }
    }
    return found;
}

std::pair<unsigned int, unsigned int> searchRound(unsigned int orig) {
    std::pair<unsigned int, unsigned int> ret = {orig, orig};
    unsigned int i;
    for (i = orig; 0 < i; i--) {
        if (h[i - 1] > 0) {
            if (i == 1) {
                ret.first = 0;
                break;
            }
            continue;
        }
        ret.first = i;
        break;
    }
    for (i = orig; i < (N - 1); i++) {
        if (h[i + 1] > 0) {
            if (i == (N - 2)) {
                ret.second = N - 1;
                break;
            }
            continue;
        }
        ret.second = i;
        break;
    }
    return ret;
}

void give(std::pair<unsigned int, unsigned int> targets) {
     for (unsigned int i = targets.first; i <= targets.second; i++) {
         h[i]--;
     }
}

void show() {
    for (unsigned int i = 0; i < N; i++) {
        cout << h[i] << ' ';
    }
    cout << endl;
}
int main() {
    cin >> N;
    h = new unsigned int(N);    
    for (unsigned int i = 0; i < N; i++) {
        cin >> h[i];
    }

    unsigned int count = 0;
    do {
        unsigned int target = findMax();
        if (target == N) break;
        count++;
        std::pair<unsigned int, unsigned int> targets = searchRound(target);
        give(targets);
        //show();
    } while (1);
    
    cout << count << endl;
    //delete [] h;
    return 0;
}



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

int main(){
    int n;
    cin>>n;
    string a,b;
    int pa=0,pb=0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(a==b){
            pa++;
            pb++;
        }
        else if(a>b){
            pa+=3;
        }
        else if(a<b){
            pb+=3;
        }
    }
    cout<<pa<<' '<<pb<<endl;
}


Measured memory_bytes: 3180
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[100]={};
    int ki=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2!=0){
            ki++;
        }
    }
  long long int ans;
    if(ki==0){
        if(k==0){
            ans=pow(2,n);
        }else{
          ans=0;
        }
    }else{
        ans=pow(2,n-1);
    }
  cout<<ans<<endl;
}



Measured memory_bytes: 512
#include <stdio.h>

using namespace std;

int main(){
   int a,b;
   double a_d,b_d;
   scanf("%d %d",&a,&b);
   a_d = static_cast<double>(a);
   b_d = static_cast<double>(b);
   printf("%d %d %.5f\n",a/b,a%b,a_d/b_d);
}


Measured memory_bytes: 2716
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    int nm = n + m - 1;

    vector<P> v(nm);
    rep(i, nm) cin >> v[i].first >> v[i].second;
    rep(i, nm) v[i].first--, v[i].second--;

    vector<int> parent_count(n, 0); // 親が何人いますか？
    for (P p : v) parent_count[p.second]++;

    int root = distance(parent_count.begin(), find(parent_count.begin(), parent_count.end(), 0));

    vector<vector<int>> edges(n);
    for (P p : v) edges[p.first].push_back(p.second);

    queue<int> q;
    q.push(root);

    vector<int> parents(n, -1);

    while (!q.empty()) {
        int t = q.front();
        q.pop();

        for (int next : edges[t]) {
            parent_count[next]--;
            if (parent_count[next] == 0) {
                parents[next] = t;
                q.push(next);
            }
        }
    }

    for (int p : parents) cout << p + 1 << endl;

}


Measured memory_bytes: 11032
import bisect
A,B,Q = map(int,input().split())

inf = 10000000000000000000000
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]

S.append(inf)
S.append(-inf)
T.append(inf)
T.append(-inf)

X = [int(input()) for _ in range(Q)]

for x in X:
    ans = 0
    S_ind = bisect.bisect_left(S,x,0,A)
    T_ind = bisect.bisect_left(T,x,0,B)

    # print(S_ind,T_ind,'tar=',x)
    # L_s,R_s = S[S_ind-1],S[S_ind]
    # L_t,R_t = T[T_ind-1],T[T_ind]

    # print(L_s,L_t, x, R_s, R_t)

    tmp1,tmp2,tmp3,tmp4 = 100000000000,100000000000,100000000000,100000000000


    L_s,R_s = S[S_ind-1],S[S_ind]
    L_t,R_t = T[T_ind-1],T[T_ind]

    if True:# 0 < S_ind < A and 0 < T_ind < B:

        # L_s,R_s = S[S_ind-1],S[S_ind]
        # L_t,R_t = T[T_ind-1],T[T_ind]

        #同じ方向に進むとき
        tmp1 = max(x - L_s, x - L_t)
        tmp2 = max(-(x - R_s), -(x - R_t))

        #行って戻るとき
        if L_s < L_t and R_s < R_t:
            tmp3 = 2*min(x - L_t, R_s - x) + max(x - L_t, R_s - x)
        if L_t < L_s and R_t < R_s:
            tmp4 = 2*min(x - L_s, R_t - x) + max(x - L_s, R_t - x)

        ans = min(tmp1,tmp2,tmp3,tmp4)

    print(ans)


Measured memory_bytes: 16140
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline #inputに置き換え可能

from bisect import bisect

# N: 数列の長さ
# A[i]: a_i の値
def solve(N, A):
    INF = 10**10

    dp = [INF]*(N+1)
    dp[0] = -1
    for a in A:
        idx = bisect(dp, a)
        dp[idx] = min(a, dp[idx])
    return max(i for i in range(N+1) if dp[i] < INF)

n = int(input())
a = [int(input()) for i in range(n)]
a.reverse()

print(solve(n, a))

Measured memory_bytes: 13892
n=int(input())
listv = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

summ = 0
for i in range(n):
    if listv[i]-listc[i]>0:
        summ += listv[i]-listc[i]
        
print(summ)

Measured memory_bytes: 3060
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  double h,a;
  cin>>h>>a;

  cout<<ceil(h/a)<<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
char S[200002];
int main(){
  int i, res=0, tmp=0;
  rd(N);
  rd(S);
  for(i=0;i<N;i++){
    if(S[i]=='I'){
      tmp++;
    }
    else{
      tmp--;
    }
    chmax(res, tmp);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N;
// char S[200002];
// {
//   int i, tmp = 0, res = 0;
// 
//   rd(N,S);
//   rep(i,N){
//     if(S[i]=='I') tmp++;
//     else          tmp--;
//     res >?= tmp;
//   }
//   
//   wt(res);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_V 100000
typedef pair<ll,int> P;
ll INF=100000000000LL;

struct edge { ll to,cap,cost,rev; };

int V;
vector<edge> G[MAX_V];
ll h[MAX_V];
ll dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init_edge(){
  for(int i=0;i<V;i++)G[i].clear();
}

void add_edge(int from,int to,int cap,ll cost){
  G[from].push_back((edge){to,cap,cost,(int)G[to].size()});
  G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
}

ll min_cost_flow(int s,int t,int f){
  ll res = 0;
  fill(h,h+V,0);
  while(f>0){

    priority_queue< P, vector<P>, greater<P> >  que;
    fill( dist, dist+V , INF );
    dist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      int v = p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&dist[e.to] > dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }

    if(dist[t]==INF){
      return -1;
    }
    for(int v=0;v<V;v++)h[v]+=dist[v];

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,(int)G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=(ll)d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int H,W;
int t[200][200];

int main(){
  cin>>H>>W;
  int si=H*W*2;
  int ti=si+1;
  V=ti+1;

  int N=H*W;
  ll mx=1e6;
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>t[i][j];
      add_edge(i*W+j,i*W+j+N,1,mx);
      add_edge(i*W+j,i*W+j+N,1,mx-t[i][j]);
      //      add_edge(i*W+j,i*W+j+N,1,mx);
      if(i+1<H){
        int id=(i+1)*W+j;
        add_edge(i*W+j+N,id,2,0);
      }
      if(j+1<W){
        int id=i*W+(j+1);
        add_edge(i*W+j+N,id,2,0);
      }
      
    }
  }
  add_edge(si, 0, 2, 0);
  add_edge( (H-1)*W+(W-1)+N , ti, 2,0);

  ll ans= min_cost_flow(si,ti,2);
  
  ans-=mx*(H+W-1)*2;
  cout<<-ans<<endl;
  return 0;
}



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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



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

const int N = 200005;

void solve()
{
	int n;
	cin >> n;
	n--;

	string ans = "";

	while (n >= 0)
	{

		int x = n % 26;
		ans += (char)('a' + x );
		n /= 26;
		n--;
	}
	reverse(all(ans));

	cout << ans << endl;
	return;

}

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



	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

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

#define COUT(x) cout << x << endl
#define CIN(x) cin >> x
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define EXIST(s, e) (s.find(e) != s.end())
#define SORT(c) sort(c.begin(), c.end())
#define ERASEUNIQE(v) v.erase(unique(v.begin(), v.end()), v.end())

// 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();
}

// math
template <class T>
inline T sqr(T x) { return x * x; }

// typedef
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

// container util
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()

// constant
const double EPS = 1e-10;
const double PI = acos(-1.0);

// debug
#define dump(x) cerr << #x << " = " << x << endl;
#define debug(x) cerr << #x << " = " << x << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int main(int argc, char const *argv[])
{
    int n, a, b;
    CIN(n);
    if (n == 1)
    {
        COUT("Hello World");
    }
    else
    {
        CIN(a), CIN(b);
        COUT(a + b);
    }
    return 0;
}


Measured memory_bytes: 256
n, m, l = map(int,input().split())

a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(m)]
c = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    for j in range(l):
        c[i][j] = str(sum(a[i][k] * b[k][j] for k in range(m)))

for i in c:
    print(*i)


Measured memory_bytes: 7284
#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	while( cin >> n , n ){
		vector<P> v;
		for(int i=0 ; i < n ; i++ ){
			int c;
			cin >> c;
			
			int k = v.size() - 1;
			if( i % 2 == 0 ){ // テ」ツ?イテ」ツ?」テ」ツ?湘」ツつ甘ィツソツ氾」ツ?陛」ツ?ェテ」ツ??
				if( v.empty() ){
					v.push_back( P(c, 1) );
				}else if( v[k].first == c ){
					v[k].second++;
				}else{
					v.push_back( P(c, 1) );
				}
			}else{ 
				if( v[k].first == c ){
					v[k].second++;
				}else{ // テ」ツ?イテ」ツ?」テ」ツ?湘」ツつ甘ィツソツ氾」ツ??
					if( v.size() >= 2 ){
						int m = v[k].second + 1;
						v.pop_back();
						k = v.size() - 1;
						v[k].second += m;
					}else{
						v[k].first = c;
						v[k].second++;
					}
				}
			}
		}
		int ans = 0;
		for(int i=0 ; i < v.size() ; i++ ){
			if( v[i].first == 0 ) ans += v[i].second;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	String s = scan.next();

	//初期のドットの数
	int firstDot = 0;
	for(int i = 0; i < n; i++){
	    if(s.charAt(i) == '.'){
		firstDot++;
	    }
	}

	int min = firstDot;
	int tmp = firstDot;
	//基準を設定
	//基準より左は .
	//基準より右は #
	for(int i = 0; i < n; i++){
	    //変える必要がない .
	    if(s.charAt(i) == '.'){
		tmp--;
		//変える必要がある#
	    }else{
		tmp++;
	    }
	    if(min > tmp){
		min = tmp;
	    }
	}

	System.out.println(min);
    }
}


Measured memory_bytes: 27664
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  
  ll sum = 0;
  ll M = N;
  while(M > 0){
    sum += M % 10;
    M /= 10;
  }

  if(N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX/ 2 + 2];

llong merge(int A[], int n, int left, int mid, int right) {
    int i, j, k;
    llong cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    for ( i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++) {
        if ( L[i] <= R[j] ) {
            A[k] = L[i++];
        }else {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

llong mergeSort(int A[], int n, int left, int right) {
    int mid;
    llong v1, v2, v3;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        v1 = mergeSort(A, n, left, mid);
        v2 = mergeSort(A, n, mid, right);
        v3 = merge(A, n, left, mid, right);
        return v1 + v2 + v3;
    }
    else return 0;
}

int main() {
    int A[MAX], n, i;
    
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> A[i];
    }
    
    llong ans = mergeSort( A, n, 0, n );
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4680
/**
 *      AGC 23 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-11 01:40:56
**/
     
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
     
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
        
    int N; scanf("%d", &N);
    int A[N] = {};
    for (int i = 0; i < N; ++i) {
        scanf("%d", &A[i]);
    }
     
    ll s[N] = {};
    s[0] = A[0];
    for (int i = 1; i < N; ++i) {
        s[i] = A[i] + s[i - 1];
    }
     
    sort(s, s + N);
     
    ll answer = 0;
    int begin = 0;
     
    for (int i = 0; i < N; ++i) {
        if (s[i] == 0){
            ++answer;
        }
    }
     
    while (begin < N){
        int end = begin;
        while (end + 1 < N && s[end + 1] == s[begin]){
            ++end;
        }
        ll len = end - begin + 1;
        answer += len * (len - 1) / 2;
        begin = end + 1;
    }
    cout << answer << endl;          
    return 0;
}

Measured memory_bytes: 2560
import Control.Applicative
import Control.Monad
import Data.List

f xs = head $ filter (`notElem` xs) ['a'..'z']

g xs = go (init xs) [last xs]
  where
    go [] _  = []
    go as bs = case filter (> la) bs of
        [] -> go (init as) (la:bs)
        cs -> init as ++ [minimum cs]
      where
        la = last as

main :: IO ()
main = do
    ss <- getLine
    if length ss /= 26
        then putStrLn $ ss ++ [f ss]
        else case g ss of
            [] -> print (-1)
            gs -> putStrLn gs

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

ll sigma(ll N){
    return (N*(N+1))/2;
}

int main(){
    ll N; cin >> N;
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        ll num = N / i;
        ans += sigma(num)*i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int l = S.size() / 2;
  while (1)
  {
    l--;
    string t = S.substr(0, l);
    string u = S.substr(l, l);
    if (t == u)
      break;
  }
  cout << l * 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int const height = 2;
    int const width = 3;
    char C[width][height];
    for (int i = 0; i < height; ++i) {
        for (int j = 0; j < width; ++j) {
            std::cin >> C[j][i];
        }
    }
    std::cout << (C[0][0] == C[2][1] && C[0][1] == C[2][0] && C[1][0] == C[1][1] ? "YES" : "NO") << std::endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s_list = list(str(input()))
r = 0
g = 0
b = 0

for i in range(n):
    if s_list[i] == 'R':
        r += 1
    elif s_list[i] == 'G':
        g += 1
    else:
        b += 1

ans = r * g * b

for d in range(1, n):
    for i in range(n):
        if i + 2 * d >= n:
            break
        if s_list[i] != s_list[i + d] and \
            s_list[i] != s_list[i + 2 * d] and \
            s_list[i + d] != s_list[i + 2 * d]:
            ans -= 1

print(ans)


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < K; i++)
    {
        ans += p[i];
    }
    
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n)-1)
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

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

    int n;
    cin >> n;
    LL x,time[2020]={},m[2020];
    vector<vector<pair<int,LL>>> a(n);
    cin >> x;
    REP(i,n){
        cin >> time[i];
        m[i]=time[i];
        a[i].push_back(make_pair(0,m[i]));
    }
    REPN(i,1,n-1){
        REP(j,n){
            m[j]=min(m[j],time[(j-i+n)%n]);
            a[j].push_back(make_pair(i,m[j]));
        }
    }
    LL ans=2E18;
    REP(i,n){
        LL tmp=0;
        REP(j,n){
            tmp+=(a[j].begin()+i)->second;
        }
        ans=min(ans,tmp+x*i);
    }

    cout << ans <<endl;


    return 0;
}


Measured memory_bytes: 64512
#include <iostream>
#include <string>

using namespace std;

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

    bool AC = true;
    if('A' != S[0]){
        AC = false;
    }else{
        int C_cnt = 0;
        for(int i = 2; i < S.length() - 1; ++i){
            if('C' == S[i]){
                ++C_cnt;
                S[i] = 'c';
            }
        }
        AC = (C_cnt == 1);
        for(int i = 1; i < S.length(); ++i){
            if(('A' <= S[i]) && (S[i] <= 'Z')){
                AC = false;
                break;
            }
        }
    }

    if(AC) cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}

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

typedef long long ll;

#define PB push_back

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	int a[n + 1];
	int b[n];
	for (int i = 0; i <= n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> b[i];
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] >= b[i]) {
			ans += b[i];
			a[i] -= b[i];
		} else {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
			if (a[i + 1] >= b[i]) {
				ans += b[i];
				a[i + 1] -= b[i];
			} else {
				ans += a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
	cout << ans << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using namespace std;


int main(void) {
    int ab, bc, ca;
    cin >> ab;
    cin >> bc;
    cin >> ca;

    // ヘロンの公式   
    auto s = (ab + bc + ca) / 2;
    auto ans = sqrt(s * (s - ab) * (s - bc) * (s - ca));

    cout << ans << endl; 

    return 0;
}

Measured memory_bytes: 256
# AOJ ITP2_4_B: Rotate
# Python3 2018.6.24 bal4u

from collections import deque
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	b, m, e = map(int, input().split())
	s = deque(a[b:e])
	s.rotate(e-m)
	a = a[:b] + list(s) + a[e:]
print(*a)


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

const string YES = "YES";
const string NO = "NO";

bool isOk2(int r, int c, ll H, ll W){
    if(c < 0){
        return false;
    }
    if(c >= W){
        return false;
    }
    if(r < 0){
        return false;
    }
    if(r >= H){
        return false;
    }
    return true;
}

bool char2row(char c){
    if(c == 'U'){
        return -1;
    }
    if(c == 'D'){
        return +1;
    }
    return 0;
}

bool char2col(char c){
    if(c == 'L'){
        return -1;
    }
    if(c == 'R'){
        return 1;
    }
    return 0;
}


void solve(long long H, long long W, long long N, long long s_r, long long s_c, std::string S, std::string T){
    int deathL = -1;
    int deathR = W;
    int deathU = -1;
    int deathD = H;
    s_r--;
    s_c--;
    for(int i=N-1; i >= 0; i--){
        if(T.at(i) == 'L' && deathR < W){
            deathR++;
        }else if(T.at(i) == 'R' && deathL > -1){
            deathL--;
        }else if(T.at(i) == 'U' && deathD < H){
            deathD++;
        }else if(T.at(i) == 'D' && deathU > -1){
            deathU--;
        }

        if(S.at(i) == 'L'){
            deathL++;
        }else if(S.at(i) == 'R'){
            deathR--;
        }else if(S.at(i) == 'U'){
            deathU++;
        }else if(S.at(i) == 'D'){
            deathD--;
        }

        if(deathL == W-1 || deathR == 0 || deathU == H-1 || deathD == 0){
            cout << NO << endl;
            return;
        }
    }

    if(s_r <= deathU || s_r >= deathD || s_c <= deathL || s_c >= deathR){
        cout << NO << endl;
        return;
    }

    cout << YES << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long N;
    scanf("%lld",&N);
    long long s_r;
    scanf("%lld",&s_r);
    long long s_c;
    scanf("%lld",&s_c);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(H, W, N, s_r, s_c, S, T);
    return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
    string n;
    cin>>n;
    ll sum=0;
rep(i,n.size()){
    char p=n[i];
    ll pp;
    if(p=='0')pp=0;
    if(p=='1')pp=1;
    if(p=='2')pp=2;
    if(p=='3')pp=3;
    if(p=='4')pp=4;
    if(p=='5')pp=5;
    if(p=='6')pp=6;
    if(p=='7')pp=7;
    if(p=='8')pp=8;
    if(p=='9')pp=9;
sum+=pp;
sum=sum%9;   
}

if(sum%9==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  string s,t;
  cin>>s>>t;
  int l=s.size();
  bool ans=false;
  rep(i,l){
    bool temp=true;
    rep(j,l) if(s[(j+i)%l]!=t[j]){
      temp=false;
      break;
    }
    if(temp){
      ans=true;
      break;
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


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

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

#define fastio                              ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
#define read                                freopen("input.txt", "r", stdin);
#define write                               freopen("output.txt", "w", stdout);
#define nl                                  '\n'
#define mem(ara,n)                          memset(ara,n,sizeof ara)
#define debug(x)                            cerr << #x << " = " << x << nl

#define ll                                  long long
#define ull                                 unsigned long long
#define vi                                  vector<int>
#define pb                                  push_back
#define vpii                                vector<pair<int, int>>
#define vpll                                vector<pair<ll, ll>>
#define mp                                  make_pair
#define ff                                  first
#define ss                                  second
#define all(v)                              v.begin(), v.end()
#define rsort(v)                            sort(v.rbegin(), v.rend())

using namespace std;

const double pi = 2*acos(0.0);

int main(){
    //fastio; 
    //read;
    ull n, count = 0, sum = 0, i = 1;
    cin >> n;
    for(ull i = 1; i <= n; i++){
        if(i%3 and i%5) sum += i;
    }
    cout << sum << nl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>

using namespace std;

string s1;
string s2;
string s3;


int main() {

	cin >> s1;
	cin >> s2;
	cin >> s3;
	cout << s1.at(0) << s2.at(1) << s3.at(2) << endl;

	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a_s = [int(input()) for _ in range(m)]

dp = [1]
n_with_a = [[i, False] for i in range(n+1)]



for a in a_s:
    n_with_a[a][1] = True



if 1 in a_s:
    dp.append(0)
else:
    dp.append(1)

for i, is_broken in n_with_a[2:]:
    if is_broken:
        dp.append(0)
    else:
        dp.append((dp[i-1] + dp[i-2]) % 1000000007)

print(dp[-1])


Measured memory_bytes: 21984
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define revrep(i,n) for(int i=n;i>=0;i--) 
#define MOD 1e9+7;
#define EPS 1e-8
#define INF 1e9+10
typedef long long ll;
using namespace std;
int main()
{
    int N,M,L;
    cin >> N >> M >> L;
    vector<vector<ll>>d(N,vector<ll>(N,INF)),e(N,vector<ll>(N,INF));
    
    rep(i,0,M){
        int A,B;
        ll C;
        cin >> A >> B;
        cin >> C;
        if(C>L){continue;}
        d[A-1][B-1]=C;
        d[B-1][A-1]=C;
    }
   
    int Q;
    cin >> Q;
    vector<int>s(Q),t(Q);
    rep(i,0,Q)cin >> s[i] >> t[i];

    rep(i,0,N){d[i][i]=0;}

    rep(k,0,N){
        rep(i,0,N){
            rep(j,0,N){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }

    rep(i,0,N){
        rep(j,0,N){
            if(d[i][j]<=L){e[i][j]=1;}
        }
    }
    rep(i,0,N){e[i][i]=0;}

    rep(k,0,N){
        rep(i,0,N){
            rep(j,0,N){
                e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
            }
        }
    }


    rep(i,0,Q){
        int fr=s[i]-1;
        int to=t[i]-1;

        if(e[fr][to]>=INF){
            cout << -1 << endl;
        }
        else{
            cout << e[fr][to] - 1 << endl;
        }
    }
}



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

int main()
{
    //freopen("C:\\Users\\tiger\\Desktop\\a.txt","r",stdin);
	int n,max;
    while ( ~scanf("%d %d", &n, &max) ) {
        int a[n];
		for (int i = 0; i < n; ++i)
        {
            scanf("%d", &a[i]);
        }

        long long cnt = 0;

        if ( a[0] > max )
        {
        	cnt = a[0] - max;
            a[0] = a[0] - cnt;
        }
        for (int i = 1; i < n; ++i)
        {
            if ( a[i]+a[i-1] > max )
            {
                cnt = cnt + a[i]+a[i-1] -max;
                a[i] = a[i] - (a[i]+a[i-1] -max);
            }
        }
        printf("%lld\n", cnt);
    }
	return 0;
}


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

typedef long long ll;

int main() {
    const double interest = 0.01;
    ll X;
    cin >> X;
    ll cur = 100;
    ll ans = 0;
    while (cur < X) {
        ans++;
        cur = cur * (1+interest);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

//union_find(親par,深さrnk)
int rnk[160801],par[160801];
void union_init(int n){
    for(int i=0;i<n;i++){
        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);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    union_init(160801);
    vector<char> c(401*401,' ');
    rep(i,H){
        rep(j,W){
            cin >> c[i*401+j];
        }
    }
    rep(i,H){
        rep(j,W-1){
            if(c[i*401+j]!=c[i*401+j+1]){
                unite(i*401+j,i*401+j+1);
            }
        }
    }
    rep(i,H-1){
        rep(j,W){
            if(c[i*401+j]!=c[(i+1)*401+j]){
                unite(i*401+j,(i+1)*401+j);
            }
        }
    }
    map<ll,ll> mp;
    rep(i,160801){
        mp[find(i)*2+i%2]++;
    }
    ll ans=0;
    rep(i,160801){
        ans+=mp[2*i]*mp[2*i+1];
    }
    cout << ans << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 24948
#include<bits/stdc++.h>
using namespace std;
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; }
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
static const int mod = 1e+7;
static const long long INF = 1LL << 60;
int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    rep(i,N) cin >> h[i];
    vector<ll>dp(100100);
    // ll dp[100100];
    rep(i,100100)dp[i] = INF;
    dp[0] = 0;
    rep(i,N){
        for(int j = 1; j <= K; j++){
            chmin(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout << dp[N-1] << endl;
}


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

int main(){
  int N, M;
  int a[60] = {}, b[60] = {}, c[60] = {}, d[60] = {};

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

  for(int i = 1; i <= N; i++){

    int min = 1000000000;
    for(int j = 1; j <= M; j++){
      int dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(dist < min){
        min = dist;
      }
    }

    for(int j = 1; j <= M; j++){
      int dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(dist == min){
        printf("%d\n", j);
        break;
      }
    }

  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,cnt=0;
  cin>>n>>x;
  int d[n],l[n];
  d[1]=0;
  for(int i=1;i<=n;i++){
    cin>>l[i];
    d[i+1]=d[i]+l[i];
  }
  for(int i=1;i<=n+1;i++){
    if(d[i]<=x)cnt++;
  }
  cout<<cnt<<endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, W;
	cin >> N >> W;
	vector<ll> w(N), v(N);
	REP(i, N) cin >> w[i] >> v[i];

	vector<pll> ws[4];
	REP(i, N){
		REP(j, 4){
			if(w[i]==w[0]+j) ws[j].push_back({v[i], w[i]});
		}
	}
	REP(i, 4) sort(ws[i].rbegin(), ws[i].rend());

	/*
	REP(i, 4){
		REP(j, ws[i].size()) cout << ws[i][j].first << " ";
		cout << endl;
	}
	*/

	vector<ll> vs[4];
	REP(i, 4){
		vs[i].push_back(0);
		REP(j, ws[i].size()){
			vs[i].push_back(vs[i][j]+ws[i][j].first);
		}
	}

	ll res = -1;
	ll w0 = ws[0][0].second;
	REP(i, vs[0].size()){
		REP(j, vs[1].size()){
			REP(k, vs[2].size()){
				REP(l, vs[3].size()){
					if(i*w0 + j*(w0+1) + k*(w0+2) + l*(w0+3) > W) continue;
					ll tmp = 0;
					tmp += (vs[0][i] - vs[0][0]);
					tmp += (vs[1][j] - vs[1][0]);
					tmp += (vs[2][k] - vs[2][0]);
					tmp += (vs[3][l] - vs[3][0]);
					res = max(res, tmp);
				}
			}
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()

    if (n == 3) {
        println(2)
        println("1 3")
        println("2 3")
    } else if (n == 4) {
        println(4)
        println("1 2")
        println("1 3")
        println("4 2")
        println("4 3")
    } else if (n % 2 == 1) {
        println((n/2 + 1)*4 - 4)

        for (i in 0..n/2) {
            if (i == 0) {
                println("$n 1")
                println("$n ${n-1}")
            } else if (i == n/2) {
                println("${n/2} $n")
                println("${n/2+1} $n")
            } else {
                println("$i ${i+1}")
                println("$i ${n-i-1}")
                println("${n-i} ${i+1}")
                println("${n-i} ${n-i-1}")
            }
        }
    } else {
        println(2*n)
        for (i in 0..n/2 - 1) {
            if (i == n/2 - 1) {
                println("1 ${n/2}")
                println("1 ${n/2 + 1}")
                println("$n ${n/2}")
                println("$n ${n/2 + 1}")
            } else {
                println("${i+1} ${i+2}")
                println("${i+1} ${n-i-1}")
                println("${n-i} ${i+2}")
                println("${n-i} ${n-i-1}")
            }
        }
    }
}

Measured memory_bytes: 31396
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

long Function(long X);

int main(){
    long A,B;
    cin >> A >> B;
    long C = Function(A-1) ^ Function(B);
    cout << C << endl;
}

long Function(long X){
    if(X % 2 == 0){
        if((X - 1) % 4 == 1){
            return X ^ 1;
        }else{
            return X;
        }
    }else{
        if(X % 4 == 1){
            return 1;
        }else{
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeMap<Integer, Unit> map = new TreeMap<>();
		int max = 0;
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    if (max < x) {
		        max = x;
		        map.put(x, new Unit(i, x));
		    } else {
		        map.lastEntry().getValue().add(x);
		    }
		}
		long[] counts = new long[n];
		Unit prev = map.pollLastEntry().getValue();
		while (map.size() > 0) {
		    Unit now = map.pollLastEntry().getValue();
		    counts[prev.idx] = prev.calcCount(now.value);
		    for (Map.Entry<Integer, Integer> entry : prev.map.entrySet()) {
		        if (now.map.containsKey(entry.getKey())) {
		            now.map.put(entry.getKey(), now.map.get(entry.getKey()) + entry.getValue());
		        } else {
		            now.map.put(entry.getKey(), entry.getValue());
		        }
		    }
		    prev = now;
		}
		counts[prev.idx] = prev.calcCount(0);
		StringBuilder sb = new StringBuilder();
		for (long x : counts) {
		    sb.append(x).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Unit {
	    int idx;
	    int value;
	    TreeMap<Integer, Integer> map = new TreeMap<>();
	    long count = 0;
	    
	    public Unit (int idx, int value) {
	        this.idx = idx;
	        this.value = value;
	        map.put(value, 1);
	    }
	    
	    public void add(int x) {
	        if (map.containsKey(x)) {
	            map.put(x, map.get(x) + 1);
	        } else {
	            map.put(x, 1);
	        }
	    }
	    
	    public long calcCount(int ceil) {
	        while (map.size() > 0) {
	            Map.Entry<Integer, Integer> entry = map.pollLastEntry();
	            int x = entry.getKey();
	            int v = entry.getValue();
	            if (x <= ceil) {
	                map.put(x, v);
	                break;
	            }
	            long size = x - ceil;
	            count += size * v;
	            if (map.containsKey(ceil)) {
	                map.put(ceil, map.get(ceil) + v);
	            } else {
	                map.put(ceil, v);
	            }
	        }
	        return count;
	    }
	}
}


Measured memory_bytes: 86684
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long a;
    cin>>a;
    cout<<a+a*a+a*a*a;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int dp[100010];

int rec(int x){
  if (x == 0) return 0;
  if (dp[x] != -1) return dp[x];

  int res = x;
  for (int pow6 = 1; pow6 <= x; pow6*=6){
    res = min(res,rec(x-pow6)+1);
  }
  for (int pow9 = 1; pow9 <= x; pow9*=9){
    res = min(res,rec(x-pow9) + 1);
  }
  return dp[x] = res;
}

int main(){
  int n;
  cin >> n;
  int ans;
  rep(i,n+1) dp[i] = -1;
  cout << rec(n) << endl;
  
  

  
  return 0;
  
}


Measured memory_bytes: 7004