akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int A[500001],n;

void   maxHeapify(int k)
{
  int l,r,largest,x,y;
  l=2*k;
  r=2*k+1;
  if(l<=n&&A[l]>A[k]) largest=l;
  else largest=k;
  if((r<=n)&&(A[r]>A[largest])) largest=r;

  if(largest!=k)
    {
      x=A[k];
      y=A[largest];
      A[k]=y;
      A[largest]=x;
      maxHeapify(largest);
    }
}

void buildMaxHeap(void)
{
  int i;
  for(i=n/2;i>=1;i--)
    {
      maxHeapify(i);
    }
}


int main()
{
  int i,k=0;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
    }

  buildMaxHeap();

  for(i=1;i<=n;i++)
    {
      printf(" %d",A[i]);
    }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2552
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
//typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	vector<pair<int,int> > A;
	REP(i, N) {
		int a, b;
		cin >> a >> b;
		A.push_back(make_pair(b,a));
	}
	SORT(A);
	int cnt = 0, tmp=0;
	REP(i, N) {
		/*if (A[i].first - A[i].second < tmp) {
			cout << "No" << endl;
			return 0;
		}*/
		cnt += A[i].second;
		tmp = A[i].first - cnt;
		//cout << tmp << endl;
		if (tmp < 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



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

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

    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (0 <= x-r && x+r <= W && 0 <= y-r && y+r <= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3224
url = "https://atcoder.jp/contests/abc092/tasks/abc092_b"

def main():
    a = int(input())
    n, m = list(map(int, input().split()))
    choko = m
    for i in range(a):
        tmp = int(input())
        if tmp == 1:
            choko += tmp * n
        else:
            choko += (n - 1) // tmp + 1
    print(choko)


if __name__ == '__main__':
    main()




Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
template <typename T> bool chmin(T &x, const T &y) {if (x < y) {x = y; return true;} return false;}
template <typename T> bool chmax(T &x, const T &y) {if (x > y) {x = y; return true;} return false;}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    map<int, int> cnt;
    rep(i, N) ++cnt[A[i]];
    vector<int> S;
    for (auto p : cnt) S.push_back(p.second);
    sort(ALL(S));
    int ans = 0;
    rep(i, max(SZ(S) - K, 0)) {
        ans += S[i];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 14356
# encoding: utf-8
import math, sys

N = int(input())

# regular connected graph ... ?

k = 1
while True:
    if k * (k + 1) // 2 == N:
        break
    elif k * (k + 1) // 2 > N:
        print("No")
        sys.exit()
    else:
        k += 1

print("Yes")
mat = [[None] * (k + 1) for i in range(k + 1)]
idx = 1
for i in range(k + 1):
    for j in range(k + 1):
        # self-connection
        if i == j: continue
        # numbering
        if mat[i][j] == None:
            mat[i][j] = idx
            mat[j][i] = idx
            idx += 1

print(k + 1)
for i in range(k + 1):
    print(k, end="")
    for val in mat[i]:
        if val != None:
            print(" ", end="")
            print(val, end="")
    print("")

Measured memory_bytes: 9516
#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<ll>

#define sz(x) ((int) (x).size())
#define pll pair<long long,long long>
#define mp make_pair
#define F first
#define S second
#define T int tt; cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);

#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define display(x) for(auto i : x) cout << i << " "; cout << '\n';
#define input(x) for(int i = 0; i < n; i++) cin >> x[i];
#define make(x,y) fill(all(x), y)
#define FO(i,startLoop,n) for (int i = startLoop; i < n; i++)

#define mod 1000000007
#define Y cout<<"YES"<<endl;
#define N cout<<"NO"<<endl;
#define ITFO(myiterator, mymap) for(auto myiterator = mymap.begin(); myiterator!=mymap.end(); ++myiterator)
using namespace std;


int main()
{
  fastio
  cin.tie(NULL); cout.tie(0);



  ll n, wei; cin >> n >> wei;
  vi w(1, 0), val(1, 0);

  ll max_val = 0;
  FO(i, 0, n)
  {
    int x, y; cin >> x >> y;
    w.pb(x), val.pb(y);
    max_val += y;
  }
  // cout << max_val;
  vector<vector<ll>>dp(n + 1, vector<ll>( max_val  + 1, INT_MAX));
  for (int i = 0; i <= n; i++)
    dp[i][0] = 0;
  FO(i, 1, n + 1)
  {
    FO(j, 1, max_val + 1)
    {
      if (j - val[i] >= 0)
        dp[i][j] = min(dp[i - 1][j - val[i]] + w[i], dp[i - 1][j]);
      else
        dp[i][j] = dp[i - 1][j];

      // cout << dp[i][j] << " ";
    }
    // cout << endl;
  }
  ll ans = 0;
  FO(i, 1, n + 1)
  {
    FO(j, 1, max_val + 1)
    {
      if (dp[i][j] <= wei)
        ans = max(ans, 1LL * j);
    }
  }
  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 80256
import string
import sys


def check_exists(word_set, rotate_dict, search):
    for word in word_set:
        rotated_word = ''.join(rotate_dict[s] for s in word)
        if rotated_word == search:
            return True
    return False


for line in sys.stdin:
    alphabets = string.ascii_lowercase
    frequency = [t[1] for t in sorted([(line.count(s), ord(s)) for s in alphabets], reverse=True)]
    freq_chr_offset = (4, 0, 19, 8, 14)
    ss = list(map(lambda word: word.strip('.\n'), line.split()))
    sl3, sl4 = set(s for s in ss if len(s) == 3), set(s for s in ss if len(s) == 4)

    i, rotate_dict = 0, None
    for order in frequency:
        for offset in freq_chr_offset:
            i = 97 + offset - order
            rotate_dict = {a: b for a, b in zip(alphabets, alphabets[i:] + alphabets[:i])}
            if (check_exists(sl3, rotate_dict, 'the')
                    + check_exists(sl4, rotate_dict, 'this')
                    + check_exists(sl4, rotate_dict, 'that')) > 0:
                break
        else:
            continue
        break

    print(''.join(rotate_dict[s] if s.isalpha() else s for s in line), end='')

Measured memory_bytes: 8020
# N
# S1
# SN
# 書かれた文字列が多いものを出力
# 全部違うときは全部出力

N = gets.to_i
hash = Hash.new(0)
cnt = 0

N.times do
  s = gets.chomp
  hash[s] += 1
  if hash[s] > cnt
    cnt = hash[s]
  end
end

puts hash.select{|key,value| value==cnt}.keys.sort


  

Measured memory_bytes: 46952
import math
def possible(l, a, k):
    for x in a:
        k -= x//l
        if x%l==0:
            k += 1
    return k>=0

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mini = 1
maxi = 10**9+7
while(mini!=maxi):
    mid = (mini+maxi)//2
    if possible(mid, a, k):
        maxi = mid
    else:
        mini = mid + 1
print(mini)


Measured memory_bytes: 31108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int X, A;
    cin >> X >> A;
    if (X < A)
        cout << 0 << endl;
    else
        cout << 10 << endl;

    // system("pause");
}

Measured memory_bytes: 256
def abc_148_d
    n = gets.chomp.to_i
    an = gets.chomp.split(/\s/).map{|x| x.to_i}

    cnt = 0
    no = 1
    for i in 1..n
        if an[i-1] == no
            no += 1
        else
            cnt += 1
        end
    end

    cnt = -1 if cnt == n
    puts cnt
end

abc_148_d

Measured memory_bytes: 16772
def seachPrimeNum(N):
    max = int(N**.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

P=seachPrimeNum(5*10**5)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)
    return arr

factorization(24) 

n=int(input())
A=[int(i) for i in input().split()]
DIC={i:0 for i in range(1,10**6+1)}
for ele in A:
    DIC[ele]+=1
pair=True
setw=True
if n!=len(A):
    pair=False

for pri in P:
    cnt=0
    for i in range(pri,10**6+1,pri):
        cnt+=DIC[i]
    if cnt>1:
        pair=False
    if cnt==len(A):
        setw=False

if pair:
    print("pairwise coprime")
elif setw:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 265628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	ll n; cin >> n ;
	vector<ll> a(n+1);	rep(i,n+1) cin >> a[i];
	vector<ll> b(n);	rep(i,n) cin >> b[i];
	ll ans = 0;
	rep(i,n){
		//b[i]に関して
		ll kill;
		kill = min(a[i],b[i]);
		ans += kill;
		a[i] -= kill;
		b[i] -= kill;
		
		kill = min(a[i+1],b[i]);
		ans += kill;
		a[i+1] -= kill;
		b[i] -= kill;	
	}
	out(ans);
}




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

int main(){
    int n; cin >> n;
    if(n >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 3620
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
  int a,b;
  cin >> a >> b;
    //処理
    //出力
    cout << (a-1)*(b-1) << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, val;
    cin >> n;
    vector<int> arr(n, 0);
    unordered_map<int, ll> cnt;
    for(int& val: arr) {
        cin >> val;
        cnt[val] += 1;
    }
    ll total = 0;
    for(auto p: cnt)
        total += p.second * (p.second-1) / 2;
    for(int i = 0; i < arr.size(); i++) {
        ll num = cnt[arr[i]];
        ll res = total - num*(num-1)/2;
        num -= 1;
        res += num*(num-1)/2;
        cout << res << endl;
    }
    return 0;
}




Measured memory_bytes: 8392
#include<bits/stdc++.h>
//#define int long long int
using namespace std;
typedef long long int ll;
ll prime[10000002];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T;
	cin >> T;
	for(int i = 1; i<=T;i++)
	{
		for(int j = i; j<=T;j+=i)
		{
			prime[j]++;
		}
	}
	ll ans = 0;
	for(ll i = 1; i<=T;i++)
	{
		ans += i*prime[i];
	}
	cout <<ans<<endl;
}


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

int main() {
    
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    int cnt = 0;
    rep(i, n-1){
        if(s[i] == s[i+1])  cnt++;
    }
    
    int ans = min(n-1, cnt+k*2);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
<?php
 
while(true) {
    $inputs = explode(' ', trim(fgets(STDIN)));
 
    if (!is_array($inputs) || count($inputs) < 2) {
        exit;
    }
 
    $a = $inputs[0];
    $b = $inputs[1];
 
    $d = numDigits($a + $b);
 
    echo $d . "\n";
}
 
function numDigits($n) {
    return (int)(log10($n) + 1);
}

Measured memory_bytes: 15216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int main(){
	
	int N, M;
	
	cin >> N >> M;
	
	string map[100];
	
	int cost[100][3];
	int DP[100][3];
	
	for(int i = 0; i < 100; i++){
		for(int k = 0; k < 3; k++){
			cost[i][k] = 0;
			DP[i][k] = (1 << 29);
		}
	}
	
	DP[0][0] = 0;
	
	for(int i = 0; i < N; i++){
		cin >> map[i];
		for(int j = 0; j < M; j++){
			if(map[i][j] == 'W'){
				cost[i][1]++;
				cost[i][2]++;
			}
			if(map[i][j] == 'B'){
				cost[i][0]++;
				cost[i][2]++;
			}
			if(map[i][j] == 'R'){
				cost[i][0]++;
				cost[i][1]++;
			}
		}
		DP[i + 1][0] = DP[i][0] + cost[i][0];
	}
	
	for(int i = 1; i <= 2; i++){
		for(int j = 2; j <= N; j++){
			DP[j][i] = min(DP[j - 1][i], DP[j - 1][i - 1]) + cost[j - 1][i];
		}
	}
	
	cout << DP[N][2] << endl;
	
	return 0;
}

Measured memory_bytes: 3180
# include <iostream>
# include <vector>
# include <cstdio>
# include <queue>
using namespace std;
struct info
{
	int d = -1;
	bool vis = false;
};
vector<int> a[105];
info *ans;
queue<int> solve;
void bfs()
{
	solve.push(1); 
	ans[1].vis = true; ans[1].d = 0;
	while(!solve.empty())
	{
		int u = solve.front(); solve.pop();
		for(int j = 0;j < a[u].size();j++)
		{
			if(!ans[a[u][j]].vis)
			{
				ans[a[u][j]].vis = true;
				ans[a[u][j]].d = ans[u].d + 1;
				solve.push(a[u][j]);
			}
		}
	}
	
}
int main(void)
{
	int n,cnt,k,u;
	scanf("%d",&n);
	ans = new info [n+1];
	for(int w = 0;w < n;w++)
	{
		scanf("%d %d",&u,&cnt);
		for(int i = 0;i < cnt;i++)
		{
			scanf("%d",&k);
			a[u].push_back(k);
		}
	}
	bfs();
	for(int i = 1;i <= n;i++) printf("%d %d\n",i,ans[i].d);
	return 0;
}


Measured memory_bytes: 3244
N= int(input())
P = []
for i in range(N):
    a, *b = (int(b) for b in input().split())
    b= b[0] if b else None
    if a == 0:
        P.append(b)
    elif a == 1:
        print(P[b])
    else:
        del P[-1]
    


Measured memory_bytes: 13380
#!/usr/bin/env python3
from itertools import accumulate
def erat(m):
    p = [1] * m
    p[0] = p[1] = 0
    for x in range(2, int((~-m)**.5) + 1):
        if p[x]:
            for y in range(x*x, m, x):
                p[y] = 0
    return p

INF = 10**5 + 1
p = erat(INF)
q = [0] * INF
for n in range(INF):
    q[n] = n%2 * p[n] * p[-~n//2]
*a, = accumulate([0] + q)
for _ in [None] * int(input()):
    l, r = map(int, input().split())
    print(a[r + 1] - a[l])

Measured memory_bytes: 8724
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  FOR(i,0,N) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = 2e9;
  FOR(i,0,N) {
    int j = i + K - 1;
    if(j >= N) break;
    ans = min(ans, h[j] - h[i]);
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;
int n, a, b, c;
int ARR[10];

int dfs(int curr, int A, int B, int C){
    if(curr == n){
        if(min({A,B,C}) <= 0) return (1 << 30);
        return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    }
    int r1 = dfs(curr+1, A, B, C);
    int r2 = dfs(curr+1, A+ARR[curr], B, C) + 10;
    int r3 = dfs(curr+1, A, B+ARR[curr], C) + 10;
    int r4 = dfs(curr+1, A, B, C+ARR[curr]) + 10;
    return min({r1,r2,r3,r4});
}

void solve(){
    scanf("%d%d%d%d", &n, &a, &b, &c);
    for(int i = 0; i < n; i++)
        scanf("%d", &ARR[i]);
    printf("%d\n", dfs(0,0,0,0));
}

int main(){
    int test_cases_number = 1;
//    scanf("%d", &test_cases_number);
//    ios_base::sync_with_stdio(0);
//    cin.tie(0); cout.tie(0);
//    cin >> test_cases_number;
    for(int i = 0; i < test_cases_number; i++)
        solve();
}


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

int main() 
{
	int h, w;
	cin >> h >> w;
	string str[h + 1];
	for (int i = 1; i <= h; i++) {cin >> str[i]; str[i] = "#" + str[i];}
	
	int xparent[h + 1][w + 1] = {}, xans[h + 1][w + 1] = {};
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			int temp = j, tans = 1;
			while(j <= w && str[i][j] == '.') 
			{
				xparent[i][j] = temp;
				xans[i][temp] = tans;
				j++; tans++;
			}
		}
	}
	
	int yparent[h + 1][w + 1] = {}, yans[h + 1][w + 1] = {};
	for (int i = 1; i <= w; i++)
	{
		for (int j = 1; j <= h; j++)
		{
			int temp = j, tans = 1;
			while(j <= h && str[j][i] == '.') 
			{
				yparent[j][i] = temp;
				yans[temp][i] = tans;
				j++; tans++;
			}
		}
	}
	
	int fun = 0;
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			if (str[i][j] == '.') fun = max(fun, xans[i][xparent[i][j]] + yans[yparent[i][j]][j] - 1);
	cout << fun;
}

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

int main()
{
	auto& in = cin;
	string str;
	in >> str;
	if (str.back() == 's') {
		str += "es";
	}
	else {
		str += "s";
	}
	cout << str;

	return 0;
}


Measured memory_bytes: 3624
SA,SB,SC = 3.times.map{gets.chomp.chars}

first = SA.shift

loop do 
    if first == 'a' && SA.empty?
        puts 'A'
        break
    elsif first == 'b' && SB.empty?
        puts 'B'
        break
    elsif first == 'c' && SC.empty?
        puts 'C'
        break
    end

    if first == 'a'
        first = SA.shift
    elsif first == 'b'
        first = SB.shift
    elsif first == 'c'
        first = SC.shift
    end
end




Measured memory_bytes: 1788
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  A=LI()

  ans=0
  st=A[0]
  for x in A[1:]:
    if st>x:
      ans+=st-x
    else:
      st=x

  return ans

# main()
print(main())


Measured memory_bytes: 33188
#include <stdio.h>
#include <string.h>
int main() {
  int D;
  scanf("%d",&D);
  if (D == 25) {
    printf("Christmas\n");
  } else if (D == 24) {
    printf("Christmas Eve\n");
  } else if (D == 23) {
    printf("Christmas Eve Eve\n");
  } else if (D == 22) {
    printf("Christmas Eve Eve Eve\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		List<Integer> list = new LinkedList<Integer>();
		System.out.print(n+":");

		for (int i=2; i*i<=n; i++) {
			while (n%i == 0) {
				n /= i;
				list.add(i);
			}
		}

		if (n > 1)
			list.add(n);

		for (int i : list) {
			System.out.print(" "+i);
		}
		System.out.println();

		br.close();
	}
}

Measured memory_bytes: 17008
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	void doIt() {
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		System.out.println(p + q + r - max3(p, q, r));
	}
	
	int max3(int a, int b, int c) {
		int max = ((a < b) ? b : a);
		return (max < c)? c : max;
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 22740
#include <stdio.h>

int func(long num, int max, int passed);
int check(int num);

int main(){
	int n;
	scanf("%d",&n);
	
	printf("%d",func(0,n,0));
	return 0;
}

int func(long num, int max, int passed){

	int cnt = 0;
	if(passed == 0){
		passed = check(num);
	}
	
	if(passed == 1){
		cnt++;
	}
	
	if(num*10+3 <= max){
		cnt += func(num*10+3,max,passed);
	}
	if(num*10+5 <= max){
		cnt += func(num*10+5,max,passed);
	}
	if(num*10+7 <= max){
		cnt += func(num*10+7,max,passed);
	}

	return cnt;

}

int check(int num){
	int sw3=0;
	int sw5=0;
	int sw7=0;
	int tmp=num;
	while(tmp != 0){
		switch(tmp%10){
			case 3:
				sw3=1;
				break;
			case 5:
				sw5=1;
				break;
			case 7:
				sw7=1;
				break;
		}
		tmp=tmp/10;
	}

	if(sw3==1 && sw5==1 && sw7==1){
		return 1;
	}else{
		return 0;
	}
}

Measured memory_bytes: 128
#include <iostream>


using namespace std;

int main(){
        int n, m;
        cin >> n >> m ;
        while(m--){
          int t;
          cin >> t;
          n -= t;
        }
        if(n < 0){
                cout << "-1" << endl;
        }else{
                cout << n << endl;
        }
        return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

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

	int x = scan.nextInt();
	int a = scan.nextInt();
	int b = scan.nextInt();

	if(b <= a){
	    System.out.println("delicious");
	}else if(b <= x+a){
	    System.out.println("safe");
	}else{
	    System.out.println("dangerous");
	}
    }
}


Measured memory_bytes: 23636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N (1<<20)
//n<=65536
long long a[2 * N];
bool b[2 * N];
long long k, n;
long long zzz;

//初期化
void init(void){
	f(i, 2 * N)a[i] = 0;
	f(i, 2 * N)b[i] = true;
	return;
}

//一斉挿入
void all_insert(void){
	long long x;
	zzz = 0;
	f(i, n){
		scanf("%lld", &x);
		x = -x;
		if (x > 0){
			a[N+i] = x%k;
			b[N+i] = true;
		}
		else if (x < 0){
			x = -x;
			x = x%k;
			x = (k - x) % k;
			a[N+i] = x;
			b[N+i] = true;
		}
		else {
			a[N+i] = 0;
			b[N+i] = false;
			zzz++;
		}
	}
	f(i, N){
		if (b[2 * (N - i - 1)] && b[2 * (N - i - 1) + 1]){
			a[N - i - 1] = a[2 * (N - i - 1)] + a[2 * (N - i - 1) + 1];
			b[N - i - 1] = true;
		}
		else if (!b[2 * (N - i - 1)] && b[2 * (N - i - 1) + 1]){
			a[N - i - 1] = a[2 * (N - i - 1)] + a[2 * (N - i - 1) + 1];
			b[N - i - 1] = false;
		}
		else if (b[2 * (N - i - 1)] && !b[2 * (N - i - 1) + 1]){
			a[N - i - 1] = a[2 * (N - i - 1) + 1] - a[2 * (N - i - 1)];
			b[N - i - 1] = false;
		}
		else{
			a[N - i - 1] = a[2 * (N - i - 1) + 1] - a[2 * (N - i - 1)];
			b[N - i - 1] = true;
		}

	}
	return;
}

//変更(k=1-n)
void change(long long k,long long x ,long long z){
	k += N;
	a[k] = x;
	b[k] = z;
	while (k > 1){
		k = k / 2;
		if (b[2 * k] && b[(2 * k) + 1]){
			a[k] = a[2 * k] + a[(2 * k) + 1];
			b[k] = true;
		}
		else 		if (!b[2 * k] && b[(2 * k) + 1]){
			a[k] = a[2 * k] + a[(2 * k) + 1];
			b[k] = false;
		}
		else 		if (b[2 * k] && !b[(2 * k) + 1]){
			a[k] = a[(2 * k) + 1] - a[2 * k];
			b[k] = false;
		}
		else {
			a[k] = a[(2 * k) + 1] - a[2 * k];
			b[k] = true;
		}
		
	}
	return;
}



int main(void){
	long long q;
	long long c, x, y;
	long long aa1, aa2;
	bool bb1, bb2;
	init();
	scanf("%lld %lld %lld",&k,&n, &q);
	all_insert();    //一斉挿入

	f(qq, q){
			scanf("%lld %lld", &x, &y);
			x--;
			y--;
			aa1 = a[N + x];
			aa2 = a[N + y];
			bb1 = b[N + x];
			bb2 = b[N + y];
			change(x, aa2, bb2);
			change(y, aa1, bb1);
			if (b[1]){
				c = a[1] + 1;
			}
			else{

				c = a[1] - 1;
			}
			if(c>=0)c = c%k;
			else{
				c = -c;
				c = c%k;
				c = (k - c) % k;
			}
			if (zzz % 2 == 0){
				if (c == 0)c = k;
			}
			else{
				c -= k;
				if (c == 0)c = -k;
			}

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

	return 0;
}


Measured memory_bytes: 21180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    while(y > 0) {
        int tmp = x % y;
        x = y;
        y = tmp;
    }
    return x;
}

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];

    int x[n], y[n];
    x[0] = a[0];
    y[n - 1] = a[n - 1];
    rep(i, 1, n) x[i] = gcd(x[i - 1], a[i]);
    for (int i = n - 2; i >= 0; i--) y[i] = gcd(y[i + 1], a[i]);
    int ans = 0;
    rep(i, 0, n) {
        int g;
        if (i == 0) g = y[1];
        else if (i == n - 1) g = x[n - 2] ;
        else g = gcd(x[i - 1], y[i + 1]);
        ans = max(ans, g);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long[] arr = new long[n];
      for(int i = 0; i < n; i++)
        arr[i] = sc.nextInt();

      long sum = arr[0];
      for(int i = 1; i < n-1; i++) {
        if(i % 2 == 1)
          sum = sum - arr[i];
        else
          sum = sum + arr[i];
      }

      long[] res = new long[n];
      res[0] = sum + arr[n - 1];
      res[n-1] = arr[n-1] * 2 - res[0];
      for(int i = 1; i < n - 1; i++)
        res[i] = arr[i-1] * 2 - res[i-1];
      for(int i = 0; i < n; i++)
        System.out.print(res[i] + " ");
      System.out.println();
  }
}

Measured memory_bytes: 65556
#解説AC

n = int(input())

def dfs(s, mx):
    if len(s) == n:
        print(s)
    else:
        for i in range(ord('a'), ord(mx)+1):

            dfs(s + chr(i), chr(ord(mx) + 1) if i == ord(mx) else mx)
dfs('', 'a')

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
ll C, H[200020];
ll dp[200020];


ll f(int i, int j){
    return dp[j] + H[j] * H[j] - 2 * H[i]* H[j];
}

bool check(int j1, int j2, int j3){
    ll a1 = - 2 * H[j1]; ll b1 = dp[j1] + H[j1] * H[j1];
    ll a2 = - 2 * H[j2]; ll b2 = dp[j2] + H[j2] * H[j2];
    ll a3 = - 2 * H[j3]; ll b3 = dp[j3] + H[j3] * H[j3];
    return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2);
}


int main(){

    cin >> N >> C;
    for(int i = 0; i < N; i++) cin >> H[i];
    deque<int> dq; dq.push_back(0);
    for(int i = 1; i < N; i++){
        // 末尾から２番目が最小値とならなければ削除
        while(dq.size() > 2){
            int j1 = dq[(int)dq.size() - 3];
            int j2 = dq[(int)dq.size() - 2];
            int j3 = dq[(int)dq.size() - 1];
            if(check(j1, j2, j3)){
                const int tmp = dq.back();
                dq.pop_back();
                dq.pop_back();
                dq.push_back(tmp);
            }
            else{
                break;
            }
        }

        // dequeの先頭要素が最小でない場合は取り除く
        while(dq.size() > 1) {
           int a = dq[0];
            int b = dq[1];
            if(f(i, a) >= f(i, b)){
                dq.pop_front();
            }
            else{
                break;
            }
        }
        // 先頭要素が最小値
        dp[i] = f(i, dq[0]) + C + H[i] * H[i];

        dq.push_back(i);
    }
    
    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 3968
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int n, m;
ll dp[1001][1001];
char a[1001][1001];

ll memo(int x, int y) {
	if(x < 0 || y < 0) return 0;
	if(a[x][y] == '#') return 0;
	if(x == 0 && y == 0) return 1;
	if(dp[x][y] != -1) return dp[x][y];
	return dp[x][y] = add(memo(x-1, y), memo(x, y-1));
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> a[i][j];
	memset(dp, -1, sizeof dp);
	cout << memo(n-1, m-1) << endl;
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Io.Read();

            var output = "";
            foreach (var c in s)
            {
                if (c == 'B')
                {
                    if (output.Length != 0)
                    {
                        output = output.Substring(0, output.Length - 1);
                    }
                }
                else
                {
                    output += c;
                }
            }

            Console.WriteLine(output);
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }

        class Io
        {
            public static string Read()
            {
                return Console.ReadLine();
            }

            public static IEnumerable<string> ReadRepeat(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read());
            }

            public static T Read<T>()
            {
                return (T)Convert.ChangeType(Read(), typeof(T));
            }

            public static IEnumerable<T> ReadRepeat<T>(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read<T>());
            }

            public static string[] ReadList(char devide = ' ')
            {
                return Read().Split(devide);
            }

            public static T[] ReadList<T>(char devide = ' ')
            {
                return ReadList(devide)
                    .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                    .ToArray();
            }

            public static IEnumerable<T[]> ReadListRepeat<T>(int count, char devide = ' ')
            {
                return Enumerable.Range(0, count).Select(_ => ReadList<T>(devide));
            }

            public static void Write(string value)
            {
                Console.WriteLine(value);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

#define L in[0]-'A'
#define R in[2]-'A'

int main(void) {
	int pos[3],temp;
	char in[10];
	pos[0]=1;pos[1]=0;pos[2]=0;
	while(1) {
		if(fgets(in,sizeof(in),stdin)==NULL)break;
		temp=pos[L];
		pos[L]=pos[R];
		pos[R]=temp;
	}
	if(pos[0])printf("A\n");
	else if(pos[1])printf("B\n");
	else if(pos[2])printf("C\n");
	return 0;
}

Measured memory_bytes: 0
<?php
$input=explode(' ',trim(fgets(STDIN))); // // 1 2 3 ……
//print_r($input);

$count=0;
for ($i = $input[0]; $i <= $input[1]; $i++) {
    if ($i==strrev($i)) {
        $count++;
    }
}
echo($count);
?>

Measured memory_bytes: 3828
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    string X;
    cin >> N >> X;

    constexpr ll MOD = 998244353;

    string S = X;
    for (char x : X) {
        S += (x == '0' ? '1' : '0');
    }

    //Sはb ~b b ~b ... b ~b みたいな列（の操作途中の列）であれば2 * |b|でループする
    //つまりループの周期をtとしたとき、tは偶数
    //当然tは2 * Nの約数である必要もあり、またXがb ~b bという形になるため2 * N / tは奇数でないといけない

    ll ans = 0;
    map<ll, ll> num;
    //周期としてあり得るものが列挙できた
    for (ll t = 1; t <= 2 * N; t++) {
        if (2 * N % t != 0 || t % 2 == 1 || (2 * N / t) % 2 == 0) {
            continue;
        }

        //周期の半分bitを考える
        //Sの先頭t / 2 bitと比較して小さいものだけ数える
        ll small = 0;
        for (ll i = 0; i < t / 2; i++) {
            (small = 2 * small + (S[i] == '1')) %= MOD;
        }

        ll n = small;

        //equalだけ愚直に構築して調べる
        string sub = S.substr(0, t / 2);
        string sub_rev = sub;
        for (char& c : sub_rev) {
            c = (c == '0' ? '1' : '0');
        }
        string str;
        for (ll i = 0; i < 2 * N / (t / 2); i++) {
            str += (i % 2 == 0 ? sub : sub_rev);
        }
        if (str <= S) {
            n++;
        }

        //包除
        for (ll i = 2; i * i <= t; i++) {
            if (t % i == 0) {
                if (t / i % 2 == 1) {
                    (n += MOD - num[i]) %= MOD;
                }

                if (i * i != t && i % 2 == 1) {
                    (n += MOD - num[t / i]) %= MOD;
                }
            }
        }

        num[t] = n;
        (ans += n * t) %= MOD;
    }

    cout << ans << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ans=0;
	cin >> n;
	VI a(n);
	rep(i,n) cin>>a[i];
	
	double w = accumulate(all(a), 0.0);
	double p= w/n;
	
	double mn = 1e100;
	ans =0;
	rep(i,n){
		if(abs(a[i] - p) < mn){
			ans =i; mn =abs(a[i] - p);
		}
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n+5];
	int sum=0;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			sum+=a[i]*a[j];
		}
	}
	cout << sum;
	return 0;
}

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

