akhauriyash/Code-Regression huggingface dataset:
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
min_diff = 1000000
ans = 0

for i in range(N):
    if abs(T - H[i] * 0.006 - A) < min_diff:
        min_diff = abs(T - H[i] * 0.006 - A)
        ans = i + 1

print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <cstdlib>

using namespace std;

const int mod=100000;
int main(){
    int n,m,st[100000],mv,t;
    cin>>n>>m;
    int acc=0,sum=0,pos=0;
    st[0]=acc;
    for(int i=1;i<n;++i){
        cin>>t;
        acc +=t;
        st[i]=acc;
    }
    for(int i=0;i<m;++i){
        cin>>mv;
        sum =(sum+abs(st[mv+pos]-st[pos]))%mod;
        pos +=mv;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <cstdlib> //絶対値整数abs
#include <cmath>   //絶対値少数fbs
#include <math.h>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll count = 0;
    ll big = 0;
    ll min = 0;
    for (ll i = 1; i <= N + 1; i++)
    {
        min += i - 1;
        big += N - i + 1;
        if (i >= K)
        {
            count += (big - min + 1);
        }
    }
    count %= 1000000007;
    cout << count << endl;
}

Measured memory_bytes: 3604
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N, K = map(int, input().split())
    ps = list(map(int, input().split()))

    ps.sort()
    return sum(ps[:K])


def main():
    print(solve())


if __name__ == "__main__":
    main()


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

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

    int n;
    cin >> n;

    long long x, y, a = 1, b = 1;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        
        /* WA
        int p = max((a + (x - 1)) / x, (b + (y - 1)) / y);
        a = x * p;
        b = y * p;
        */

       long long p1 = a / x + (a % x ? 1 : 0);
       long long p2 = b / y + (b % y ? 1 : 0);

       a = x * max(p1, p2);
       b = y * max(p1, p2);
    }

    cout << a + b << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    long long s; cin >> s;

    if(s == 1){
        cout << 0 << " " << 0 << " " << 1 << " " << 0 << " " << 0 << " " << 1 << endl;
    }
    else if(s == 1e18){
        cout << 0 << " " << 0 << " " << 1000000000 << " " << 0 << " " << 0 << " " << 1000000000 << endl;
    }
    else{
        long long n = 1;
        while(n*n <= s){
            n++;
        }

        long long ds = n*n - s;
        long long x3 = sqrt(ds);
        long long y2;
        while(x3 >= 0){
            if(x3 >= n) continue;
            if(ds % x3 == 0){
                y2 = ds / x3;
                break;
            }
            x3--;
        }
        if(x3 < 0 || 1e9 < x3 || 1e9 < y2) cout << "error" << endl;
        else{
            cout << 0 << " " << 0 << " " << n << " " << y2 << " " << x3 << " " << n << endl;
            // cout << n*(n+1) - x3*y2;
        }   
    }

    return 0;
}

Measured memory_bytes: 384
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 3005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

LL dp[MAX][MAX][4];
LL a[MAX][MAX];

LL _max(LL n1, LL n2) {
	if(n1 > n2) return n1;
	return n2;
}

