akhauriyash/Code-Regression huggingface dataset:
// 7/10
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

int f[10010];

int main() {
    int N;
    cin >> N;
    rep(i, 10010) f[i] = 0;

    for (int x = 1; x * x <= N; x++) {
        for (int y = 1; y * y <= N; y++) {
            for (int z = 1; z * z <= N; z++) {
                int now = x*x + y*y + z*z + x*y + y*z + z*x;
                if (now <= N) f[now] += 1;
            }
        }
    }

    rep(i, N) {
        cout << f[i + 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3660
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    static long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        int H = sc.nextInt(), W = sc.nextInt();
        char[][] g = new char[H][];
        for(int i=0;i<H;i++) g[i] = sc.next().toCharArray();
        int[][] left = new int[H][W], right=new int[H][W], up=new int[H][W], down=new int[H][W];
        // do left and right first
        for(int i=0;i<H;i++){
            // do right first
            int cnt = 0;
            for(int j=0;j<W;j++){
                if(g[i][j]=='#') cnt=0;
                else left[i][j] = cnt++;
            }
            cnt = 0;
            for(int j=W-1;j>=0;j--){
                if(g[i][j]=='#') cnt=0;
                else right[i][j] = cnt++;
            }
        }
        // do up and down
        for(int j=0;j<W;j++){
            // do up first
            int cnt = 0;
            for(int i=0;i<H;i++){
                if(g[i][j]=='#') cnt = 0;
                else up[i][j] = cnt++;
            }
            cnt = 0;
            for(int i=H-1;i>=0;i--){
                if(g[i][j]=='#') cnt=0;
                else down[i][j] = cnt++;
            }
        }
        int ans = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(g[i][j]=='#') continue;
                int cur = 1+left[i][j]+right[i][j]+up[i][j]+down[i][j];
                ans = Math.max(ans,cur);
            }
        }
        System.out.println(ans);
    }
}



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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, m, x;
  cin >> n >> m >> x;
  int a[n+1]={}, ia[n+1]={};
  for(int i=0; i<m; i++){
    int c; cin >> c;
    a[c] = 1;
  }
  int tmp=0, itmp=0;
  for(int i=0; i<x; i++){
    if(a[i]) tmp++;
  }
  for(int i=x+1; i<=n; i++){
    if(a[i]) itmp++;
  }
  int ans = min(tmp, itmp);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> N;
	vl sum(N + 1);
	sum[0] = 0;
	for (i = 0; i < N; i++) {
		sum[i + 1] = sum[i] + i + 1;
	}
	ll M = 0;
	ll P = 0;
	for (i = 1; i < N+1; i++) {
		if (N <= sum[i]) {
			M = i;
			P = sum[i] - N;
			break;
		}
	}
	for (i = 1; i <= M; i++) {
		if (i != P) cout << i << endl;
	}
}

Measured memory_bytes: 78336
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int h,w;cin>>h>>w;
  int m;cin>>m;
  map<P,int> bomb;
  rep(i,m){
    int a,b;cin>>a>>b;
    bomb[{a,b}]+=1;
  }
  vector<lint> rsm(h+1,0);
  vector<lint> csm(w+1,0);
  for(auto const& it:bomb){
    csm[it.first.second]+=it.second;
    rsm[it.first.first]+=it.second;
  }
  int cmx=-1;
  rep1(i,w){
    cmx=max(cmx,csm[i]);
  }
  int rmx=-1;
  rep1(i,h){
    rmx=max(rmx,rsm[i]);
  }
  vector<int> rmxind;
  rep1(i,h){
    if(rsm[i]==rmx)rmxind.push_back(i);
  }
  lint res=-1;
  rep1(i,w){
    if(csm[i]==cmx){
      for(auto& val:rmxind){
        int add=bomb[{val,i}];
        res=max(res,cmx+rmx-add);
        if(add==0){
          cout<<res<<"\n";
          return 0;
        }
      }
    }
  }
  cout<<res<<"\n";
  return 0;
}


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

int main(void) {
	string str;

	cin >> str;
	int c = 0;

	if (str == "SSS")
		c = 0;
	else if (str == "SSR")
		c = 1;
	else if (str == "SRS")
		c = 1;
	else if (str == "SRR")
		c = 2;
	else if (str == "RSS")
		c = 1;
	else if (str == "RSR")
		c = 1;
	else if (str == "RRS")
		c = 2;
	else if (str == "RRR")
		c = 3;

	cout << c << endl;

}

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>

