akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  vector<P> v;
  rep(i,n) {
    if(a[i]!=n) v.pb(P(i,a[i]));
  }
  ll d[n+1];
  rep(k,m) {
    mem(d);
    rep(i,v.size()) {
      ll x=v[i].F,y=v[i].S;
      d[max(0LL,x-y)]++;
      d[min(n,x+y+1)]--;
    }
    d[0]+=n-v.size();
    d[n]-=n-v.size();
    rep(i,n) d[i+1]+=d[i];
    vector<P> g;
    rep(i,n) {
      ll x=i;
      ll y=d[x];
      if(y!=n) g.pb(P(x,y));
    }
    v=g;
    if(!v.size()) {
      PR(d,n);
      return;
    }
  }
  PR(d,n);
}

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


Measured memory_bytes: 16584
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索 """

    ok = mn
    ng = mx
    while ok+1 < ng:
        mid = (ok+ng) // 2
        if func(mid):
            # 上を探しに行く
            ok = mid
        else:
            # 下を探しに行く
            ng = mid
    return ok

T1, T2 = MAP()
A1, A2 = MAP()
B1, B2 = MAP()

# a,bの状態からT1,T2の操作を行った後のa,bと、この操作での交差回数を返す
def calc(a, b):
    cnt = 0
    a1 = a + T1 * A1
    b1 = b + T1 * B1
    if a > b and a1 <= b1 or a < b and a1 >= b1:
        cnt += 1
    a2 = a1 + T2 * A2
    b2 = b1 + T2 * B2
    if a1 > b1 and a2 <= b2 or a1 < b1 and a2 >= b2:
        cnt += 1
    return a2, b2, cnt

# x+1回目の操作でまだ交差するか
def check(x):
    a = (T1 * A1 + T2 * A2) * x
    b = (T1 * B1 + T2 * B2) * x
    _, _, cnt = calc(a, b)
    return cnt >= 1

# 初回で同値に飛んだらその先もずっと繰り返す
a, b, cnt = calc(0, 0)
if a == b:
    print('infinity')
    exit()

# 最後に交差する直前までの操作回数を調べる
res = bisearch_max(-1, 10**18, check)
# 初回でも交差しなければ0
if res == -1:
    print(0)
    exit()

# 直前までの操作では、初回は1回、以降は2回ずつ交差する
ans = max(0, res * 2 - 1)
# 最後に交差する直前までa,bを移動させる
a = (T1 * A1 + T2 * A2) * res
b = (T1 * B1 + T2 * B2) * res
# 最後が1回か2回か確認
_, _, cnt = calc(a, b)
ans += cnt
print(ans)


Measured memory_bytes: 3192
#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, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i,m){
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    vector<bool> seen(n, false);
    int ans = 0;
    rep(i,n){
        if(seen[i]) continue;
        ans++;
        seen[i] = true;
        queue<int> que;
        que.push(i);
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(auto nv : g[v]){
                if(seen[nv]) continue;
                seen[nv] = true;
                que.push(nv);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9552
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var S string
	fmt.Scan(&S)
	Fint, _ := strconv.Atoi(S[0:2])
	Sint, _ := strconv.Atoi(S[2:4])
	if Fint == 0 && Sint == 0 {
		fmt.Println("NA")
		return
	}
	if Fint > 12 && Sint > 12 {
		fmt.Println("NA")
		return
	}
	if Fint <= 12 && Sint <= 12 {
		if Fint == 0 {
			fmt.Println("YYMM")
			return
		}
		if Sint == 0 {
			fmt.Println("MMYY")
			return
		}
		fmt.Println("AMBIGUOUS")
	} else if Fint <= 12 && Sint > 12 {
		if Fint == 0 {
			fmt.Println("NA")
			return
		}
		fmt.Println("MMYY")
	} else if Fint > 12 && Sint <= 12 {
		if Sint == 0 {
			fmt.Println("NA")
			return
		}
		fmt.Println("YYMM")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main(){
	stack<int> s;
	stack<pair<int,int> > ss;
	char ch;int i = 1,ans = 0;
	while(cin >> ch){
		if(ch == '\\') {//需要转义 
			s.push(i);
		}
		else if(ch == '/' && s.size()){
			int temp = s.top();s.pop();
			int res = i - temp; 
			ans += res;
			while(ss.size() && ss.top().first > temp){
				res += ss.top().second;
				ss.pop();
			}
			ss.push(make_pair(temp,res));
		}
		i++;
	}
	cout << ans << endl;
	vector<int> vec;
	while(ss.size()){
		vec.push_back(ss.top().second);
		ss.pop();
	}
	cout << vec.size();
	for(auto z = vec.rbegin(); z != vec.rend(); z++){
		cout << " " << *z ;
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <set>

using namespace std;

struct unionfind {
  vector<long long> par;
  vector<long long> _size;

  // コンストラクタ
  unionfind(long n) : par(n), _size(n,1) {
    for(long long i=0; i<n; i++) par[i]=i;
  }

  void init(long long n) {
    par = vector<long long>(n);
    _size = vector<long long>(n);
    for(long long i=0; i<n; i++) par[i]=i;
  }

  long long root(long long x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x==y) return false;

    if(_size[x]<_size[y]) swap(x,y);

    _size[x] += _size[y];
    par[y] = x;
    return true;
  }

  bool issame(long long x, long long y) {
    return root(x) == root(y);
  }

  long long size(long long x) {
    return _size[root(x)];
  }
};

int main() {
  int n,m;
  int ans = 0;
  cin >> n >> m;
  vector<int> p(n+1);
  for (int i=1; i<=n; i++) cin>>p[i];

  unionfind uni(n+1);

  for (int i=0; i<m; i++) {
    int x,y;
    cin >> x >> y;
    uni.merge(x,y);
  }

  for (int i=1; i<=n; i++) {
    if (p[i] == i || uni.issame(i,p[i]) ) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 2176
'''
ITP-1_8-D
 ????????°
???????????????????????°??¶???????????? ss ???????????????????????????????¨????????????£?¶????????????????????????????????????§???
????????? pp ??????????????????????????????????????°????????????????????????????????????
???Input
????????????????????? ss ????????????????????????
????????????????????? pp ????????????????????????
???Output
pp  ??????????????´?????? Yes ??¨?????????????????´?????? No ??¨????????????????????????????????????
'''
# inputData
x = str(input())
y = str(input())

xString = []
for i in x:
    xString.append(i)
yString = []
for i in y:
    yString.append(i)

n = len(yString)
flag = 0
for i in range(len(xString)):
    if xString[i:i+n] == yString:
        flag = 1
        break

    if i+n > len(xString):
        if xString[i:]+xString[0:(i+n)%len(xString)] == yString:
            flag = 1
            break

# outputCheck 
if flag == 0:
    print('No')
elif flag == 1:
    print('Yes')

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

int main() {
    int a,b; scanf("%d %d", &a, &b);

    if (a <= 0 && 0 <= b) {
        printf("Zero\n");
    } else if (b < 0 && (b-a+1) % 2 == 1) {
        printf("Negative\n");
    } else {
        printf("Positive\n");
    }

    return 0;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())

table = {}
for ti in t:
    table[ti] = []
    
for i, si in enumerate(s):
    # print("##", si)
    if table.get(si) != None:
        table[si].append(i)

# print("#", table)

import bisect

if [] in table.values():
    print(-1)
else:
    ans = 0
    pos = min(table[t[0]])
    for i in range(len(t) - 1):
        src = t[i]
        dst = t[i + 1]
        idx_tmp = bisect.bisect_right(table[dst], pos)
        if idx_tmp == len(table[dst]):
            ans += len(s)
            pos = table[dst][0]
        else:
            pos = table[dst][idx_tmp]
        # print("##", (src, dst), idx_tmp, pos, ans + pos + 1)
    #    
    print(ans + pos + 1)

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

int main(void) {
  ll i, j, k, n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  printf("%lld", n / (a + b) * a + (n % (a + b) > a ? a : n % (a + b)));
  return 0;
}

Measured memory_bytes: 128
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  vector<int> B(N + 1);
  vector<int> C(N);

  rep(i, N) {
    int a;
    cin >> a;
    A.at(i) = a;
  }
  rep(i, N) {
    int b;
    cin >> b;
    B.at(i) = b;
  }
  rep(i, N - 1) {
    int c;
    cin >> c;
    C.at(i) = c;
  }

  int sum = 0;
  rep(i, N) {
    sum += B.at(A.at(i) - 1);
    if (i != 0 && (A.at(i) - A.at(i - 1)) == 1) {
      sum += C.at(A.at(i) - 2);
    }
  }
  cout << sum << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, H, W, ans=0;
	int a[100005];

	cin >> H >> W >> N;
	rep(i,N) cin >> a[i];

	int pos = 0, cur = 0;
	int out[105][105];
	rep(y,H) rep(x,W){
		if( y%2 ) pos = W-1-x;
		else pos = x;
		out[y][pos] = cur+1;
		a[cur]--;
		if( a[cur] <= 0 ) cur++;
	}

	rep(y,H){
		rep(x,W) cout << out[y][x] << " ";
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 384
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int main()
{
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	if ((a&1)!=(b&1))
	{
		ll raz, dwa;
		raz=a+b-1;
		dwa=(n-a+1)+(n-b+1)-1;
		printf("%lld\n", min(raz, dwa)/2);
	}
	else
	{
		printf("%lld\n", abs(a-b)/2);
	}
	return 0;
}


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


int n;
pair<pair<string, int>, int> p[100];

int main(){

	cin >> n;
	for (int i = 0; i < n; i++){
		int in;
		string s;
		cin >> s >> in;
		p[i] = make_pair(make_pair(s, -in), i);
	}

	sort(p, p + n);
	for (int i = 0; i < n; i++) cout << p[i].second + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  ll ld = 1;
  ll rd = 100000;
  while(rd - ld > 1){
    ll md = (rd + ld) / 2;
    if(md * md > n)rd = md;
    else ld = md;
  }
  cout << ld * ld << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()

#define MAX_N 30
#define swap(a, b) { int t; t = a; a = b; b = t; }

int
main(int argc, char** argv)
{
	int l[MAX_N + 1];
	int w;
	int n;
	int a, b;
	int i;

	scanf("%d", &w);
	for (i = 1; i <= w; ++i)
		l[i] = i;

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

	for (i = 1; i <= w; ++i)
		printf("%d\n", l[i]);

	return 0;
}

Measured memory_bytes: 596
A, B, C, D, E, F = map(int, input().split())

water = []
for i in range(32):
    if 100 * A * i > F:
        continue
    for j in range(32):
        if 100 * A * i + 100 * B * j > F:
            continue
        if i == 0 and j == 0:
            continue
        water.append(100 * A * i + 100 * B * j)

sugar = [0] * (F * F)
for i in range(F):
    if i * C > F:
        continue
    for j in range(F):
        if i * C + j * D > F:
            continue
        sugar.append(C * i + D * j)
sugar = list(set(sugar))

water.sort()
sugar.sort()
ans = 0
wa = 0
su = 0
for i in water:
    for j in sugar:
        if i + j <= F:
            if ans <= (100 * j / (i + j)) and (i / 100 * E) >= j:
                ans = (100 * j / (i + j))
                wa = i
                su = j

print(wa + su, su)

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

void solve(long long N, long long A){
    cout << N * N - A << '\n';
}

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


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[101000];
int n, m, BIT[101000];
void Add(int a, int b){while(a <= n){BIT[a] += b; a += (a&-a);}}
int Sum(int a){int r = 0;while(a){r += BIT[a]; a -= (a&-a);}return r;}
int main(){
    int i, a, b, j;
    scanf("%d%d",&m,&n);
    for(i=1;i<=m;i++){
        scanf("%d%d",&a,&b);
        E[b-a+1].push_back(a);
    }
    int R = m;
    for(i=1;i<=n;i++) {
        for(j=0;j<E[i].size();j++){
            Add(E[i][j], 1);
            Add(E[i][j]+i, -1);
            R--;
        }
        int r = 0;
        for(j=i;j<=n;j+=i) r += Sum(j);
        printf("%d\n",R+r);
    }
}

Measured memory_bytes: 6784
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    m = defaultdict(int)

    for i in range(N):
        m[S()] += 1

    print(len(m.keys()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 110904
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

#define MOD 1000000007

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

    int N; cin >>N;
    vector<int> A(N+1);
    vector<int> pos(N, -1);
    int l, r;
    rep(i, N+1) {
        cin >> A[i];
        A[i]--;
        if (pos[A[i]] == -1) {
            pos[A[i]] = i;
        } else {
            l = pos[A[i]];
            r = i;
        }
    }

    vector<int> fact(N+1+1);
    vector<int> finv(fact.size());
    vector<int> inv(fact.size());
    
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[0] = 0; inv[1] = 1;
    for (int i = 2; i < fact.size(); i++) {
        fact[i] = (ll)fact[i-1] * i % MOD;
        inv[i] = MOD - (ll)inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (ll)finv[i - 1] * inv[i] % MOD;
    }

    auto C = [&](int n, int r) { return (ll)fact[n] * finv[n-r] % MOD * finv[r] % MOD; };

    cout << N+1-1 << endl;
    for (int k = 2; k <= N+1; k++) {
        int a = C(N+1, k);
        int b = l + N+1-(r+1) >= k - 1 ? C(l + N+1-(r+1), k-1) : 0;
        int s = ((ll)a - b) % MOD;
        while (s < 0) s += MOD;
        cout << s << endl;
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  ll n,m;
  cin>>n>>m;
  vector<pair<ll,ll>> ab(n);
  rep(i,n) {
    int a,b;
    cin>>a>>b;
    ab[i]=make_pair(a,b);
  }
  sort(ab.begin(),ab.end());
  int c=0;
  ll ans=0;
  rep(i,n) {
    if(c+ab[i].second<=m) {
      c+=ab[i].second;
      ans+=ab[i].first*ab[i].second;
    } else {
      ans+=ab[i].first*(m-c);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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


// ABC126A - Dice and Coin
// https://atcoder.jp/contests/abc126/tasks/abc126_c
void ABC126C() {
	int N, K;
	cin >> N >> K;


	double ans = 0.0;
	for (int n = 1; n <= N; n++)
	{
		double y = n;

		//コインを振る
		double tmp = 1.0;
		while (K > y) {
			y *= 2.0;   //コインを振る度に得点が2倍になる
			tmp /= 2.0; //Kを超えるまでに表が連続で出続ける確率
		}
		//cout << "tmp : " << tmp << endl;
		ans += (1.0 / N) * tmp;
	}

	printf("%.12f\n", ans);
}

int main() {
	ABC126C();

	return 0;
}

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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  int x=0,y=0,z=0,turn=0;
  char p;
  for(int i=0;i<500;i++){
    if(turn==0){
      if(x==a.size()){
        cout<<"A"<<endl;
        return 0;
      }
      p=a[x];
      x++;
    }
    if(turn==1){
      if(y==b.size()){
        cout<<"B"<<endl;
        return 0;
      }
      p=b[y];
      y++;
    }
    if(turn==2){
      if(z==c.size()){
        cout<<"C"<<endl;
        return 0;
      }
      p=c[z];
      z++;
    }
    if(p=='a'){
      turn=0;
    }
    if(p=='b'){
      turn=1;
    }
    if(p=='c'){
      turn=2;
    }
  }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextMap()
	Q := sc.NextInt()
	total := 0
	for k, v := range A {
		total += k * v
	}
	for i := 0; i < Q; i++ {
		B, C := sc.NextInt(), sc.NextInt()
		if v, ok := A[B]; ok {
			total = total - B*v + C*v
			delete(A, B)
			A[C] += v
		}
		fmt.Println(total)
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]int {
	s.pre()
	start := s.p
	mp := map[int]int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v]++
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v]++

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 9424
import sys
input = sys.stdin.readline

MOD = 10**9 + 7
def main():
    S = input()
    N = len(S)-1

    if S[0] == '?':
        dp = [1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
        dp[int(S[0])] = 1

    for i in range(1,N):
        dppre = dp
        dp = [0] * 13

        if S[i] == '?':
            R = range(10)
        else:
            R = [int(S[i])]
        
        for j in range(13):
            for k in R:
                dp[(j * 10 + k) % 13 ] += dppre[j]
        for j in range(13):
            dp[j] %= MOD

    print(dp[5])
if __name__ == '__main__':
    main()

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();

		pr.printf("%c%c%c\n", a[0], b[0], c[0]);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* UnionFind */
struct UnionFind {
    vector<ll> par,rank,siz;

    UnionFind(ll N) : par(N),rank(N),siz(N) {
        REP(i,N){
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    ll root(ll x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        if(rank[rx] < rank[ry]){
            par[rx] = ry;
            siz[ry] += siz[rx];
        }else{
            par[ry] = rx;
            siz[rx] += siz[ry];
            if(rank[rx] == rank[ry])rank[rx]++;
        }
    }

    ll size(ll x){
        return siz[root(x)];
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,M;
    cin >> N >> M;
    UnionFind uf(N);
    REP(i,M){
        ll A,B;
        cin >> A >> B;
        A--;
        B--;
        uf.unite(A,B);
    }
    ll ma = 0;
    REP(i,N){
        chmax(ma,uf.size(i));
    }
    cout << ma << "\n";
}

Measured memory_bytes: 7944
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int inf = numeric_limits<int>::max()/2;
const ll mod = 1e9 + 7;

int main(void){
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  b -= a;
  for(int i = 0;i < n;++i){
    ll u = d * i - c * (n-1-i);
    ll l = c * i - d * (n-1-i);
    if(l <= b && b <= u){
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}


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

int main() {
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double tim=h*60+m;
    double ac=a*cos((tim/(6*60))*acos(-1)),bc=b*cos(m/30*acos(-1)),as=a*sin((tim/(6*60))*acos(-1)),bs=b*sin(m/30*acos(-1));
    printf("%.15f\n", sqrt((ac-bc)*(ac-bc)+(as-bs)*(as-bs)));
}

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

int main(){

    
    int s;
    cin >> s;
    
    int table[1000000] = {};
    table[s] = 1;

    int res = 1;

    while (true){
        res ++;
        if(s % 2 == 0){
            s = s / 2;
        }else{
            s = 3*s+1;
        }

        if(table[s]){
            cout << res << endl;
            return 0;
        }else{
            table[s] = 1;
        }
    }
    return 0;
}

Measured memory_bytes: 4096
object Main extends App {
	val Array(n, m, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val a = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val test = new Array[Int](n+1)

	for(x<-a){
		test(x) = 1
	}

	var left = 0
	var right = 0


	for(i<-0 until x){
		left += test(i)
	}

	for(i<-x to n){
		right += test(i)
	}

	println(math.min(left, right))

}

Measured memory_bytes: 25412
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <numeric>
#include <cmath>
#include <cctype>

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int main(){
  stack<int> s;
  string c;
  while(cin >> c){
    if(c=="+"){
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push( a+b );
    }else if(c== "-"){
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push( a-b );
    }else if(c=="*"){
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push( a*b );
    }else{
      s.push( __stoi(c) );
    }
  }
  cout << s.top() <<"\n";
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a[101];
bool nibun(int x){
	int s=0,q=0,t=0;
	r(i,n){
		if(s+a[i]<=x)s+=a[i];
		else s=0,q++,i--,t++;
		if(t>300)return 0;
	}
	return m>=q+1;
}
main(){
	while(cin>>m>>n,m){
	  r(i,n)cin>>a[i];
	  int l=0,r=1500001;
	  while(l<r){
    	int mid=(l+r)/2;
		if(nibun(mid))r=mid;
		else l=mid+1;
	  }
	  cout<<l<<endl;
    }
}

Measured memory_bytes: 3068
#include <stdio.h>

int main(){

    int n,a,x,an = 0;

    scanf("%d",&n);
    for( x = 0 ; x < n ; x++ ){
        scanf("%d",&a);

        if(a % 2 == 0) {
            for (; a % 2 == 0;) {
                a /= 2;
                an++;
            }
        }
    }

    printf("%d\n",an);


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
int main(void){
    int N;
    cin>>N;
    long long ans1=0,ans2=0;
    for(int i=0;i<N;i++){
        int t,a;
        cin>>t>>a;
        long long n=max(ans1/t,ans2/a);
        if(n==0)n=1;
        while(1){
            if(n*t>=ans1&&n*a>=ans2){
                ans1=n*t;
                ans2=n*a;
                break;
            }
            n++;
        }
    }
    cout<<ans1+ans2<<endl;
    return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    rep(i, 2, N + 2){
        if(i * (i - 1) == 2 * N){
            cout << YES << endl;
            cout << i << endl;
            vector<vector<i64>> g(i);
            i64 cnt = 1;
            rep(j, i - 1){
                rep(k, j + 1, i){
                    g[j].push_back(cnt);
                    g[k].push_back(cnt);
                    cnt++;
                }
            }
            rep(j, i){
                cout << g[j].size() << " ";
                rep(k, g[j].size()) cout << g[j][k] << " ";
                cout << endl;
            }
            return;
        }
    }
    cout << NO << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3200
s=int(input())
MAX=1000000
i=2
F=[0]*1000001
F[1]=s

def calc(n):
  n=F[n-1]
  if n%2==0:
    return n//2
  else:
    return 3*n+1

while i<=MAX:
  ans=calc(i)
  if ans in F:
    break
  F[i]=ans
  i+=1
print(i)


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

int main(){
        int N;
        string S;
        cin >> N;
        cin >> S;
        if(N % 2 != 0) {
                cout <<  "No" << endl;
                return 0;
        }
        string A = S.substr(N / 2, N);
        string B = S.substr(0,N / 2);
//        cout << A << " " << B << endl;

        cout << (A == B ? "Yes" : "No") << endl;

}


Measured memory_bytes: 256
n,k=$<.map(&:to_i)
c=0
ans=1<<32
(1<<n).times{|i|
  tmp=1
  n.times{|b|
    if i&(1<<b) >0
      tmp*=2
    else
      tmp+=k
    end
  }
    ans=tmp if ans>tmp

}
p ans


Measured memory_bytes: 1788
import itertools
import math

m = int(input())
g = list(range(1, m+1))
res = 0
for c in itertools.combinations_with_replacement(g, 3):
  set_c = set(c)
  set_list_c = list(set_c)
  if len(set_c) == 3:
    n = 6
    tmp_res = math.gcd(set_list_c[0], set_list_c[1])
    tmp_res = math.gcd(tmp_res, set_list_c[2])
  elif len(set_c) == 2:
    n = 3
    tmp_res = math.gcd(set_list_c[0], set_list_c[1])
  else:
    n = 1
    tmp_res = set_list_c[0]
  res += tmp_res * n
print(res)

Measured memory_bytes: 9220
use std::io;

fn main() {
    loop {
        let (h, w) = input();
        if (h, w) == (0, 0) {
            break;
        }

        for i in 0..h {
            for j in 0..w {
                print!("{}", if (i + j) % 2 == 0 { "#" } else { "." });
            }
            println!("");
        }
        println!("");
    }
}

fn input() -> (i32, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();

    (a, b)
}



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

using namespace std;

int n, m, k, s, ans = 0;
vector<int> v[11];
int p[11];

bool glow(int b, int sw) {
	int cnt = 0;
	for(auto i : v[b]) {
		if(sw & (1 << (i - 1))) cnt++;
	}
	if(cnt % 2 == p[b]) return true;
	return false;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		cin >> k;
		for(int j = 0; j < k; j++) {
			cin >> s;
			v[i].push_back(s); 
		}
	}
	for(int i = 0; i < m; i++) cin >> p[i];
	for(int i = 0; i < (1 << n); i++) {
		bool flag = true;
		for(int j = 0; j < m; j++) {
			if(!glow(j, i)) {
				flag  = false;
				break;
			} 
		}
		if(flag) ans++;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var M = cin.ReadInt;

            var sum = 0;

            for (int i = 0; i < M; i++)
            {
                sum += cin.ReadInt;
            }
            WriteLine(N - sum >= 0 ? N - sum : -1);
        }

    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }


        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 28884
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
int n,a[N];
bool pa(int x){
	priority_queue<int> b;
	unordered_map<int,int> c;c.clear();
	while (!b.empty()) b.pop();
	for (int i=1;i<=n;i++){
		if (a[i]<=a[i-1]){
			if (x==1) return false;
			while (!b.empty()&&b.top()>a[i]){c[b.top()]=0;b.pop();}
			c[a[i]]++;if (c[a[i]]==1) b.push(a[i]);
			int y=a[i];
			while (c[y]>=x){
				b.pop();c[y]=0;
				if (y==1) return false;
				y--;c[y]++;if (c[y]==1) b.push(y);
			}
		}
	}
	return true;
}
int main(){
	read(n);
	for (int i=1;i<=n;i++)read(a[i]);
	int l=1,r=n,mid;
	if (n>100) if (pa(100)) r=100;
	while (l<r){
		mid=(l+r)/2;
		if (pa(mid)) r=mid;else l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 8948
import sys
input = sys.stdin.readline

class WeightedUnionFind:
    def __init__(self, N):
        self.parent = list(range(N))
        self.rank = [0] * N
        self.weight = [0] * N

    def find(self, x):
        stack = [x]
        while self.parent[x] != x:
            x = self.parent[x]
            stack.append(x)
        r = stack[-1]
        while stack:
            x = stack.pop()
            self.weight[x] += self.weight[self.parent[x]]
            self.parent[x] = r
        return r

    def unite(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        w += self.weight[x] - self.weight[y]
        x = rx
        y = ry
        if x == y:
            return False

        if self.rank[x] < self.rank[y]:
            x, y = y, x
            w = -w
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.parent[y] = x
        self.weight[y] = w
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        self.find(x)
        self.find(y)
        return self.weight[y] - self.weight[x]

n, q = map(int, input().split())
wuf = WeightedUnionFind(n)
for _ in range(q):
    t, *data = map(int, input().split())
    if t == 0:
        x, y, z = data
        wuf.unite(x, y, z)
    else:
        x, y = data
        if not wuf.same(x, y):
            print('?')
        else:
            print(wuf.diff(x, y))


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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll A, B;
    cin >> A >> B;
    cout << max(A + B, max(A, B) * 2 - 1);
    return 0;
}



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

using namespace std;

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

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

    int N;
    cin >> N;

    long long a[N][3];

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }

    long long dp[N + 1][3];

    for (int i = 0; i < N + 1; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = 0;
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) {
                    continue ;
                }
                change_max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long ans = 0;

    for (int i = 0; i < 3; i++) {
        change_max(ans, dp[N][i]);
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            int iC = int.Parse(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "No";
            if (iA <= iC && iC <= iB) { sOut = "Yes"; }

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
struct P{
    double x,y;
    P(){}
    P(double x,double y):x(x),y(y){
    }
    P operator + (P p){
        return P(x+p.x,y+p.y);
    }
    P operator - (P p){
        return P(x-p.x,y-p.y);
    }
    double det(P p){
        return x*p.y+(-y*p.x);
    }
};

bool cmp_x(const P& p,const P& q){
    if(p.x!=q.x)return p.x<q.x;
    return p.y<q.y;
}
vector<P>convex_hull(P* ps,int n){
    sort(ps,ps+n,cmp_x);
    int k=0;
    vector<P>qs(n*2);
    REP(i,n){
        while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
        qs[k++]=ps[i];
    }
    for(int i=n-2,t=k;i>=0;i--){
        while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
        qs[k++]=ps[i];
    }
    qs.resize(k-1);
    return qs;
}
LL dist(const P& p,const P& q){
    return abs(p.x-q.x)+abs(p.y-q.y);
}
int main(){
    int N;cin>>N;
    vector<P>xy;
    REP(i,N){
        int x,y;
        cin>>x>>y;
        xy.PB(P(x,y));
    }
    vector<P>qs=convex_hull(&xy[0],N);
    LL res=0;
    REP(i,SZ(qs)){
        REP(j,i){
            res=max(res,dist(qs[i],qs[j]));
        }
    }
    cout<<res<<endl;
    return 0;
}

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

int main(){
    int A, B;  cin >> A >> B;
    if(A>B) swap(A,B);
    if((B-A)%2==0){
        cout << (A+B)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 256
{**
 * Author  : Nguyen Canh Toan
 * Problem : A - Kth Term
 * Link    : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_a
**}
uses math;
const std='tmp';
var n:longint;
    v:array[1..32]of longint=(1,0,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);
    input,output:text;
procedure main();
begin
  readln(n);
  writeln(v[n]);
end;
BEGIN
  //assign(input,std+'.inp');reset(input);
  //assign(output,std+'.out');rewrite(output);
    main();
  //close(input);
  //close(output);
END.

Measured memory_bytes: 128
import math
 
 
def gcd(a, b, c):
  d = math.gcd(a, b)
  return math.gcd(c, d)
 
K = int(input())
sum = 0
for i in range(1, K+1):
  sum += gcd(i, i, i)
  
for i in range(1, K+1):
  for j in range(i, K+1):
    for k in range(j, K+1):
      if i == j and j == k:
        sum += 0
      elif i == j or j == k or i == k:
        sum += gcd(i , j , k )*3
      elif i != j and j != k :
        sum += gcd(i, j, k)*6

print(sum)

Measured memory_bytes: 9220
# -*- coding: utf-8 -*-
s = input()

dp = [0] * 100007 # sの最大値+t_element_listの要素の最大値以上

t_element_list = ["dream", "dreamer", "erase", "eraser"]

dp[0] = 1
for i in range(len(s)):
    if dp[i] == 1:
        for j in range(len(t_element_list)):
            if s[i:i+len(t_element_list[j])] == t_element_list[j]:
                dp[i + len(t_element_list[j])] = 1

if dp[len(s)] == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 4084
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 100000 + 5;
const int MAXQ = 50000 + 5;
int ans = 0;
void binarySearch(const int a[],const int key,const int n)
{
	int left=0, right=n;
	int mid;
	while(left<right)
	{
		mid = (left + right)/2;
		if (a[mid]==key)
		{
			ans++;
			return ;
		}
		else if (a[mid]<key)
		{
			left = mid +1;
		}
		else right = mid ;
	}
	return ;
}
int main(int argc, char const *argv[])
{
	int n,q;
	int S[MAXN];
	int T[MAXQ];
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&S[i]);			
	}
	cin>>q;
	for (int i = 0; i < q; ++i)
	{
		scanf("%d",&T[i]);
		binarySearch(S,T[i],n);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,z,w;cin>>n>>z>>w;
  int a[n];for(int i=0;i<n;i++)cin>>a[i];
  if(n==1){
    cout<<abs(a[0]-w)<<endl;
    return 0;
  }
  cout<<max(abs(w-a[n-1]),abs(a[n-2]-a[n-1]))<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> la(n);
  for (int &a: la) cin >> a;
  int s = 1;
  int ans = 0;
  for (int a: la) { 
    if (a != s) ++ans;
    else ++s;
  }
  if (s == 1) cout << -1 << endl;
  else cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main() {
  string s;
  cin >> s;
  sort(all(s));
  s.erase(unique(all(s)), s.end());
  rep(i, 26) {
    char alpha = 'a' + i;
    auto it = find(all(s), alpha);
    if(it == s.end()) {
      cout << alpha << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512