akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,c; cin >> a >> b >> c;
    out(c/a*b);

    return 0;
}

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

int A[1000000];

int main()
{
    long long N,B,C;
    while(cin >> N,N){
        long long cnt[4001]={};
        bool NAflag=true,used[4001]={};
        for(int i=0;i<N;i++){
            cin>>A[i]>>B>>C;
            cnt[A[i]] += B*C;

        }
        for(int i=0;i<N;i++){
            if(cnt[A[i]]>=1000000 && used[A[i]]==false){
                printf("%d\n",A[i]);
                used[A[i]]=true;
                NAflag=false;
            }
        }
        if(NAflag==true){
            cout<<"NA"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

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

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

    vector<int> X(N);
    int sub[N];
    int B[N];
    for(int i = 0; i < N; i++) cin >> X[i], sub[i] = X[i];
    sort(X.begin(),X.end());
    int a,b;
    a = X[N/2 - 1];
    b = X[N/2];
    for(int i = 0; i < N; i++)
    {
        if(sub[i] <= a )B[i] = b;
        else if(sub[i] >= b) B[i] = a;
    }
    for(int i = 0; i < N; i++)
    {
        cout << B[i] << endl;
    }

}

Measured memory_bytes: 4480
using System;
using System.Linq;

namespace Volume0_0021
{
    class Program
    {
        static void Main(string[] args)
        {
            var count = Convert.ToInt32(Console.ReadLine());
            for(var i = 0; i < count;i++)
            {
                var input = Console.ReadLine().Split(' ').Select(s => Convert.ToSingle(s)).ToArray();
                Console.WriteLine
                (
                    Line.IsParallel
                    (
                        new Line
                        (
                            new Vector2(input[0], input[1]), new Vector2(input[2], input[3])
                        ),
                        new Line
                        (
                            new Vector2(input[4], input[5]), new Vector2(input[6], input[7])
                        )
                    )
                    ? "YES" :
                    "NO"
                );
            }
        }
    }

    public class Line
    {
        public Vector2 P1 { get; set; }
        public Vector2 P2 { get; set; }

        public Line(Vector2 p1, Vector2 p2)
        {
            P1 = p1;
            P2 = p2;
        }

        public static bool IsParallel(Line line1, Line line2)
        {
            var a1 =  (line1.P2.Y - line1.P1.Y) / (line1.P2.X - line1.P1.X);
            var a2 = (line2.P2.Y - line2.P1.Y) / (line2.P2.X - line2.P1.X);
            return a1 == a2;
        }

    }


    public class Vector2
    {
        public float X { get; set; }
        public float Y { get; set; }
        public Vector2(float x, float y)
        {
            X = x;
            Y = y;
        }
    }
}

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

int main() {
  int N;
  int A;
  cin >> N >> A;
  
  bool res = false;
  for (int i = 0; i<=A; ++i) {
    for (int j = 0; j<=100; ++j){
      if (500*j+i==N) {
	res = true;
	break;
	
	}
      }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,k;
  cin>>n>>k;
  int ans=0;
  while(n){
    ans++;
    n/=k;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
for i in range(0, N-1):
    if H[N-i-2]-1 == H[N-i-1]:
        H[N-i-2] = H[N-i-2]-1
    elif H[N-i-2]-1 > H[N-i-1]:
        print ("No")
        break
else:
    print ("Yes")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

map<int, int>mp;

signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		int a;
		cin >> a;
		mp[a-1]++;
	}
	int m;
	cin >> m;
	rep(i, m) {
		int a;
		cin >> a;
		if (mp[a-1] == 0) {
			cout << "NO" << endl;
			return 0;
		}
		else {
			mp[a-1]--;
		}
	}
	cout << "YES" << endl;

	return 0;
}


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

constexpr long long int MOD = 1000000007;
long long int ans = 0;
int main(int argc, char const *argv[]) {
  long long int N;
  long long int K;
  cin >> N >> K;

  long long int B;
  long long int S;
  for (long long int i = K; i <= N + 1; i++){
    S = i*(i-1)/2;
    B = N*i - S;
    ans = ans + B - S + 1;
  }
  cout << ans % MOD << endl;
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> arr(n);
	for( int i=0; i<n; i++ ){
		cin >> arr[i];
	}
	int count = 0;
	for( int i=0; i<n; i++ ){
		int mini = i;
		for( int j=i+1; j<n; j++ ){
			if( arr[mini] > arr[j] ){
				mini = j;
			}
		}
		if( i != mini ){
			int tmp = arr[mini];
			arr[mini] = arr[i];
			arr[i] = tmp;
			count++;
		}
	}
	cout << arr[0];
	for( int i=1; i<n; i++ ){
		cout << " " << arr[i];
	}
	cout << endl;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
#include <algorithm>
#include <tuple>
using namespace std;
int N, M; tuple<int, int, int> D[20000]; bool infected[20000];
int main() {
	while (true) {
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0) break;
		infected[0] = true;
		for (int i = 1; i < N; i++) infected[i] = false;
		for (int i = 0; i < M; i++) scanf("%d%d%d", &get<0>(D[i]), &get<1>(D[i]), &get<2>(D[i])), get<1>(D[i])--, get<2>(D[i])--;
		sort(D, D + M);
		int ret = 1;
		for (int i = 0; i < M; i++) {
			if (infected[get<1>(D[i])] && !infected[get<2>(D[i])]) {
				infected[get<2>(D[i])] = true; ret++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2920
n,m = map(int,input().split())
li = [int(input()) for i in range(m)]

st = [1]*(n+1)
for i in range(m):
    st[li[i]-1] = 0

if st[0] == 0 and st[1] == 0:
    print(0)
    exit()
elif st[0] == 0 and st[1] != 0:
    st[1] = 1
elif st[0] == 1 and st[1] != 0:
    st[1] = 2

for i in range(2,n+1):
    if st[i] == 0:
        continue
    else:
        st[i] = (st[i-1] + st[i-2])%1000000007
print(st[n-1])
    


Measured memory_bytes: 7848
from collections import deque
h,w = map(int,input().split())
map = [list(input()) for _ in range(h)]
dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

def bfs():
    q = deque([])
    q.append((0,0))
    d = [([-1]*w)for _ in range(h)]

    d[0][0] =  ~-sum(1 for i in range(h) for j in range(w) if map[i][j] == ".")

    while q:
        x,y = q.popleft()
        if (x,y) == (h-1,w-1):
            break
        for i in range(4):
            nx = x+dx[i]
            ny = y+dy[i]
            if 0<=nx<h and 0<=ny<w and d[nx][ny]==-1 and map[nx][ny]!="#":
                q.append((nx,ny))
                d[nx][ny]= d[x][y] -1
    return d[h-1][w-1]
print(bfs())

Measured memory_bytes: 3444
N, A, B, K = map(int, input().split())

MAX = 400000
MOD = 998244353
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

r = 0
for i in range(N+1):
  if (K-A*i)%B != 0:
    continue
  j = (K-A*i)//B
  if 0 <= j <= N:
    r = (r+COM(N, i)*COM(N, j))%MOD
print(r)


Measured memory_bytes: 50468
#include <iostream>

#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

lint L(lint K, lint X, vector<lint> po) {
  if(K==0) return 1;
  if( X<= 1) return 0;
  if(X <= po[K-1]*4-2) return L(K-1, X-1, po);
  if(X <= po[K-1]*4-1) return L(K-1, X-2, po)+1;
  if(X <= po[K]*4-4) return L(K-1, X-(po[K-1]*4-1), po) + po[K]-1 + 1;
  return po[K+1]-1;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;
    lint X; cin >> X;

    vector<lint> po;
    po.push_back(1);
    FOR(i,1,  N+2) {
      po.push_back(po[i-1]*2);
    }

    PRINT(L(N, X, po));
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for _ in range(N)]

dic = defaultdict(int)

for x in S:
	dic[x] += 1

ma = max(dic.values())

a = []
for i in dic.items():
	if i[1] == ma:
		a.append(i[0])

a = sorted(a)
for i in a:
	print(i)

Measured memory_bytes: 112388
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define re(s) reverse(s.begin(),s.end())
int32_t main()
{
    io
string s,t;
cin>>s>>t;int cnt=0;
for(int i=0;i<s.length();i++)
{
  if(s[i]!=t[i])cnt++;
}
cout<<cnt<<endl;
}

Measured memory_bytes: 3740
N = int(input())
H = list(map(int,input().split()))

i = 0
c = 0
max = 0
while(i < N-1):
    if H[i+1] <= H[i]:
        c += 1
    else:
        if max < c:
            max = c
        c = 0
    i += 1
if max < c:
    max = c
print(max)

Measured memory_bytes: 15020
import numpy as np
N, K = map(int, input().split())
a = [0 for i in range(N)]
b = [0 for i in range(N)]
for i in range(N):
    a[i], b[i] = map(int, input().split())
S = 0
s = list(np.argsort(np.array(a)))
for i in range(N):
    if S<K<=S+b[s[i]]:
        print(a[s[i]])
        break
    S += b[s[i]]


Measured memory_bytes: 24580
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 10000;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
ll fac[N] ;
ll mul ( ll a , ll b )
{
    return ((a % MOD )* (b % MOD )) % MOD ;

}
ll fastExp( ll base , ll pow )
{
    ll res = 1 ;
    while ( pow > 0 )
    {

        if ( pow & 1 ) res = mul ( res , base );
        base = mul ( base , base ) ;
        pow >>= 1 ;

    }
    return res ;
}
ll Inv ( ll base  )
{
    return fastExp( base , MOD - 2  );
}
void fact()
{
    fac[0] = 1 ;
    for ( int i = 1 ; i < N ; ++i )
        fac[i]= mul( fac[i-1] , i );

}
ll nCr ( ll n , ll r ){
ll C = fac[n];
C = mul(C , Inv(fac[r]));
C = mul (C , Inv ( fac[n - r] ));
return C ;


}
int main()
{
    fast_io();
    fact();
    int n , blue  ;
    cin >> n >> blue ;
    int red = n - blue ;
    ll res = 0 ;
    for ( int i = 1 ; i <= blue ; ++ i )
     {  if ( i > red+1  ){cout << "0";br  continue ;}
        res = mul ( nCr ( red + 1 , i ) , nCr( blue - 1  , i - 1  ));
        cout << res ;
        br
     }

    return 0 ;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  vector<int>l(n),r(n);
  for(int i=0;i<(n-1);i++){
    l.at(i+1)=gcd(l.at(i),a.at(i));
  }
    for(int i=n-1;i>=1;i--){
      r.at(i-1)=gcd(r.at(i),a.at(i));
    }
      int ans=1;
  for(int i=0;i<n;i++){
    ans=max(ans,gcd(l.at(i),r.at(i)));
  }
    cout<<ans<<endl;
}

      

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

using namespace std;

typedef long long ll;

int main()
{
    int n,c;
    scanf("%d%d",&n,&c);
    const int m=1e5+1;
    vector<ll> x(m,-1e9);
    x[0]=0;
    for(int i=0;i<n;++i)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        for(int j=m-1;j>=a;--j)
            x[j]=max(x[j-a]+b,x[j]);
    }
    ll res=0;
    for(int i=c;i>=0;--i)
        res=max(res,x[i]);
    printf("%lld\n",res);
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
#include <memory.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <queue>
#include <stack>
#include <cstdio>
#include <bitset>

using namespace std;

#define nfs ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define ll long long
#define ull unsigned long long
#define ld long double
#define ef else if
#define loc(x) (x).begin(),(x).end() 
#define locR(x) (x).rbegin(),(x).rend()
#define no puts("NO")
#define yes puts("YES")
#define ex puts("-1")
#define en puts("")
#define _ cout  
#define __ <<
#define outV(v) for(int i = 0 ; i < v.size() ; i++)cout << v[i] << ' ';
#define outA(x,l,r) for(int i = l ; i < r ; i++)cout << x[i] << ' ';

const ld EPS = 1e-18;
const double DEPS = 1e-9;
const ld PI = 3.141592653589793238;
const ll MOD = 998244353;
const int N = (int)(3e5) + 1;


ll gcd(ll fx, ll fy)
{
	if (!fy) return fx;
	return gcd(fy, fx % fy);
}

inline void fill(int* ar, int sz, int val)
{
	for (int i = 0; i < sz; i++)
	{
		ar[i] = val;
	}
}

int n, a[3030];
ll dp[3001][3001];
bool mark[3001][3001];

ll dfs(int l, int r)
{
	if (l > r || r < l)return 0;
	bool t = (r - l) % 2 == n % 2;
	ll& dp = ::dp[l][r];
	if (mark[l][r])return dp;
	mark[l][r] = 1;
	ll x = (t ? -1 : 1) * a[l] + dfs(l + 1, r);
	ll y = (t ? -1 : 1) * a[r] + dfs(l, r - 1);

	return dp = (!t ? max(x, y) : min(x, y));
}

int main()
{
	cin >> n;
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < n; i++)
	{
		scanf("%d", a + i);
	}

	printf("%lld", dfs(0, n - 1));
}

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

int main(){
  ll k;cin >> k;
  queue<ll> q;
  for(ll i=1;i<10;++i) q.push(i);
  rep(i,k-1){
    ll p = q.front();q.pop();
    if( p%10 != 0 ) q.push( p*10 + p%10 -1 );
    q.push( p*10 + p%10 );
    if( p%10 != 9 ) q.push( p*10 + p%10 + 1 );
  }
  cout << q.front() << endl;
  return 0;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ld> sd;
typedef set<ll> sl;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define Plabs     ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
    ll n;
    cin>>n;
    string s="";
    while(n)
    {
        ll x=n%26;

        if(x==0)
        {
            s+="z";
            n/=26;
            n-=1;
        }
        else
        {
            char y=x-1+'a';
            s+=y;
            n/=26;
        }

    }
    reverse(s.begin(),s.end());
    cout<<s;
}











Measured memory_bytes: 3604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int k = sc.nextInt();
        int ans = 0;
        while(num>0){
            num = num / k;
            ans++;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long

ll MIN(ll num1,ll num2){
    return num1<num2?num1:num2;
}

int main(){

    ll N,A,B;
    cin>>N>>A>>B;
    if(((A+B*(N-1))-(A*(N-1)+B)+1)>0)cout<<(A+B*(N-1))-(A*(N-1)+B)+1<<endl;
    else cout<<0<<endl;
    //cout<<(((A+B*(N-1))-(A*(N-1)+B)+1)>0)?(A+B*(N-1))-(A*(N-1)+B)+1:0<<endl;

    return 0;
}

Measured memory_bytes: 256
use std::cmp;
use whiteread::parse_line;

fn main() {
    let _n: usize = parse_line().unwrap();
    let k: i32 = parse_line().unwrap();
    let x: Vec<i32> = parse_line().unwrap();
    let mut res: i32 = 0;
    for i in x {
        res += cmp::min(i, (k - i).abs());
    }
    // 往復
    res *= 2;
    println!("{}", res);
}


Measured memory_bytes: 2156
import sys
input = sys.stdin.readline


def compress(set_):
    """座標圧縮した辞書を返す"""
    array2 = sorted(list(set_))
    memo = {value: index for index, value in enumerate(array2)}
    return memo


def calc_s(hi, wj):
    """座標圧縮後の範囲hi <= i < hi - 1, wj <= j < wj + 1について、
    座標圧縮前の面積を求める
    """
    res = abs(h_rests[hi] - h_rests[hi - 1]) * abs(w_rests[wj] - w_rests[wj + 1]) 
    return res   


h, w = map(int, input().split())
info_h = [list(map(int, input().split())) for i in range(h)]
info_w = [list(map(int, input().split())) for i in range(w)]
INF = 10 ** 20

h_coords = set([-INF, 0, INF])
w_coords = set([-INF, 0, INF])

for h1, h2, w1 in info_h:
    h_coords.add(h1)
    h_coords.add(h2)
    w_coords.add(w1)
for h1, w1, w2 in info_w:
    h_coords.add(h1)
    w_coords.add(w1)
    w_coords.add(w2)

# 座標圧縮
h_comps = compress(h_coords)
w_comps = compress(w_coords)

# 座標復元
h_rests = {h_comps[index]: index for index in h_comps}
w_rests = {w_comps[index]: index for index in w_comps}

# grid[i][j]から進める/進めない方向の情報を管理
# いずれにも進める = 1
# 左右に進めない = 2
# 上下に進めない = 3
# 上下左右にも進めない = 6

# 半開区間の線分で管理
# 横線
# ●-●-●-●-○
# 縦線
# ○
# |
# ●
# |
# ●
# |
# ●

grid = [[1] * (len(w_rests) + 2) for i in range(len(h_rests) + 2)]
for h1, h2, w1 in info_h:
    h1, h2, w1 = h_comps[h1], h_comps[h2], w_comps[w1]
    for hi in range(h1 + 1, h2 + 1):
        grid[hi][w1] *= 2

for h1, w1, w2 in info_w:
    h1, w1, w2 = h_comps[h1], w_comps[w1], w_comps[w2]
    for wi in range(w1, w2):
        grid[h1][wi] *= 3


used = [[False] * (len(w_rests) + 2) for i in range(len(h_rests) + 2)]
si, sw = h_comps[0], w_comps[0]
OFFSET = 5000
stack = [si * 5000 + sw]
ans = 0
used[si][sw] = True

while stack:
    ij = stack.pop()
    i, j = divmod(ij, OFFSET)
    ans += calc_s(i, j)

    # 上移動
    nxt_i, nxt_j = i - 1, j
    if grid[nxt_i][nxt_j] % 3 == 0 or used[nxt_i][nxt_j]:
        # 上に進めない
        pass
    else:
        used[nxt_i][nxt_j] = True
        stack.append(nxt_i * OFFSET + nxt_j)

    # 下移動
    nxt_i, nxt_j = i + 1, j
    if grid[i][j] % 3 == 0 or used[nxt_i][nxt_j]:
        # 下に進めない
        pass
    else:
        used[nxt_i][nxt_j] = True
        stack.append(nxt_i * OFFSET + nxt_j)

    # 右移動
    nxt_i, nxt_j = i, j + 1
    if grid[nxt_i][nxt_j] % 2 == 0 or used[nxt_i][nxt_j]:
        # 右に進めない
        pass
    else:
        used[nxt_i][nxt_j] = True
        stack.append(nxt_i * OFFSET + nxt_j)
        
    # 左移動
    nxt_i, nxt_j = i, j - 1
    if grid[i][j] % 2 == 0 or used[nxt_i][nxt_j]:
        # 左に進めない
        pass
    else:
        used[nxt_i][nxt_j] = True
        stack.append(nxt_i * OFFSET + nxt_j)
        
    if ans > INF:
        #広々としたところに出た場合はINF
        print("INF")
        exit()

print(ans)

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;

int sumDigit(int num) {
  int ans;
  while(num!=0) {
    ans += num % 10;
    num /= 10;
  }
  return ans;
}

int main() {
  int N; cin >> N;
  int total;
  while(N){
    total += N%10;
    N /=10;
  }
  if(total==1) dump("10");
  else dump(total);
}


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

main(){
  int n,i,ans=0;
  cin >> n;
  string s;
  cin >> s;
  
  for(i=0;i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        boolean[] sunuke = new boolean[n];
        for (int i = 0; i < k; i++){
            int d = input.nextInt();
            for (int j = 0; j < d; j++){
                sunuke[input.nextInt() - 1] = true;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++){
            if (!sunuke[i]){
                ans += 1;
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 46192
N = int(input())
t = [0] + list(map(int, input().split()))
v = [0] + list(map(int, input().split()))
max_speed_from_left = [0] * (N + 1) #index i = t[i] とt[i + 1]の間
max_speed_from_right = [0] * (N + 1) #index i = t[i] とt[i + 1]の間

for i in range(1, N):
    start = max_speed_from_left[i - 1]
    max_speed_from_left[i] = min(start + t[i], v[i], v[i + 1])

for i in range(N - 1, 0, -1):
    start = max_speed_from_right[i + 1]
    max_speed_from_right[i] = min(start + t[i + 1], v[i], v[i + 1])

speed = [min(x, y) for x, y in zip(max_speed_from_left, max_speed_from_right)]

def dist(left_speed, right_speed, t, v):
    x = (v - left_speed) + (v - right_speed)
    if x >= t:
        v = (left_speed + right_speed + t)/2
        x = t
    #最高速度vに到達してt-x余る
    d = (left_speed + v) * (v - left_speed)/2
    d += v * (t - x)
    d += (right_speed + v) * (v - right_speed)/2
    return d

ans = 0
for i in range(1, N + 1):
    ans += dist(speed[i -1], speed[i], t[i], v[i])
print (ans)

     



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

class Dice {
    public:
        int *num;

        Dice(int *n) {
            num = n;
        }

        void move(char c) {
            int n[6];
            for (int i = 0; i < 6; i++) {
                n[i] = num[i];
            }
            if (c == 'N') {
                num[0] = n[1];
                num[1] = n[5];
                num[4] = n[0];
                num[5] = n[4];
            } else if (c == 'S') {
                num[0] = n[4];
                num[1] = n[0];
                num[4] = n[5];
                num[5] = n[1];
            } else if (c == 'W') {
                num[0] = n[2];
                num[2] = n[5];
                num[3] = n[0];
                num[5] = n[3];
            } else {
                num[0] = n[3];
                num[2] = n[0];
                num[3] = n[5];
                num[5] = n[2];
            }
        }
};

int main() {
    int n;
    cin >> n;
    int num[n][6];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 6; j++) {
            cin >> num[i][j];
        }
    }

    bool result = true;
    for (int a = 0; a < n - 1; a++) {
        for (int b = a + 1; b < n; b++) {
            Dice ad(num[a]), bd(num[b]);
            for (int j = 0; j < 4; j++) {
                if (ad.num[1] == bd.num[1]) break;
                ad.move('S');
            }
            if (ad.num[1] != bd.num[1]) {
                ad.move('W');
                for (int j = 0; j < 4; j++) {
                    if (ad.num[1] == bd.num[1]) break;
                    ad.move('S');
                }
            }
            for (int j = 0; j < 4; j++) {
                if (ad.num[0] == bd.num[0]) break;
                ad.move('W');
            }
            bool eq = true;
            for (int i = 0; i < 6; i++) {
                eq = eq && (ad.num[i] == bd.num[i]);
            }
            result = result && !eq;
        }
    }
    if (result) cout << "Yes"; else cout << "No";
    cout << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <math.h>
#include <bitset>
using namespace std;
using ll = long long;
 
int main(){
  ll n; cin >> n;
  vector<ll> v(5);

  for(ll i = 0; i < 5; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  ll res = (n-1) / v[0];
  ll time = res + 5;
  cout << time << endl;
}

Measured memory_bytes: 256
h,w=gets.split
h=h.to_i
w=w.to_i

arr=[]
h.times{
    arr<<gets.chomp.split("")}

arr2=Array.new(h).map{Array.new(w,10000)}
arr2[0][0]=0

cc=arr.flatten.count("#")

now=[0] 
ii=1
loop{
    
    ll=now.length
    
                  jj=0
                  ll.times{
                         if now[jj]%w+1>=0 && now[jj]%w+1<w &&   arr[now[jj]/w][now[jj]%w+1]=="."  &&  arr2[now[jj]/w][now[jj]%w+1]==10000
                             
                            arr2[now[jj]/w][now[jj]%w+1]=ii
                            now=now+[now[jj]+1]
                        end
                        
                        
                         if now[jj]%w-1>=0 && now[jj]%w-1<w &&   arr[now[jj]/w][now[jj]%w-1]=="."  &&  arr2[now[jj]/w][now[jj]%w-1]==10000
                             
                            arr2[now[jj]/w][now[jj]%w-1]=ii
                            now=now+[now[jj]-1]
                        end
                        
                         if now[jj]/w-1>=0 &&   arr[now[jj]/w-1][now[jj]%w]=="."  &&  arr2[now[jj]/w-1][now[jj]%w]==10000
                             
                            arr2[now[jj]/w-1][now[jj]%w]=ii
                            now=now+[now[jj]-w]
                        end
                        
                         if now[jj]/w+1>=0 && now[jj]/w+1<h &&   arr[now[jj]/w+1][now[jj]%w]=="."  &&  arr2[now[jj]/w+1][now[jj]%w]==10000
                             
                            arr2[now[jj]/w+1][now[jj]%w]=ii
                            now=now+[now[jj]+w]
                        end
                      
                      jj+=1
                  }          
    
    
   now=now[ll..-1]
    if now.length==0
        puts -1
        exit
    end
    
    if arr2[h-1][w-1]<10000
        ii+=1
        break
    end
        
    
    
    
   ii+=1
   
   
}


puts h*w-ii-cc



Measured memory_bytes: 2940
// AtCoder Beginner Contest 057
// D - Maximum Average Sets

#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#define MAX_N 50
#define EPS 1e-10
using namespace std;
typedef long long int ll;


ll N, A, B;
map<ll, ll> count;
ll c[MAX_N + 1][MAX_N + 1];
ll ans;

int main() {

  ll v, sum, p_count, used, diff;

  scanf("%lld%lld%lld", &N, &A, &B);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &v);
    count[v] = count[v] + 1;
  }

  memset(c, 0, sizeof(c));
  for (int i = 0; i <= N; i++) {
    c[i][0] = 1;
    c[i][i] = 1;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }

  sum = 0;
  used = 0;
  ans = 1;
  for (auto itr = count.rbegin(); itr != count.rend(); itr++) {
    // printf("%lld, %lld\n", itr->first, itr->second);
    p_count = itr->second;
    if (used < A) {
      diff = min(itr->second, A - used);
      sum += itr->first * diff;
      used += diff;
      itr->second -= diff;
    }
    if (A <= used && used < B && (itr->first - ((double)sum / used)) >= EPS) {
      diff = min(itr->second, B - used);
      sum += itr->first * diff;
      used += diff;
      itr->second -= diff;
    }
    ans *= c[p_count][itr->second];
    // printf("c[%lld][%d] = %lld\n", p_count, itr->second, c[p_count][itr->second]);
    if (A <= used && used < B && abs(itr->first - ((double)sum / used)) < EPS) {
      diff = min(itr->second, B - used);
      for (int i = 1; i <= diff; i++) {
        // printf("c[%lld][%d] = %lld\n", p_count, itr->second - i, c[p_count][itr->second - i]);
        ans += c[p_count][itr->second - i];
      }
      sum += itr->first * diff;
      used += diff;
      itr->second -= diff;
    }
    // printf("%lld, %lld, %lld, %lld\n", itr->first, itr->second, sum, used);
  }

  printf("%lf\n", (double)sum / used);
  printf("%lld\n", ans);

  return 0;

}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b;
void func(int x,int y){
	if(y==0){
		cout<<x<<' '<<a/x*b<<endl;
	}else{
		func(y,x%y);
	}
}
int main(){
	while(cin>>a>>b){
		if(a>b)
		func(a,b);
		else func(b,a);
	}
	return 0;
}

Measured memory_bytes: 0
operation :: String -> String
operation [] = []
operation l@(h:_) = show (length eq) ++ h : operation other
  where
    (eq, other) = span (h == ) l

main :: IO ()
main = do
  n <- fmap (\num -> read num::Int) getLine
  if (n == 0) then return ()
  else
    do
      str <- getLine
      putStrLn $ foldl (\s _ -> operation s) str [1..n]
      main

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int A[110000];
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++)cin >> A[i];
    sort(A, A + N);
    int ans = 0;
    if (N % 2 == 0) {
        for (int i = 0; i < N / 2; i++)ans -= 2 * A[i];
        for (int i = N / 2; i < N; i++)ans += 2 * A[i];
        ans += A[N / 2 - 1] - A[N / 2];
    } else {
        int cur1 = 0;
        for (int i = 0; i < N / 2; i++)cur1 -= 2 * A[i];
        for (int i = N / 2; i < N; i++)cur1 += 2 * A[i];
        cur1 -= A[N / 2] + A[N / 2 + 1];
        int cur2 = 0;
        for (int i = 0; i < N / 2 + 1; i++)cur2 -= 2 * A[i];
        for (int i = N / 2 + 1; i < N; i++)cur2 += 2 * A[i];
        cur2 += A[N / 2] + A[N / 2 - 1];
        ans = max(cur1, cur2);

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
  static final int INF = Integer.MAX_VALUE / 2;
  static int n, m;
  static int[] a, b, c, d;

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

    n = sc.nextInt();
    m = sc.nextInt();
    a = new int[n];
    b = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    c = new int[m];
    d = new int[m];
    for(int i = 0; i < m; i++){
      c[i] = sc.nextInt();
      d[i] = sc.nextInt();
    }

    int[] p = new int[n];
    for(int i = 0; i < n; i++){
      int min = INF, minI = -1;
      for(int j = 0; j < m; j++){
        int dist = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
        if(dist < min){
          min = dist;
          minI = j;
        }
      }
      p[i] = minI;
    }

    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < n; i++){
      sb.append(p[i] + 1);
      sb.append(System.lineSeparator());
    }

    System.out.print(sb);
  }
}


Measured memory_bytes: 21972
def many_eq(i: int, f: str) -> int:
    if i == n-1:
        return sum(list(map(int, f.split("+"))))
    
    return many_eq(i+1, f+s[i+1]) + \
        many_eq(i+1, f+"+"+s[i+1])


s = input()
n = len(s)

print(many_eq(0, s[0]))

Measured memory_bytes: 67092
s = str(input())
t = str(input())
s_list = list(s)
t_list = list(t)
s_list.sort()
t_list.sort()
t_list = t_list[::-1]
count = 0
while count < max(len(s_list), len(t_list)):
    if s_list[count] > t_list[count]:
        print("No")
        break
    if s_list[count] < t_list[count]:
        print("Yes")
        break
    if s_list[count] == t_list[count]:
        if count + 1 == min(len(s_list), len(t_list)):
            if len(s_list) >= len(t_list):
                print("No")
                break
            else:
                print("Yes")
                break
        else:
            count += 1
            continue
        break


Measured memory_bytes: 3064
h1,m1,h2,m2,k = list(map(int,input().split()))

h = h2 - h1

if m1 <= m2:
    m = m2 - m1
else:
    m = (60 - m1) + m2
    h = h - 1

t = (h * 60) + m

print(t-k)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
const int maxn=12;

inline char gc(){
	return getchar();
	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
    ll x=0;char c=gc();bool neg=0;
    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    return neg?(~x+1):x;
}

int f[maxn]={0,1,2,3,6,10,17,30,48,79},N,a[maxn];
ll ans[maxn][maxn];
map<ll,int> mp;

int main(){
    //freopen("","r",stdin);
    N=rd();
    ll now=1;
    
    for(int i=1;i<=N;i++){
    	int n=0;
    	for(int j=1;j<=N&&n<N;j++){
    		if(ans[i][j]||i==j) continue;
    		ans[i][j]=ans[j][i]=f[++n]*now;
    	}
    	now*=f[n]+f[n-1]+1;
    }
    for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) printf("%lld%c",ans[i][j]," \n"[j==N]);
    	
	return 0;
    for(int i=1;i<=N;i++) a[i]=i;
    	ll ma=0;
   	do{
   		ll now=0;
   		for(int i=1;i<N;i++) now+=ans[a[i]][a[i+1]];
   			ma=max(ma,now);
   		// for(int i=1;i<=N;i++) printf("%d ",a[i]);
   			// printf(":%lld\n",now);
   		assert(mp[now]<=1);
   		// assert(now<=1e11);
   		mp[now]+=1;
   	}while(next_permutation(a+1,a+N+1));
   	printf("%lld\n",ma);
    return 0;
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n;cin>>n;
  int a[n]={};
  int sum = 0;
  rep(i, n){
    cin>>a[i];
    sum += a[i];
  }

  if (sum%(n*(n+1)/2)!=0){
    cout << "NO" << endl;
    return 0;
  }
  int k = sum/(n*(n+1)/2);

  int x[n]={};
  int total = 0;
  rep(i, n){
    int j = (i+1)%n;
    int r = k - (a[j]-a[i]);
    if (r%n!=0 || r<0){
      cout << "NO" << endl;
      return 0;
    }
    else{
      x[i] = r/n;
      total += x[i];
    }
  }
  dump_1d(x, n);
  if (total!=k) {
    cout << "NO" << endl;
  }
  else{
    // a[0]の絶対値を検証
    int val = 0;
    rep(i, n){ val += x[i]*(n-i); }
    if (val!=a[0]){
      cout << "NO" << endl;
    }

    cout << "YES" << endl;
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 100, INF = 1e9 + 10, MOD = 1e9 + 7;

vector<ll> vec, ans, cur;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void input() {
    ll n, l;
    cin >> n;
    vec.resize(n);
    for (int i = 0; i < n; i++) cin >> vec[i];
}

void rand_test() {
    ll n = rand() % 100 + 1;
    vec.clear();
    cout << "----------------\n";
    for (int i = 0; i < n; i++) {
        ll q = rand() % 100 - 100;
        cout << q << " ";
        vec.push_back(q);
    }
    cout << "\n";
}

void sol() {
    bool flag = true;
    pair<ll, ll> mx = { -INF, -INF };
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] > 0) flag = false;
        mx = max(mx, { vec[i], i });
    }

    if (flag) {
        cout << mx.first << "\n";
        cout << vec.size() - 1 << "\n";
        ll lft = vec.size();
        for (int i = 0; i < mx.second; i++) {
            cout << "1\n";
            lft--;
        }
        for (int i = mx.second + 1; i < vec.size(); i++) {
            cout << lft << "\n";
            lft--;
        }

        return;
    }

    ll s[2];
    s[0] = 0;
    s[1] = 0;

    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] >= 0) s[i % 2] += vec[i];
    }

    cur = vec;
    cout << max(s[0], s[1]) << "\n";
    if (s[0] < s[1]) {
        ans.push_back(1);
        cur.erase(cur.begin());
    }
    while (cur.size() != 1) {
        if (cur[0] < 0) {
            ans.push_back(1);
            ans.push_back(1);
            cur.erase(cur.begin());
            cur.erase(cur.begin());
            continue;
        }
        if (cur.size() == 2) {
            ans.push_back(2);
            cur.erase(cur.begin() + 1);
            continue;
        }
        if (cur[2] > 0) {
            ans.push_back(2);
            cur[0] += cur[2];
            cur.erase(cur.begin() + 1);
            cur.erase(cur.begin() + 1);
            continue;
        }
        if (cur[2] < 0) {
            ans.push_back(3);
            if (cur.size() == 3) {
                cur.erase(cur.begin() + 2);
            }
            else {
                cur.erase(cur.begin() + 2);
                cur.erase(cur.begin() + 2);
            }
            continue;
        }
    }

    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << "\n";
    }
}

int main()
{
    fastInp;

    ll t;
    t = 1;

    while (t--) {
        input();
        sol();
    }

    return 0;
}

Measured memory_bytes: 3692
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  int n;
  cin>>n;
  vector<int> v(n);
  vector<int> u(n);
  for(int i=0; i<n; i++) {
    cin>>v[i];
  }
  int ans = 100*100;
  for(int i=0; i<n-1; i++) {
    int l=0;
    int r=0;
    for(int j=0; j<=i; j++) {
      l+=v[j];
    }
    for(int j=i+1; j<n; j++) {
      r+=v[j];
    }
    ans=min(ans, abs(l-r));
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll fac[2000005];
ll invfac[2000005];
ll inv[2000005];
inline ll exp(int a, int x ){
    if (x == 0) return 1;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x % 2 == 1){
        p *= a;
        p %= mod;
    }
    return p;
}
inline ll ways(int r, int c){
    return (((fac[r+c]*invfac[r])%mod)*invfac[c])%mod;
}
int main(){
    int r1,r2,c1,c2;
    scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
    fac[0] = invfac[0] = 1;
    for (int i = 1; i <= r2+c2+2; i++){
        fac[i] = (fac[i-1]*i)%mod;
        inv[i] = exp(i,mod-2);
        invfac[i] = (invfac[i-1]*inv[i])%mod;
    }
    ll ans = (ways(r2+1,c2+1) - ways(r2+1,c1) - ways(r1,c2+1) + ways(r1,c1) + mod)%mod;
    printf("%lld ",ans);
}


Measured memory_bytes: 47104
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())))[::-1]
q = sorted(list(map(int, input().split())))[::-1]
r = list(map(int, input().split()))