int main(void){
  int i;
  int dice[6];
  int sum,tmp;
  char d[7];
  int n;

  while(1){
    scanf(" %d ",&n);
    if(!n)break;
    for(i=0;i<6;i++)dice[i] = i+1;
    sum = 1;
    for(i=0;i<n;i++){
      scanf(" %s ",d);
      if(!strcmp(d,"North")){
	tmp = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = dice[4];
	dice[4] = tmp;
      }else if(!strcmp(d,"East")){
	tmp = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = tmp;
      }else if(!strcmp(d,"West")){
	tmp = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = dice[3];
	dice[3] = tmp;
      }else if(!strcmp(d,"South")){
	tmp = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = tmp;
      }else if(!strcmp(d,"Right")){
	tmp = dice[1];
	dice[1] = dice[2];
	dice[2] = dice[4];
	dice[4] = dice[3];
	dice[3] = tmp;
      }else if(!strcmp(d,"Left")){
	tmp = dice[1];
	dice[1] = dice[3];
	dice[3] = dice[4];
	dice[4] = dice[2];
	dice[2] = tmp;
      }
      sum += dice[0];
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
p = []

for i in range(n):
    p.append(int(input()))

maxV = max(p)
count = 0
isDone = False

for i in range(n):
    if p[i] == maxV and not isDone:
        count += maxV // 2
        isDone = True
    else:
        count += p[i]

print(count)


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

ll a,b,c,d,nx,ny,nz,dx,dy,dz,px,py,pz,ans;
vector<pair<ll,ll> > p;

bool cmp(pair<ll,ll> a,pair<ll,ll> b) {
	return a.first*b.second<a.second*b.first;
}

int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	for (int i=0;i<=d;i++) {
		if (i<a) {
			p.push_back(mp(i,a));
			p.push_back(mp(a-i-1,a));
		}
		if (i<b) {
			p.push_back(mp(i,b));
			p.push_back(mp(b-i-1,b));
		}
		if (i<c) {
			p.push_back(mp(i,c));
			p.push_back(mp(c-i-1,c)); 
		}
	}
	sort(p.begin(),p.end(),cmp);
	
	for (int i=0;i<p.size();i++)
	{
		nx=a*p[i].first/p[i].second;
		ny=b*p[i].first/p[i].second;
		nz=c*p[i].first/p[i].second;
		dx=min(a-1,px+d)-max(0ll,px-d)+1;
		dy=min(b-1,py+d)-max(0ll,py-d)+1;
		dz=min(c-1,pz+d)-max(0ll,pz-d)+1;
		if (nx+d<a) ans+=(nx-px)*dy%mod*dz%mod;
		if (ny+d<b) ans+=(ny-py)*dx%mod*dz%mod;
		if (nz+d<c) ans+=(nz-pz)*dx%mod*dy%mod;
		ans%=mod;
		px=nx; py=ny; pz=nz;
	}
	ans+=(min(a-1,d)+1)*(min(b-1,d)+1)%mod*(min(c-1,d)+1)%mod;
	printf("%lld\n",ans%mod);
	return 0;
}

Measured memory_bytes: 10348
from heapq import heappop, heappush
INF = 10 ** 20

def main():
  while True:
    n, m, l, k, a, h = map(int, input().split())
    if n == 0:
      break
  
    if l == 0:
      input()
      sisetu = [a, h]
    else:
      sisetu = list(map(int, input().split()))
      sisetu += [a, h]
  
    edges = [[] for _ in range((m + 1) * n)]
    for _ in range(k):
      x, y, t = map(int, input().split())
      for i in range(t, m + 1):
        edges[i * n + x].append((t, (i - t) * n + y))
        edges[i * n + y].append((t, (i - t) * n + x))
    
    for node in sisetu:
      for i in range(m):
        edges[i * n + node].append((1, (i + 1) * n + node))
  
    que = []
    heappush(que, (0, m * n + a))
    costs = [INF] * ((m + 1) * n)
    costs[m * n + a] = 0
    
    while que:
      total, node = heappop(que)
      for dist, to in edges[node]:
        if costs[to] > total + dist:
          costs[to] = total + dist
          heappush(que, (total + dist, to))
    ans = min([costs[i * n + h] for i in range(m + 1)])
    if ans == INF:
      print("Help!")
    else:
      print(ans)

main()



Measured memory_bytes: 18396
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

int n, r;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> r;
if(n < 10){
	cout << r + 100 * (10 - n) << endl;
}
else{
	cout << r << endl;
}

return 0;
}



Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    const ll SIZE=30;
    ll n;
    while(cin>>n,n){
    vector<vector<ll>> A(SIZE,vector<ll>(SIZE,0));
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        A[x][y]++;
    }
    ll m;
    cin>>m;
    ll ans=0;
    ll X=10,Y=10;
    for(int i=0;i<m;i++){
        char c;
        ll d;
        cin>>c>>d;
        auto pls=[&](){
            if(c=='N'){Y+=1;}
            if(c=='E'){X+=1;}
            if(c=='S'){Y-=1;}
            if(c=='W'){X-=1;}
            ans+=A[X][Y];
            A[X][Y]=0;
        };
        for(int j=0;j<d;j++){pls();}
    }
        cout<<(ans==n?"Yes":"No")<<endl;
    }
    
    return 0;
}



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

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int j = 1;
  for (int i = 1; i <N;i++) {
    if (S[i-1] != S[i]) j++;
  }
  cout<<j<<endl;


  return 0;
}

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

