akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
using namespace std;
const int mod=1000000007;
typedef long long ll;
typedef pair<int,int> P;

//*---mint---*/
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  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){ (x*=a.pow(mod-2).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 operator/(const mint& a)const{ return mint(*this) /= a;}
  mint pow(ll t) const {
    if(!t) return 1;
    mint res = pow(t/2);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
struct comb {
  vm f, g;
  comb(){}
  comb(int mx):f(mx+1),g(mx+1) {
    f[0] = 1;
    rep(i,1,mx) f[i] = f[i-1]*i;
    g[mx] = f[mx].pow(mod-2);
    for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
  }
  mint c(int a, int b) {
    if (a < b) return 0;
    return f[a]*g[b]*g[a-b];
  }
} c(3e6);
//c.c(a,b)=>aCb mod


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,0,n-1)cin >> a[i];

    mint ans = 0;
    sort(a.begin(),a.end());

    rep(i,0,n-1){
        ans += c.c(i,k-1) * a[i];
        // cout << a[i] << " " << c.c(i,k-1) << endl;
    }
    reverse(a.begin(),a.end());
    rep(i,0,n-1){
        ans -= c.c(i,k-1) * a[i];
        // cout << a[i] << " " << c.c(i,k-1) << endl;
    }
    // rep(i,0,n-k){
    //     minus += a[i] * c.c(n-i-1,k-1);
    // }    

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 47488
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long N,KK;
    cin>>N>>KK;
    vector<long long> vec(N);
    for(long long i=0;i<N;i++){
        cin>>vec.at(i);
    }
    long long ans=-1000000000;
    vector<long long> check(0);
    vector<long long> memo;
    vector<long long> memomemo(0);
    for(long long K=0;K<=KK;K++){
    for(long long i=0;i<=K;i++){
        check=memomemo;
        if(i%2!=K%2 || i>N){
            continue;
        }
        for(long long L=0;L<=N;L++){
            if(L>0)check.push_back(vec.at(L-1));
            memo=check;
            for(long long R=0;R<=N;R++){
                long long x=0;
                if(R>0)check.push_back(vec.at(N-R));
                if(L+R>N || L+R<i || L+R>K || L+R+L+R-i>K){
                    continue;
                }
                //L+R-iが返す量
                //iが残る量
                sort(check.begin(),check.end());
                reverse(check.begin(),check.end());
                for(long long j=0;j<i;j++){
                    x+=check.at(j);
                    //cout<<L<<" "<<R<<" "<<check.at(j)<<endl;
                }
                ans=max(ans,x);
            }
            check=memo;
        }
    }
    }
    cout<<ans<<endl;
}

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

int main(void) 
{
   int n;
   cin >> n;
   int r = n%10;
   if(r == 3) cout << "bon" << endl;
   else if((r == 0 || r == 1 || r== 6 ||r == 8)) cout << "pon" <<endl;
   else cout << "hon" << endl;
   return 0;
}

Measured memory_bytes: 3636
n,k=map(int,input().split())
a=list(map(int,input().split()))

L=[0]
for i in range(n):
  L.append(L[i]+a[i])

L2=[0]
for i in range(n):
  L2.append(L2[i]+max(0,a[i]))

ans=[]
for i in range(n-k+1):
  x=L[i+k]-L[i]
  y=L2[n]-L2[i+k]+L2[i]
  ans.append(max(y,x+y))
print(max(ans))

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

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

typedef long long ll;

const int INF=1e9+7;

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	ll prev;
	cin>>prev;
	ll ans=0;
	rep(i,n-1){
		ll x;
		cin>>x;
		if((x-prev)*a>=b)ans+=b;
		else ans+=(x-prev)*a;
		prev=x;
	}
	cout<<ans<<endl;
}


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

