akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

void solve(){
    int n, m, res=0;
    vector<int> x, cost;
    cin >> n >> m;
    rep(i, m){
        int temp;
        cin >> temp;
        x.push_back(temp);
    }
    sort(x.begin(), x.end());
    for(auto i = x.begin(); i != x.end(); i++){
        if(i == x.end()-1) break;
        int c = (*(i+1)) - (*i);
//        cout << "cost: " << c << endl;
        cost.push_back(c);
        res += c;
    }
//    cout << "res: " << res << endl;
    sort(cost.begin(), cost.end());
    reverse(cost.begin(), cost.end());
    if(n >= m){
        cout << 0 << endl;
        return;
    }else{
        for(int i = 0; i < n-1; i++){
            res -= cost[i];
        }
    }
    cout << res << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 1400
//52
#include<iostream>
#include<algorithm>
#include<sstream>
#include<string>

using namespace std;

int main(){
  int d[99][50]={{}};
  string s;
  int l;
  for(l=0;getline(cin,s);l++){
    stringstream ss(s);
    for(int j=0,n;ss>>n;j++){
      d[l][j]=n;
      ss.ignore();
    }
  }
  int a[99][50]={{}};
  a[0][0]=d[0][0];
  for(int i=1;i<99;i++){
    for(int j=0;j<50;j++){
      a[i][j]=max(a[i][j],a[i-1][j]+d[i][j]);
      if(l/2<i){
	a[i][j]=max(a[i][j],a[i-1][j+1]+d[i][j]);
      }else{
	if(0<=j-1){
	  a[i][j]=max(a[i][j],a[i-1][j-1]+d[i][j]);
	}
      }
    }
  }
  cout<<a[98][0]<<endl;
  return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vector<int> C(N-1), S(N-1), F(N-1);
    for(int i = 0; i <N-1; i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    vector<int> ans(N, 0);

    for(int i = 0; i < N-1; i++){
        for(int j = i; j < N-1; j++){
            if(ans[i] <= S[j]) ans[i]= S[j] + C[j];
            else{
                int next = (ans[i] + F[j] -1) / F[j];
                ans[i] = next * F[j] + C[j];
            }
        }
    }
    
    for(int i = 0; i < N; i++) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int h,w;
	cin>>h>>w;
	int a,ans=0;
	int c[10][10];
	rep(i,10){
		rep(j,10){
			cin>>c[i][j];
		}
	}
	rep(k,10){
		rep(i,10){
			rep(j,10){
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
			}
		}
	}
	rep(i,h){
		rep(j,w){
			cin>>a;
			if(a==-1)continue;
			ans+=c[a][1];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		long mod = 1000000007;
		if(N==3){
			Console.WriteLine("61");
		} else {
		long[,]A = new long[N,256];
		long[,]B = new long[N,256];
		for(var i=0;i<256;i++){
			A[3,i] = 1;
		}
		for(var i=0;i<=3;i++){
			B[3,24+i] = 1;
			A[3,24+i] = 0;
			B[3,64*i+6] = 1;
			A[3,64*i+6] = 0;
			B[3,36+i] = 1;
			A[3,36+i] = 0;
			B[3,64*i+9] = 1;
			A[3,64*i+9] = 0;
			B[3,72+i] = 1;
			A[3,72+i] = 0;
			B[3,64*i+18] = 1;
			A[3,64*i+18] = 0;
			B[3,16*i+6] = 1;
			A[3,16*i+6] = 0;
			B[3,4*i+18] = 1;
			A[3,4*i+18] = 0;
		}
		int[]C = new int[32]{24,25,26,27,6,70,134,198,36,37,38,39,9,73,137,201,72,73,74,75,18,82,146,210,6,22,38,54,18,22,26,30};
		for(var i=4;i<N;i++){
			for(var j=0;j<=255;j++){
				if(C.Contains(j)){
					B[i,j] += A[i-1,j/4]+A[i-1,j/4+64]+A[i-1,j/4+128]+A[i-1,j/4+192];
					B[i,j] %= mod;
				} else {
					A[i,j] = A[i-1,j/4]+A[i-1,j/4+64]+A[i-1,j/4+128]+A[i-1,j/4+192];
					A[i,j] %= mod;
				}
			}
			for(var j=0;j<=255;j++){
				B[i,j] += B[i-1,j/4]+B[i-1,j/4+64]+B[i-1,j/4+128]+B[i-1,j/4+192];
				B[i,j] %= mod;
			}
		}
		long ans = 1;
		for(var j=0;j<N;j++){
			ans = ans * 4 % mod;
		}
		long ans2 = 0;
		for(var j=0;j<256;j++){
			ans2 = (ans2 + B[N-1,j]) % mod;
		}
		ans = ans + mod - ans2;
		Console.WriteLine(ans%mod);
		}
	}
}

Measured memory_bytes: 17324
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main(){
    ll n; cin >> n;
    multiset<ll> se;
    rep(i,n){
        ll a; cin >> a;
        se.insert(a);
    }
    ll ans = 0;
    multiset<ll> se2;
    for(ll bit=35; bit>=1; bit--){
        ll b = 1LL<<bit;
        se2 = se;
        for(auto i : se2){
            auto itr = se.find(i);
            if(itr == se.end()) continue;
            auto itr2 = se.find(b-i);
            if(itr==itr2) itr2++;
            if(itr2 != se.end() && *itr + *itr2 == b){
                se.erase(itr);
                se.erase(itr2);
                ans++;
            }
            if(se.size()==0 || se.size()==1) break;
        }
        if(se.size()==0 || se.size()==1) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 20992
#include <iostream>
using namespace std;
int main(void){
    //変数の定義
    int a, b, c;
    
    //変数：約数の個数を定義
    int count = 0;
    
    //変数の入力
    cin >> a >> b >> c;
    
    //a〜bの間の約数を探す
    for(int i = a; i <= b; i++){
        //if；余りがあるかないかで条件を設定
        if(c % i == 0) count++;
    }
    
    //約数の個数を出力する
    cout << count << endl;
    
    
}



Measured memory_bytes: 3116
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib> //abs() これは整数のみ

using namespace std;

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

const int max_v = 300;
const int INF = 1000000;



int main() {
	int n;
	cin >> n;
	//vector <int> A(n);
	//string str;
	if(n < 1200){
		 cout << "ABC" << endl; return 0;}
	if(n < 2800) {cout << "ARC" << endl; return 0;}
	else cout << "AGC" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

   int n, k, x[100], ans = 0;
   cin >> n;
   cin >> k;
   REP(i, n) cin >> x[i];

   REP(i, n) ans += min(k-x[i], x[i])*2;

   cout << ans << endl;
   
   rtn 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
	int x;
	cin >> x;
	int c = x /500;
	ll sum = c * 1000;
	x -= c * 500;
	sum += (x / 5) * 5;
	cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<iterator>
#include <stack>
#define ll long long
typedef long double ld;
#define all(v) ((v).begin()),((v).end())
#define vec2(n,m) vector<vector<ll>>vv(n + 10, vector<ll>(m + 10, 0));
#define p_q1   priority_queue<int,vector<int>,greater<int>>pq1;
#define format(n) fixed<<setprecision(n)
#define ll_min LLONG_MIN;
#define ll_max LLONG_MIN;
#define endl "\n"
#define F first 
#define S second
#define mkpr(x,y)  make_pair(x,y)
using namespace std;
void weza()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
    weza();
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
const int N=10000000;
bool S[N];
void squre(){
  for(int i=0;i<N;i++){
    S[i]=false;
  }
  for(int i=0;i<=350;i++){
    int s=pow(i,2);
    S[s]=true;
  }
}
int main(){
  int a,b;
  cin>>a>>b;
  squre();
  string stra=to_string(a);
  string strb=to_string(b);
  string strc=stra+strb;
  int ans = atoi(strc.c_str());
  //cout<<ans<<endl;
  if(S[ans]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 9984
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun main ()
  (let* ((str (read-line))
         (k (read)))
    (println
     (loop for idx from 0 below k
           for digit = (- (char-code (aref str idx)) 48)
           unless (= digit 1)
           do (return digit)
           finally (return 1)))))

#-swank(main)



Measured memory_bytes: 15840
A,B,C,D,E,F = list(map(int, input().split()))
#x is a list which represents for the volumn of water
x = set()

#y is a list which represents for the volumn of sugar
y = set()

for i in range(F//C+1):
    for j in range((F-C*i)//D+1):
        #if i + j == 0:
            #continue
        y.add( i * C + j * D)

for i in range(F//(100 * A)+1):
    for j in range((F-100*A*i)//(100*B)+1):
        if i + j == 0:
            continue
        x.add(i * A * 100 + j * B * 100)
#print(x)
#print(y)
ans_sweetwater = 1
ans_sugar = -1
#ans_density = -1
#density = E/(100+E)
#print("density: ",density)
for m in x:
    for n in y:
        #tmp_density = n/(m+n)
        if m + n <= F and m*E/100 >= n and ans_sugar/ans_sweetwater <= n/(m+n):
            ans_sweetwater =  m + n
            ans_sugar = n
            #ans_density = tmp_density
print(ans_sweetwater,ans_sugar)


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main()
{
	char a;
	int cnt = 1;
	while (1)
	{
		a = getchar();
		if (a == '\n')break;

		if (cnt % 2 != 0)
		{
			cout << a;
		}
		cnt = cnt + 1;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
datas = [int(input()) for _ in range(N)]
now_max = max(datas[1:])
max_index = (N-1) - datas[::-1].index(now_max)
_min = min(datas)
min_index = datas.index(_min)

if max_index > min_index:
    diff = now_max - _min
else:
    diff = now_max - datas[0]
    
    for i in range(1,N-1):
        if i == max_index:
            now_max = max(datas[i+1:])
            max_index = datas.index(now_max,i+1)
        new_diff = now_max - datas[i]
        if diff < new_diff:
            diff = new_diff

print(diff)


Measured memory_bytes: 15092
#include<bits/stdc++.h>
using namespace std;
const int M=100001;
int n,A[M];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	int ans=1,t=1;
	for(int i=2;i<=n;i++){
		if(A[i]>A[i-1])t=1;
		else {
			t++;
			ans=max(ans,t);
		}
	}
	printf("%d\n",ans-1);
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<P> p(n);
    rep(i, 0, n){
        cin >> p[i].first;
        p[i].second = i + 1;
    }
    sort(p.begin(), p.end());
    rep(i, 0, n){
        cout << p[i].second << " ";
    }
    cout << endl;
    return 0;
}


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

int n, m;
vector <int> s;
vector <int> c;

bool  ok(string str) {
    if (str.length() != n) return false;

    for (int j = 0; j < m; j++) {
        if (str.at(s.at(j)) != to_string(c.at(j)).at(0)) return false;
    }

    return true;
}

int main() {
    cin >> n >> m;
    s.resize(m), c.resize(m);

    for (int i = 0; i < m; i++) {
        cin >> s.at(i) >> c.at(i);
        s.at(i)--;
    }

    for (int i = 0; i <= 999; i++) {
        if (ok(to_string(i))) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<tuple<string, int, int>> p(N);
  for(int i=0;i<N;i++){
    string a;
    int b;
    cin>>a>>b;
    p.at(i)=make_tuple(a, -b, i+1);
  }
  sort(p.begin(), p.end());
  for(int i=0;i<N;i++){
    string a;
    int b,c;
    tie(a, b, c)=p.at(i);
    cout<<c<<endl;
  }
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;
const int maxn = 1000;
int main(){
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a[k - 1] << '\n'; 
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var x, ans int
	fmt.Scanf("%d", &x)

	found := false
	for !found {
		if big.NewInt(int64(x)).ProbablyPrime(0) {
			found = true
			ans = x
		}
		x++
	}

	fmt.Printf("%d", ans)
}


Measured memory_bytes: 2012
r, c = gets.split.map(&:to_i)

src_array = r.times.map do |_|
  gets.split.map(&:to_i)
end

sum_row = c.times.map do |i|
  r.times.reduce(0) do |sum, j|
    sum += src_array[j][i]
  end
end

dist_array = src_array << sum_row
dist_array.each do |row|
  puts (row << row.sum).join(' ')
end


Measured memory_bytes: 7076
#include <stdio.h>
#include <stdint.h>

int main (void)
{
    char s[4];
    int i;
    uint8_t flag;

    scanf("%s", s);

    for (i = 0; i < 3; i++) {
        flag |= 1 << (s[i] - 'a');
    }

    if (flag == 0x07) puts("Yes"); else puts("No");
}


Measured memory_bytes: 128
#

import sys
from collections import deque
input=sys.stdin.readline

def main():
    N,M=map(int,input().split())
    adj=[[] for i in range(N)]
    for i in range(M):
        A,B=map(int,input().split())
        adj[A-1]+=[B-1]
        adj[B-1]+=[A-1]
    parent=[-1]*N
    qu=deque([0])
    qup=qu.popleft
    qua=qu.append
    parent[0]=0
    while(len(qu)>0):
        v=qup()
        for nv in adj[v]:
            if parent[nv]!=-1:
                continue
            else:
                parent[nv]=v
                qua(nv)
    print("Yes")
    for i in range(1,N):
        print(parent[i]+1)
        
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 34280
n = gets.to_i
if n >= 1800
  puts '1'
elsif n >= 1600
  puts '2'
elsif n >= 1400
  puts '3'
elsif n >= 1200
  puts '4'
elsif n >= 1000
  puts '5'
elsif n >= 800
  puts '6'
elsif n >= 600
  puts '7'
else
  puts '8'
end

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

int main(){
    int N,M;
    cin >> N >> M;
    int res = N * (N-1) / 2 + M * (M-1) / 2;
    cout << res << endl;
    return 0;
}

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

int main()
{
	int i, H, W;
	char s[2002][2002];
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(s[i][1]));
	for (i = 0; i <= H + 1; i++) {
		s[i][0] = '#';
		s[i][W+1] = '#';
	}
	for (i = 1; i <= W; i++) {
		s[0][i] = '#';
		s[H+1][i] = '#';
	}
	
	int j, k, l, count[2002][2002] = {}, max = 0;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (s[i][j] == '#') continue;
			for (k = j; s[i][k] != '#'; k++);
			for (l = j; l < k; l++) count[i][l] += k - j;
			j = k;
		}
	}
	for (j = 1; j <= W; j++) {
		for (i = 1; i <= H; i++) {
			if (s[i][j] == '#') continue;
			for (k = i; s[k][j] != '#'; k++);
			for (l = i; l < k; l++) count[l][j] += k - i;
			i = k;
		}
	}
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) if (count[i][j] > max) max = count[i][j];
	}
	
	printf("%d\n", max - 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 19712
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

score = 0

last_lst = [""]*K

for i in range(N):
    if T[i] == last_lst[i%K]:
        last_lst[i%K] = ""
        continue
    else:
        if T[i] == "r":
            score += P
        elif T[i] == "p":
            score += S
        else:
            score += R
        last_lst[i%K] = T[i]
print(score)

Measured memory_bytes: 3828
#pragma GCC optimize("O3")
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 ll n,k;
 cin>>n>>k;
 V<V<ll>> w(2*k+1,V<ll>(2*k+1,0)),b(2*k+1,V<ll>(2*k+1,0));
 ll all_w=0,all_b=0;
 for(int i=0;i<n;i++){
     ll x,y;
     cin>>x>>y;
     x%=(2*k);y%=(2*k);
     char c;
     cin>>c;
     if(c=='W'){
         w[x+1][y+1]++;
         all_w++;
     }else{
         b[x+1][y+1]++;
         all_b++;
     }
 }
 for(int i=0;i<=2*k;i++){
     for(int j=0;j<2*k;j++){
         w[i][j+1]+=w[i][j];
         b[i][j+1]+=b[i][j];
     }
 }
  for(int i=0;i<=2*k;i++){
     for(int j=0;j<2*k;j++){
         w[j+1][i]+=w[j][i];
         b[j+1][i]+=b[j][i];
     }
 }
 ll ans=0;
 for(int i=k;i<2*k;i++){
     for(int j=k;j<2*k;j++){
         ll wsum=0,bsum=0;
         wsum+=w[2*k][2*k]-w[2*k][j]-w[i][2*k]+w[i][j];//右下
         wsum+=w[i][j]-w[i-k][j]-w[i][j-k]+w[i-k][j-k];//真ん中
         wsum+=w[i-k][j-k];//左上
         wsum+=w[i-k][2*k]-w[i-k][j];//右上
         wsum+=w[2*k][j-k]-w[i][j-k];//左下
         bsum+=b[2*k][2*k]-b[2*k][j]-b[i][2*k]+b[i][j];//右下
         bsum+=b[i][j]-b[i-k][j]-b[i][j-k]+b[i-k][j-k];//真ん中
         bsum+=b[i-k][j-k];//左上
         bsum+=b[i-k][2*k]-b[i-k][j];//右上
         bsum+=b[2*k][j-k]-b[i][j-k];//左下    
         chmax(ans,wsum+(all_b-bsum));
         chmax(ans,bsum+(all_w-wsum));
     }
 }
 cout<<ans<<"\n";
}


Measured memory_bytes: 62976
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    int N, K;
    cin >> N >> K;
    
    if (K > (N-1)*(N-2)/2) {
        cout << -1 << endl;
        return 0;
    }
    vector<vector<int>> ans(0, vector<int>());
    cout << (N-1) + ((N-1)*(N-2)/2 - K) << endl;
    for (int i = 2; i <= N; i++) {
        cout << "1 " << i << endl;
    }
    int cnt = (N-1)*(N-2)/2;
    
    if (cnt == K) return 0;
    
    for (int i = 2; i <= N-1; i++) {
        bool check = false;
        for (int j = i+1; j <= N; j++) {
            cout << i << " " << j << endl;
            cnt--;
            if (cnt == K) {
                check = true;
                break;
            }
        }
        if (check) break;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> ans(10010);
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        int sum = x * x + y * y + z * z + x * y + y * z + z * x;
        if (sum < 10010) ans[sum]++;
      }
    }
  }
  for (int i = 1; i <= N; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
	int n, m, l;
	int i, j, k;
	int a[100][100], b[100][100];
	long long sum;

	scanf("%d %d %d", &n, &m, &l);

	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
			scanf("%d", &a[i][j]);
	}

	for(i=0;i<m;i++){
		for(j=0;j<l;j++)
			scanf("%d", &b[i][j]);
	}


	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			sum = 0;
			for(k=0;k<m;k++)
				sum += a[i][k] * b[k][j];
			if(j==l-1)
				printf("%ld", sum);
			else
				printf("%ld ", sum);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 680
N,M = list(map(int,input().split()))

e_list = [[] for i in range(N+M)]

for i in range(N):
    D = list(map(int,input().split()))
    for j in range(1,D[0]+1):
        e_list[i].append(N+(D[j]-1))
        e_list[N+(D[j]-1)].append(i)

vi = 0 #時と場合によってここを変える
from collections import deque
Q = deque([vi])
checked_list = [False]*(N+M)
checked_list[vi]=True
while len(Q)>0:
    v = Q.pop()
    for v1 in e_list[v]:
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.appendleft(v1)
flag=True
for i in range(N):
    if not checked_list[i]:
        flag=False

if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 72500
#include<stdio.h>
int main(){
	double a;
	while(~scanf("%lf",&a)){
		if(a<=48)printf("light fly\n");
		else if(a<=51)printf("fly\n");
		else if(a<=54)printf("bantam\n");
		else if(a<=57)printf("feather\n");
		else if(a<=60)printf("light\n");
		else if(a<=64)printf("light welter\n");
		else if(a<=69)printf("welter\n");
		else if(a<=75)printf("light middle\n");
		else if(a<=81)printf("middle\n");
		else if(a<=91)printf("light heavy\n");
		else printf("heavy\n");
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>  
using namespace std;  
  
#define fast ios::sync_with_stdio(false);cin.tie(NULL)  
#define fi first  
#define se second  
#define all(v) (v).begin(),(v).end()  
#define pb push_back  
#define eb emplace_back
#define em emplace
#define mp make_pair
  
typedef long long ll;  
typedef pair<int,int> pii;  
typedef pair<ll,ll> pll;  
const long long INF = 1e18;  
const int inf = 1e9;
const ll Mod = 998244353;

int n, q;

ll p[200010];
ll dp[200010];
ll tree[800010];
ll lazy[800010];

void propagate(int node, int s, int e) {
	if(!lazy[node]) return;

	tree[node] = (dp[e] - dp[s-1] + Mod) % Mod * lazy[node] % Mod;

	if(s != e) {
		lazy[node*2] = lazy[node*2+1] = lazy[node];
	}

	lazy[node] = 0;
}

void update(int node, int s, int e, int l, int r, int x) {
	propagate(node, s, e);
	if(r < s || e < l) return;
	if(l <= s && e <= r) {
		lazy[node] = x;
		propagate(node, s, e);
		return;
	}

	update(node*2, s, (s+e)/2, l, r, x);
	update(node*2+1, (s+e)/2+1, e, l, r, x);

	tree[node] = (tree[node*2] + tree[node*2+1]) % Mod;
}

int main() {
	fast;

	cin >> n >> q;

	for(int i=1; i<=n; i++) {
		dp[i] = (dp[i-1] * 10 + 1) % Mod;
	}

	update(1, 1, n, 1, n, 1);

	while(q--) {
		int l, r, d;
		cin >> l >> r >> d;

		update(1, 1, n, n - r + 1, n - l + 1, d); 

		cout << tree[1] << "\n";
	}
}

Measured memory_bytes: 13416
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int N = sc.nextInt();
    ArrayList<Integer> A = new ArrayList(N);

    for (int i=0; i<N; i++) {
      A.add(sc.nextInt());
    }
    
    int a = A.get(A.size()-1);
    for (int i=A.size()-2; i>=0; i--) {
      a = gcd(a, A.get(i));
    }

    System.out.println(a);
  }

  static int gcd(int a, int b) {
    if (b == 1) return 1;
    if (b == 0) return a;
    return gcd(b, a%b);
  }

}


Measured memory_bytes: 59664
import std.array;
import std.conv;
import std.math;
import std.algorithm;
import std.string;
import std.stdio;

void main() {
	int n;
	readf("%s\n", &n);

	auto happinessTable = new int[][3];
	foreach (ref e;happinessTable) {
		e = new int[n];
	}

	foreach (i;0..n) {
		readf(
			" %s %s %s\n",
			&happinessTable[0][i],
			&happinessTable[1][i],
			&happinessTable[2][i]
		);
	}

	auto dp = new int[][3];
	foreach (ref e;dp) {
		e = new int[n + 1];
	}
	
	foreach (i;0..n) {
		dp[0][i + 1] = max(dp[1][i], dp[2][i]) + happinessTable[0][i];
		dp[1][i + 1] = max(dp[0][i], dp[2][i]) + happinessTable[1][i];
		dp[2][i + 1] = max(dp[0][i], dp[1][i]) + happinessTable[2][i];
	}

	writeln(max(dp[0][n], dp[1][n], dp[2][n]));
}


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

int main() {
  int N;
  cin >> N;
  
  double A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  
  sort(A, A+N);
  
  double ans = (A[0] + A[1]) / 2;
  for (int i = 2; i < N; i++) {
    ans = (ans + A[i]) / 2; 
  }
  
  cout << fixed << setprecision(10) << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a, b, k; cin >> a >> b >> k;
	int gcd;
	int c = max(a, b);
	int d = min(a, b);
	while (true) {
		if (c % d == 0) {
			gcd = d;
			goto C;
		}
		else {
			c -= d;
			if (c <= d) {
				swap(c, d);
			}
		}
	}
C:if (k%gcd != 0)cout << "NO\n"; else cout << "YES\n";
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;



void one_case() {
    int h, w, d;
    cin >> h >> w >> d;
    vector<vector<int>> grid(h, vector<int>(w));
    map<int, pair<int, int>> pos;
    for (auto& row : grid) {
        for (auto& el : row) {
            cin >> el;
            --el;
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            pos[grid[i][j]] = make_pair(i, j);
        }
    }
    vector<vector<int>> pref_dist_for_reminder(d);
    for (int rem = 0; rem < d; ++rem) {
        int cur = rem;
        int dist = 0;
        pref_dist_for_reminder[rem].pb(dist);
        while (cur + d < h * w) {
            auto next = cur + d;
            auto cp = pos[cur];
            auto np = pos[next];
            dist += abs(cp.first - np.first) + abs(cp.second - np.second);
            pref_dist_for_reminder[rem].pb(dist);
            cur = next;
        }
    }
    int q;
    cin >> q;

    while (q-- ) {
        int l, r;
        cin >> l >> r;
        --l;
        --r;
        auto rem = l % d;
        cout << pref_dist_for_reminder[rem][r / d] - pref_dist_for_reminder[rem][l / d] << "\n";
    }
}

// 0 rem rem + d, rem + 2 d
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 11392
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

//#define INF 100000000
//#define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    string s;
    cin >> s;

    bool flag = true;

    int i;
    int n = s.size();
    for(i = 0; i < n; i++){
        if(s[i] != s[n-1-i]) flag = false;
        //cout << s[i] << " " << s[n-1-i] << endl;
    }

    for(i=0; i < (n-1)/2; i++){
        if(s[i] != s[(n-1)/2-1-i]) flag = false;
        //cout << s[i] << " " << s[(n-1)/2-1-i] << endl;
    }

    for(i = (n+3)/2-1; i < n; i++){
        if(s[i] != s[n-1-i]) flag = false;
        //cout << s[i] << " " << s[n-1-i] << endl;
    }

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

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<stdlib.h>
#include<sstream>

void listen_doneTask(std::map<int,std::map<int,int> > &eachMan_done);
void listen_taskCost_And_Echo_result(std::map<int,std::map<int,int> > &eachMan_done,const int craftsmanCount,const int taskCount);


//------------------------------main----------------------------------
int main()
{
	using namespace std;
	int craftsmanCount,taskCount;
	cin>>craftsmanCount>>taskCount;
	
	map<int,map<int,int> > eachMan_done;
	listen_doneTask(eachMan_done);
	
	int calc_count;
	cin>>calc_count;
	
	for(int i=calc_count;i;--i)
	{
		listen_taskCost_And_Echo_result(eachMan_done,craftsmanCount,taskCount);
	}
	
	return 0;
}
//--------------------------------------------------------------------

void listen_doneTask(std::map<int,std::map<int,int> > &eachMan_done)
{
	using namespace std;
	
	int man,task,count;
	
	while(cin>>man>>task>>count,man)/*0 0 0でない限り*/
	{
		eachMan_done[man][task]=count;
	}
}

void listen_taskCost_And_Echo_result(std::map<int,std::map<int,int> > &eachMan_done,const int craftsmanCount,const int taskCount)
{
	using namespace std;
	
	//---------------------------------listen--------------------------
	long long sum[craftsmanCount+1];
	memset(sum,0,sizeof(sum));
	int cost[taskCount+1],roop=1;
	string str,tmp;
	while(getline(cin,str),str=="");
	stringstream tmp_stream(str);
	
	while(getline(tmp_stream,tmp,' '))
	{
		cost[roop++]=atoi(tmp.c_str());
	}
	//----------------------------------calc----------------------------
	map<int,int>::iterator itr;
	for(int i=1;i<=craftsmanCount;++i)
	{
		for(itr=eachMan_done[i].begin();itr!=eachMan_done[i].end();++itr)
		{
			sum[i]+=cost[itr->first]*itr->second;
		}
	}
	//------------------------------------echo-----------------------------
	cout<<sum[1];
	for(int i=2;i<=craftsmanCount;++i)
	{
		cout<<" "<<sum[i];
	}
	cout<<endl;
}

Measured memory_bytes: 4752
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    map <string, ll> m;
    string s, t, u;
    cin >> s >> t;
    cin >> m[s] >> m[t];
    cin >> u;
    m[u]--;
    cout << m[s] << ' ' << m[t] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class B4{
  public static void Main(){
    int n,q,l = 0,count = 0;
    n = int.Parse(Console.ReadLine());
    //string[] S = new string[n];
    string[] str = Console.ReadLine().Split(' ');
    int[] S = new int[n];
    for(int i = 0;i < n;i++){
      S[i] = int.Parse(str[i]);
    }

    /*for(int i = 0;i < n;i++){
      S[i] = str[i];
    }*/

    q = int.Parse(Console.ReadLine());
    //string[] T = new string[q];
    string[] str2 = Console.ReadLine().Split(' ');
    int[] T = new int[n];

    for(int i = 0;i < q;i++){
      T[i] = int.Parse(str2[i]);
    }

  /*  for(int i = 0;i < q;i++){
      T[i] = str2[i];
    }*/

    int[] memory = new int[n];
    for(int i = 0;i < q;i++){
      if(binarySearch(S,T[i]) != -1){
        memory[l] = binarySearch(S,T[i]);
        l++;
      }
    }

  /*  for(int i = 0;i < l;i++){
      Console.Write(memory[i] + " ");
    }
    Console.WriteLine("");
*/
    for(int i = 0;i < l;i++){
      for(int j = 0;j < l;j++){
        if(memory[i].Equals(memory[j])){
          count++;
          break;
        }
      /*bool flag = false;
      for(int j = 0;j < l;j++){
        if(memory[i].Equals(memory[j]) && flag == false){
           count++;
           flag = true;
        }*/
      }
    }
    Console.WriteLine(count);

  }

  static int binarySearch(int[] S,int key){
    int left = 0;
    int right = S.Length;
    while(left < right){
      int mid = (left + right) / 2;
      if(S[mid] == key) return mid;
      else if(key < S[mid]) right = mid;
      else left = mid + 1;
    }
    return -1;
  }
}


Measured memory_bytes: 22276
import java.util.Scanner

fun main() {
	val scn = Scanner(System.`in`)
	val k = scn.nextInt()
	val s = scn.next()
	val l = s.length
	val f = mutableListOf(ModInt(1))
	for (i in 1..l+k){
		f.add(f.last()*i)
	}
	val bef = Array(k+1){ModInt.pow(25, it)*f[l-1+it]/(f[it]*f[l-1])}
	val arr = mutableListOf(ModInt(1))
	for (c in 1..k){
		arr.add(arr.last()*26+bef[c])
	}
	println(arr.last())
}

class ModInt {
	var v: Long
		private set
	constructor(v: Int){
		this.v = when {
			v>=0 -> v.toLong() % MOD
			v==Int.MIN_VALUE -> 852516373
			else -> MOD.toLong() - (-v%MOD)
		}
	}
	constructor(v: Long){
		this.v = when {
			v>=0 -> v % MOD
			v==Long.MIN_VALUE -> 708828003
			else -> MOD - (-v%MOD)
		}
	}

	override fun toString() = v.toString()
	fun toInt() = v.toInt()
	fun toLong() = v
	override fun equals(other: Any?): Boolean {
		return if (other is ModInt) v == other.v else false
	}
	override fun hashCode() = 31*17 + v.hashCode()

	operator fun unaryPlus() = this
	operator fun unaryMinus() = ModInt(MOD-this.v)

	private operator fun plus(o: Long) = ModInt(this.v + o)
	operator fun plus(o: ModInt) = this.plus(o.v)
	operator fun plus(o: Int) = this.plus(o.toLong())
	private operator fun minus(o: Long) = this.plus(-o)
	operator fun minus(o: ModInt) = this.minus(o.v)
	operator fun minus(o: Int) = this.minus(o.toLong())
	private operator fun times(o: Long) = ModInt(this.v*o)
	operator fun times(o: ModInt) = this.times(o.v)
	operator fun times(o: Int) = this.times(o.toLong())
	private operator fun div(o: Long) = this.times(pow(o, MOD-2))
	operator fun div(o: ModInt) = this.div(o.v)
	operator fun div(o: Int) = this.div(o.toLong())

	operator fun inc() = this.plus(1)
	operator fun dec() = this.minus(1)

	companion object{
		const val MOD = 1000000007

		private fun pow(b:Long, e: Int): ModInt{
			if (b==1L) return ModInt(1)
			var ans = 1L
			var b = b; var e = e
			while (e!=0){
				if (e%2==1) ans = (ans*b)%MOD
				b = (b*b)%MOD
				e /= 2
			}
			return ModInt(ans)
		}
		fun pow(b: Int, e: Int): ModInt = pow(b.toLong(), e)
		fun pow(b: ModInt, e: Int): ModInt = pow(b.v, e)
	}
}


Measured memory_bytes: 163596
n = input()
current = n[0]
flag = False
for i in range(len(n)):
    # not doublet
    if n[i] != current:
        # and also the rest of number is bigger than the first one
        if n[i] > current:
            flag = True
            break
        # but the rest of the number is smaller than the first one
        else:
            n = current * 3
            break

if flag:
    x = int(current) + 1
    print(int(str(x) * 3))
else:
    print(n)


Measured memory_bytes: 3060
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<b + min(c, a + b + 1)<<endl;
}


Measured memory_bytes: 256
#include<cstdio> 
#include<cmath>
#include<cstring>
#include<algorithm>  
 double i,N,m,n;
 int main()
{
	  while(~scanf ("%lf",&N))
	{
		for (double i=N;i <=N;N--)
	{
      m=sqrt(i);
      if (m==int(m))
	  {
	  	  printf("%.0lf\n",i);
	  	  break;
	  	  }
	i--;
	}
	}
	  	  return 0;

	}



Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jul 25 22:14:29 JST 2020
 **/

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

constexpr int N = 15;
int x[N], y[N];
Int p[N];
int min_dist[N], orig_dist[N];
signed main() {
    int n;
    std::cin >> n;
    REP(i, n) std::cin >> x[i] >> y[i] >> p[i];
    std::vector<int> x_ord(n), y_ord(n);
    std::iota(ALL(x_ord), 0), std::sort(ALL(x_ord), [&](int i, int j) { return x[i] < x[j]; });
    std::iota(ALL(y_ord), 0), std::sort(ALL(y_ord), [&](int i, int j) { return y[i] < y[j]; });
    REP(i, n) orig_dist[i] = std::min(std::abs(x[i]), std::abs(y[i]));
    std::vector<Int> ans(n + 1, 1e18);
    REP(S, 1 << n) {
        Int cnt = __builtin_popcount(S);
        // Sの部分集合の列挙
        for (int T = S;; T = (T - 1) & S) {
            // 操作
            REP(i, n) min_dist[i] = orig_dist[i];
            REP(_, 2) {
                int l = 1e9;
                for (int i : x_ord) {
                    if (T >> i & 1) l = x[i];
                    chmin(min_dist[i], std::abs(x[i] - l));
                }
                std::reverse(ALL(x_ord));
            }
            REP(_, 2) {
                int l = 1e9;
                for (int i : y_ord) {
                    if ((S ^ T) >> i & 1) l = y[i];
                    chmin(min_dist[i], std::abs(y[i] - l));
                }
                std::reverse(ALL(y_ord));
            }
            Int acc = 0;
            REP(i, n) acc += p[i] * min_dist[i];
            chmin(ans[cnt], acc);
            if (T == 0) break;
        }
    }
    for (Int z : ans) std::cout << z << "\n";
}


Measured memory_bytes: 3656
#include<stdio.h>

#define N 100

void BubbleSort(int *);

int n;
int count=0;


int main(){
  int A[N+1];
  int i,m;
  
  scanf("%d", &n);
  for( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  
  BubbleSort(A);
  
  printf("%d\n",count);
  return 0;
}

void BubbleSort(int A[]){
  int i,j,key,m;
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j]<A[j-1]){

	key=A[j];
	A[j]=A[j-1];
	A[j-1]=key;
	count++;
      }
    }
  }
  for ( m = 0; m <= n-1; m++ ){
    if ( m > 0 ) printf(" ");
    printf("%d", A[m]);
  }
  printf("\n");
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;

  set<ll> mi;
  rep(i, 26) mi.insert(i);

  ll n = s.size();
  string ans = "";
  rep(i, n) {
    ll idx = s[i] - 'a';
    if (mi.find(idx) != mi.end()) {
      mi.erase(idx);
      ans += s[i];
    } else {
      auto citr = mi.begin();
      ans += *citr + 'a';
      mi.erase(citr);
    }
  }  // i

  if (s == ans) {
    if (!mi.empty()) {
      rep(i, 26) {}
      ans += *mi.begin() + 'a';
    } else {
      vector<char> tst;
      rep(i, 26) tst.push_back(s[i]);
      next_permutation(tst.begin(), tst.end());
      string cmp = "";
      for (char c : tst) cmp += c;
      if (cmp < s) {
        puts("-1");
        return 0;
      } else {
        rep(i,26) if(ans[i] != cmp[i]){
          ans = cmp.substr(0, i+1);
          break;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int ans;
	for(int i = 1; i <= 5; ++i) {
		int x;
		cin >> x;
		if(x == 0) ans = i;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <map>
#include <utility>

using namespace std;


int main()
{
  int H,W,D,Q;
  cin >> H >> W >> D;
  vector <pair<int, int> > Aij(H*W+1);
  for( int i=0;i<H;i++ )
    for( int j=0;j<W;j++ )
      {
	int tmp;
	cin >> tmp;
	Aij[tmp] = make_pair(i+1,j+1);
      }
  cin >> Q;
  
  vector<int>cost(H*W+1, 0);
  for( int i=0;i<D;i++ )
    {
      int tmp=0;
      for( int j=i+1;j<H*W+1;j+=D)
	{
	  cost[j] = tmp;
	  if(j+D<W*H+1)
	    tmp += abs(Aij[j+D].first-Aij[j].first)+abs(Aij[j+D].second-Aij[j].second);
	}
    }



  for( int q=0;q<Q;q++ )
    {
      int ans = 0;    
      int L,R;
      cin >> L >> R;
      cout << cost[R]-cost[L] << endl;
    }
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cassert>
#include<utility>
#include<algorithm>
#include<complex>
 
using namespace std;
int ans;
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  for(int i=1;i<=n;i++){
    int c=i,t=0;
    while(c!=0){
      t+=c%10;
      c/=10;
    }
    if(t>=a && t<=b){ans+=i;}
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define	INF	0x3f3f3f3f
#define	LL	long long
#define	MAXN	10010
using namespace std;
int n, a[MAXN], b[MAXN], c[MAXN], g, p[MAXN], pri[MAXN], cnt;
vector <int> ans; 

template <typename T> void chkmin(T &x, T y){x = min(x, y);}
template <typename T> void chkmax(T &x, T y){x = max(x, y);}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

int gcd(int a, int b){
	if (a == 0 || b == 0) return a | b;
	return gcd(b, a % b);
}

void fj(int x){
	if (x < 2) return;
	int y = x;
	for (int i = 2; i * i <= y; ++i){
		if (x % i) continue;
		ans.push_back(i);
		while (x % i == 0) x /= i;
	}
	if (x != 1) ans.push_back(x);
}

void init(int n){
	for (int i = 2; i <= n; ++i){
		if (!p[i]) p[i] = i, pri[++cnt] = i;
		for (int j = 1; j <= cnt && pri[j] * i <= n && pri[j] <= p[i]; ++j)
			p[pri[j] * i] = pri[j];
	}
}

void work(int p){
	for (int i = 0; i < n; ++i){
		b[i] = a[i + 1] % p;
		if (b[i] < 0) b[i] += p;
	}
	for (int i = n - p; i >= 0; --i){
		c[i] = b[i + p - 1];
		b[i + p - 1] = 0;
		b[i] = (b[i] + c[i] >= p) ? (b[i] + c[i] - p) : (b[i] + c[i]);
	}
	for (int i = 0; i < n; ++i)
		if (b[i]) return;
	ans.push_back(p);
}

int main(){
	read(n);
	init(n);
	g = 0;
	for (int i = n; i >= 0; --i)
		read(a[i]), g = gcd(g, abs(a[i]));
	fj(g);
	for (int i = 1; i <= cnt; ++i)
		if (a[0] % pri[i] == 0) work(pri[i]);
	sort(ans.begin(), ans.end());
	for (unsigned i = 0, si = ans.size(); i < si; ++i)
		if (!i || ans[i] != ans[i - 1]) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 384
@case_num = 1
while true do
  w = gets.to_i
  break if w == 0
  n = gets.to_i
  table = n.times.map{ gets.split(',').map(&:to_i) }

  mw, mv = w, 0
  dp = Array.new(n+1){Array.new}
  dp[0][0] = 0
  table.each.with_index(1) do |p, i|
    (0..w).reject{ |wi| dp[i-1][wi].nil? }.each do |wi|
      va = dp[i][wi] = [dp[i][wi]||0, dp[i-1][wi]].max
      mw, mv = wi, va if va > mv || (va==mv && wi < mw)
      if wi + p[1] <= w
        va = dp[i][wi+p[1]] = [dp[i][wi+p[1]]||0, dp[i-1][wi] + p[0]].max
        mw, mv = wi + p[1], va if va > mv || (va==mv && (wi + p[1])< mw)
      end
    end
  end
  puts "Case #{@case_num}:", mv, mw
  @case_num += 1
end

Measured memory_bytes: 16664