int main(){
      int n;cin >> n;
      int arr[n + 10];
      int ans = 0;
      for(int i = 0;i < n;i++)cin >> arr[i];
      for(int i = 0;i < n - 1;i++){
            for(int j = i + 1;j < n;j++){
                  ans += arr[i] * arr[j];
            }
      }
      cout << ans;
}

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

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

    int N;
    cin >> N;

    vector<int> A(N);
    rep(i,0,N-1) {
        int tmp;
        cin >> tmp;
        A[tmp - 1]++;
    }

    rep(i,0,N) {
        cout << A[i] << endl;
    }
}


Measured memory_bytes: 3960
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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


vector < vector<pair<ll, ll> > > VW(100001);
vector<bool> col(100001, false);

void sol(ll parent, bool value ,ll num) {

	col[num] = value;

	rep(i, VW[num].size()) {
		if (VW[num][i].first != parent) {
			if (VW[num][i].second % 2 == 1) {
				sol(num, !value, VW[num][i].first);
			}
			else {
				sol(num, value, VW[num][i].first);
			}
		}
	}
}

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

	ll N;
	cin >> N;

	vector<ll> U(N), V(N), W(N);

	rep(i, N - 1) {
		cin >> U[i] >> V[i] >> W[i];
		VW[U[i]].pb(mp(V[i], W[i]));
		VW[V[i]].pb(mp(U[i], W[i]));
	}

	rep(i, VW[1].size()) {
		if (VW[1][i].second % 2 == 1) {
			sol(1, true, VW[1][i].first);
		}
		else {
			sol(1, false, VW[1][i].first);
		}
	}








	rep(i, N) {
		if (col[i+1]) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int32_t main()
{
	ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
	ll n,sum = 0;
	cin>>n;
	
	map<ll,ll>m;
	
	for(ll i =0 ;i<n;i++)
	{
		ll a;
		cin>>a;
		if(m.find(a) == m.end())
		{
			m.insert(make_pair(a,1));
		}
		else{
			m[a]++;
		}
		sum+=a;
	}
	
	ll q;
	cin>>q;
	
	while(q--)
	{
		ll b,c;
		cin>>b>>c;
		if(m.find(c) ==m.end())
		{
			m.insert(make_pair(c,m[b]));
		}
		else{
			m[c] += m[b];
		}
		sum = sum - m[b]*b + m[b]*c;
		cout<<sum<<endl;
		m[b] = 0;
	}
	return 0;
}


Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n[5];
    for(i=0; i<5; i++)
        {
            scanf("%d",&n[i]);
            if(n[i]==0)
                printf("%d\n",i+1);
        }
    return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n;
    cin>>n;
    string s;
    while(n>0){
        ll k=(n-1)%26;
        s+=char(k+'a');
        n=(n-1)/26;
    }
    reverse(all(s));
    cout<<s;
}

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

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

using namespace std;

int main(){
	int a,b; cin>>a>>b;
	string B[100];
	rep(i,100) B[i]=string(50,'.')+string(50,'#');

	a--; b--;
	rep(j,25) rep(i,50) if(b>0) B[2*i][   2*j]='#', b--;
	rep(j,25) rep(i,50) if(a>0) B[2*i][99-2*j]='.', a--;

	cout<<"100 100"<<endl;
	rep(i,100) cout<<B[i]<<endl;

	return 0;
}


Measured memory_bytes: 256
n=int(input())
infy=float('inf')
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])




Measured memory_bytes: 13928
//#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;

