akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int cul(string s){ //足し算引き算のあるstringを計算する
    int ans;
    string ss;
    int length = (int)(s.length());
    bool pm=true;
    int count=0;
    for(int i=0;i<length;i++){
        if(s[i]!='+' and s[i]!='-'){
            ss+=s[i];
        }
        
        else if(s[i]=='+'){
            if(pm or count==0) ans+=stoi(ss);
            else ans-=stoi(ss);
            ss="";
            pm=true;
            count=1;
        }
        else if (s[i]=='-'){
            if(pm or count==0) ans+=stoi(ss);
            else ans-=stoi(ss);
            ss="";
            pm=false;
            count=1;
        }
    }
    if(pm or count==0) ans+=stoi(ss);
    else ans-=stoi(ss);
    return ans;
}


int main(){
    string n;
    cin >> n;
    string ans="";
    string out;

    for(int bit=0;bit<(1<<3);bit++){
        out=n[0];  
        for(int i=0;i<3;i++){
            if(bit & (1<<i)){
                out+="+";
                out+=n[i+1];
            }
            else{
                out+="-";
                out+=n[i+1];
            } 
        }
        //cout << out << endl;
        int result=cul(out);
        //cout << result << endl;
        if(result==7){
            ans=out+"=7";
            break;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	max := 0
	sum := 0
	for i := 0; i < n; i++ {
		var p int
		fmt.Scan(&p)
		if p > max {
			max = p
		}
		sum += p
	}
	fmt.Println(sum - (max / 2))
}


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

using namespace std;

#define int long long
#define PB push_back
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;

constexpr int INF = 1LL << 60;
constexpr int MOD = 1000000007;
constexpr int MAX_K = 200005;

int d[MAX_K][2], n, m, k;
vector<ppiii> xy, yx;
vector<pipii> G[MAX_K][2];

int Dijkstra() {
    fill(d[0], d[MAX_K], INF);
    d[k][0] = 0;
    priority_queue<pipii, vector<pipii>, greater<pipii>> pq;
    pq.push({ 0,{ k, 0 } });

    while (pq.size()) {
        pipii p = pq.top();
        pq.pop();
        int v = p.second.first;
        int st = p.second.second;
        if (d[v][st] < p.first) continue;

        for (int i = 0; i < G[v][st].size(); ++i) {
            int tov = G[v][st][i].second.first, tost = G[v][st][i].second.second;
            if (d[tov][tost] <= p.first + G[v][st][i].first) continue;
            d[tov][tost] = p.first + G[v][st][i].first;
            pq.push({ d[tov][tost],{ tov, tost } });
        }
    }

    int res = min(d[k + 1][0], d[k + 1][1]);
    return INF <= res ? -1 : res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> m >> n >> k;

    for (int i = 0; i < k; ++i) {
        int x, y;
        cin >> x >> y;
        xy.PB({ { x, y }, i });
        yx.PB({ { y, x }, i });
        G[i][0].PB({ 1,{ i, 1 } });
        G[i][1].PB({ 1,{ i, 0 } });

        if (x == 1) {
            G[k][0].PB({ y - 1,{ i, 0 } });
        }
        if (x == m) {
            G[i][0].PB({ n - y,{ k + 1, 0 } });
        }
        if (y == n) {
            G[i][1].PB({ m - x,{ k + 1, 1 } });
        }
    }
    sort(ALL(xy));
    sort(ALL(yx));

    for (int i = 0; i < k; ++i) {
        for (int j = i + 1; j < k; ++j) {
            if (xy[i].first.first != xy[j].first.first) {
                i = j - 1;
                break;
            }

            int cost = xy[j].first.second - xy[j - 1].first.second;
            int to = xy[j].second, from = xy[j - 1].second;
            G[from][0].PB({ cost,{ to, 0 } });
            G[to][0].PB({ cost,{ from, 0 } });
        }
    }

    for (int i = 0; i < k; ++i) {
        for (int j = i + 1; j < k; ++j) {
            if (yx[i].first.first != yx[j].first.first) {
                i = j - 1;
                break;
            }

            int cost = yx[j].first.second - yx[j - 1].first.second;
            int to = yx[j].second, from = yx[j - 1].second;
            G[from][1].PB({ cost,{ to, 1 } });
            G[to][1].PB({ cost,{ from, 1 } });
        }
    }

    cout << Dijkstra() << endl;
}

Measured memory_bytes: 101664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  string s;
  cin >> n >> s;
  vint eng(26);
  rep(i,n){
    eng[s[i]- 'a']++;
  }
  int ans = 1;
  rep(i,26){
    ans *= eng[i]+1;
    ans %= MOD;
  }
  cout << ans - 1 << endl; 
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int n,a[1000];
    scanf("%d",&n);
    for (int i=0;i<=n-1;i++){
        scanf("%d",&a[i]);
    }
    printf("%d",a[n-1]);
    for (int j=1;j<=n-1;j++){
        printf(" %d",a[n-1-j]);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 3220
uses math;
var
 i,j,k,n,x:longint;
begin
 read(n,x);
 if (n*10000<x) or (n*1000>x) or (x mod 1000<>0) then begin writeln('-1 -1 -1');halt;end;
 for i:=0 to min(x div 10000,n) do
  for j:=0 to n-i do
   begin
    k:=n-i-j;
    if (i*10000+j*5000+k*1000=x) then
     begin
      writeln(i,' ',j,' ',k);
      halt;
     end;
    end;
 writeln('-1 -1 -1');
end.

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	sum := 0
	var maxHeight int
	for i := 0; i < n; i++ {
		var height int
		fmt.Scan(&height)

		if height >= maxHeight {
			maxHeight = height
			sum++
		}
	}

	fmt.Printf("%d\n", sum)
}


Measured memory_bytes: 512
N,T = map(int,input().split())

C=[]
TT=[]
for i in range(N):
    c,t = map(int,input().split())
    C.append(c)
    TT.append(t)

TLE=0

for j in range(N):
    if TT[j]>T:
        TLE= TLE+1
    else:
        pass
    
if TLE==N:
    print("TLE")

else:   
    ans=max(C)

    for k in range(N):
        if TT[k]>T:
            pass
        elif C[k]<ans:
            ans=C[k]

    print(ans)


Measured memory_bytes: 3064
program main
	integer N, C, i, j, k
	integer(8) ans
	integer, allocatable :: D(:, :), cl(:, :), S(:, :)
	read(*, *) N, C
	allocate(D(1: C, 1:C))
	do i = 1, C
		read(*, *) D(i, 1: C)
	end do
	allocate(cl(1: N, 1:N))
	do i = 1, N
		read(*, *) cl(i, 1:N)
	end do
	allocate(S(1:C, 0:2))
	S(1:C, 0:2) = 0
	do l = 0, 2
		do k = 1, C
			do j = 1, N
				do i = 1, N
					if(mod(i+j, 3) == l) then
						S(k, l) = S(k, l) + D(cl(i,j), k)
					end if
				end do
			end do
		end do
	end do
	ans = 300000000
	do i = 1, C
		do j = 1, C
			do k = 1, C
				if(i /= j .and. j /= k .and. k /= i) then
					ans = min(S(i,0) + S(j,1) + S(k, 2), ans)
				end if
			end do
		end do
	end do
	write(*, *) ans
end program main

Measured memory_bytes: 1152
import sys

# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()

    l = len(s)
    for i in range(1, l):
        if (l-i) % 2 == 1:
            continue
        front = s[:(l-i) // 2]
        rear = s[(l-i) // 2:-i]

        if front == rear:
            print(l-i)
            exit(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long int
// #include"Template.cpp"

void solve() {
    int ans = 0;
    int n, d; cin >> n >> d;
    for(int i = 0; i < n; i ++) {
        int x, y; cin >> x >> y;
        if(((x*x) + (y*y)) <= (d*d)) {
            ans ++;
        }
    }
    cout << ans << endl;
}


int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(){
  int n,i,j,max=0,A,C[100001];
  
  scanf("%d",&n);

  for(i=0;i<=10000;i++){
    C[i]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d",&A);
    if(max<A)
      max=A;

    C[A]++;
  }


  for(i=0;i<max;i++){
    if(C[i]>0){
      for(j=0;j<C[i];j++){
	printf("%d ",i);
      }
    }
  }

  if(C[max]>1){
    for(i=0;i<C[max]-1;i++){
      printf("%d ",max);
    }

    printf("%d\n",max);
  }

  else{
    printf("%d\n",max);
  }


  return 0;
}



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

int main() {
    string s, w;
    int count = 0;

    cin >> s;
    for (int i=0; i<s.size(); i++) {
        if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] + 32;
    }

    cin >> w;
    while(w != "END_OF_TEXT") {
        for (int i=0; i<w.size(); i++) {
            if (w[i] >= 'A' && w[i] <= 'Z')
                w[i] = w[i] + 32;
        }
        if (w == s)
            count++;
        cin >> w;
    }
    cout << count << endl;
}


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

#define ll long long

void chmax(ll& a, ll b) {
  if (a < b) a = b;
}

void chmin(ll& a, ll b) {
  if (a > b) a = b;
}

int main() {
  int N;
  cin >> N;
  
  
  ll z_max = -10000000000, z_min = 10000000000;
  ll w_max = -10000000000, w_min = 10000000000; 
  for (int i = 0; i < N; i++) {
    ll x,y;
    cin >> x >> y;
    
    ll z = x + y, w = x - y;
    
    chmax(z_max, z);
    chmin(z_min, z);
    chmax(w_max, w);
    chmin(w_min, w);
  }
  
  cout << max(z_max-z_min, w_max- w_min) << endl;
 
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin>>s;
    if(s=="ABC")cout<<"ARC";
    else cout<<"ABC";
    
//system("pause");
return 0;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t l,r;
    cin >> l >> r;
    int64_t lmod = l%2019;
    int64_t rmod = r%2019;
    if(r/2019!=l/2019){
        cout << 0 << endl;
    }else{
        // 左が最大とは限らないので、全パターン網羅が必要
        // cout << (lmod * (lmod+1))%2019 << endl;
        int64_t res = INF, temp;
        for(int64_t i=lmod; i<rmod; i++){
            for(int64_t j=i+1; j<=rmod; j++){
                res = min(res, (i*j)%2019);
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int a[500];
int f(int a) {
    if (a<0) return -a;
    return a;
} 
int main(){
    int n,r,z=0;
    scanf("%d",&n);
    if (n==0) printf("0",0);
    r=2;
    int m=f(n);
    while (m) {
        a[++z]=m%r; 
        m/=r;
    }
    int x=0;
    if (n>=0) x=2;else x=1; 
    for (int i=x;i<=z;i+=2)
    if (a[i]>0)  {
        a[i+1]++;
        if (a[i+1]>=r) a[i+2]+=a[i+1]/r,a[i+1]%=r;
        if (a[z+1]) z++; 
        a[i]=-(r-a[i]);
    }
    for (int i=z;i>0;i--)
    if (f(a[i])<10) printf("%d",f(a[i]));else 
    printf("%c",(char)f(a[i])+'A'-10);
    return 0;
} 

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        char[] c = S.toCharArray();

        ArrayList<HashSet<Integer>> list = new ArrayList<HashSet<Integer>>();
        for (int i=0;i<N+1;i++) {
            HashSet<Integer> set = new HashSet<Integer>();
            list.add(set);
        }
        for (int i=N-1;i>=0;i--) {
            HashSet<Integer> set = new HashSet<Integer>(list.get(i+1));
            set.add((int)c[i]-48);
            list.get(i).addAll(set);
        }

        int ans = 0;
        for (int i=0;i<10;i++) {
            for (int j=0;j<10;j++) {
                boolean i_flag = false;
                for (int k=0;k<N;k++) {
                    if (i_flag==false && (int)c[k]-48==i) {
                        i_flag=true;
                        continue;
                    }
                    if (i_flag==true && (int)c[k]-48==j) {
                        ans += list.get(k+1).size();
                        // System.out.println("i, j, k, size:"+i+" "+j+" "+k+" "+list.get(k+1).size());
                        break;
                    }
                }
            }
        }
        System.out.println(ans);

        // for (int i=0;i<list.size();i++) {
        //     System.out.println(list.get(i));
        // }
    }
}

Measured memory_bytes: 46904
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int a[55];

int main() {
    int n;
    cin >> n;
    int mx = 0;
    int mxi = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (abs(a[i]) > abs(mx)) {
            mx = a[i];
            mxi = i;
        }
    }
    vector<pair<int, int>> ans;
    for (int i = 0; i < n; i++) {
        if (signbit(mx) != signbit(a[i])) {
            ans.push_back({mxi, i});
        }
    }
    if (mx >= 0) {
        for (int i = 1; i < n; i++) {
            ans.push_back({i - 1, i});
        }
    } else {
        for (int i = n - 1; i > 0; i--) {
            ans.push_back({i, i - 1});
        }
    }

    cout << ans.size() << endl;
    for (auto x: ans) {
        printf("%d %d\n", x.first + 1, x.second + 1);
    }
}


Measured memory_bytes: 3732
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    now = 1000
    stock_num = 0

    for i in range(len(a)-1):
        # buy
        if stock_num == 0:
            if a[i] < a[i + 1]:
                stock_num = int(now / a[i])
                now -= a[i] * stock_num

        # sell
        else:
            if a[i] > a[i + 1]:
                now += a[i] * stock_num
                stock_num = 0

    if not stock_num == 0:
        now += a[-1] * stock_num
    print(now)

Measured memory_bytes: 80540
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

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

int main()
{
	int num = 0; cin >> num;
	string dat[12] = { "", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	rep(i, num)
	{
		string str; cin >> str;
		vector<int> hit(10, 0);
		rep(j, (int)str.size())
		{
			hit[str[j] - '0'] += 1;
			if (j == 0 || str[j - 1] == '0') {}
			else if (str[j] == '0')
			{
				int tmp = str[j - 1] - '0', n = hit[tmp];
				while (1)
				{
					if (n <= (int)dat[tmp].size()) { break; }
					n -= (int)dat[tmp].size();
				}
				/*n = hit[tmp] % (int)dat[tmp].size();
				if (n == 0){ n = hit[tmp] + 1; }
				if (n >= 3 && (int)dat[tmp].size() == 3) { n -= 1; }*/
				printf("%c", dat[tmp][n - 1]);
				rep(i, 10){ hit[i] = 0; }
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2992
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  map<char, int> mp;
  for(int i = 0; i < s.length(); ++i) mp[s[i]]++;
  int mini, maxx;
  mini = min(mp['a'], min(mp['b'], mp['c']));
  maxx = max(mp['a'], max(mp['b'], mp['c']));
  if(abs(maxx - mini) <= 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    int N, M;
    cin >> N >> M;

    vector<int> A(M);
    int sum = 0;
    for (int i = 0; i < M; i++) {
        cin >> A[i];
        sum += A[i];
    }

    cout << max(N - sum, -1) << endl;

    return 0;
}



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

using namespace std;
int n;
int ma;
int v[20];
int a[20][20];
void dfs(int k,int s)
{
    if(k==n)
    {
        int vv[20];
        memset(vv,-1,sizeof(vv));
        for(int i=1; i<=n; i++)
        {
            if(v[i])
            {
                for(int j=1; j<=n; j++)
                {
                    if(a[i][j]==-1)
                        continue;
                    else if(v[j]==0&&a[i][j]==1||v[j]==1&&a[i][j]==0)
                    {
                        s=0;
                        break;
                    }
                    else
                    {
                        vv[j]=a[i][j];
                    }
                }
            }
        }
        ma=max(ma,s);
    }
    else
    {
        v[k+1]=0;
        dfs(k+1,s);
        v[k+1]=1;
        dfs(k+1,s+1);
    }
}
int main()
{
    cin>>n;
    memset(a,-1,sizeof(a));
    for(int i=1; i<=n; i++)
    {
        int b;
        cin>>b;
        for(int j=0; j<b; j++)
        {
            int x,op;
            cin>>x>>op;
            a[i][x]=op;
        }
    }
    ma=0;
    dfs(0,0);
    cout<<ma<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
int a,b,sum; 
inline void into(){
  scanf("%d%d",&a,&b);
}
inline void work(){
  for (int i=1;i<b-a;i++)
    sum+=i;
}
inline void outo(){
  printf("%d\n",sum-a);
}
int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
struct UnionFind {
    vector<int> par;
    int n, cnt;
    UnionFind(const int& x = 0) { init(x); }
    void init(const int& x) { par.assign(cnt = n = x, -1); }
    inline int find(const int& x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
    inline bool same(const int& x, const int& y) { return find(x) == find(y); }
    inline bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return false;
        --cnt;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const { return cnt; }
    inline int count(int x) { return -par[find(x)]; }
};

struct edge {
    ll u;
    ll v;
    ll cost;
    edge() {}
    edge(ll u, ll v, ll c) :u(u), v(v), cost(c) {}
    bool operator < (const edge& o) const {
        return cost < o.cost;
    }
    bool operator > (const edge& o)const {
        return cost > o.cost;
    }
};

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll V, E; cin >> V >> E;
    UnionFind uf(V);
    priority_queue<edge,vector<edge>,greater<edge>> G;
    for (int i = 0; i < E;i++) {
        ll s, t, w; cin >> s >> t >> w;
        G.push(edge(s, t, w));
    }
    ll ans = 0;
    while (!G.empty()) {
        auto e = G.top(); G.pop();
        if (uf.same(e.u, e.v)) continue;
        uf.unite(e.u, e.v);
        ans += e.cost;
    }
    if (uf.count() == 1) cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6012
n,x = map(int, input().split())
a = [1]
p = [1]
for i in range(n):
    a.append(a[i]*2 + 3)
    p.append(p[i]*2 + 1)

def f(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=1 + a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1] + 1 + f(n-1,x-2-a[n-1])

print(f(n,x))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int i,a,ans,min=10000;
	for (i=0;i<3;i++){
		cin>>a;
		if (min>a){
			min=a;
		}
	}
	ans=min-50;
	min=10000;
	for (i=0;i<2;i++){
		cin>>a;
		if (min>a){
			min=a;
		}
	}
	ans=ans+min;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int A, B, C, D ;
  cin >> A >> B >> C >> D ;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

#define all(x) (x).begin(), (x).end()

const int N = 2e5 + 3;
vector<int> g[N];
int a[N];
int ans[N];
vector<int> t(4 * N);
void upd(int v, int l, int r, int L, int R, int x) {
    if (l >= R || L >= r) {
        return;
    }
    if (L <= l && r <= R) {
        t[v] = x;
        return;
    }
    upd(v * 2, l, (l + r) / 2, L, R, x);
    upd(v * 2 + 1, (l + r) / 2, r, L, R, x);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int get(int v, int l, int r, int L, int R) {
    if (l >= R || L >= r) {
        return 0;
    }
    if (L <= l && r <= R) {
        return t[v];
    }
    return max(get(v * 2, l, (l + r) / 2, L, R),
    get(v * 2 + 1, (l + r) / 2, r, L, R));
}

void dfs(int v, int pr) {
    int was = get(1, 0, N, a[v], a[v] + 1);
    int mx = get(1, 0, N, 0, a[v]);
    upd(1, 0, N, a[v], a[v] + 1, mx + 1);
    ans[v] = get(1, 0, N, 0, N);
    for (auto i : g[v]) {
        if (i != pr) {
            dfs(i, v);
        }
    }
    upd(1, 0, N, a[v], a[v] + 1, was);
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> f;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        f.emplace_back(a[i]);
    }
    sort(all(f));
    f.erase(unique(all(f)), f.end());
    for (int i = 1; i <= n; ++i) {
        a[i] = lower_bound(all(f), a[i]) - f.begin() + 1;
    }
    for (int i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << '\n';
    }

}


Measured memory_bytes: 33884
#include <stdio.h>
typedef long long ll;

int main() {
  int k;
  scanf("%d", &k);
  ll a[100005];
  for (int i = 0; i < k; i++) {
    scanf("%lld", &a[i]);
  }
  ll mn = 2;
  ll mx = 2;
  for (int i = k - 1; i >= 0; i--) {
    // [L, R]のaの倍数のminは、ceil(L/a)*a
    //                  maxは、floar(R/a)*a
    if (mn % a[i]) {
      mn += a[i] - mn % a[i];
    }
    mx = mx - mx % a[i] + a[i] - 1;
    if (mn > mx) {
      puts("-1");
      return 0;
    }
  }
  printf("%lld %lld", mn, mx);
}


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int r = scanner.nextInt();
        System.out.println(3*r*r);



    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21332
using System;

namespace B___Sum_of_Three_Integers
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var k = int.Parse (input[0]);
            var s = int.Parse (input[1]);
            var ans = 0;
            for (var i = 0; i <= k; i++)
            {
                for (var j = 0; j <= k; j++)
                {
                    var z = s - i - j;
                    if (0 <= z && z <= k)
                        ans++;
                }
            }
            Console.WriteLine (ans);
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
 
int main() {
	int n, l, i, sum;
 
	scanf("%d%d", &n, &l);
	sum = 0;
	for (i = 1; i <= n; i++)
		sum += (l + i - 1);
	printf("%d\n", sum - (l > 0 ? l : (l + n - 1 >= 0 ? 0 : l + n - 1)));
	return 0;
}

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

vector< vector< pair<int,int> > > to(100005);
vector< int> col(100005, 0);
vector< int> par(100005, 0);


int main() {
  int N;
  cin >> N;
  int pre = 0;
  int K = 1;
  int mia = N;
  REP(i,N-1) {
    int a,b;
    cin >> a >> b;
    to[a].emplace_back(b,i);
    to[b].emplace_back(a,i);
    mia = min( mia, a );
  }
  queue<int> q;
  q.push(mia);
  while( !q.empty()){
    auto v = q.front(); q.pop();
    int c = 1;
    for( auto nv: to[v] ) {
      int nn = nv.first;
      int i = nv.second;
      if ( col[i] != 0 ) continue;
      if ( c == par[v] ) c++;
      col[i] = c;
      par[nn] = c;
      K = max(K,c);
      c++;
      q.push(nn);
    }
  }
  cout << K << endl;
  REP(i,N-1) {
    cout << col[i] << endl;
  }
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;



void solve(){

    string s;
    cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;


}

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


Measured memory_bytes: 3656
#include<iostream>
#include<cstring>
#define maxn 200005
using namespace std;
int main(void)
{
	char s[maxn],t[maxn];
	while(~scanf("%s %s",s,t))
	{
		int sum=0;
		int len=strlen(s);
		for(int i=0;i<len;++i)
		{
			if(s[i]!=t[i])
			sum++;
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 3612
#!/usr/bin/env python

def main():
    while True:
        n, x = list(map(int, input().split()))
        if n == 0 and x == 0:
            exit()

        else:
            ans = 0
            a = tuple(range(1, n+1))
            for idx1 in range(len(a)-1):
                target = x - a[idx1]
                idxl = idx1+1
                idxr = len(a)-1 
                while idxl < idxr:
                    if a[idxl] + a[idxr] == target:
                        ans += 1
                        idxl += 1
                        idxr -= 1
                    elif a[idxl] + a[idxr] < target:
                        idxl += 1
                    else:
                        idxr -= 1
            print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
int ans=0;
		for (int i1 = 0; i1 <= a; i1++) {
			for (int i2 = 0; i2 <= b; i2++) {
				for (int i3 = 0; i3 <= c; i3++) {

			if(500*i1+100*i2+50*i3==x){
				ans++;
			}


				}
			}
		}
System.out.println(ans);
	}
}


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

namespace ARC099A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = nk[0]-nk[1];
            int cnt = 1;
            while (n > 0)
            {
                n = (n + 1) - nk[1];
                cnt++;
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 18016
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef pair<int, int> pii;
typedef double lf;
typedef long long ll;
const int inf=0x3f3f3f3f, mod=1000000007;

inline int read()
{
    int x=0,f=1; char ch=getchar();
    for (; ch<'0' || ch>'9'; ch=getchar()) if (ch=='-') f=-1;
    for (; ch>='0' && ch<='9'; ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}

int main()
{
    int n=read(), ans=0;
    for (int i=1; i<=n; i++) 
    {
        int x=read();
        ans+=(x&1);
    }
    if (ans) puts("first"); else puts("second");
    return 0;
}


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

// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr

#ifdef PCM
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DUMPOUT<<"  "; \
  DUMPOUT<<#__VA_ARGS__; \
  DUMPOUT<<":=> "; \
  dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
#define dump_1d(x,n) DUMPOUT <<"  " \
  <<#x<<"["<<#n<<"]"<<":=> {"; \
  rep(i,n){ DUMPOUT << x[i] << (((i)==(n-1))?"}":", "); } DUMPOUT <<" in [" << __LINE__ << "]" << endl;

#define dump_2d(x,n,m) DUMPOUT <<"  " \
    <<#x<<"["<<#n<<"]"<<"["<<#m<<"]"<<":=> \n"; \
    rep(i,n)rep(j,m){ DUMPOUT << ((j==0)?"     |":" ") << x[i][j] << (((j)==(m-1))?"|\n":" "); } \
    DUMPOUT <<"  in [" << __LINE__ << "]" << endl;
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif

// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/

#define rep(i, x) for(int i = 0; i < (int)(x); i++)/*{{{*/
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define INF 2147483647
#define INFLL 1000000000000000000LL
#define MOD 1000000007/*}}}*/

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;/*{{{*/
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*}}}*/

// global variables

int main() {
  int n;cin>>n;
  string s[n];
  rep(i,n)cin>>s[i];

  int cnt[n][26]={};

  rep(i,n){
    rep(j, s[i].size()){
      cnt[i][s[i][j] - 'a'] += 1;
    }
  }

  rep(j, 26){
    int m = INF;
    rep(i, n) m = min(m, cnt[i][j]);
    assert (m>=0);
    std::cout << string(m, 'a'+j);
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n, m;
  int a, last_a;
  int max_diff = 0;
  int diff;

  cin >> n >> m;

  cin >> a;
  last_a = a;
  max_diff = a -1;

  for (int i = 1; i < m; i++) {
    cin >> a;
    diff = a - last_a - 1;
    !(diff % 2) ? diff /= 2 : diff = diff / 2 + 1;
    if (diff > max_diff) max_diff = diff;
    last_a = a;
  }

  if (n - a > max_diff) max_diff = n - a;

  cout << max_diff << endl;
}



Measured memory_bytes: 3116
#include <iostream>

using namespace std;

int main(void) {
	int N;
	
	cin >> N;
	for(int i = 0; i < N; i++) {
		int len[3];
		cin >> len[0] >> len[1] >> len[2];
		
		if(len[0] > len[1]) {
			int tmp = len[0];
			len[0] = len[1];
			len[1] = tmp;
		}
		if(len[1] > len[2]) {
			int tmp = len[1];
			len[1] = len[2];
			len[2] = tmp;
		}
		if(len[0] > len[1]) {
			int tmp = len[0];
			len[0] = len[1];
			len[1] = tmp;
		}
		
		if(len[2] * len[2] == len[0] * len[0] + len[1] * len[1]) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
import sys
from collections import deque
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

deq=deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

K=II()
for i in range(K-1):
    v = deq.popleft()
    last = v % 10
    if last == 0:
        deq.append(10*v)
        deq.append(10*v + 1)
    elif last == 9:
        deq.append(10*v + 8)
        deq.append(10*v + 9)
    else:
        deq.append(10*v + last-1)
        deq.append(10*v + last)
        deq.append(10*v + last+1)

print(deq.popleft())


Measured memory_bytes: 11956
#include <stdio.h>

int main() {

    int a, b, tmp;
    
    scanf("%d %d", &a, &b);
    
    tmp = a * b;
    
    if (tmp < a - b) {
        tmp = a - b;
    }
    if(tmp < a + b) {
        tmp = a + b;
    }
    
    printf("%d\n", tmp);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

const int MAXN = 100 * 1000 + 5;
long long arr[MAXN];
long long temp[MAXN];

int n, k;

int main () {
	cin >> n >> k;
	// input and temp
	for (int i = 0; i < n; i ++) {
		cin >> arr[i];
		if (i > 0) {
			if (arr[i] > 0)
				temp[i] = temp[i - 1] + arr[i];
			else
				temp[i] = temp[i - 1];
			arr[i] = arr[i - 1] + arr[i];	
		}
		else {
			if (arr[i] > 0)
				temp[i] = arr[i];
			else 
				temp [i] = 0;
		}
	}
	
	long long ans = 0;
	for (int i = 0; i <= n - k; i ++) {
		long long tmpans = 0;
		long long jam;
		if (i > 0)
			jam = arr[i + k - 1] - arr[i - 1];
		else
			jam = arr[i + k - 1];
		if (jam > 0)
			tmpans = jam;
		if (i >= 1)
			tmpans += temp[i - 1];
		tmpans += (temp[n - 1] - temp[i + k - 1]);
		ans = tmpans > ans ? tmpans : ans;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n,m;
  cin>>n>>m;
  map<int,int> road;
  rep(i,n){
    road[i+1]=0;
  }
  rep(i,m){
    int a,b;
    cin>>a>>b;
    road[a]++;
    road[b]++;
  }
  for(auto x:road){
    cout<<x.second<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int S = 0, T = 0, s[4], t[4];

	for(int i = 0; i < 4; i++){
		cin >> s[i];
		S += s[i];
	}
	for(int i = 0; i < 4; i++){
		cin >> t[i];
		T += t[i];
	}

	if(S > T) cout << S << endl;
	else cout << T << endl;

	return 0;
}

Measured memory_bytes: 3064
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.rbegin(), a.rend());

    ll ans = 0;
    set<pair<int,int> > z;
    for (i = 0; i < n; i++) {
        if (i == 0) {
            z.insert(make_pair(a[i],i*2));
        }
        else {
            assert(!z.empty());
            auto it=z.rbegin();
            int tmp = it->first;
            ans += tmp;
            z.erase(*it);
            z.insert(make_pair(a[i], i * 2));
            z.insert(make_pair(a[i], i * 2+1));
        }
    }
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cout << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#define INFILE freopen("input.txt", "r", stdin)
#else
#define debug(x)
#define INFILE
#endif

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL9_MOD = 1000000009LL;
static constexpr ll LL7_MOD = 1000000007LL;
static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll memo[100010];

ll longest_path(ll vertex, const vector<vector<int>>& adj_list) {
  if (memo[vertex] != -1) return memo[vertex];
  if (adj_list[vertex].size() == 0) return memo[vertex] = 0;

  ll max_path = 0;
  for (ll next_vertex : adj_list[vertex]) {
    chmax(max_path, longest_path(next_vertex, adj_list));
  }

  return memo[vertex] = max_path + 1;
}

int main(int argc, char* argv[]) {
  INFILE;

  ll n, m;
  cin >> n >> m;

  vector<vector<int>> v(n + 1, vector<int>(0));
  Fill(memo, ll(-1));

  REP(i, 0, m) {
    int from, to;
    cin >> from >> to;
    v[from].push_back(to);
  }

  for (int i = 1; i < n + 1; i++) {
    if (memo[i] != -1) continue;
    longest_path(i, v);
  }

  cout << *max_element(begin(memo), begin(memo) + n + 1) << endl;

  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


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

int main() {
    int a,b; cin >> a >> b;
    int count = 0;
    for(int i = a; i <= b; i++) {
        string s = to_string(i);
        if(s[0]==s[4] && s[1]==s[3]) count ++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    ll ans = a[0] - 1, now = 1;
    for(int i = 1; i < n; i++){
        if(a[i] == now + 1) now++;
        else ans += (a[i] - 1) / (now + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    int s, k, m = 0;
    x = 0;

    k = getchar_unlocked();

    if (k == '-') s = 1;
    else if ('0' <= k && k <= '9')  x = k - '0';

    while (true)
    {
        k = getchar_unlocked();

        if (k < '0' || k > '9') break;
        x = x * 10 + k - '0';
    }

    if (m) x = -x;
}

// void del(int *A) と同じ
template<class T> void del(T A[])
{
    delete[] A;
}

int main()
{
    const char *YES = "YES";
    const char *NO = "NO";

    long long int N;
    gc(N);

    if (N == 1)
    {
        printf("%s\n", YES);
        return 0;
    }

    long long int a;
    long long int sum = 0LL;

    long long int *A = new long long int[ N ]();

    for (int i = 0; i < N; i++)
    {
        gc(a);
        A[i] = a;
        sum += a;
    }

    long long int val = N * (N + 1) / 2;
    if (sum % val != 0LL)
    {
        printf("%s\n", NO);
        return 0;
    }

    long long int times = sum / ((N * (N + 1)) / 2);

    long long int div;

    for (int i = 0; i < N; i++)
    {
        long long int div = A[(i + 1) % N] - A[i] - times;

        if (div > 0LL || div % N != 0LL)
        {
            printf("%s\n", NO);
            return 0;
        }
    }

    printf("%s\n", YES);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin>>n;
	ll a[n];
	ll c=0,z=1,v=0;
	for(ll i=0; i<n; i++){
		cin>>a[i];
		if(a[i]==z){
			v=1;
			z++;
		}
		else
			c++;
	}
	if(v==1)
		cout<<c;
	else
		cout<<-1;

}

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

long long func(long long b, long long n) {
	if (b < 2) return -1;
	if (b > n) return n;
	else return func(b, n / b) + (n % b);
}
 
int main() {
	long long n, s;
	cin >> n >> s;
	if (n == s) {
		cout << n + 1 << "\n";
	}
	else {
		bool is = true;
		for (long long i = 2; i * i <= n; i++) {
			if (func(i, n) == s) {
				cout << i << "\n";
				is = false;
				break;
			}
		}
		if (is) {
			long long result = -1;
			for (long long i = 1; i * i <= n; i++) {
				long long key = (n - s) / i + 1;
				if (func(key, n) == s) result = key;
			}
			cout << result << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dump(X) cout << #X << ' ' << X << endl
#define pe(X) cout << X << endl
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll L,R;
int main(){
	cin >> L >> R;
	if(R-L>2030ll)cout << 0 << endl;
	else{
		ll ans = INF;
		for(ll i=L;i<=R;i++){
			for(ll j=i+1;j<=R;j++){
				ans = min(ans,(i*j)%2019ll);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def make_prime_factors(n: int) -> list:
    """自然数nの素因数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 156 -> [2, 2, 3, 13]
    """
    prime_factors = []
    for k in range(2, int(n ** 0.5) + 1):
        while n % k == 0:
            prime_factors.append(k)
            n = n // k
    if n != 1:
        prime_factors.append(n)
    return prime_factors


n = int(input())
ans = make_prime_factors(n)
print('{}: {}'.format(n, ' '.join(map(str, ans))))


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

bool palindrome(string s)
{
	string k = s;
	reverse(all(s));
	return k == s;
}
bool s_palindrome(string s)
{
	string f = s.substr(0,s.size()/2);
	string l = s.substr(s.size()/2+1);
	if(!palindrome(f)||!palindrome(l)||!palindrome(s))return 0;
	return 1;
}
int main()
{
	string s;
	cin>>s;
	if(s_palindrome(s))
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}


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

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

    int n, m;
    while (cin >> n >> m) {
        if (n == 0) break;
        vector<vector<int>> as(m + 1);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            as[a].push_back(b);
        }
        for (int i = 1; i <= m; i++) {
            sort(as[i].rbegin(), as[i].rend());
        }
        long long ans = 0;
        for (int i = 1; i <= m; i++) {
            ans += as[i][0];
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 3104
k = int(input())
import math
import fractions
ans = 0
e = 0
d = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        #e = math.gcd(a,b)
        e = fractions.gcd(a,b)
        for c in range(b,k+1):
            #d = math.gcd(e,c)
            d = fractions.gcd(e,c)
            if a != b and b!= c and a!= c:
                ans+= d*6
            elif (a==b and a!=c) or (a==c and a!= b) or (b == c and a!= b):
                ans+= d*3
            else:
                ans+= d
print(ans)


Measured memory_bytes: 10652