akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

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

const long long INF = 1LL << 60;
const int MAX_V = pow(10, 3) * 100 + 1;

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

    vector<long long> w(N), v(N);
    rep(i, N)
    {
        cin >> w[i] >> v[i];
    }

    vector<vector<long long>> dp(N, vector<long long>(MAX_V + 1, INF));

    dp[0][0] = 0;
    for (int j = 1; j <= v[0]; j++)
    {
        dp[0][j] = w[0];
    }

    for (int i = 1; i < N; i++)
    {
        rep(j, MAX_V + 1)
        {
            chmin(dp[i][j], dp[i - 1][j]);

            if (j - v[i] >= 0)
            {
                chmin(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            }
        }
    }

    long long res = 0;
    rep(j, MAX_V + 1)
    {
        if (dp[N - 1][j] <= W)
        {
            res = j;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 79488
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
inline void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
inline void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
const int mod = 1000000007;

struct unionfind {
    vector<int> par,rank;
    unionfind(int n):par(n,-1),rank(n,0) {}
    int root(int x) {
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool same(int x,int y) {
        return root(x) == root(y);
    }
    bool merge(int x,int y) {
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x,y);
        if(rank[x] == rank[y]) rank[x]++;
        par[x] += par[y];
        par[y] = x;
        return true;
    }
};

struct edge {
    int x,y;
    ll cost;
    edge(int x,int y,ll cost):x(x),y(y),cost(cost) {}
};

ll kruskal(int n,vector<edge> v) {
    unionfind uf(n);
    sort(all(v),
            [](const edge& a,const edge& b){ return a.cost < b.cost; });
    ll ret = 0;
    for(auto e : v) {
        if(uf.same(e.x,e.y)) continue;
        uf.merge(e.x,e.y);
        ret += e.cost;
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<LP,int>> v(n),nv(n);
    vector<edge> ve;
    rep(i,n) cin >> v[i].first.first >> v[i].first.second;
    rep(i,n) v[i].second = i;
    nv = v;
    sort(all(nv),
         [](const auto& a,const auto& b){ return a.first.first < b.first.first; });
    rep(i,n-1) {
        ve.emplace_back(nv[i].second,nv[i+1].second,
                abs(nv[i].first.first-nv[i+1].first.first));
    }
    swap(v,nv);
    sort(all(nv),
            [](const auto& a,const auto& b){ return a.first.second < b.first.second; });
    rep(i,n-1) {
        ve.emplace_back(nv[i].second,nv[i+1].second,
                        abs(nv[i].first.second-nv[i+1].first.second));
    }
    cout << kruskal(n,ve) << endl;
}


Measured memory_bytes: 12780
#include<bits/stdc++.h>
#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__)

using namespace std;
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; }

const long long INF = 1LL << 60;

int main()
{
  int N;
  cin >> N;
  int A[100010];
  
  rep(i,N) cin >> A[i];
  sort(A,A+N);

  int M = 0;
  int ans[100010][2];
  int y;
  int x;
  
  x = A[N-1];
  y = A[0];
  rep(i,1,N-1){
    if(A[i]<0){
      ans[i-1][0] = x;
      ans[i-1][1] = A[i];
      x -= A[i];
    }else{
      ans[i-1][0] = y;
      ans[i-1][1] = A[i];
      y -= A[i];
    }
  }
  ans[N-2][0] = x;
  ans[N-2][1] = y;
  M = x-y;
  
  cout << M << endl;
  rep(i,N-1){
    cout << ans[i][0] << " " << ans[i][1] << endl;
  }
}


Measured memory_bytes: 3072
R=range
def F(a,b):A=len(a);return[all([len(set([a[i+j],b[j],'?']))<3for j in R(min(A-i,len(b)))])for i in R(A)]+[1]
def Z(X):
 i,j,k=X;A,B,C=map(len,[S[t]for t in X]);q=1e5
 for l in R(A+1):
  if M[i][j][l]:
   for r in R(l,A+B+1):
    if(B<r-l or M[j][k][r-l])*M[i][k][min(A,r)]:q=min(q,max(A,l+B,r+C))
 return q
S=[input()for i in R(3)]
M=[[F(i,j)for j in S]for i in S]
from itertools import*;print(min([Z(i)for i in permutations(R(3))]))

Measured memory_bytes: 54236
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int grid[1000][1000] = {};
int x[8] = { 1,1,1,0,-1,-1,-1,0 };
int y[8] = { 1,0,-1,-1,1,-1,0,1 };
int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 1;i <= h;++i) {
		string s;
		cin >> s;
		for (int q = 1;q <= w;++q) {
			if (s[q-1] == '#') {
				grid[i][q] = 10;
				for (int t = 0;t < 8;++t) {
					grid[i + x[t]][q + y[t]]++;
				}
			}
		}
	}
	for (int i = 1;i <= h;++i) {
		for (int q = 1;q <= w;++q) {
			if (grid[i][q] >= 10) {
				cout << "#";
			}
			else {
				cout << grid[i][q];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
int ans;

string S;
int N;

void dfs(vector<int> v, int tmp){
    //cout << "dfs:" << tmp << endl;
    vector<int> u[26];
    //cout << "d:" << tmp << endl;
    for(int i = 0; i < v.size(); i++){
        if(v[i]+1 >= N) continue;
        int c = S[v[i]+1] - 'a';
        //cout << v[i] << ' ' << c << endl;
        if(true){
            //cout << "push" << endl;
            if(v[i]+1 < N) u[c].push_back(v[i]+1);
            if(u[c].size() >= 2) {
                if(u[c][0]+tmp-1 < v[i]){
                    ans = max(ans, tmp+1);
                }
            }
        }
    }
    for(int i = 0; i < 26; i++){
        sort(u[i].begin(), u[i].end());
        if(u[i].size() >= 2) {
            dfs(u[i], tmp+1);
        }
    }
}

int main(){
    cin >> N >> S;
    vector<int> v;
    for(int i = 0; i < N; i++){
        v.push_back(i-1);
    }
    dfs(v, 0);
    cout << ans << endl;
}

Measured memory_bytes: 114176
n,k=map(int,input().split())
a=list(map(int,input().split()))
ng=0
ok=max(a)+1
while ok-ng>1:
    mid=(ng+ok)//2
    count=0
    for i in range(n):
        if a[i]%mid==0:
            count+=((a[i]//mid)-1)
        else:
            count+=(a[i]//mid)
    if count>k:
        ng=mid
    else:
        ok=mid
print(ok)

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  string S, T;
  cin >> S;
  cin >> T;
  vector<int> Rst(26, -1);
  vector<int> Rts(26, -1);
  REP(i, S.size()) {
    if(Rst[S[i] - 'a'] == -1) {
      Rst[S[i] - 'a'] = T[i] - 'a';
    } else if(Rst[S[i] - 'a'] != T[i] - 'a') {
      cout << "No" << endl;
      return 0;
    }
    if(Rts[T[i] - 'a'] == -1) {
      Rts[T[i] - 'a'] = S[i] - 'a';
    } else if(Rts[T[i] - 'a'] != S[i] - 'a') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define MAX 200009
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
long long power(long long x, unsigned long long y, unsigned int m){
    if(y == 0) return 1;
    unsigned long long p = power(x, y/2, m) % m;
    p = (p * p) % m;
    
    if(y & 1)
        return  ((x % m)*p) % m;
    else 
        return p;
}
bool chk(int b, int x){
	for(int j = -x; j*j*j*j*j <= b; j++){
		if(j*j*j*j*j == b) return true;
	}
	return false;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		
		int x; cin >> x;
		for(int i = -1000; i <= 1000; i++){
			for(int j = -1000; j <= 1000; j++){
				if(i*i*i*i*i - j*j*j*j*j == x){
					cout << i << " " << j;
					return 0;
				}
			}
		}
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int rec(int A,int B,int K,int borrow,int C,int ten){
	if(A == 0) return C;
	int a = A%10, b = B % 10;
	if(a-borrow>=b){
		return rec(A/10, B/10, K, 0, C+ten*(a-borrow-b), ten*10);
	}else{
		int res = rec(A/10, B/10, K, 1, C+ten*(a-borrow+10-b), ten*10);
		if(K > 0)res = max(res, rec(A/10, B/10, K-1, 0, C+ten*(a-borrow+10-b), ten*10));
		return res;
	}
}

int main(){
	int A,B,K;
	cin>>A>>B>>K;
	cout<<rec(A,B,K,0,0,1)<<endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for(int i = 1; i < N; i++) {
    cin >> A[i];
    }
    vector<int> C(N, 0);
    for(int i = 1; i < N; i++) {
        C[A[i] - 1]++;
    }
    for(int i = 0; i < N; i++) {
        cout << C[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4844
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = set([int(readline().decode()) for _ in range(N)])

print(len(S))



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

using namespace std;

int main(void)
{
  int x;
  cin >> x;
  if(x == 3 || x == 5 || x == 7){
    cout << "YES" << endl;
    return 0;
  }  else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double sum=0;
    for(int i=1;i<=n;++i)
    {
        string z;
        double cnt;
        cin>>cnt>>z;
        if(z=="BTC")
            sum+=cnt*380000;
        else
            sum+=cnt;
        
    }
    cout<<sum<<endl;
}

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

const int a[12] = {1, -1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1};
int main() {
    int x, y; cin >> x >> y;
    if(a[x-1] == a[y-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define mp(a,b) make_pair(a,b)
#define pb push_back
using namespace std; 

vector<pair<int,int>> edges; 

void construct(vector<int> v){
	int n=v.size();
	if(n==3){
		edges.pb(mp(v[0],v[2])); 
		edges.pb(mp(v[1],v[2])); 
		return ;
	}
	if(n==4){
		edges.pb(mp(v[0],v[2]));
		edges.pb(mp(v[0],v[1]));
		edges.pb(mp(v[3],v[2]));
		edges.pb(mp(v[3],v[1]));
		return ;
	}
	if(n%2==0){
		rep(i,1,n-2){
			edges.pb(mp(v[n-1],v[i])); 
			edges.pb(mp(v[0],v[i])); 
		}
		v.pop_back(); v.erase(v.begin()); 
		construct(v); 
	}else{
		rep(i,0,n-2)edges.pb(mp(v[n-1],v[i])); 
		v.pop_back(); 
		construct(v); 
	}
}

int main(int argc,char *argv[]){
	int n; cin>>n; vector<int> v; rep(i,1,n)v.pb(i); construct(v); 
	cout<<(int)edges.size()<<endl; 
	for(auto t:edges)printf("%d %d\n",t.first,t.second);return 0; 
}

Measured memory_bytes: 384
from collections import deque
import heapq
def f(d,n):
    a = list(d)
    heapq.heapify(a)
    while n > 0 and len(a) > 0:
        tmp = heapq.heappop(a)
        if tmp >= 0:
            heapq.heappush(a,tmp)
            break
        n -= 1
    return sum(a)
#マイナスを取り除いて和を求める関数をあらかじめ作っておく
#優先度付きキューを使うと楽
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for i in range(1,min(N,K)+1):
    d = deque()
    for k in range(i):
        d.append(V[k])
    ans = max(ans,f(d,K-i))
    for k in range(i):
        d.pop()
        d.appendleft(V[N-1-k])
        ans = max(ans,f(d,K-i))
print(ans)
#解説中のa+b,bについてループで全探索している


Measured memory_bytes: 51420
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    string ans[] = {"AMBIGUOUS","MMYY","YYMM","NA"};
    int y1,y2,m1,m2;
    int x = 0;
    y1 = m2 = ((s[0]-'0')*10+(s[1]-'0'));
    y2 = m1 = ((s[2]-'0')*10+(s[3]-'0'));
    if (m1 > 12 || m1 == 0) {
        x |= 1<<0; 
    }
    if (m2 > 12 || m2 == 0) {
        x |= 1<<1;
    }
    cout << ans[x] << '\n';
    return 0;
}

Measured memory_bytes: 256
s = input()
if len(s) < 26:
    for i in range(26):
        c = chr(ord("a")+i)
        if c not in s:
            print(s+c)
            exit()
else:
    for i in reversed(range(1,26)):
        if s[i-1] < s[i]:
            s1 = s[0:i-1]
            for j in range(26):
                c = chr(ord("a")+j)
                if c > s[i-1] and c not in s1:
                    print(s1+c)
                    exit()
    print(-1)

Measured memory_bytes: 38384
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		s: [String; n],
		m: usize,
		t: [String; m],
	}

	let mut ans = -99999999999999isize;
	for i in 0..n {
		let mut sum = 0isize;
		for b in 0..n {
			if s[i] == s[b] {
				sum += 1;
			}
		}
		for r in 0..m {
			if s[i] == t[r] {
				sum -= 1;
			}
		}
		ans = max(ans, sum);
	}
	if ans < 0 {
		println!("0");
	}
	else {
		println!("{}", ans);
	}
}



Measured memory_bytes: 2168
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll A[100001];
ll N, M, ans, cnt; 
set<ll> B;

inline ll solve() {
    ans = A[0] - 1;
    M = 2;
    FOR(i, 1, N-1) {
        if(A[i] % M) ans += A[i] / M;
        else {
            if(A[i] == M) M++;
            else ans += A[i] / M - 1;
        }
    }
    return ans;
}

int main() {
    fastio();
    cin >> N;
    REP(i, N) cin >> A[i];
    cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cerr << (#x) << " is " << (x) << endl
#define INF 1e13
#define LL_MAX 1e18
// memset(array, -1, sizeof(array[0][0]) * row * count)
using namespace std;
 
ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 
bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }
bool check(ll i,ll j,ll n){return (i>=0 && i<n && j>=0 &&  j<n);} //matrix boundary checking
 
 
ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
 
// max({a, b, c, d})
// cout << fixed for removing e notation
 
bool comp(pair<ll, ll>a, pair<ll, ll>b)
{
    if(a.se-a.fi < b.se-b.fi) return true;
    else return false;
}
 
void convert(int arr[], int n) 
{ 
    int temp[n+1];
    for(int i=1;i<=n;i++)
        temp[i] = arr[i]; 
    // memcpy(temp, arr, n*sizeof(int)); 
  
    sort(temp+1, temp+n+1);   
    unordered_map<int, int> umap;
    int val = 1; 
    for (int i = 1; i <= n; i++) 
        umap[temp[i]] = val++;
    for (int i = 1; i <= n; i++) 
        arr[i] = umap[arr[i]]; 
}
 
bool prime[10000005];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime)); 
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++) 
    {
        if (prime[p] == true) 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
    }
}

int main()
{
    char a;
    cin >> a;

    cout << char(a+1) << "\n"; 
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    cin>> n;
    int a[n];


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

    sort ( a, a+n);
    cout << a[n/2]- a[n/2 -1] ;
    nl;


    return 0;
}




Measured memory_bytes: 4004
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    s = set(IS())
    if s == {'N','S'} or s == {'W','E'} or s == {'N','S','W','E'}:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
      
  		int[] l=new int[n];
		for(int c=0;c<n;c++){
    		l[c]=sc.nextInt();
    	}
  		Arrays.sort(l);
    	int ans=0;
  	for(int a=0;a<n-2;a++){
      for(int b=a+1;b<n-1;b++){
        int max=n;
        int min=b+1;
        if(l[min]-l[b]>=l[a]){
        	continue;
        }
        while(max-min>1){
        	if(l[(max+min)/2]-l[b]<l[a]){
            	min=(max+min)/2;
            }else{
            	max=(max+min)/2;
            }
        }
       int ok=min;
       ans+=ok-b;
      }
    
    }


    	System.out.println(ans);
    }
}


Measured memory_bytes: 27832
import sys
from math import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    a, b, x = map(int, input().split())
    h = x / a / a
    if h == b:
        print(0)
    elif h >= b / 2:
        c = (b - h) * 2
        print(degrees(atan(c / a)))
    else:
        c = 2 * a * h / b
        print(degrees(atan(b / c)))

main()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("4 8");
            //8
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("1 1 3");
            //3
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("3");
            WillReturn.Add("4 2 5");
            //5
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("4");
            WillReturn.Add("-100 -100 -100 -100");
            //0
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        int ASum = AArr.Sum();

        var AvgList = new List<int>();
        if (ASum % AArr.Length == 0)
            AvgList.Add(ASum / AArr.Length);
        else {
            if (ASum > 0) {
                AvgList.Add(ASum / AArr.Length);
                AvgList.Add(ASum / AArr.Length + 1);
            }
            else {
                AvgList.Add(ASum / AArr.Length);
                AvgList.Add(ASum / AArr.Length - 1);
            }
        }

        int Answer = int.MaxValue;
        foreach (int EachAvg in AvgList) {
            int DiffJijyouSum = 0;
            foreach (int EachInt in AArr) {
                DiffJijyouSum += (EachAvg - EachInt) * (EachAvg - EachInt);
            }
            if (DiffJijyouSum < Answer)
                Answer = DiffJijyouSum;
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 3032
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=202202;
int n,d,k;
struct AC{
	int pos,v;	
}a[N];
int add[N];
int cmp(AC x,AC y){
	return x.pos<y.pos;	
}
int solve(int x){
	return x/k+(x%k!=0);	
}
int main(){
	scanf("%d%d%d",&n,&d,&k);
	for (int i=1; i<=n; i++)
		scanf("%d%d",&a[i].pos,&a[i].v);
	sort(a+1,a+1+n,cmp);
	int Now=a[1].pos+d,Pre=1,point=1;
	ll ans=0,cnt=0;
	while (1){
//		printf("%d %d %d\n",Pre,point,cnt);
		while (Pre<=n&&a[Pre].v+cnt<=0)	cnt+=add[Pre++];
//		printf("%d %d %d\n",Pre,point,cnt);
		if (Pre==n+1)	break;
		Now=a[Pre].pos+d;
		while (point<n&&Now+d>=a[point+1].pos)	point++;
		int g=solve(a[Pre].v+cnt);
//		printf("%d\n",g);
//		if (Pre!=point){
			//printf("%daaaa%d\n",point,g);
			add[point]+=g*k,cnt-=g*k;
//		}
		ans+=g;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int n,m;
vector <int> adj[101];
bitset <101> mark;
bool NF[101];
bool Cyc;

void dfs(int x)
{
    if(NF[x])return;
    if(mark[x])
        Cyc=1;
    if(Cyc)
        return ;
    mark[x]=1;
    for(int i=0;i<adj[x].size();i++)
        dfs(adj[x][i]);
    mark[x]=0;
}


int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
    }
    for(int i=0;i<n;i+=5)
    {
        dfs(i);
        NF[i]=1;
    }

    if(Cyc)
        cout<<1<<endl;
    else
        cout<<0<<endl;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main() {
	char A, B, C;
	scanf("%c %c %c", &A, &B, &C);
	
	if(A==B && A!=C)
	puts("Yes");
	
	if(B==C && B!=A)
	puts("Yes");
	
	if(A==C && B!=A)
	puts("Yes");
	
	if(A==B && A==C)
	puts("No");
	
	return 0;
}

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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

bool judge(int N, int trampoline[]){
    int can_go_rightmost = 0;
    for(int i = 0; i <= can_go_rightmost && can_go_rightmost < N; i++){
        can_go_rightmost = max(can_go_rightmost, i + trampoline[i] / 10);
    }
    return can_go_rightmost >= N;
}

int main(){
    int N;
    cin >> N;
    int trampoline[N];
    for(int i = 0; i < N; i++){
        cin >> trampoline[i];
    }
    if(!judge(N, trampoline)){
        cout << "no" << endl;
        return 0;
    }
    reverse(trampoline, trampoline + N);
    if(judge(N, trampoline)){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
}




Measured memory_bytes: 4280
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    ll n;
    cin>>n;
    ll co[100001][2];
    memset(co,0,sizeof(co));
    ll temp;
    for(ll i=0;i<n;i++)
    {
    	cin>>temp;
    	if(i%2)
    		co[temp][1]++;
		else
			co[temp][0]++;
    }
    ll cnta=0,pos=-1;
    for(ll i=0;i<=100000;i++)
    	if(co[i][0]>cnta)
    	{
    		cnta=co[i][0];
    		pos=i;
    	}
    ll pos2=-1;
    ll cntb=0;
    for(ll i=0;i<=100000;i++)
    	if(co[i][0]>cntb&&i!=pos)
    	{
    		cntb=co[i][0];
    		pos2=i;
    	}
    ll pos3=-1,pos4=-1;
    ll cntc=0;
    for(ll i=0;i<=100000;i++)
    	if(co[i][1]>cntc)
    	{
    		cntc=co[i][1];
    		pos3=i;
    	}
    ll cntd=0;
    for(ll i=0;i<=100000;i++)
    	if(co[i][1]>cntd&&i!=pos3)
    	{
    		cntd=co[i][1];
    		pos4=i;
    	}
    //cout<<pos<<" "<<pos2<<" "<<pos3<<" "<<pos4<<endl;
    ll t1=cnta+cntd;
    ll t2=cntb+cntc;
    ll t3=cnta+cntc;
    //cout<<t1<<" "<<t2<<" "<<t3<<endl;
    if(pos==pos3)
    {
    	cout<<n-max(t1,t2)<<endl;
    }
    else
    	cout<<n-t3<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           (long long)1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }

template<typename T>
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
const int BLOCK = 700;

struct Query {
    int l, r, idx;
};

bool cmp(Query x, Query y) {
    if(x.l/BLOCK != y.l/BLOCK) {
        // different blocks, so sort by block.
        return x.l/BLOCK < y.l/BLOCK;
    }
    // same block, so sort by R value
    return x.r < y.r;
}

int arr[511111], cnt[511111], ans=0;


void add(int idx){
    cnt[arr[idx]]++;
    if(cnt[arr[idx]]==1) {
        ans++;
    }
}
void remove(int idx){
    cnt[arr[idx]]--;
    if(cnt[arr[idx]]==0) {
        ans--;
    }
}

vector<int> mo_s_algorithm(vector<Query> &queries) {
    vector<int> res(queries.size());
    sort(all(queries), cmp);
    
    int cur_l = 0;
    int cur_r = -1;
    for (Query q : queries) {
        while (cur_l > q.l) {
            cur_l--;
            add(cur_l);
        }
        while (cur_r < q.r) {
            cur_r++;
            add(cur_r);
        }
        while (cur_l < q.l) {
            remove(cur_l);
            cur_l++;
        }
        while (cur_r > q.r) {
            remove(cur_r);
            cur_r--;
        }
        res[q.idx] = ans;
    }
    return res;
}
void solve(){
    int n, a, b, q;
    cin>>n>>q;
    FOR(i, 0, n) cin>>arr[i];
    Query qq;
    vector<Query> qu;
    FOR(i, 0, q) {
        cin>>a>>b;
        a--, b--;
        qq.l = a, qq.r = b, qq.idx=i;
        qu.pb(qq);
    }
    vector<int> res = mo_s_algorithm(qu);
    for(int x:res) {
        cout<<x<<endl;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);     
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){ 
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
 
}


Measured memory_bytes: 27260
#include<bits/stdc++.h>
#define int long long

using namespace std ;


signed main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL)  ;

    int n ;
    cin >> n  ;
    priority_queue<pair<int,int> ,vector<pair<int,int>>> pq  ;
    vector<int> v (n);
    for(int i = 0 ; i < n ; ++i )
    {

        cin >> v[i] ;
    }
    sort(v.begin() , v.end() ,greater<int>());

    pq.push(make_pair(v[1] , v[0])) ;
    pq.push(make_pair(v[1] , v[0])) ;
    int ans = v[0] ;

    for(int i =2 ; i  <n ; ++i)
    {
        auto p = pq.top() ;
        ans += p.first ;
        int temp1 = p .first ;
        int temp2 = p.second ;
        pq.pop() ;
        pq.push(make_pair(v[i],temp1)) ;
        pq.push(make_pair(v[i] ,temp2)) ;


    }
    cout << ans << endl ;

}


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

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

    if(d==25){
        cout << "Christmas";
    }
    else if(d==24){
        cout << "Christmas Eve";
    }
    else if(d==23){
        cout << "Christmas Eve Eve";
    }
    else if(d==22){
        cout << "Christmas Eve Eve Eve";
    }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(a, b, c, i) for (int i = a; i < b; i++)
#define ff first
#define ss second
#define newl "\n"

using namespace std;

class Repsept{
public:
	ll first7(ll k){
		ll count = 1;
		ll x = 7;
		if (k == 1 || k == 7) return 1;
		if (k % 2 == 0|| k % 5 == 0) return -1;
		while (x > 0){
			x = (x * 10 + 7) % k;
			count++;
		}
		return count;
	}
};

int main(){
	ll k;
	cin >> k;
	Repsept r7;
	cout << r7.first7(k) << newl;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=3500,mo=1e9+7;
int m,n;
int f[N][N];
int DP(int n,int m)
{
    memset(f,0,sizeof(f));
    fo(i,0,n)f[0][i]=1;
    fo(i,1,m)fo(j,0,n)
    {
        if(j<n)((f[i][j]+=f[i-1][j+1])>=mo?f[i][j]-=mo:0),((f[i][j]+=f[i-1][j])>=mo?f[i][j]-=mo:0);
        if(j)((f[i][j]+=f[i-1][j])>=mo?f[i][j]-=mo:0),((f[i][j]+=f[i-1][j-1])>=mo?f[i][j]-=mo:0);
    }
    int ans=0;
    fo(i,0,n)((ans+=f[m][i])>=mo?ans-=mo:0);
    return ans;
}
int main()
{
    scanf("%d%d",&n,&m);
    printf("%d\n",(DP(n,m)-DP(n-1,m)+mo)%mo);
    return 0;
} 

Measured memory_bytes: 48000
# coding: utf-8
n, m = [int(x) for x in input().split(" ")]
ans = 0
pens = 0
prbstate = {}
fins = {}
A = []
for i in range(m):
    A.append(input().split(" "))
for a in A:
    if a[1] == "AC":
        fins.setdefault(a[0], 1)
for x in fins.values():
    ans += x
for i in range(m):
    p, s = A[i]
    prbstate.setdefault(p, 0)
    fins.setdefault(p, 0)
    if s == "AC":
        prbstate[p] += 1
    if s == "WA" and prbstate[p] < 1 and fins[p] == 1:
        pens += 1
print(ans, pens)

Measured memory_bytes: 50556
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        int k = sc.nextInt();

        // 処理
        long out = 0;
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    long gcd1 = gcd(a, b);
                    long gcd2 = gcd(gcd1, c);
                    out += gcd2;
                }
            }
        }

        // 出力
        System.out.println(out);
    }
    public static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

}

Measured memory_bytes: 35840
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int n;
  cin >> n;
  vector<ll> A(n);
  ll sum_p = 0LL;
  ll sum_n = 0LL;
  ll ans_p = 0LL;
  ll ans_n = 0LL;
  for(int i=0; i<n; i++) {
    cin >> A[i];
    sum_p += A[i];
    sum_n += A[i];
    if(i % 2 == 0) {
      if(sum_p <= 0) {
	ans_p += abs(1 - sum_p);
	sum_p += 1 - sum_p;
      }
      if(sum_n >= 0) {
	ans_n += abs(- 1 - sum_n);
	sum_n += - 1 - sum_n;
      }
    } else {
      if(sum_p >= 0) {
	ans_p += abs(- 1 - sum_p);
	sum_p += - 1 - sum_p;
      }
      if(sum_n <= 0) {
	ans_n += abs(1 - sum_n);
	sum_n += 1 - sum_n;
      }
    }
  }
  cout << min(ans_p, ans_n) << endl;
  return 0;
}


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


a = [0]
b = [0]

for i in range(N):
    a.append(a[i] + A[i])
for j in range(M):
    b.append(b[j] + B[j])

ans = 0
j = M

for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i+j)
    
            
print(ans)


Measured memory_bytes: 47488
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
using namespace std;

long long f(long long A) {
    if (A < 0)return 0;
    if (A % 4 == 0)return A;
    if (A % 4 == 1)return 1;
    if (A % 4 == 2)return A^1;
    if (A % 4 == 3)return 0;
}

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

    cout << (f(A - 1)^f(B));
    

    return 0;
}

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

int main (void){

    int a,b,c;
    int x;

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);

    int sum = 0;

    for(int i = 0; (i <= x/500) && (i <= a); i++){
    
        for(int j = 0; (j <= ((x-500*i)/100)) && (j <= b); j++){
          
                  if( (x-500*i-100*j)/50 <= c )
                    sum++;
                     
        }

    }
    
    printf("%d", sum);

    return 0;   
}