apple = []
apple.extend(p[:X])
apple.extend(q[:Y])
apple.extend(r)

apple = sorted(apple)[::-1]

print(sum(apple[:X+Y]))

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

long long data[400001],n;
long long sum(int i){
	long long s = 0;
	while(i > 0){
		s += data[i];
		i -= i & -i;
	}
	return s;
}
void add(int i, long long x){
	while(i <= n){
		data[i] += x;
		i += i & -i;
	}
}

map<int,int> zip;
int unzip[100001];
int compress(vector<int> x_){
	vector<int> x = x_;
	sort(x.begin(),x.end());
	x.erase(unique(x.begin(),x.end()),x.end());
	for(int i=0;i<x.size();i++){
		zip[x[i]] = i;
		unzip[i] = x[i];
	}
	return x.size();
}

int main(void){
	int N;
	cin >> N;
	n = N;
	vector<int> A(N);
	vector<int> a1,a2;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(i % 2 == 0)a1.push_back(A[i]);
		else a2.push_back(A[i]);
	}

	if( N == 1 ){
		cout << 0 << endl;
		return 0;
	}else if(N == 2){
		if(A[0] > A[1])cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	compress(A);

	sort(a1.begin(),a1.end());
	sort(a2.begin(),a2.end());

	vector<int> B;
	for(int i=0;i<a1.size();i++){
		B.push_back(zip[a1[i]]);
		if(i < a2.size())B.push_back(zip[a2[i]]);
	}
		
	int cnt = 0;
	for(int i=0;i<B.size();i++){
		if(i%2==0 && B[i]%2 == 1)cnt++;
		if(i%2==1 && B[i]%2 == 0)cnt++;
	}

	long long ret = 0;
	for(int j=0;j<N;j++){
		ret += j - sum(B[j] + 1);
		add(B[j] + 1,1);
	}
	cout << cnt/2 << endl;

	return 0;
}

Measured memory_bytes: 7788
#include <cstdio>
using namespace std;
int v[200005];
int main() {
    int n;
    scanf("%d",&n);
    bool f=true;
    long long  s=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&v[i]);
        if(i==1&&v[i]!=0)
            f=false;
        if(v[i]-v[i-1]>1)
            f=false;
        s=s+v[i];
        if(v[i]-v[i-1]==1)
            s=s-(v[i]-1);
    }
    if(f)
        printf("%lld\n",s);
    else
        printf("-1\n");
    return 0;
}

Measured memory_bytes: 896