int main(){
  int n,x,y;
  cin >> n >> x >> y;
  vector<int> a(n,0);
  for(int i=1;i<n;i++){
    for(int j=i+1;j<n+1;j++){
      int to_x=abs(x-i);
      int to_y=abs(y-j);
      a[min(to_x+to_y+1,j-i)]++;
    }
  }
  for(int i=1;i<n;i++){
    cout << a[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    black = defaultdict(int)
    white = defaultdict(int)
    for _ in range(N):
        x, y, c = input().split()
        x = int(x)
        y = int(y)
        if c == 'B':
            x_, y_ = x % (2*K), y % (2*K)
            if x_ < K and y_ < K:
                black[x_ * K + y_] += 1
            elif x_ >= K and y_ < K:
                white[(x_ - K) *K +y_] += 1
            elif x_ < K and y_ >= K:
                white[x_ * K + y_ - K] += 1
            else:
                black[(x_ - K)*K + y_ - K] += 1
        else:
            x_, y_ = x % (2 * K), y % (2 * K)
            if x_ < K and y_ < K:
                white[x_*K + y_] += 1
            elif x_ >= K and y_ < K:
                black[(x_ - K)*K + y_] += 1
            elif x_ < K and y_ >= K:
                black[x_*K+ y_ - K] += 1
            else:
                white[(x_ - K)*K + y_ - K] += 1

    cs_b = [[0] * (K+1) for _ in range(K+1)]
    cs_w = [[0] * (K+1) for _ in range(K+1)]
    for i in range(K):
        for j in range(K):
            cs_b[i+1][j+1] = cs_b[i+1][j] + cs_b[i][j+1] - cs_b[i][j] + black[i*K+j]
            cs_w[i + 1][j + 1] = cs_w[i + 1][j] + cs_w[i][j + 1] - cs_w[i][j] + white[i*K+j]

    ans = 0
    for i in range(K):
        for j in range(K):
            ans_b = cs_b[i][j] + cs_b[-1][-1] - cs_b[-1][j] - cs_b[i][-1] + cs_b[i][j]
            ans_w = cs_w[i][-1] - cs_w[i][j] + cs_w[-1][j] - cs_w[i][j]
            ans_w2 = cs_w[i][j] + cs_w[-1][-1] - cs_w[-1][j] - cs_w[i][-1] + cs_w[i][j]
            ans_b2 = cs_b[i][-1] - cs_b[i][j] + cs_b[-1][j] - cs_b[i][j]
            ans = max(ans, ans_b + ans_w, ans_b2 + ans_w2)

    print(ans)
    '''
    print(cs_b)
    print(cs_w)
    print(black)
    print(white)
    '''


if __name__ == '__main__':
    main()


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

int main(){
  int n,q,si,ti,c=0;
  int S[100005],T[50005];
  
  cin >> n;
  for (si=0;si<n;si++)cin >> S[si];

  cin >> q;
  for (ti=0;ti<q;ti++)cin >> T[ti];

  for (ti=0;ti<q;ti++){
    S[n]=T[ti];
    si=0;
    while (S[si]!=T[ti])si++;
    if (si<n)c++;
  }

  cout << c << endl;
  
  return 0;
}

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

int main(int argc, char const *argv[])
{
	ll n, a, b; cin >> n >> a >> b;
	cout << n / (a + b) * a + min(a, n % (a + b)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll INF = (1LL << 31) - 1;
const ll sqrtN = 512;
struct SqrtDecomposition {
  ll N, K;
  vector<ll> data;
  vector<ll> bucketMin;
  vector<ll> lazyUpdate;
  SqrtDecomposition(ll n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketMin.assign(K, INF);
    lazyUpdate.assign(K, 0);
  }
  void eval(ll k) {
    if (lazyUpdate[k]) {
      for (ll i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
        data[i] += lazyUpdate[k];
      }
      lazyUpdate[k] = 0;
    }
  }
  // [s, t)
  void update(ll s, ll t, ll x) {
    for (ll k = 0; k < K; ++k) {
      ll l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        bucketMin[k] += x;
        lazyUpdate[k] += x;
      } else {
        eval(k);
        for (ll i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
        }
        ll &minVal = bucketMin[k] = INF;
        for (ll i = l; i < r; ++i) {
          minVal = min(minVal, data[i]);
        }
      }
    }
  }
  // [s, t)
  int find(ll s, ll t) {
    ll minVal = INF;
    for (ll k = 0; k < K; ++k) {
      ll l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        minVal = min(minVal, bucketMin[k]);
      } else {
        eval(k);
        for (ll i = max(s, l); i < min(t, r); ++i) {
          minVal = min(minVal, data[i]);
        }
      }
    }
    return minVal;
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, q;
  cin >> n >> q;
  SqrtDecomposition sd(n);
  FOR(i,0,q) {
    ll f;
    cin >> f;
    if(f) {
      ll s,t;
      cin >> s >> t;
      cout << sd.find(s, t+1) << endl;
    } else {
      ll s,t,x;
      cin >> s >> t >> x;
      sd.update(s,t+1,x);
    }
  }
}


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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int gcd(int a,int b);

int main(void)
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int max,min,o;
  max = MAX(MAX(a,b),c);
  min = MIN(MIN(a,b),c);
  o = a+b+c-max-min;
  printf("%d",max-min);
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
map=[]
3.times {map.push(gets.split.map(&:to_i))}
flag=[[false,false,false],[false,false,false],[false,false,false]]

n=gets.to_i
n.times do
    g=gets.to_i
    3.times do |i|
        3.times do |j|
            flag[i][j] = true if map[i][j]==g
        end
    end
end

correct=false
3.times do |i|
    f=true
    3.times do |j|
        f=false if flag[i][j]==false
    end
    correct = true if f==true
end

3.times do |i|
    f=true
    3.times do |j|
        f=false if flag[j][i]==false
    end
    correct = true if f==true
end

if flag[0][0]==flag[1][1] and flag[1][1]==flag[2][2] and flag[2][2]==true
    correct = true
elsif flag[0][2]==flag[1][1] and flag[1][1]==flag[2][0] and flag[2][0]==true
    correct = true
end

puts correct ? "Yes" : "No"

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
//    freopen("in.in", "r", stdin);
//    freopen("out.out", "w", stdout);
}

const int N = 1e5 + 9, M = 2e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int ok[N];

int main(){
    init();

    int n, m;   cin >> n >> m;
    int a[n + 1];
    for(int i = 1;i <= n;i++)    cin >> a[i], ok[i] = 1;


    for(int i = 0;i < m;i++){
        int u, v;   cin >> u >> v;
        if(a[u] <= a[v])   ok[u] = 0;
        if(a[v] <= a[u])   ok[v] = 0;
    }

    int ans = 0;
    for(int i = 1;i <= n;i++){
        ans += ok[i];
    }
    cout << ans;
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    FOR(i, 0, 26) {
        bool is = false;
        each(c, s)is |= c == char('a' + i);
        if (is)continue;
        cout << char('a' + i) << "\n";
        return 0;
    }
    cout << "None\n";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline ll rd()
{
	ll x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=100005;
int n,a[N];
int main()
{
	n=rd();rep(i,1,n)a[i]=rd();
	sort(a+1,a+n+1);reverse(a+1,a+n+1);
	rep(i,1,n)if(a[i+1]<i+1)
	{
		int ans=0;
		for(int j=i+1;a[j]==i;j++)ans^=1;
		ans|=(a[i]-i)&1;
		puts(ans?"First":"Second");
		return 0;
	}
	return 0; 
}


Measured memory_bytes: 640