Measured memory_bytes: 128
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn gcd(x: u64, y: u64) -> u64 {
    if x == 0 {
        y
    } else {
        gcd(y % x, x)
    }
}

fn main() {
    let v = read_vec::<u64>();
    let a = v[0];
    let b = v[1];
    println!("{}", gcd(a, b));
}



Measured memory_bytes: 5028
/// awoooooo
 
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair < int, int > pii;
 
const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;
 
 
int n;
int x[N], y[N], p[N];
 
int main(){
  cin >> n;
 
  for(int i = 1; i <= n; ++i){
    cin >> x[i] >> y[i];
    p[i] = i;
  }
  ld ans = 0;
  int cnt = 0;
  do{
    for(int i = 1; i < n; ++i){
      ans += sqrtl((x[p[i]] - x[p[i + 1]]) * (x[p[i]] - x[p[i + 1]]) + (y[p[i]] - y[p[i + 1]]) * (y[p[i]] - y[p[i + 1]]));
    }
    ++cnt;
  }while(next_permutation(p + 1, p + 1 + n));
  cout << fixed << setprecision(11) << ans / cnt;
 
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
nums = gets.split.map &:to_f
c = 0
(n-1).times do 
    a = nums.min
    nums.delete_at(nums.index(a))
    b = nums.min
    nums.delete_at(nums.index(b))
    
    c = (a+b)/2
    nums.push(c)
end

puts c

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



 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    t=1;
    // cin>>t;
    //sieve();
    for(int cs=1;cs<=t;cs++)
    {
        
        ll n;
        cin>>n;
        ll ar[n+1]={0};
        for(int i=1;i<n+1;i++)
        {
            for(int j=i;j<n+1;j+=i)
            {
                ar[j]++;
            }

        }
        ll res=0;
        for(int i=1;i<n+1;i++)
        {
            res+=(i*ar[i]);
        }
        cout<<res<<endl;
 
    }
    return 0;
} 