void solve() {
	int r, c, k;
	in2(r, c);in(k);
	for(int i=0;i<=r;i++) {
		for(int j=0;j<=c;j++) {
			a[i][j] = 0;
			for(int x=0;x<4;x++) dp[i][j][x] = 0;
		}
	}
			
	for(int i=0;i<k;i++) {
		int x,y;
		LL v;
		in2(x, y);inl(v);
		a[x][y] = v;
	}
	
	//~dp[0][0][1] = a[0][0];
	//~for(int j=1;j<c;j++) {
		//~dp[0][j][0] = dp[0][j-1][0];
		//~dp[0][j][1] = _max(dp[0][j-1][1], a[0][j]!=0 ? (dp[0][j-1][0] + a[0][j]) : 0);
		//~dp[0][j][2] = _max(dp[0][j-1][2], a[0][j]!=0 ? (dp[0][j-1][1] + a[0][j]) : 0);
		//~dp[0][j][3] = _max(dp[0][j-1][3], a[0][j]!=0 ? (dp[0][j-1][2] + a[0][j]) : 0);
	//~}
	
	//~for(int i=1;i<r;i++) {
		//~dp[i][0][0] = dp[i-1][0][0];
		//~dp[i][0][1] = _max(dp[i-1][0][1], a[i][0]!=0 ? (dp[i-1][0][0] + a[i][0]) : 0);
		//~dp[i][0][2] = _max(dp[i-1][0][2], a[i][0]!=0 ? (dp[i-1][0][1] + a[i][0]) : 0);
		//~dp[i][0][3] = _max(dp[i-1][0][3], a[i][0]!=0 ? (dp[i-1][0][2] + a[i][0]) : 0);
	//~}
	
	for(int i=1;i<=r;i++) {
		for(int j=1;j<=c;j++) {
			LL maxi = 0;
			for(int x=0;x<4;x++) maxi = _max(maxi, dp[i-1][j][x]);
			
			dp[i][j][0] = _max(maxi, dp[i][j-1][0]);
			if(a[i][j]!=0) {
				dp[i][j][1] = _max(maxi+a[i][j], dp[i][j-1][0]+a[i][j]);
				dp[i][j][2] = dp[i][j-1][1]+a[i][j];
				dp[i][j][3] = dp[i][j-1][2]+a[i][j];
			}
			dp[i][j][1] = _max(dp[i][j][1], dp[i][j-1][1]);
			dp[i][j][2] = _max(dp[i][j][2], dp[i][j-1][2]);
			dp[i][j][3] = _max(dp[i][j][3], dp[i][j-1][3]);
		}
	}
	
	LL ans = 0;
	for(int x=0;x<4;x++) ans = _max(ans, dp[r][c][x]);
	
	cout<<ans<<en;
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 355712
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
//回答が整数の場合
int ans;
//整数値の入力
int a,b,c;
cin >> a>>b>>c;

ans=b/a;
if(ans>c){ans=c;}
//回答
cout << ans << endl;
return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

int cnts[100005];

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

  int n, m;
  cin >> n >> m;

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    cnts[a]++;
    cnts[b]++;
  }

  bool canDo = true;
  rep(i, n+1) {
    if(cnts[i]%2) canDo = false;
  }

  cout << (canDo?"YES":"NO") << endl;
}

Measured memory_bytes: 640
from collections import defaultdict
d = defaultdict(int)

n = int(input())
a = list(map(int,input().split()))

for ai in a:
    d[ai] += 1

ans = 0
for k,v in d.items():
    if(k > v):
        ans += v
    else:
        ans += (v-k)

print(ans)

Measured memory_bytes: 22296
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 1e7 + 10;