int main() {
	int a[1000001];
	int k;
	cin >> k;
	a[1] = 7 % k;
	for (int i = 2; i <= k; i++) a[i] = (a[i - 1] * 10 + 7) % k;

	for (int i = 1; i <= k; i++) {
		if (a[i] == 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 7480
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
Int divup(Int x, Int y) { return (x+y-1)/y; }
Int more(int S) {
    vector<char> A(2e7);
    int t = 1, k = 0;
    for (int i = 0; i < A.size(); i++) {
        if (i == t) k++, t *= 10;
        A[i] = k;
    }
    int i = 1, j = 1, sum = 0;
    Int ans = 0;
    while (A[i] <= 6) {
        while (sum < S) { sum += A[j]; j++; }
        if (A[i] + 1 < A[j - 1] && sum == S) ans++;
        sum -= A[i];
        i++;
    }
    return ans;
}
Int two(int S) {
    Int ans = 0;
    for (Int i = 1; i + (i+1) <= S; i++) {
        // i * (-S+(i+1)*n) + (i+1) * (S-i*n) == S
        Int nmin = 0, nmax = INT_MAX;
        // -S+(i+1)*n >= 1
        nmin = max(nmin, divup(1 + S, i+1));
        // S-i*n >= 1
        nmax = min(nmax, (S - 1) / i);
        if (i <= 7) {
            Int k = 9*(Int)pow(10, i-1);
            // -S+(i+1)*n <= 9*10^(i-1)
            nmax = min(nmax, (k+S)/(i+1));
            // S-i*n <= 9*10^i
            nmin = max(nmin, divup(S-k*10, i));
        }
        ans += max(0LL, nmax - nmin + 1);
        ans %= MOD;
    }
    return ans;
}
Int one(int S) {
    Int ans = 0;
    Int nine = 9; // 9 * 10^(i-1) mod MOD
    for (int i = 1; i <= S; i++, nine = (nine * 10) % MOD) {
        if (S % i != 0) continue;
        if (i <= 8 && S / i > nine) continue;
        ans = (ans + nine + MOD - (S / i) + 1) % MOD;
    }
    return ans;
}
int main() {
    int S; cin >> S;
    cout << (one(S) + two(S) + more(S)) % MOD << endl;
    return 0;
}


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

using int64 = long long;

int64 dp[60][60][2600];

int main() {
	int N, A;
	cin >> N >> A;
	
	int x[50];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	
	dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			for (int sum = 0; sum <= 50 * j; sum++) {
				dp[i + 1][j][sum] += dp[i][j][sum];
				dp[i + 1][j + 1][sum + x[i]] += dp[i][j][sum];
			}
		}
	}
	
	int64 ans = 0;
	for (int n = 1; n <= N; n++) {
		ans += dp[N][n][n * A];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 61696
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int k;
  cin>>k;
  cout<<a[k-1];
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
N=int(input())
A=[int(input()) for i in range(N)]

ans=0
ans+=(A[0]-1)

S=2
for i in range(1,N):
    if A[i]>=S+1:
        ans+=(A[i]-1)//S
    elif A[i]==S:
        S+=1
    elif A[i]<S:
        continue
print(ans)

Measured memory_bytes: 44124
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main(){

	lli x,a,b;
	cin>>x>>a>>b;

	lli la = abs(x-a);
	lli lb = abs(x-b);

	if(la<lb){
		cout<<"A"<<endl;
	}
	else{
		cout<<"B"<<endl;
	}

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	ll h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		put(1);
		return 0;
	}
	ll t = h * w;
	ll res;
	if (t % 2 == 1) {
		res = (t + 1) / 2;
	} else {
		res = t / 2;
	}
	put(res);
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
tmp = [10]*n

for _ in range(m):
    s,c = map(int, input().split())
    if tmp[s-1] == 10 or tmp[s-1]==c:
        tmp[s-1] = c
    else:
        print('-1')
        exit()

for i in range(n):
    if tmp[i] == 10:
        if i == 0 and n != 1:
            tmp[i] = 1
        else:
            tmp[i] = 0

ans = ''.join(map(str,tmp))

if n != 1 and ans[0] == '0':
    print('-1')
else:
    print(ans)

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt() - 1;
		int[] C = new int[N];
		int[] S = new int[N];
		int[] F = new int[N];
		for(int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
			S[i] = sc.nextInt();
			F[i] = sc.nextInt();
		}

		for(int i = 0; i < N + 1; i++) {
			// i to N - 1
			int tmp = 0;
			for(int j = i; j < N; j++) {
				int cor = Math.max((tmp + F[j] - 1) / F[j] , S[j] / F[j]);
				tmp = cor * F[j] + C[j];
			}
			System.out.println(tmp);
		}
	}
}

Measured memory_bytes: 26476
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007, inv2 = 500000004;
int p[3010][3010];
int a[3010], n, m;
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) p[i][j] = a[i] > a[j];
    for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (x > y) swap(x, y);
        for (int i = 1; i <= n; i++) {
            if (i == x || i == y) continue;
            p[x][i] = p[y][i] = 1ll * (p[x][i] + p[y][i]) * inv2 % mod;
            p[i][x] = p[i][y] = 1ll * (p[i][x] + p[i][y]) * inv2 % mod;
        }
        p[x][x] = p[y][y] = 0;
        p[x][y] = p[y][x] = 1ll * (p[x][y] + p[y][x]) * inv2 % mod;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++) ans = (ans + p[i][j]) % mod;
    for (int i = 1; i <= m; i++) ans = ans * 2 % mod;
    return cout << ans << endl, 0;
}

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