int main() {
    int n, k, s = 0; // a and b robot, size, sum

    cin >> n >> k;

    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;

        // 4 > 3
        s += min(k - a, a);
    }

    cout << s * 2 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_N 1000
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N - 1));
  queue<int> que;
  rep(i, N) {
    rep(j, N - 1) {
      cin >> A[i][j];
      A[i][j]--;
    }
    reverse(A[i].begin(), A[i].end());
    que.push(i);
  }
  que.push(-1);

  int Ans = N * (N - 1) / 2;
  vector<bool> seen(N + 1);
  int Num = 0;
  while (!que.empty()) {
    auto M = que.front();
    que.pop();
    if (M == -1) {
      if (Num == 0) {
        Ans = -1;
        break;
      }
      Ans -= (Num - 1);
      if (que.size() == 0) break;
      seen.assign(N + 1, false);
      Num = 0;
      que.push(-1);
      continue;
    }
    if (seen[M]) continue;
    int X = A[M].back();
    if (seen[X]) continue;
    int Y = A[X].back();
    if (Y == M) {
      seen[M] = true;
      seen[X] = true;
      A[M].pop_back();
      if (A[M].size() != 0) que.push(M);
      A[X].pop_back();
      if (A[X].size() != 0) que.push(X);
      Num++;
    }
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 4224
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n, m;
vi adj[100010], rev_adj[100010];
int memo[100010];

int dp(int at)
{
    if (memo[at] != -1) return memo[at];
    int ans = 0;
    for (auto u : rev_adj[at]) {
        ans = max(ans, dp(u) + 1);
    }
    return memo[at] = ans;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    memset(memo, -1, sizeof(memo));
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a - 1].PB(b - 1);
        rev_adj[b - 1].PB(a - 1);
    }
    for (int i = 0; i < n; i++) {
        if (adj[i].empty() && memo[i] == -1) {
            dp(i);
        }
    }
    int mx = 0;
    for (auto u : memo) {
        mx = max(mx, u);
    }
    cout << mx << endl;

    return 0;
}

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

using namespace std;

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

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

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

	ll a[3];
	rep(i, 3) cin >> a[i];

	ll b[3];
	rep(i, 3) cin >> b[i];

	vector<ll> dp(n+1, 0);
	dp[0] = n;
	
	rep(i, 3){
		rep(j, n+1) {
			if(j-a[i] >= 0) chmax(dp[j], dp[j-a[i]] + b[i] - a[i]); 
		}
	}

	ll m = 0;
	rep(j, n+1) chmax(m, dp[j]);

	vector<ll> dp2(m+1, 0);
	dp2[0] = m;

	rep(i, 3){
		rep(j, m+1){
			if(j-b[i] >= 0) chmax(dp2[j], dp2[j-b[i]] + a[i] - b[i]);
		}
	}

	ll ans = 0;
	rep(j, m+1) chmax(ans, dp2[j]);
	cout << ans << endl;
}


Measured memory_bytes: 198416
#include <iostream>

using namespace std;
long long i,n,nr;
char s[55];
int main()
{
    cin>>n;
    cin>>s;
    for(i=2;i<n;i++)
    {
        if(s[i]=='C' && s[i-1]=='B' && s[i-2]=='A')
            nr++;
    }
    cout<<nr;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
#include <cstdlib>

using namespace std;

int N,M;
multiset<int> s;
pair<int,int> rec[100005];

inline void output()
{
	long long ans=0;
	for (int i=1; i<=N; i++)
	{
		set<int>::iterator it=s.lower_bound(0);
		ans+=*it;
		s.erase(it);
	}
	cout << ans;
	exit(0);
}

int main()
{
	cin >> N >> M;
	for (int i=1; i<=N; i++)
	{
		int A;
		cin >> A;
		s.insert(A);
	}
	for (int i=1; i<=M; i++) cin >> rec[i].second >> rec[i].first;
	sort(rec+1,rec+M+1,greater< pair<int,int> >());
	for (int i=1; i<=M; i++)
	{
		while (rec[i].second--)
		{
			set<int>::iterator it=s.lower_bound(0);
			if (*it>=rec[i].first) output();
			else 
			{
				s.erase(it);
				s.insert(rec[i].first);
			}
		}
	}
	output();
	return 0;
}

Measured memory_bytes: 5760
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

p1000 = (function () {
	var ary = [];
	for (var i = 2; i <= 1000; i++) {
		var is_prime = true;
		for (var j in ary) {
			if (i % ary[j] === 0) {
				is_prime = false;
				break;
			}
		}
		if (is_prime) ary.push(i);
	}
	return ary;
}) ();

p1000000 = (function () {
	var ary = [];
	for (var i = 1001; i <= 1000000; i++) {
		var is_prime = true;
		for (var j in p1000) {
			if (i % p1000[j] === 0) {
				is_prime = false;
				break;
			}
		}
		if (is_prime) ary.push(i);
	}
	return ary;
}) ();

prime = p1000.concat(p1000000);

require('fs').readFileSync(config.input, 'ascii')
	.trim()
	.split(config.newline)
	.forEach(function (line) {
		var n = parseInt(line);
		console.log(prime.filter(function (x) { return x <= n; }).length);
	})
	;

Measured memory_bytes: 33312
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> a(N);
  for(auto& t : a) cin >> t;
  sort(a.begin(), a.end());
  vector<int> used(N, 0);
  int res = 0;
  for(int target = (1<<30);target >= 2;target /= 2){
    int low = 0, high = N-1;
    while(true){
      while(low < N && used[low]) ++low;
      while(high >= 0 && used[high]) --high;
      if(low >= high) break;
      long long sum = a[low] + a[high];
      if(sum == target){
        ++res;
        used[low] = used[high] = 1;
      } else if(sum < target) {
        ++low;
      } else {
        --high;
      }
    }
  }
  cout << res << endl;
}

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

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] s2 = ReadLine().Split(' ').Select(int.Parse).ToArray();
            WriteLine(
                s[0] == s2[0]-1 && s2[1] == 1 ? 1:0
                );
        }
    }
}