LL a[N];

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

	for (int i = 1;i <= n;i++)
		for (int j = i;j <= n;j += i)
			a[j]++;

	LL ans = 0;

	for (int i = 1;i <= n;i++)
		ans += a[i] * i;

	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 81292
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	ll arra[a],arrb[b],arrc[c];
	vi v[3];
	priority_queue <pii> p;
	rep(i,0,a)
	{
		cin>>arra[i];
		p.push({arra[i],0});
	}
	rep(i,0,b)
	{
		cin>>arrb[i];
		p.push({arrb[i],1});
	}
	rep(i,0,c)
	{
		cin>>arrc[i];
		p.push({arrc[i],2});
	}
	ll s=0;
	while(sz(v[0])+sz(v[1])+sz(v[2])<x+y)
	{
		pii pp=p.top();
		p.pop();
		if(pp.S==2){
			v[2].pb(pp.F);
			s+=pp.F;
		}
		if(pp.S==1){
			if(sz(v[1])<y)
			{
				s+=pp.F;
				v[1].pb(pp.F);
			}
		}
		if(pp.S==0)
		{
			if(sz(v[0])<x)
			{
				s+=pp.F;
				v[0].pb(pp.F);
			}
		}
	}
	cout<<s<<endl;
}
signed main()
{
	
		/***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
		
	}
	TIME
	return 0;
}

Measured memory_bytes: 12396
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
const int INF = 1 << 29;
#define mp make_pair
#define el putchar('\n')
#define sp putchar(' ')
#define Fill(a,val) memset(a,val,sizeof a)
#define all(a) a.begin(),a.end()
#ifndef ONLINE_JUDGE
#define tr(a, it) for (decltype(a.begin()) it = a.begin(); it != a.end(); ++it)
#else
#define tr(a, it) for (typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#endif
#define in(n) scanf("%d",&n)
#define inl(n) scanf("%I64d",&n)
#define out(n) printf("%d",n);
#define outl(n) printf("%I64d",n);

bool gr(string a, string b){
	int n = a.length();
	int m = b.length();
	if (n != m)
		return n > m;
	for (int i = 0; i < n; ++i){
		if (a[i] != b[i])
			return a[i]>b[i];
	}
	return false;
}

int main(){
	string a, b; cin >> a >> b;
	if (a == b){
		puts("EQUAL");
		return 0;
	}
	if (gr(a, b)){
		puts("GREATER");
	}
	else{
		puts("LESS");
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
m = str(n) + ":"
a = True
l = n
i = 2
while a:
  if l % i == 0:
    l /= i
    m += ' ' + str(i)
    i -= 1
  a = i < l**0.5
  i += 1
if l != 1:
  m += ' ' + str(int(l))
print(m)


Measured memory_bytes: 5648
#include<iostream>                                                    
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;

struct Node{
    int key;
    Node *right,*left,*parent;
};

Node *root,*NIL;

void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key)
            x=x->left;
        else
            x=x->right;
    }
    z->parent=y;
    if(y==NIL)
        root=z;
    else{
        if(z->key<y->key)
            y->left=z;
        else
            y->right=z;
    }    
}
void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main(){
    int n,x;
    char com[7];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>com;
        if(com[0]=='i'){
            cin>>x;
            insert(x);
        }else if(com[0]=='p'){
            inorder(root);
            putchar('\n');
            preorder(root);
            putchar('\n');


        }

    }
    
    return 0;

}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   string s;cin >>s;
   ll ans=0;
   ll cnt=0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i]=='B')cnt++;
        else ans+=cnt;
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 3700
SA = input()
SB = input()
SC = input()

S_dict={'a':SA,'b':SB,'c':SC}
ans_dict={'a':'A','b':'B','c':'C'}

person = 'a'

while True:
    S = S_dict[person]

    if len(S) <= 0:
        print(ans_dict[person])
        break
        
    else:
        S_dict[person] = S[1:]
        person = S[0]

Measured memory_bytes: 9100
mod = 998244353
n,k = map(int,input().split())
c = [0 for _ in range(n+1)]
cs = [0 for _ in range(n+1)]
c[1] = 1
cs[1] = 1
csi = 1
lr = [(0,0) for _ in range(k)]
for i in range(k):
  li,ri = map(int,input().split())
  lr[i] = (li,ri)
for i in range(2,n+1):
  for lri in lr:
    l,r = lri
    if i-l > 0:
      c[i] = (c[i]+cs[i-l]-cs[max(0,i-r-1)])%mod
  csi = (c[i]+csi)%mod
  cs[i] = csi
print(c[n]) 

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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int a[n];
  int b[n];
  int magic_number = 0;
  REP(i,n) cin >> a[i];
  REP(i,n) {
    int tmp = in();
    int diff = tmp - a[i];
    if(diff > 0) magic_number += diff/2;
    else if(diff < 0) magic_number += diff;
  }
  
  if(magic_number >= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 384
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using graph=vector<vector<int>>;
using field=vector<string>;
using p =pair<int,int>;
const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    int d,G;
    cin>>d>>G;
    vector<int> p(d);
    vector<int> c(d);
    rep(i,d)cin>>p[i]>>c[i];
    int ans=mod;
    for(int i=0;i<pow(2,d);++i){
        int sum=0;
        int cnt=0;
        int temp=0;
        rep(j,d){
            if((i>>j)&1){
                sum+=(c[j]+p[j]*100*(j+1));
                cnt+=p[j];
            }else{
                temp=j;
            }
        }
        rep(l,p[temp]){
            if(sum>=G)break;
            sum+=(temp+1)*100;
            ++cnt;
        }
        if(sum>=G){
            ans=min(ans,cnt);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4072
import math  # noqa: F401
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def count(A: List[int]) -> Dict[int, int]:
    D: Dict[int, int] = {}
    for a in A:
        if a not in D:
            D[a] = 1
        else:
            D[a] += 1
    return D


def main(N: int, A: List[int], Q: int, B: List[int], C: List[int]):
    D = count(A)
    sum_ = sum(A)
    for b, c in zip(B, C):
        sum_changing = D.get(b, 0) * (c - b)
        if c not in D:
            D[c] = 0
        D[c] += D.get(b, 0)
        D[b] = 0
        sum_ += sum_changing
        print(sum_)


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B: List[int] = []
    C: List[int] = []
    for _ in range(Q):
        b, c = map(int, input().split())
        B.append(b)
        C.append(c)
    main(N, A, Q, B, C)


Measured memory_bytes: 31292
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn=1e5;
const int maxm=2e2+6;
const int INF=0x7fffffff;

int c[maxm],dp[maxn];
int n,m;

int main (){
	std::ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>c[i];
	}
	dp[0]=0;
	for(int i=1;i<=n;i++){
		dp[i]=INF;
	}
	for(int i=1;i<=m;i++){
		for(int j=c[i];j<=n;j++){
			dp[j]=min(dp[j],dp[j-c[i]]+1);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;

void solve(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  V<string> t(n);
  FOR(i,0,n){
    cin >> t[i];
    sort(ALL(t[i]));
  }
  sort(ALL(t));
  ll ans = 0;
  int l=0, r=l+1;
  for(;l<n && r<n;){
    while(t[l]==t[r]){
      ++r;
      if(r==n) break;
    }
    ans += (ll)(r-l)*(r-l-1)/2;
    l = r;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 5760
def insersion_sort(a):
    print(*a)
    n = len(a)
    for i in range(1, n):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(*a)

input()
insersion_sort([int(i) for i in input().split()])

Measured memory_bytes: 5980
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    string s;
    cin >> s;
    int a = (s[0]-'0')*10 + (s[1]-'0');
    int b = (s[2]-'0')*10 + (s[3]-'0');
    cerr << a << " " << b << endl;
    if(1 <= a && a <= 12 && 1 <= b && b <= 12){
        cout << "AMBIGUOUS" << endl;
    }else if(1 <= a && a <= 12){
        cout << "MMYY" << endl;
    }else if(1 <= b && b <= 12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }

    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc126.contest.atcoder.jp/tasks/abc126_a

Measured memory_bytes: 256
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    res = 0
    i = 1
    seven_res = 7 % k
    while True:
        res = (res * 10 + seven_res) % k
        if res == 0:
            break
        else:
            i += 1
    print(i)

Measured memory_bytes: 9180
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextLong
  
  def loop(m: Long, count: Long): Long = {
    if (m < 10) count
    else loop(m / 5, count + m / 10)
  }
  
  println(if (n % 2 == 1) 0 else loop(n, 0))
}

Measured memory_bytes: 27208
<?php

$inputList = explode(' ', preg_replace('/(\\r|\\n|\\r\\n)/', '',fgets(STDIN)));

$displayNumberIndex = $inputList[0] > $inputList[1] ? 1 : 0;
$displayNumber = $inputList[$displayNumberIndex];
$count = $inputList[1 - $displayNumberIndex];

$result = '';
for($i = 0; $i < $count; $i++){
    $result .= $displayNumber;
}

echo $result.PHP_EOL;

Measured memory_bytes: 3956
s = input()
YYMM = False
MMYY = False

if 0 <= int(s[:2]) < 100 and 0 < int(s[2:]) < 13:
    YYMM = True
if 0 < int(s[:2]) < 13 and 0 <= int(s[2:]) < 100:
    MMYY = True
if YYMM == True and MMYY == True:
    print('AMBIGUOUS')
elif YYMM == True:
    print('YYMM')
elif MMYY == True:
    print('MMYY')
else:
    print('NA')

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

int main(void) {

  int min;
  int N;
  int A;
  int ans;

  std::cin >> N;
  
  std::cin >> A;
  min = A;

  std::cin >> A;
  ans = A - min;
  min = std::min(min, A);

  for(int i = 2; i < N; ++i) {
    std::cin >> A;
    ans = std::max(ans, A - min);
    min = std::min(min, A);
  }

  std::cout << ans << std::endl;
  
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int ans=0;
  int m=0;
  for(int i=1; i<=n; i++){
    int count=0;
    int a=i;
    while(a%2==0){
      a/=2;
      count++;
    }
    if(count>=m){
      m=count;
      ans=i;
    }      
 
  }
  
  cout << ans << endl;  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main()
{
    int n,m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;
        
        int ans = 0;
        vector<pair<int,int> > v(n);
        rep(i,n) {
            cin >> v[i].second >> v[i].first;
            ans += v[i].first * v[i].second;
        }

        sort(v.begin(),v.end(),greater<pair<int,int> >());
        
        rep(i,n) {
            if(m == 0) break;
            if(m - v[i].second >= 0) {
                ans -= v[i].first * v[i].second;
                m -= v[i].second;
            } 
            else {
                ans -= v[i].first * m;
                m = 0;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1272
s = input()
n = [1]*len(s)
for i in range(len(s)-2):
  if s[i]=="R" and s[i+1]=="R":
    n[i+2]+=n[i]
    n[i]=0
for i in range(len(s)-1,1,-1):
  if s[i]=="L" and s[i-1]=="L":
    n[i-2]+=n[i]
    n[i]=0
print(*n)

Measured memory_bytes: 6400
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rnk=[0]*(n+1)

    def Find_Root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        if x==y:
            return
        elif self.rnk[x]>self.rnk[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y]+=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
uf=UnionFind(n)
ans=[0]*m
ans.append((n*(n-1))//2)
for i in range(m-1,-1,-1):
    if uf.isSameGroup(ab[i][0],ab[i][1]):
        ans[i]=ans[i+1]
    else:
        ans[i]=ans[i+1]-uf.Count(ab[i][0])*uf.Count(ab[i][1])
        uf.Unite(ab[i][0],ab[i][1])
for i in range(1,m+1):
    print(ans[i])


Measured memory_bytes: 111320
import sys


def main():

    N = int(sys.stdin.readline().rstrip())
    A = list(map(int, input().split()))
    
    cnt = 0
    exist_odd = False
    while True:
        for i in range(N):
            if A[i] % 2 != 0:
                exist_odd = True
                
        if exist_odd == True:
            break
            
        for i in range(N):
            A[i] /= 2
        cnt += 1
        
    print(cnt)
        
        
            
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
alice, bob = 0, 0
for i in range(n):
    temp_max = max(a)
    a.remove(temp_max)
    if i % 2 == 0:
        alice += temp_max
    else:
        bob += temp_max
print(alice - bob)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main (){
	int a,b;
	cin >> a >> b;
	int count = 0;
	for (int i = a; i <= b;i++){
		if (i/10000==i%10&&(i/1000)%10==(i%100)/10)count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll t1,t2,a1,a2,b1,b2,ans=0;
	cin>>t1>>t2>>a1>>a2>>b1>>b2;
	ll suma=t1*a1+t2*a2,sumb=t1*b1+t2*b2;
	if(suma==sumb){
		cout<<"infinity"<<endl;
		return 0;
	}
	if(a1<b1&&a2<b2||a1>b1&&a2>b2){
		cout<<"0"<<endl;
		return 0;
	}
	if(a1>b1){
		swap(a1,b1);
		swap(a2,b2);
		swap(suma,sumb);
	}
	if(suma>sumb){
		ans=(((b1-a1)*t1))/(suma-sumb);
		if((((b1-a1)*t1))%(suma-sumb)==0)ans--;
		ans+=((b1-a1)*t1)/(suma-sumb)+1;
	}
	puta(ans);
}


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

const int MAXN = 100005;

int N, Q;
int T[MAXN], L[MAXN], P[MAXN][20];  // direct parent, depth, ancestor
vector<int> adjList[MAXN];

void dfs(int node = 0, int depth = 0) {
    L[node] = depth;
    for (int i = 0; i < adjList[node].size(); i++) {
        int child = adjList[node][i];
        dfs(child,depth+1);
    }
}

int query(int u, int v) {
    int tmp;
    if (L[u] < L[v])
        tmp = u, u = v, v = tmp;

    int LOG2;
    for (LOG2 = 1; 1 << LOG2 <= L[u]; LOG2++); LOG2--;

    for (int i = LOG2; i >= 0; i--)
        if (L[u] - (1 << i) >= L[v])
            u = P[u][i];

    if (u == v)
        return u;

    for (int i = LOG2; i >= 0; i--)
        if (P[u][i] != -1 && P[u][i] != P[v][i])
            u = P[u][i], v = P[v][i];

    return T[u];
}

int main() {

    scanf("%d",&N);
    for (int u = 0, M; u < N; u++) {
        scanf("%d",&M);
        for (int i = 0, v; i < M; i++) {
            scanf("%d",&v);

            T[v] = u;
            adjList[u].push_back(v);
        }
    }

    // rooted at 0
    dfs();

    for (int i = 1; i <= N; i++)
        P[i][0] = T[i];
    for (int j = 1; 1 << j < N; j++)
        for (int i = 1; i <= N; i++)
            P[i][j] = P[P[i][j-1]][j-1];

    scanf("%d",&Q);
    for (int i = 0, u, v; i < Q; i++) {
        scanf("%d%d",&u,&v);
        printf("%d\n", query(u,v));
    }

    return 0;
}

Measured memory_bytes: 18372
#include<iostream>
#include<string>
using namespace std;
int main(){
  string t,h;
  int n,pt=0,ph=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> t >> h;
    if(t==h)pt++,ph++;
    else if(t>h) pt+=3;
    else ph+=3;
  }
  cout << pt << " " << ph << endl;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    ll N;

    cin >> N;

    vector<int> A(N+1),B(N);

    rep(i,0,N+1){
        cin >> A[i];
    }
    rep(i,0,N){
        cin >> B[i];
    }
    ll cnt=0;
    ll re=0;
    rep(i,0,N){
        re=min(A[i],B[i]);
        cnt+=re;
        B[i]-=re;
        re=min(A[i+1],B[i]);
        A[i+1]-=re;
        cnt+=re;
    }
    // rrep(i,N,0){
    //     if(B[i]>A[i+1]){
    //         B[i]-=A[i+1];
    //         cnt+=A[i+1];
    //         A[i+1]=0;
    //         if(A[i] > B[i]){
    //             A[i]-=B[i];
    //             cnt+=B[i];
    //             B[i]=0;
    //         }else{
    //             cnt+=A[i];
    //             A[i]=0;
    //             B[i]-=A[i];
    //         }
    //     }else{
    //         B[i]=0;
    //         cnt+=A[i+1];
    //         A[i+1]-=B[i];
    //     }
    // }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
// ITP1_6_D Matrix Vector Multiplication
import java.io.*;

public class Main {
   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry1 = (br.readLine()).split(" ");
         int n = Integer.parseInt(strAry1[0]);
         int m = Integer.parseInt(strAry1[1]);
         int[][] A = new int[n][m];
         int[] b = new int[m];
         int[] c = new int[n];

         for (int i = 0; i < A.length; i++) {
            String[] strAry2 = (br.readLine()).split(" ");
            for (int j = 0; j < A[i].length; j++) {
               A[i][j] = Integer.parseInt(strAry2[j]);
            }
         }

         for (int i = 0; i < b.length; i++) {
            String str = br.readLine();
            b[i] = Integer.parseInt(str);
         }

         for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < A[i].length; j++) {
               c[i] += A[i][j] * b[j];
            }
         }

         for (int result : c)
            System.out.printf("%d\n", result);
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
}

Measured memory_bytes: 24384
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <numeric>
using namespace std;




//We Love Golf
//*
int main() {

	int k,a,b;

	cin >> k >> a >> b;

	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}

	cout << "NG" << endl;
	return 0;
}
//*/

Measured memory_bytes: 3624
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$A = $key->A[0];
$sum=0;
foreach($key->X[0] as $v) {
  $l[]=$v;
  $sum+=$v;
  $s[]=$sum;
}
$sum=0;
$min=999999999999;
for($i=$A-1;$i>0;$i--) {
  $sum+=$l[$i];
  $ara[]=$sum;
  $min=min(abs($s[$i-1]-$sum),$min);
}
printf("%d\n",$min);


Measured memory_bytes: 119020
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
#define KMAX 100000
int parent(int i){
  return i/2;
}
int left (int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

int main(){
int n,l,r,root;
int i,j;
int Key[KMAX+1];

  scanf("%d",&n);

  for(i=1;i<=n;i++) {
    scanf("%d",&Key[i]);
}
  for(i=1;i<=n;i++) {
    printf("node %d: key = %d, ",i,Key[i]);
    if(parent(i)>=1) printf("parent key = %d, ",Key[parent(i)]);
    if(left(i)<=n) printf("left key = %d, ",Key[left(i)]);
    if(right(i)<=n) printf("right key = %d, ",Key[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int n;
long long k;
char s[105];
int main() {
    scanf(" %s%lld",s+1,&k);
    n = strlen(s+1);
    int r = 0;
    for(int i=1;i<=n;i++) {
        if(s[i]=='1') r = i;
        else break;
    }
    if(k<=r) printf("1");
    else printf("%c",s[r+1]);
}


Measured memory_bytes: 256
/**
  @file b.cpp
  @title B - Power Socket
  @url https://atcoder.jp/contests/abc139/tasks/abc139_b
**/

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

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

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

  int ans = 0;
  while ((A - 1) * ans + 1 < B) {
    ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>

using namespace std;

int main(){
  int a;
  cin >> a;
  
  int n;
  priority_queue<int, vector<int>, greater<int>> q;
  for (int i =0;i<a;i++){
    cin >> n;
    q.push(n);
  }

  while(-1){
    int s = q.top();
    priority_queue<int, vector<int>, greater<int>> p;
    p.push(s);
    q.pop();
    while(!q.empty()){
      q.pop();
      if (q.top() % s > 0) p.push(q.top() % s);
    }
    q.swap(p);
    if(q.size() == 1) break;
  }
  cout <<q.top()<<endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n-1],b[n-1],w[n-1];
    vector<vector<pair<int,int>>>pas(n);
    for(int i=0;i<n-1;i++){
        cin>>a[i]>>b[i]>>w[i];
        pas[a[i]-1].push_back(make_pair(b[i]-1,w[i]));
        pas[b[i]-1].push_back(make_pair(a[i]-1,w[i]));
    }
    int color[n];
    color[0]=0;
    int check[n]={};
    queue<int>q;
    q.push(0);
    check[0]=1;
    while(q.size()){
        int f=q.front();
        q.pop();
        for(int i=0;i<pas[f].size();i++){
            if(check[pas[f][i].first]==0){
                q.push(pas[f][i].first);
                check[pas[f][i].first]=1;
                if(pas[f][i].second%2)color[pas[f][i].first]=1-color[f];
                else color[pas[f][i].first]=color[f];
            }
        }
    }
    for(int i=0;i<n;i++)cout<<color[i]<<endl;
    return 0;
}

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

using namespace std;

#define x first
#define y second
typedef long long ll;
const int N = 100010;
const int mod = 1000000007;
const int oo = 1e9;
const int base = 27;
typedef pair<int,int> pii;

ll k , a , b;

int main() {
  cin >> k >> a >> b;
  ll ans = 1;
  if(b <= a+1){
    printf("%lld\n",k+1);
    return 0;
  }else{
    if(k >= a-1){
      ans = a;
      k -= a-1;
      ans = ans+(1ll*b-a)*(k/2);
      k %= 2;
    }
    ans += k;
    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 256
def s()
  gets()
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end

n = i()
as = []
n.times{
  as << s()
}
res = [0,0,0,0,0]
n.times{|i|
  if (as[i][0] == "M")
    res[0] += 1
  elsif (as[i][0] == "A")
    res[1] += 1
  elsif (as[i][0] == "R")
    res[2] += 1
  elsif (as[i][0] == "C")
    res[3] += 1
  elsif (as[i][0] == "H")
    res[4] += 1
  end
}
sum = 0
3.times{|i|
  (i+1).upto(3){|j|
    (j+1).upto(4){|k|
      sum += res[i]*res[j]*res[k]
    }
  }
}
puts sum

Measured memory_bytes: 9852
using System;

namespace Volume0_0002_DigitNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                String input = Console.ReadLine();

                if (input == null) break;

                String[] inputs = input.Split(' ');
                int a = Convert.ToInt32( inputs[0] );
                int b = Convert.ToInt32( inputs[1] );

                Console.WriteLine((a + b).ToString().Length);
            }
        }
    }
}

Measured memory_bytes: 5696
var
i,j,c,d,e,b,n:longint;
a:array[1..100000] of longint;
begin
readln(n);
n:=n*2;
for i:=1 to n do
read(a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then begin d:=a[i];a[i]:=a[j];a[j]:=d;end;
i:=1;
e:=0;
while(i<=n) do
begin
e:=e+a[i];
i:=i+2;
end;
writeln(e);
end.

Measured memory_bytes: 128
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll n,m;
  cin>>n>>m;
  cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
//  #ifndef ONLINE_JUDGE
//       // for getting input from input.txt
//      freopen("input.txt", "r", stdin);
// //     // for writing output to output.txt
// //     freopen("output1.txt", "w", stdout);
//  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x7fffffff
#define INFL 0x7fffffffffffffffLL

vector<pair<ll,ll>> a(2000);
ll n;
ll dp[2000][2000];

ll calc(ll x, ll y) {
	int idx = x + ((n-1) - y);
	if (idx == n) return 0;
	if (dp[x][y]!=0) return dp[x][y];
	ll ans = max( abs(a[idx].second-x)*a[idx].first + calc(x+1 , y) , abs(a[idx].second-y)*a[idx].first + calc(x , y-1) );
	dp[x][y] = ans;
	return ans; 
}

int main() {
	ll		b,c,i,j,k,m,x,y,ans = 0;
	string	str;

	cin >> n;

	for(i=0;i<n;i++) {
		cin >> j;
		a[i] = make_pair(j , i);
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	x=0;
	y=n-1;

	ans = calc(x , y);

	cout << ans << endl;

}


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

int main(){
  int n,a,b,ans;

  cin >> n >> a >> b;
 
  ans=n*a;

  if(ans<b){
    cout << ans << '\n';
  }else{
    cout << b << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

ll AN(ll A, ll N){
  if (N == 0){
    return 1;
  }else{
    if (N % 2 == 0){
      return AN(A * A % nmax, N / 2) % nmax;
    }else{
      return A * AN(A * A % nmax, N / 2) % nmax;
    }
  }
}

ll nCk(ll N, ll K){
  ll ans = 1;
  for (ll i = 0; i < K; i++){
    ans *= N - i; ans %= nmax;
    ans *= AN(i + 1, nmax - 2); ans %= nmax;
  }
  return ans;
}

int main(){
  ll N, M, K; cin >> N >> M >> K;

  ll num = nCk(N * M - 2, K - 2);

  vector <ll> dx(N), dy(M);
  for (ll i = 1; i < N; i++){
    dx[i] = M * M * (N - i) * i % nmax;
    dx[i] += dx[i - 1]; dx[i] %= nmax;
  }

  for (ll i = 1; i < M; i++){
    dy[i] = N * N * (M - i) * i % nmax;
    dy[i] += dy[i - 1]; dy[i] %= nmax;
  }
  ll ans = dx[N - 1] + dy[M - 1]; ans %= nmax;
  ans *= num; ans %= nmax;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
 int W,H,x,y,r;

 scanf("%d",&W);
 scanf("%d",&H);
 scanf("%d",&x);
 scanf("%d",&y);
 scanf("%d",&r);

 if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0){printf("Yes\n");}
 else{printf("No\n");}
 return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define N 210000
using namespace std;
int  a[N][2],b[N][2],i,j,n,m,k,l,d,num,hea1,hea2,tail1,tail2;
long long ans,sum1,sum2;
struct sl
{
	int x,h;
} t[N];
bool cmp(sl x,sl y)
{
	return x.x<y.x;
}
int main()
{
	scanf("%d%d%d",&n,&d,&num);
	for (i=1;i<=n;i++)
	scanf("%d%d",&t[i].x,&t[i].h);
	sort(t+1,t+n+1,cmp);
	hea1=1;hea2=1;
	for (i=n;i>=1;i--)
	{
		while (hea1<=tail1&&a[hea1][0]>=t[i].x) sum1+=a[hea1++][1];
		while (hea2<=tail2&&b[hea2][0]>=t[i].x) sum2+=b[hea2++][1];
		if (sum1-sum2>=t[i].h) continue;else
		{
			t[i].h-=(sum1-sum2);
			int x=t[i].h/num;
			if (t[i].h%num) x++;
			ans+=x;
			a[++tail1][0]=t[i].x;a[tail1][1]=x*num;
			b[++tail2][0]=t[i].x-(2*d+1);b[tail2][1]=x*num;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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 (b<a) { a=b; return 1; } return 0; }

int sum,A,H,N;

int main(){
    cin>>H>>N;
    rep(i,N){
        cin>>A;
        sum+=A;
    }
    if(sum>=H)out("Yes");
    else out("No");
    
}

Measured memory_bytes: 256