struct Line{
  int a,b;
};

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

  vector<Line> h_line(n);
  vector<int> ans(w);

  // input
  for(int i=0,a,b;i<n;++i){
    scanf("%d,%d", &a, &b);
    h_line[i].a = a;
    h_line[i].b = b;
  }

  // solve
  for(int i=1;i<=w;++i){
    int now = i;
    for(int j=0;j<n;++j){
      if(h_line[j].a == now)
        now = h_line[j].b;
      else if(h_line[j].b == now)
        now = h_line[j].a;
    }
    ans[now-1] = i;
  }

  // output answer
  for(int i=0;i<w;++i)
    cout<<ans[i]<<endl;

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1236
#include<stdio.h>
#define N 200000
int main(){
  int x,i,max=0,min,result,a[N];
  scanf("%d",&x);
  for(i=0;i<x;i++)
    scanf("%d",&a[i]);
  min=a[0];
  max=a[1]-a[0];
  for(i=1;i<x;i++){    
    if(a[i]-min>max)
      max=a[i]-min;
    if(a[i]<min)
      min=a[i];
    
  }
  printf("%d\n",max);
  return 0;
}
  



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

void solve(long long A, long long B, long long C){
    cout << min(B / A, C) << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
program probd
    implicit none
    integer(16) :: N, i
    integer :: a(1000005)
    integer :: ans
    integer :: tmp
    read(*,*) N

    do i = 2, 1000005
        a(i) = 0
        do while(mod(N, i) == 0)
            a(i) = a(i) + 1
            N = N / i
        end do
    end do

    ans = 0

    if(N /= 1) then
        ans = ans + 1
    end if

    do i = 2, 1000005
        tmp = 1
        do while(a(i) >= tmp)
            ans = ans + 1
            a(i) = a(i) - tmp
            tmp = tmp + 1
        end do
    end do

    write(*,*) ans

    stop
contains
end program probd

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n, k; 
    cin >> n >> k;
    int ans = 0;
    rep(i,n){
        int h; cin >> h;
        if(h >= k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

def AllPatern(n, all):
    numbers = []
    all = []
    for i in range(n):
        numbers.append(i+1)
    for i in itertools.permutations(numbers):
        all.append(list(i))

    return all


def WhichNumber(p, q, all):
    val_p = 0
    val_q = 0
    for i in range(len(all)):
        val_p += 1
        if p == all[i]:
            break
    for i in range(len(all)):
        val_q += 1
        if q == all[i]:
            break

    return val_p, val_q

def main():
    n = int(input())
    p = [int(i) for i in input().split()]
    q = [int(i) for i in input().split()]
    all = []

    all = AllPatern(n, all)
    val_p, val_q = WhichNumber(p, q, all)
    print(abs(val_p - val_q))



if __name__ == '__main__':
    main()


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


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

  int n;
  cin >> n;
  int d[n];

  int c = 0;

  for (int i = 0; i < n; i++) {
    cin >> d[i];
    bool t = false;
    for (int k = 0; k < i; k++) {
      if (d[i] == d[k]) {
        t = true;
      }
    }
    if (!t) {
      c++;
    }
  }
  cout << c << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

//プロトタイプ宣言
void faster(void);
ll gcd(auto , auto);
ll get_digent(auto);
ll POW(auto , auto);



int main(){
  faster();
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22) cout << "bust" << endl;
  else cout << "win" << endl;
}





























//以下、ライブラリ

//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
ll gcd(auto a, auto b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
ll get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
ll POW(auto x,auto y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>

#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	
	int n;
	cin >>  n;
	vector<int> vec(n);

	rep(i,n){
		cin >> vec[i];
	}

	ll ans = 0;

	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			ans += vec[i]*vec[j];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[100001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, A[100001];
	long long M;
	scanf("%d %lld", &N, &M);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	merge_sort(A, N);
	
	int j, l = A[0] * 2, r = A[N-1] * 2 + 1, m;
	long long count;
	while (l < r) {
		m = (l + r) / 2;
		count = 0;
		for (i = 0, j = N; i < N; i++) {
			for (; j > 0 && A[i] + A[j-1] >= m; j--);
			count += N - j;
		}
		
		if (count <= M) r = m;
		else l = m + 1;
	}
	
	long long ans = 0, sum = 0;
	for (i = 0, j = N, count = 0; i < N; i++) {
		for (; j > 0 && A[i] + A[j-1] >= l; j--) sum += A[j-1];
		ans += sum + (long long)A[i] * (N - j);
		count += N - j;
	}
	printf("%lld\n", ans + (M - count) * (l - 1));
	fflush(stdout);
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

vii G;
vi value;

void dfs(int now, int par, int score) {
  value[now] += score;
  rep (i, G[now].size()) {
    if (G[now][i] == par) continue;
    dfs(G[now][i], now, value[now]);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  G.resize(n);
  value.resize(n);
  rep (i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  rep (i, q) {
    int u, x;
    cin >> u >> x;
    u--;
    value[u] += x;
  }

  dfs(0, -1, 0);

  rep (i, n) {
    cout << value[i] << " ";
  }
  cout << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	int n;
	cin>>n;
	unordered_map<int,int> vals;
	for(int i=0;i<n;i++) {
		int val;
		cin>>val;
		vals[val]++;
	}
	ll sum = 1;
	if(n&1) {
		for(auto m:vals) {
			if(m.F>=n||(m.F&1)){
				goto wrong;
			}
			if(m.F==0&&m.S>1)goto wrong;
			if(m.F!=0&&m.S>2)goto wrong;
			if(m.F!=0){
				sum<<=1;
				sum%=(ll)1e9+7;
			}
		}
	} else {
		for(auto m:vals) {
			if(m.F>=n||!(m.F&1)){
				goto wrong;
			}
			if(m.S>2)goto wrong;
			sum<<=1;
			sum%=(ll)1e9+7;
		}
	}
	cout<<sum;
	return;
	wrong:
	cout<<0;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 6604
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  string S;
  string T;
  cin >> S >> T;
  int cnt = 0;
  rep(i,3){
    if(S.at(i) == T.at(i))cnt++;
  }
  cout << cnt <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	set<int> s;
	for(int i=0;i<n;i++){
		cin >> a[i];
		s.insert(a[i]);
	}
	cout << s.size() << endl;
}


Measured memory_bytes: 7756
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
const int N = 5000 + 5, M = 50000 + 5, INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    cout << s;
    if (s[s.size() - 1] == 's') {
        cout << "es" << endl;
    } else {
        cout << 's' << endl;
    }
    return 0;
}

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

//macro
#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, n, m) for(int i = m; i < n; ++i)
#define LL long long

using namespace std;

typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int main(){
    int n;
    int s[105];
    int fib[105];
    int ans = 0;
    cin >> n;
    fib[0] = 0;
    REP(i, n){
        cin >> s[i];
        ans += s[i];
    }

    sort(s, s + n);
    
    REP(i, n){
        fib[i + 1] = s[i] + fib[i]; 
    }
    if(ans % 10 != 0){
        cout << ans << endl;
        return 0;
    }

    int i = 0;
    while(ans % 10 == 0 && i != n){
        if(s[i] <= fib[i]){
            if((ans - s[i]) % 10 != 0){
                 ans -= s[i];
                 cout << ans << endl;
                 return 0;
            }
        }else if(s[i] > fib[i]){ 
            if((ans - fib[i]) % 10 != 0){
                 ans -= fib[i];
                 cout << ans << endl;
                 return 0;
            }
        }
        ++i;
    }
    ans = 0;
    cout << ans << endl;
    
}

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

int N, A, B;
int main(){
	scanf("%d %d %d", &N, &A, &B);
	
	if((B - A) % 2 == 0)printf("Alice\n");
	else printf("Borys\n");
	
	return 0;
}


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

namespace {

#ifdef LOCAL
#define run_if_local(statement) statement
#else
#define run_if_local(statement)
#endif

#ifdef LOCAL
auto start_timestamp = clock();
void tag_execution_time() {
  std::cerr << "Execution timestamp: " << std::setprecision(4) << std::fixed
            << ((double)clock() - start_timestamp) / CLOCKS_PER_SEC << "s\n";
}
#else
void tag_execution_time() {}
#endif

template <typename Arg, typename... Args>
void __internal_print(std::ostream& out, Arg&& arg, Args&&... args) {
  out << std::forward<Arg>(arg);
  using expander = int[];
  (void)expander{0, (void(out << ' ' << std::forward<Args>(args)), 0)...};
  out << "\n";
}

template <typename Arg, typename... Args>
void __internal_read(Arg&& arg, Args&&... args) {
  std::cin >> std::forward<Arg>(arg);
  using expander = int[];
  (void)expander{0, (void(std::cin >> std::forward<Args>(args)), 0)...};
}

#define __internal_print_array(out, start, end)     \
  for (auto iter = start; iter != end; ++iter) {    \
    out << *iter << (iter + 1 == end ? "\n" : " "); \
  }

#define __internal_print_2d_array(out, array, rows, cols) \
  for (int i = 1; i <= rows; ++i) {                       \
    for (int j = 1; j <= cols; ++j) {                     \
      out << array[i][j] << (j == cols ? "\n" : " ");     \
    }                                                     \
  }

#define print(...) __internal_print(std::cout, __VA_ARGS__)
#define debug(...) __internal_print(std::cerr, __VA_ARGS__)
#define print_array(start, end) __internal_print_array(std::cout, start, end)
#define debug_array(start, end) __internal_print_array(std::cout, start, end)
#define print_2d_array(array, rows, cols) __internal_print_2d_array(std::cin, array, rows, cols)
#define read(...) __internal_read(__VA_ARGS__)
#define read_array(array, start, end)     \
  for (int _i = start; _i <= end; ++_i) { \
    std::cin >> (array)[_i];              \
  }
#define read_2d_array(array, n, m) \
  for (int i = 1; i <= n; ++i) {   \
    for (int j = 1; j <= m; ++j) { \
      std::cin >> array[i][j];     \
    }                              \
  }

#define update_max(a, b) if ((a) < (b)) (a) = (b)
#define update_min(a, b) if ((a) > (b)) (a) = (b)

}  // namespace

const int N = 200;

int a[N], b[N], n;

void run(int case_id = 0) {
  read(n);
  read_array(b, 1, n - 1);

  long long answer = b[1] + b[n - 1];
  a[1] = b[1];
  a[n] = b[n - 1];
  for (int i = 2; i <= n - 1; ++ i) {
    a[i] = std::min(b[i - 1], b[i]);
    answer += a[i];
  }
  print(answer);
}

int main() {
  std::ios::sync_with_stdio(false);
  run();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int w,h;
    int i,j,k;
    for(;;){
    cin>>h>>w;
    if(h==0&&w==0)break;
    for(j=0;j<h/2;j++){
    for(i=0;i<w/2;i++){
    cout<<"#";
    cout<<".";
    }
    if((w+1)/2-w/2>0){cout<<"#";}
    cout<<endl;
    for(i=0;i<w/2;i++){
    cout<<".";
    cout<<"#";
    }
    if((w+1)/2-w/2>0){cout<<".";}
    cout<<endl;
    }
    if((h+1)/2-h/2>0){
    for(i=0;i<w/2;i++){
    cout<<"#";
    cout<<".";}
    if((w+1)/2-w/2>0){cout<<"#"<<endl;}
    else{cout<<endl;}
    }cout<<endl;}}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int parse(string &T, int &pos){
  if (T[pos] == '0'){
    pos++;
    return 0;
  } else if (T[pos] == '1'){
    pos++;
    return 1;
  } else if (T[pos] == '2'){
    pos++;
    return 2;
  } else if (T[pos] == '-'){
    pos++;
    int A = parse(T, pos);
    return 2 - A;
  } else {
    pos++;
    int A = parse(T, pos);
    char c = T[pos];
    pos++;
    int B = parse(T, pos);
    pos++;
    if (c == '*'){
      return min(A, B);
    }
    if (c == '+'){
      return max(A, B);
    }
  }
}
int main(){
  while (1){
    string S;
    cin >> S;
    if (S == "."){
      break;
    }
    int N = S.size();
    int ans = 0;
    for (int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j++){
        for (int k = 0; k < 3; k++){
          string T = S;
          for (int l = 0; l < N; l++){
            if (T[l] == 'P'){
              T[l] = '0' + i;
            }
            if (T[l] == 'Q'){
              T[l] = '0' + j;
            }
            if (T[l] == 'R'){
              T[l] = '0'+ k;
            }
          }
          int pos = 0;
          if (parse(T, pos) == 2){
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3152
n,k=map(int,input().split())
l=[]
for i in range(n+1):
    l.append(i)
l1=[l[0]]
for x in l[1:]:
    l1.append(l1[-1]+x)
#print(l1)
S=0
for i in range(k,n+1):
    S+=l1[n]-l1[n-i]-(l1[i-1]-1)
S+=1

print(S%(10**9+7))

Measured memory_bytes: 28672
#include <iostream>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    if (b == 'H')
      cout << "H\n";
    else
      cout << "D\n";
  }
  else {
    if (b == 'H')
      cout << "D\n";
    else
      cout << "H\n";
  }
  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,c = input().rstrip().split()
    print(a[0]+b[0]+c[0])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <cmath>

#define rep(i, s, n) for(int (i) = (s); (i) < (n); ++(i))
#define repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define print(x) cout << (x) << endl 
#define min2(a, b) ((a) < (b)) ? (a) : (b)
#define max2(a, b) ((a) > (b)) ? (a) : (b)
#define count counting_variable

using namespace std;

int D, G;
int p[11], c[11];


int solve(int state){
    int count = 0, score = 0;
    int rest[11];
    rep(i, 1, D + 1){
        if((state >> (i - 1)) & 1){
            score += 100 * i * p[i] + c[i];
            count += p[i];
            rest[i] = 0;
        }else{
            rest[i] = p[i];
        }
    }
    if(score >= G){
        return count;
    }
    int i = D;
    while(score < G && i > 0){
        if(rest[i] == 0){
            i--;
        }else{
            score += 100 * i;
            count++;
            rest[i]--;
        }
    }
    if(score < G){
        return INT16_MAX;
    }else{
        return count;
    }
}

int main(){
    cin >> D >> G;
    rep(i, 1, D + 1){
        cin >> p[i] >> c[i];
    }
    int min = INT16_MAX;
    rep(i, 0, (int)pow(2, D)){
        min = min2(min, solve(i));
    }
    print(min);
    return 0;
}

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    k--;

    vector<vector<double>> points(n);
    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x >> y;
        points[i] = {x, y};
    }

    bool ret = false;
    for (int i = 0; i < n; i++) {
        map<double, int> ma;
        int divzero = 0;
        for (int j = 0; j < n; j++) {
            if (i == j)continue;

            double xdis = points[j][0] - points[i][0];
            double ydis = points[j][1] - points[i][1];
            if (xdis == 0)divzero++;
            else ma[ydis / xdis]++;
        }
        for (auto x:ma)
            if (x.second >= k)ret = true;
        if (divzero >= k)ret = true;
    }

    cout << (ret ? 1 : 0) << endl;
    return 0;
}


Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;
LL p[N];
int main() {
  	ios::sync_with_stdio(false);
  	cin>>n;
  	auto get=[&](int x){
  		int l,r=-1;//cout<<x<<' ';
  		while(x){
  			l=x%10;
  			if(r==-1)r=l;
  			x/=10;
  		}
  		//cout<<l<<' '<<r<<endl;
  		return mp(l,r);
  	};
  	auto ge=[&](int x,int l,int r){
  		int ans=0;
  		if(!x){
  			if(l<=n)ans++;
  		}
  		if(l*10+r<=n)ans++;
  		int p=l*100;
  		int g=100;
  		while(1){
  			if(p+r>n)break;
  			int L=p+r,R=p+r+g-10;
  			if(R<=n)ans+=g/10;
  			else{
  				int z=n-L;
  				ans+=z/10+1;
  			}
  			p*=10;g*=10;
  		}
  		return ans;
  	};
  	LL ans=0;
  	for(int i=1;i<=n;i++){
  		auto f=get(i);
  		int s=1;
  		if(f.fi==f.se)s=0;
  		int res=0;
  		if(f.se)res=ge(s,f.se,f.fi);
  		//cout<<i<<' '<<res<<endl;
  		ans+=res;
  	}
  	cout<<ans<<'\n';
 	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const long long MOD = 1000000007;
int main(){
  long long n,k;
  cin>>n>>k;
  long long ans=0;
  for(long long i=k;i<=n+1;i++){
    long long sub=i*(i-1)-1;
    ans=(ans+(i*n)%MOD-sub)%MOD;
  }
  if(ans<0){
    ans+=MOD;
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 3636