Measured memory_bytes: 13268
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

N = int(input())
S = set(input().split())
if len(S) == 3:
    print("Three")
else:
    print("Four")
 


Measured memory_bytes: 7880
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;


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

	vector<int> arr(n);

	vector<int> sss(200001);
	//sss = { 0 };

	for (int i = 0; i < n; i++) cin >> arr[i];

	for (int i = 0; i < n; i++)	sss[arr[i]]++;
	
	int count = 0;

	sort(sss.begin(), sss.end(),greater<>());
	
	int ball=0;
	for (int i = 0; i < 200001; i++) {
		if (sss[i] != 0) count++;
		if (count > k) {
			ball = ball + sss[i];
		}

	}
	
	cout << ball << endl;
	
	return 0;
}

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

using namespace std;

int main()
{
  int m, n[2];
  while(cin >> m >> n[0] >> n[1], m || n[0] || n[1]){
    int P[200];
    for(int i = 0; i < m; i++) cin >> P[i];
    int idx = n[0];
    for(int i = n[0]; i <= n[1]; i++){
      if(P[i-1] - P[i] >= P[idx-1] - P[idx]) idx = i;
    }
    cout << idx << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <float.h>
using namespace std;


int main() {
	unsigned int n, x, min, count = 0, a[100];
	cin >> n >> x;
	for (unsigned int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	min = a[0];
	x -= a[0];
	count++;
	for (unsigned int i = 1; i < n; ++i) {
		if (a[i] < min) min = a[i];
		x -= a[i];
		count++;
	}
	while (x >= min) {
		x -= min;
		count++;
	}
	cout << count << endl;
	return 0;
}


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

int main() {
    int r, c; cin >> r >> c;
    int res_chart[r + 1][c + 1] = {};
    
    int all_sum = 0;
    // get input and calc row sum
    for (int row = 0; row < r; ++row) {
        int row_sum = 0;
        for (int col = 0; col < c; ++col) {
            int val; cin >> val;
            row_sum += val;
            res_chart[row][col] = val;
        }
        res_chart[row][c] = row_sum;
        all_sum += row_sum;
    }
    // calc col sum
    for (int col = 0; col < c; ++col) {
        int col_sum = 0;
        for (int row = 0; row < r; ++row) {
            col_sum += res_chart[row][col];
        }
        res_chart[r][col] = col_sum;
    }
    res_chart[r][c] = all_sum;
    
    // output
    for (int row = 0; row < r + 1; ++row) {
        for (int col = 0; col < c; ++col) {
            cout << res_chart[row][col] << " ";
        }
        cout << res_chart[row][c] << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[200005];
vector<vector<int>> d(50);
long long dp[50];

int main() {
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  int tmp;
  tmp =  (h2*60 + m2) -(h1*60 + m1) -k; 
 
  cout << tmp << endl;
  
 }

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
	
	public static class Pair{
		int val;
		int i;
		int j;
		public Pair(int val, int i, int j) {
			this.val = val;
			this.i = i;
			this.j = j;
		}
	}
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//StringTokenizer st = new StringTokenizer(br.readLine());
		
		//int N = Integer.parseInt(st.nextToken()); int W = Integer.parseInt(st.nextToken());
		
		String s = br.readLine(); String t = br.readLine();
		int slen = s.length(); int tlen = t.length();
		
		int[][] dp = new int[slen+1][tlen+1];
		for(int i=0; i<=slen; i++) {
			dp[i][0] = 0;
		}
		for(int j=0; j<=tlen; j++) {
			dp[0][j] = 0;
		}
		
		for(int i=1; i<=slen; i++) {
			for(int j=1; j<=tlen; j++) {
				if(s.charAt(i-1)==t.charAt(j-1)) {
					dp[i][j] = dp[i-1][j-1]+1;
				}else {
					dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
				}
			}
		}
		
		String ans = "";
		int i = slen; int j= tlen;
		while(true) {
			if(s.charAt(i-1)==t.charAt(j-1)) {
				ans = s.charAt(i-1) + ans;
				i--; j--;
			}else {
				if(dp[i-1][j] > dp[i][j-1]) {
					i--;
				}else {
					j--;
				}
			}
			if(i==0 || j==0) {
				break;
			}
		}
		System.out.println(ans);
//		Pair[][] dp = new Pair[slen+1][tlen+1];
//		dp[0][0] = new Pair(0, 0, 0);
//		
//		for(int i=0; i<slen; i++) {
//			for(int j=0; j<tlen; j++) {
//				if(s.charAt(i)==t.charAt(j)) {
//					if(dp[i+1][j+1]==null) dp[i+1][j+1] = new Pair(0, 0, 0);
//					if(dp[i][j].val+1 > dp[i+1][j+1].val) {
//						dp[i+1][j+1] = new Pair(dp[i][j].val+1, i, j);
//					}
//				}
//				if(dp[i+1][j]==null) dp[i+1][j] = new Pair(0, 0, 0);
//				if(dp[i][j+1]==null) dp[i][j+1] = new Pair(0, 0, 0);
//				if(dp[i][j].val > dp[i+1][j].val) {
//					dp[i+1][j] = new Pair(dp[i][j].val, i, j);
//				}
//				if(dp[i][j].val > dp[i][j+1].val) {
//					dp[i][j+1] = new Pair(dp[i][j].val, i, j);
//				}
//			}
//		}
//		
//		Pair ans = new Pair(0, 0, 0);
//		for(int i=0; i<=slen; i++) {
//			for(int j=0; j<tlen; j++) {
//				ans = new Pair(Math.max(ans.val, dp[i][j].val), i, j);
//			}
//		}
//		System.out.println(ans);
	}

}


Measured memory_bytes: 87032
n, mm, q = map(int,input().split())
a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
import itertools
td = []
ttd = []

m = []
for i in range(1,mm+1):
    m.append(i)

s = list(itertools.combinations_with_replacement(m, n))
for j in range(len(s)):
    for i in range(q):
        if s[j][b[i]-1] - s[j][a[i]-1] == c[i]:
            td.append(d[i])
    ttd.append(sum(td))
    td = []
if ttd==[]:
    print(0)
else:
    print(max(ttd))

Measured memory_bytes: 25360
h, w, n = map(int,input().split())

xy_pos = dict()

for i in range(n):
    a, b = map(int, input().split())
    for k in range(-2,1):
        for l in range(-2,1):
            x = (a-1) + k
            y = (b-1) + l
            if (0 <= x <=(h-1)-2) and (0 <= y <=(w-1)-2):
                xy = str(x) + "x" + str(y)
                if xy in xy_pos:
                    xy_pos[xy] += 1
                else:
                    xy_pos[xy] = 1

ans = [0]*10                    
for v in xy_pos.values():
    ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans)
for i in range(10):
    print(ans[i])

Measured memory_bytes: 126228
import sys

N = int(input())
A = [int(input()) for _ in range(N)]

if N == 1:
	print(1)
	sys.exit()
A = sorted(A, reverse = True)

t = A[0]
cnt = 1
for i in range(1,N):
	if A[i] < t:
		cnt += 1
		t = A[i]
	
print(cnt)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef int_fast64_t ll;

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<100000, ll, MOD> fact;

ll N, M, ans = 1;
ll th = 1LL<<45;
ll cnt = 1;
char S[200000];

int main() {
    scanf("%lld\n", &N);
    M = N << 1;
    fread_unlocked(S, 1, M, stdin);
    if(S[0] == 'B' && S[M-1] == 'B') {
        bool f = false;
		size_t i = 0;
        while(i < M-1) {
            if(S[i++] == S[i]) f ^= true;
            if(f) {
                ans *= (cnt << 1) - i;
                if(ans > th) ans %= MOD;
            }
            else if(++cnt > N) break;
        }
        if(cnt != N) ans = 0;
        else ans = ((ans % MOD) * fact.fact[N]) % MOD;
    } else ans = 0;
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I H,W,h,w;
  cin >> H >> W >> h >> w;
  I t = H * W - (h * W + w * H - h * w);
  t = min(H*W, t);
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
typedef long long ll;

const int maxn=2e5+5;

using namespace std;

char s[maxn];
int cnt[maxn];
int p,n;
ll ans,poww,now;

int main()
{
    scanf("%d%d",&n,&p);
    scanf("%s",s);
    cnt[0]=1;
    poww=1;
    if(p==2)
    {
        for(int i=n-1;i>=0;i--)
        {
            if((s[i]-'0')%2==0)
                ans+=(i+1);
        }
    }
    else if(p==5)
    {
        for(int i=n-1;i>=0;i--)
        {
            if((s[i]-'0')%5==0)
                ans+=(i+1);
        }
    }
    else
    {
        for(int i=n-1;i>=0;i--)
        {
            now=(now+poww*(s[i]-'0'))%p;
            poww=(poww*10)%p;
            ans+=cnt[now];
            cnt[now]++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 400050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
using namespace std;
int pr[N],su[N],n,k,c;
string s;
int fi[N];
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k>>c>>s;
    int ma = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='x'){
            pr[i] = ma;
        }
       else{
           if(i<=c)pr[i] = 1;
        else pr[i] = 1+pr[i-c-1];
       }
       ma = max(ma,pr[i]);
    }
    ma = 0;
    int ans = 0;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='x'){
            su[i] = ma;
        }
        else{
            if(i+c+1>=n)su[i] = 1;
            else su[i] = 1+su[i+c+1];
        }
        ma = max(ma,su[i]);
    }
    int rp = 0;
    set< int > o;
  for(int i=0;i<n;i++)
    o.insert(i);
    if(su[1]>=k)o.erase(0);
 	if(n>1&&pr[n-2]>=k)o.erase(n-1);
    for(int i=0;i<n;i++){
   // 	cout<<i<<" "<<rp<<"\n";
      	rp = max(rp,i+1);
      	if(pr[i]+su[i+c+1]>=k){
          while(rp<i+c+1){
            o.erase(rp++);
          }
        }
      else continue;
        while(rp+1<n&&pr[i]+su[rp+1]>=k)o.erase(rp++);
        if(rp>=n-1)break;
    }
    for(auto j: o)
        cout<<j+1<<"\n";
        return 0;
}


Measured memory_bytes: 17300
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    rep(i,m){
        cin >> s[i] >> c[i];
    }

    int cnt = 10;
    reps(i,1,n){
        cnt *= 10;
    }
    string num;
    bool flag = true;
    if(n == 1){
        rep(i,10){
            num = to_string(i);
            flag = true;
//            cout << i << " ";
            rep(j,m){
                if(num[s[j]-1] != c[j]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                cout << i << endl;
                return 0;
            }
        }
    }else{
        reps(i,cnt/10,cnt){
            num = to_string(i);
            flag = true;
            //cout << i << " ";
            rep(j,m){
                if(num[s[j]-1] != c[j]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                cout << i << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;


    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String str = s.nextLine();
		
		char[] a = str.toCharArray();
		for(int i = a.length-1; i >= 0; i--) {
			System.out.print(a[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 17124
#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 k;
    cin >> k;
    string s;
    cin >> s;
    int l = s.size();
    if (l <= k) {
        cout << s << endl;
    }
    else {
        cout << s.erase(k) + "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
L, R = map(int, input().split())

ans = 10 ** 9
for i in range(L, R):
    for j in range(i+1, R+1):
        tmp = (i*j)%2019
        if ans > tmp:
            ans = tmp
        if ans == 0:
            break
    else:
        continue
    break
print(ans)

Measured memory_bytes: 3060
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

a_list=[]
for i,j in enumerate(a):
 a_list+=[i+1]*j

inx=0
ans=[0]*w
for i in range(h):
 if i%2==0:
  for j in range(w):
   ans[j]=a_list[inx]
   inx+=1
 else:
  for j in range(w-1,-1,-1):
   ans[j]=a_list[inx]
   inx+=1

 print(*ans)

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

typedef long long LL;
const int N = 101;
const int V = 100001;

LL dp[N][V], w[N], v[N];

int main() {
    // freopen("a.txt", "r", stdin);
    int N, mod = 1e9 + 7;
    string s;
    cin >> N >> s;

    vector<vector<int> > dp(N, vector<int>(N, 0));
    dp[0][0] = 1;
    for(int i = 1; i < N; ++i) {
        if(s[i - 1] == '<') {
            for(int j = 1; j <= i; ++j) {
                dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod;
            }
        }
        else {
            for(int j = i - 1; j >= 0; --j) {
                dp[i][j] = (dp[i][j + 1] + dp[i - 1][j]) % mod;
            }
        }
    }

    int res = 0;
    for(int j = 0; j < N; ++j) {
        res = (res + dp[N - 1][j]) % mod;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 37632
#include<iostream>

using namespace std;
int main()
{
    int x, y; cin >> x >> y;
    if(x < y)
    {
        for (int i = 0; i < y; i++)
        {
            cout << x;
        }
    }
    else 
    {
        for (int i = 0; i < x; i ++)
        {
            cout << y;
        }
    }
}

Measured memory_bytes: 256
T = int(input())

def gcd(a, b):
  if a < b:
    a, b = b, a
  if b == 0:
    return 0
  while a % b:
    a, b = b, a % b
  return b

while T:
  T -= 1
  
  A, B, C, D = map(int, input().split())
  
  if B > A or B > D:
    print("No")
  else:
    p = A - (A - C + B - 1) // B * B
    r = D % B
    g = gcd(r, B - r)
    if p < 0:
      print("No")
    elif r == 0 or (C - r - p + g) // g * g + p - B + r >= 0:
      print("Yes")
    else:
      print("No")

Measured memory_bytes: 3064
object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)

		val a=Array.fill(5)(s.nextInt).sortBy(i=>(i+9)%10)

		for(i<-1 to 4)
			a(i)=(a(i) + 9) / 10 * 10

		println(a.sum)
	}
}

Measured memory_bytes: 25560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String o = sc.next();
		String e = sc.next();
		StringBuffer sb = new StringBuffer();
		
		int i;
		for(i = 0; i < o.length(); i++) {
			sb.append(o.charAt(i));
			if(i < e.length()) {
				sb.append(e.charAt(i));
			}
		}
		
		System.out.println(sb);

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<(n+1)/2;i++)ans++;
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement


def main():
    n, m, q = map(int, input().split())
    abcd = []
    for i in range(q):
        tmp = list(map(int, input().split()))
        tmp[0] -= 1
        tmp[1] -= 1
        abcd.append(tmp)
    # abcd.sort(key=lambda x: x[3], reverse=True)

    ans = 0
    for comb in combinations_with_replacement(range(1, m+1), n):
        # print(comb)
        tmp = 0
        for a, b, c, d in abcd:
            if comb[b]-comb[a] == c:
                tmp += d
        if ans < tmp:
            ans = tmp
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 67852
S = input()[::-1]

X = ['dream', 'dreamer', 'erase', 'eraser']
X = [s[::-1] for s in X]
i = 0
while i < len(S):
  if i+5 <= len(S) and S[i+2] == 'e':
    if S[i:i+5] == X[0]:
      i += 5
    else:
      print('NO')
      break
  elif i+7 <= len(S) and S[i+2] == 'm':
    if S[i:i+7] == X[1]:
      i += 7
    else:
      print('NO')
      break
  elif i+5 <= len(S) and S[i+2] == 'a':
    if S[i:i+5] == X[2]:
      i += 5
    else:
      print('NO')
      break
  elif i+6 <= len(S) and S[i+2] == 's':
    if S[i:i+6] == X[3]:
      i += 6
    else:
      print('NO')
      break
  else:
    print('NO')
    break
else:
  print('YES')


Measured memory_bytes: 3188
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Linq.Expressions;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, M) = Slice2<int>();
            var ss = new bool[M, N];
            for (var i = 0; i < M; ++i)
            {
                var ksi = Sarray();
                for (var j = 1; j < ksi.Length; ++j)
                    ss[i, ksi[j] - 1] = true;
            }
            var pi = Sarray();
            var uLim = 1 << N;
            var cnt = 0L;
            for (var i = 0; i < uLim; ++i)//スイッチの状態
            {
                var ons = new long[M];
                for (int t = i, j = 0; 0 < t; t >>= 1, ++j)
                {
                    if ((t & 1) != 0)
                    {
                        for (var m = 0; m < M; ++m)
                            if (ss[m, j]) ++ons[m];
                    }
                }
                var flg = true;
                for (var m = 0; m < M; ++m)
                    if (ons[m] % 2 != pi[m]) flg = false;
                if (flg) ++cnt;
            }
            WriteLine(cnt);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28380
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int  n;
	cin>>n;
	int c=0;
	for(int i=1;i<10;i++)
	{
		if((n%i==0)&&(n/i <10))
		{
			cout<<"Yes";
			c=1;
			break;
		}
	}
	if(c==0)
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		List<Integer> wordLength = new ArrayList<Integer>();
		while(stdIn.hasNext()){
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			int c = a + b;
			wordLength.add(Integer.toString(c).length());
		}
		for(int i:wordLength){
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 12000
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

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

P = (A1-B1)*T1
Q = (A2-B2)*T2

if P+Q == 0:
	print("infinity")
	exit()
elif 0 <= P*(P+Q):
	print(0)
	exit()
else:
	a = abs(P)
	b = abs(P - (2*P+Q))
	n = a//b
	if a%b:
		print(2*n+1)
	else:
		print(2*n)


Measured memory_bytes: 10528
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    deque<int> a(3 * n);
    for (int i = 0; i < 3 * n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll ans = 0;
    while(a.size() >= 3){
        a.pop_back();
        a.pop_front();
        ans += a.back();
        a.pop_back();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int height, width;
		int h, w;

		height = sc.nextInt();
		width = sc.nextInt();

		while(height != 0 || width != 0){
			for(w = 0;w < width;w++){
				System.out.print("#");
			}
			System.out.println();
			for(h = 0;h < height - 2;h++){
				System.out.print("#");
				for(w = 0;w < width - 2;w++){
					System.out.print(".");
				}
				System.out.println("#");
			}
			for(w = 0;w < width;w++){
				System.out.print("#");
			}
			System.out.println("\n");
			height = sc.nextInt();
			width = sc.nextInt();
		}
	}
}


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

const int mod = 1e9+7;
const int N = 10000003;
int prime[N];
unordered_map <ll, ll> max_map;

ll power(ll x, ll y){
	x %= mod;
	if(y == 0) return 1;
	if(y == 1) return x;
	ll num = power(x,y/2) % mod;
	if(y%2 ==  0) return (num*num)%mod;
	else return (((num*num)%mod)*x)%mod;
}

void solve(){
 	
 	int d;
 	cin >> d;
 	if(d == 25) cout << "Christmas";
 	if(d == 24) cout << "Christmas Eve";
 	if(d == 23) cout << "Christmas Eve Eve";
 	if(d == 22) cout << "Christmas Eve Eve Eve";

	return;
}


int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		solve();
		// cout << "\n";
	}

	// cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 1000000005
#define NIL -1
ll mod = 1e9+7;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int E_cnt[n] = {0}, W_cnt[n] = {0};
    if(s[0] == 'E'){
        E_cnt[0] = 1;
        W_cnt[0] = 0;
    } else if(s[0] == 'W'){
        W_cnt[0] = 1;
        E_cnt[0] = 0;
    }
    for(int i = 1; i < n; i++){
        if(s[i] == 'E'){
            E_cnt[i] = E_cnt[i-1] + 1;
            W_cnt[i] = W_cnt[i-1];
        } else if(s[i] == 'W'){
            W_cnt[i] = W_cnt[i-1] + 1;
            E_cnt[i] = E_cnt[i-1];
        }
    }
    int mn = 3000000;
    mn = min(mn, E_cnt[n-1] - E_cnt[0]);
    for(int i = 1; i < n; i++){
        int cnt;
        cnt = W_cnt[i-1] + E_cnt[n-1] - E_cnt[i];
        mn = min(mn, cnt);
    }
    cout << mn << endl;
}

Measured memory_bytes: 2948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        struct Pair
        {
            public readonly int C;
            public readonly long D;
            public Pair(long[] args)
            {
                C = (int)args[0];
                D = args[1];
            }
        }

        static long Solve(int N, int M, long[] A, Pair[] pairs)
        {
            long[] bests = new long[N];
            Array.Sort(pairs, (a, b) => (b.D.CompareTo(a.D)));
            int i = 0;
            foreach (var pair in pairs)
            {
                for (int j = 0; j < pair.C; ++j)
                {
                    bests[i++] = pair.D;
                    if (i == N) { break; }
                }
                if (i == N) { break; }
            }
            Array.Sort(A);
            long sum = 0;
            for (int j = 0; j < N; ++j) { sum += Math.Max(A[j], bests[j]); }
            return sum;
        }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int N = V[0], M = V[1];
            var A = ReadLongs();
            var pairs = new Pair[M];
            for (int i = 0; i < M; ++i) { pairs[i] = new Pair(ReadLongs()); }
            Console.WriteLine(Solve(N, M, A, pairs));
        }
    }
}


Measured memory_bytes: 31552
import java.io.*;

import java.util.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.math.BigInteger.*;
import static java.lang.Character.*;

class AOJ2010 {
	int points, ace;
	boolean hasTenPointsCard;

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); sc.nextLine();
		while(N-- > 0) {
			char[] s = sc.nextLine().toCharArray();
			char[] t = sc.nextLine().toCharArray();
			ace = 0;
			points = 0;
			hasTenPointsCard = false;
			for(int i = 0; i < s.length; i += 2)
				point(s[i]);

			boolean bust = false;
			boolean bj = false;
			for(int i = 0;; i += 2) {
				if(points == 21 && ace == 1 && hasTenPointsCard) {
					bj = true;
					break;
				}
				if(i == t.length || points > 16 && ace == 0 || points > 17)
					break;

				point(t[i]);

				if(points > 21) {
					bust = true;
					break;
				}
			}
			System.out.println(bj ? "blackjack" : bust ? "bust" : points);
		}
	}
	void point(char c) {
		if(isDigit(c))
			points += c - '0';
		else if(c == 'A') {
			points += 11;
			ace++;
		}
		else {
			points += 10;
			hasTenPointsCard = true;
		}
		while(ace > 0 && points > 21) {
			ace--;
			points -= 10;
		}
	}
}

public class Main {
	public static void main(String... args) {
		new AOJ2010().run();
	}

	public static void debug(Object... os) {
		System.err.println(java.util.Arrays.deepToString(os));
	}
}

class Scanner {
	final java.util.Scanner sc;

	public double nextDouble() {
		return Double.parseDouble(sc.next());
	}

	public Scanner(java.io.InputStream is) {
		this.sc = new java.util.Scanner(is);
	}

	public boolean hasNext() {
		return sc.hasNext();
	}

	public String next() {
		return sc.next();
	}

	public int nextInt() {
		return Integer.parseInt(sc.next());
	}

	public String nextLine() {
		return sc.nextLine();
	}

	public long nextLong() {
		return Long.parseLong(sc.next());
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[n-1]-a[0] << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int gcd(int a, int b) {
	if (a < b)swap(a, b);
	if (a%b == 0)return b;
	else return gcd(a%b, b);
}
signed main() {
	int a, b, c, d, e; cin >> a >> b >> c >> d;
	e = c*d/gcd(c, d);
	cout << b - a - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d) - (b / e - (a - 1) / e))+1 << endl;
	cin >> a;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

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

  priority_queue<ll> a;
  rep (i, 0, n) {
    ll tmp;
    cin >> tmp;
    a.push(tmp);
  }


  rep (i, 0, m) {
    ll tmp = a.top();
    a.pop();
    a.push(tmp / 2);
  }

  ll res = 0;
  while (a.size() != 0) {
    res += a.top();
    a.pop();
  }

  cout << res << endl;
	return 0;
}


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

int main()
{
    std::string s,t;
    int i;
    int j;
    int flag;
    std::cin>> s >> t;
    for (i = 0; i < s.size(); i++) {
        flag = 1;
        for (j=0;j<s.size();j++)
            if (s[(i+j)%s.size()]!=t[j]) {
                flag = 0;
            }
        if (flag) {
            printf("Yes\n");
        return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int dp1[13],dp2[13];
int main(){
    string s;
    cin>>s;
    int n = s.size();
    dp1[0]=1;
    for(int i=1;i<=n;i++){
        memset(dp2,0,sizeof(dp2));
        for(int j=0;j<13;j++){
            if(s[i-1]!='?'){
                int tmp = s[i-1]-'0';
                dp2[(10*j+tmp)%13] += dp1[j];
                dp2[(10*j+tmp)%13] %= mod;
            }else{
                for(int t=0;t<10;t++){
                    dp2[(10*j+t)%13] += dp1[j];
                    dp2[(10*j+t)%13] %= mod;
                }
            }
        }
        swap(dp2,dp1);
    }
    cout<<dp1[5]<<endl;
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;


using namespace std;


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	unordered_map<string, ll>mp;

	tc(t)
	{
		string s;
		cin >> s;

		sort(s.begin(), s.end());

		++mp[s];
	}


	ll res = 0;

	for (auto it : mp)
	{
		res  += it.second * (it.second - 1) / 2 ;
	}

	cout << res << endl;


}

Measured memory_bytes: 10352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var d = p[0];
		var t = p[1];
		var s = (double)p[2];
		Console.WriteLine(d/s>t?"No":"Yes");
	}

	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 27516
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
#define mod 1000000007


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n; ll arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    ll ans=arr[n-1]; int curr=1;
    for(int i=n-2;i>=0;i--){
        if(curr<n-1){
            ans+=arr[i]; curr++;
            if(curr<n-1){
                ans+=arr[i];curr++;
            }
        }
    }
    cout<< ans <<endl;

}


Measured memory_bytes: 5216
#include <iostream>
using namespace std;
#define min(x,y) (x<y)?x:y 
#define max(x,y) (x>y)?x:y

int euclid(int a, int b)
{
	int x = max(a, b);
	int y = min(a, b);
	int re = x % y;
	while (re > 0) {
		x = y;
		y = re;
		re = x % y;
	}

	return y;
}

int main(void)
{
	int A, B;
	cin >> A >> B;
	int gcm = euclid(A, B);
	long long int ans = (long long int)A * B / gcm;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256