Measured memory_bytes: 81740
#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#define rep(i,a,b) for( int i=a;i<b;i++)
#define repr(i,a,b) for( int i=a;i>=b;i--)
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define vii vector<ii>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Raag4924 ios_base::sync_with_stdio(0);
#define fastio cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Raag4924
    fastio
 

    int n;
    cin>>n;

    vector<double> v;

    for(int i=1;i<=n;i++)
    {
        double x;
        cin>>x;
        v.pb(x);
    }

    double dp[n+1][n+1];

    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++) 
            dp[i][j] = 1.0;

    for(int i=1;i<=n;i++)
    {
        dp[i][0] = dp[i-1][0]*(1-v[i-1]);
        for(int j=1;j<=i;j++)
        {
            // dp[i][j] = probablity of having j heads in first i coins.

            dp[i][j] = dp[i-1][j-1]*v[i-1];
            if(i-1>=j)
            dp[i][j]+=dp[i-1][j]*(1-v[i-1]);
        }
    }
   
    double ans =0;

  for(int i=n/2+1;i<=n;i++)
  {
     ans+=dp[n][i];
  }

 printf("%.10lf",ans);


    
  
 
 






 
#ifndef LOCAL_DEFINE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 74180
let dp = Array.make_matrix (50 + 1) (50 + 1) ~-1
let rec c n k = if dp.(n).(k) > -1 then dp.(n).(k) else (dp.(n).(k) <- if n < k then 0 else if n = k then 1 else if k = 0 then 1 else c (n - 1) (k - 1) + c (n - 1) k; dp.(n).(k))
let n, a, b = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b - 1, c - 1
let vs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let m = Array.(sort (fun x y -> y - x) vs; vs.(0))
let k = ref (b + 1)
let f = Array.fold_left (fun c v -> if v = vs.(!k) then c + 1 else c) 0
let _ = Array.(iteri (fun i v -> if a <= i && i < !k && v < m then k := i) vs; if a < !k then decr k; let t = f vs in
  Printf.printf "%.6f\n%d\n" (float (sub vs 0 (!k + 1) |> fold_left (+) 0) /. (float !k +. 1.)) @@ if vs.(!k) = m then let s = ref 0 in for i = a + 1 to b + 1 do s := !s + c t i done; !s else c t (f (sub vs 0 (!k + 1))))

Measured memory_bytes: 384