akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		long ans = 0;
		long mod = 1000000007;
		long mod2 = 1000000005;

		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		String[] substr = str.split(" ", 0);

		int n = Integer.parseInt(substr[0]);
		int a = Integer.parseInt(substr[1]);
		int b = Integer.parseInt(substr[2]);

		scan.close();
		ans = modPow(2, n, mod) -1;
		ans = ans - conviModPow2(n, a, b, mod, mod2);
		if (ans < 0) {
			ans += mod;
		}
		if (ans < 0) {
			ans += mod;
		}
		if (ans > mod) {
			ans = ans % mod;
		}
		System.out.println(ans);
	}

	static public long conviModPow2(int n, int a, int b, long mod, long mod2)
	{
		long m1 = factorialModPow(a, mod, mod2);
		long m3 = m1 * factorialModPowN2A(b, b-a, mod, mod2) % mod;

		long m2 = factorialModN2A(n, a, mod);
		long m4 = m2 * factorialModN2A(n-a, b-a, mod) % mod;

		m2 = (m1 * m2) % mod;
		m4 = (m3 * m4) % mod;

		return m2+m4;
	}

	static long factorialModN2A (int n, int a, long mod) {
		long[] ar = new long[a];
		for (int i=0; i<a; i++) {
			ar[i] = (long)(n-a+i+1);
		}
		int t = 1;
		int length = ar.length;
		while (t <= length) {
			for (int i=0; i<length; i+=(t<<1)) {
				if (t+i < length) {
					ar[i] = ar[i] * ar[i+t] % mod;
				}
			}
			t = t<<1;
		}
		return ar[0];
	}


	static long factorialModPowN2A (int n, int a, long mod, long mod2) {
		long[] ar = new long[a];
		for (int i=0; i<a; i++) {
			ar[i] = modPow(n-a+i+1, mod2, mod);
		}
		int t = 1;
		int length = ar.length;
		while (t <= length) {
			for (int i=0; i<length; i+=(t<<1)) {
				if (t+i < length) {
					ar[i] = ar[i] * ar[i+t] % mod;
				}
			}
			t = t<<1;
		}
		return ar[0];
	}

	static long factorialModPow (int n, long mod, long mod2) {
		long [] ar = new long[n];
		for (int i=0; i<n; i++) {
			ar[i] = modPow(i+1, mod2, mod);
		}
		int t = 1;
		int length = ar.length;
		while (t <= length) {
			for (int i=0; i<length; i+=(t<<1)) {
				if (t+i < length) {
					ar[i] = ar[i] * ar[i+t] % mod;
				}
			}
			t = t<<1;
		}
		return ar[0];
	}

	public static final long modPow(long x, long n, final long mod) {
	    long sum = 1;
	    while (n > 0) {
	        if ((n & 1) == 1) {
	            sum = sum * x % mod;
	        }
	        x = x * x % mod;
	        n >>= 1;
	    }
	    return sum;
	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,c=0; cin>>n;
  vector<int> p(n),q(n); for(int i=0;i<n;i++) cin>>p[i],q[i]=p[i];
  sort(q.begin(),q.end());
  for(int i=0;i<n;i++) if(p[i]!=q[i]) c++;
  cout<<(c<=2?"YES":"NO");
}

Measured memory_bytes: 3576
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))

    A, count = selectionSort(A, N)

    print(' '.join([str(a) for a in A]))
    print(count)

def selectionSort(A, N):
    count = 0

    for i in range(0, N-1):
        minj = i

        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j

        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            count += 1

    return A, count

if __name__ == '__main__':
    main()

Measured memory_bytes: 7752
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

#define MOD 1000000007

#define int long long

string L;
bool visited[100005][2][2][2] = {};
int dp[100005][2][2][2];
int solve(int now, int kuri, int ok, int one){
	if(now == L.size()){
		if(kuri == 0 && ok == 1 && one == 1) return 1;
		return 0;
	}
	if(visited[now][kuri][ok][one]) return dp[now][kuri][ok][one];
	visited[now][kuri][ok][one] = true;
	int ret = 0;
	if(kuri == 0 && one == 1) ret += 1;
	if(kuri == 0){
		ret += solve(now+1, 0, (L[now] == '0' ? ok : 1), 0); //0,0
		ret += solve(now+1, 1, (L[now] == '0' ? ok : 1), 1); //1,1
		ret += solve(now+1, 0, (L[now] == '1' ? ok : 0), 1)*2; //1,0
	}
	return dp[now][kuri][ok][one] = ret % MOD;
}

signed main(){
	cin >> L;
	reverse(L.begin(), L.end());
	cout << (solve(0, 0, 1, 0)+1)%MOD << endl;
}

Measured memory_bytes: 13696
x = int(input())

y = 200
s = -200
t = -200

a = 0
b = 0

while s < y:
    t = -y
    while t < y:
        if s ** 5 - t ** 5 == x:
            a = int(s)
            b = int(t)
        t += 1
    s += 1

print(a, b)






Measured memory_bytes: 9136
N = list(map(int, list(input())))

if N[1] < N[0]:
  print(N[0] * 111)
elif N[1] > N[0]:
  print((N[0]+1) * 111)
else:
  if N[2] <= N[0]:
    print(N[0] * 111)
  else:
    print((N[0]+1) * 111)



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin >> n;
    long long int r = 1;

    for (int i = 1; i <= n; i++) {
        r *= i;
        r %= 1000000007; 
    }

    
    cout << r;
}

Measured memory_bytes: 3540
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int[] nums = new int[1001];
		for(int i = 2; i <= x; i++) {
			int num = i;
			int warusu = 2;
			while(num > 1) {
				if(num%warusu==0) {
					nums[warusu]++;
					num/=warusu;
				} else warusu++;
			}
		}
		long ans = 1;
		for(int j = 2; j <= 1000; j++) {
			ans = (ans*(nums[j]+1)) % 1000000007;
		}
		System.out.println(ans);
	}
}

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

/* {{{ */
#define PI(N) ((M_PI * (N)) / 180) //角度をラジアンに変換する
#define CL(N) (cout << (N) << endl)
#define DCT(N) (cout << "debug " << (N) << endl)
#define REP(i, N) for (int i = 0; i < (N); i++)
/* }}} */

int main()
{
    int n, t[101], m;

    cin >> n;

    int s = 0;
    REP(i, n){
        cin >> t[i];
        s += t[i];
    }

    cin >> m;

    int sum[101];

    fill(sum, sum + 100, s);

    REP(i, m){
        int p, x;
        cin >> p >> x;
        REP(j, n){
            if (p - 1 == j){
                sum[i] -= t[j];
                sum[i] += x;
            }
        }
    }

    REP(i, m){
        CL(sum[i]);
    }

    return (0);
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
using namespace std;
typedef std::pair<ll, ll> mp;
#define fi first
#define se second
#define MOD 1000000007
inline ll read()
{
	ll x = 0, f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { (x *= 10) += ch - '0'; ch = getchar(); }
	return x * f;
}

const int maxk = 100, mod = 1000000007;
ll fib[maxk], res; int mx;
std::vector<mp> excellent[maxk];

int main() {
	int k = 1;
	fib[0] = fib[1] = 1;
	ll lim = 1000000000000000000;
	while(fib[k] + fib[k - 1] <= lim) {
		++ k;
		fib[k] = fib[k - 1] + fib[k - 2];
	}

 excellent[1].push_back(mp(1, 2));
	for (int i = 2; i <= k; i++)
	{
		for (pair<ll, ll> p : excellent[i-1])
			excellent[i].push_back(mp(p.se, p.fi + p.se));
		excellent[i].push_back(mp(fib[i+1], fib[i+1] + fib[i-1]));
	}

 int T = read();
	while (T--)
	{
		ll x = read(), y = read(); mx = 1, res = 0;
		if (x > y) swap(x, y);
		while (mx+2 <= k && fib[mx+1] <= x && fib[mx+2] <= y) mx++;
		for (pair<ll, ll> p : excellent[mx])
		{
			if (p.fi <= x && p.se <= y)
				(res += (y - p.se) / p.fi + 1) %= MOD;
			if (p.se <= x)
				(res += (x - p.se) / p.fi + 1) %= MOD;
		}
		if (mx == 1) res += x;
		printf("%d %lld\n", mx, res);
	}
}

Measured memory_bytes: 4408
#include <stdio.h>

int main(void){
  int i, j, k, l, q, n;

  scanf("%d", &n);

  int m[n+1][n+1];
  for(i = 0; i < n+1; i++)
    for(j = 0; j < n+1; j++)
      m[i][j] = -1;

  int r[n], c[n];
  for(i = 0; i < n; i++)
    scanf("%d%d", &r[i], &c[i]);

  int p[n+1];
  p[0] = r[0];
  p[n] = c[n-1];
  for(i = 1; i < n+1; i++)
    p[i] = c[i-1];

//matrixChainOrder
   
  for(i = 1; i < n+1; i++)
    m[i][i] = 0;

  for(l = 2; l < n+1; l++){
    for(i = 1; i < n-l+2; i++){
      j = i+l-1;
      m[i][j] = 100000000;
      for(k = i; k < j; k++){
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        if(m[i][j] > q){
          m[i][j] = q;
        }
      }
    }
  }

  printf("%d\n", m[1][n]);
  return 0;
}

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

void solve(long long N, long long K) {
cout<<N-K+1;}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 256
def roll(s, rolllist):
    news = list(s)
    for i in range(6):
        news[i] = s[rolllist[i]]
    return news


rl = {0: [0, 1, 2, 3, 4, 5],
      1: [1, 5, 2, 3, 0, 4],  # N
      2: [2, 1, 5, 0, 4, 3],  # W
      3: [3, 1, 0, 5, 4, 2],  # E
      4: [4, 0, 2, 3, 5, 1],  # S
      5: [5, 4, 2, 3, 1, 0]}
rollz = [0, 3, 1, 4, 2, 5]
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
if not (s1[0] in s2):
    print("No")
    exit()
# t = s2.index(s1[0])
tl = [i for i, x in enumerate(s2) if x == s1[0]]
for t in tl:
    s2 = roll(s2, rl[t])
    ss = s2
    for i in range(6):
        if s1 == ss:
            print("Yes")
            exit()
        ss = roll(ss, rollz)
print("No")


Measured memory_bytes: 5612
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),n,m){

        int yasai[1024]={0};
        for(int i = 0;i < n; i++){
            scanf("%d",&yasai[i]);
        }
        sort(yasai,yasai+n);
        for(int i = n;i >= 0; i-=m){
            yasai[i] = 0;
        }
        int ans=0;
        for(int i = 0;i < n; i++){
            ans += yasai[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1048
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

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

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());

	bool check = false;
	s.size() == t.size() ? check = true : check = false;

	if(check){
		if(s == t){
			cout << "No" <<endl;
			return 0;
		}
	}

	int cnt = min(s.size(), t.size());
	s.size() < t.size() ? check = true : check = false;
	
	for(int i = 0; i < cnt; ++i){
		if(s[i] < t[i]){
			cout<<"Yes"<< endl;	
			return 0;		
		}
		else if(s[i] > t[i]){
			cout << "No" <<endl;
			return 0;
		}
		if(s[i] == t[i] && i == cnt -1 && check){
			cout<<"Yes"<< endl;	
			return 0;		
		}
		else if(s[i] == t[i] && i == cnt -1 && !check){

			cout << "No" <<endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    let pattern = [a * c, a * d, b * c, b * d];
    let ans = pattern.iter().max().unwrap();

    println!("{}", ans);
}


Measured memory_bytes: 2112
h, w, k = gets.split.map(&:to_i)
c = h.times.map {gets.chomp}

ans = 0
(1 << h).times do |i|
    (1 << w).times do |j|
        sum = 0
        h.times do |x|
            next if i[x] == 1

            w.times do |y|
                next if j[y] == 1
                sum += 1 if c[x][y] == ?#
            end
        end
        ans += 1 if sum == k
    end
end

p ans

Measured memory_bytes: 14276
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = null;
		PrintStream out = null;
		try {
			sc = new Scanner(System.in);
			out = System.out;
			exec(sc, out);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			if(out != null) {
				out.close();
			}
			if(sc != null) {
				sc.close();
			}
		}
		System.exit(0);
	}
	public static void exec(final Scanner sc, final PrintStream out) throws Exception{
		final String S = sc.next();
		final String T = sc.next();

		int cnt = 0;
		for(int i=0;i<3;i++) {
			if(S.charAt(i)==T.charAt(i)) {
				cnt++;
			}
		}
		out.println(cnt);

	}
}


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

typedef long long ll;

int main() {
	//code
    int k;
    cin >> k;
    int ans = 0;
    ll num = 0;
    unordered_set<ll> ust;
    bool ok = false;
    while (1)
    {
        num = (num * 10 + 7) % k;
        ++ans;
        if (!num) 
        {
            ok = true;
            break;
        }
        if (ust.find(num) != ust.end())
        {
            break;
        }
        else ust.insert(num);
    }
    if (ok) cout << ans << endl;
    else cout << -1 << endl;
	return 0;
}

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

N = int(input())
A = []
for _ in range(N):
    n = input().rstrip()
    if '.' not in n:
        A.append(int(n) * 10**9)
    else:
        a, b = n.split('.')
        b += '0' * (9 - len(b))
        A.append(int(a + b))
cnt = defaultdict(int)
ans = 0
for i in range(N):
    cnt2 = cnt5 = 0
    while A[i] % 2 == 0:
        A[i] //= 2
        cnt2 += 1
    while A[i] % 5 == 0:
        A[i] //= 5
        cnt5 += 1
    cnt[(cnt2, cnt5)] += 1
for p1, c1 in cnt.items():
    for p2, c2 in cnt.items():
        if p1 > p2:
            continue
        if p1[0] + p2[0] >= 18 and p1[1] + p2[1] >= 18:
            if p1 == p2:
                ans += c1 * (c1 - 1) // 2
            else:
                ans += c1 * c2
print(ans)


Measured memory_bytes: 80320
//sum 3 int
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,s,tmp,sum=0;
char r1,r2,op;
int main(){
	cin>>k>>s;
	for (int i=0;i<=k;i++){
		for (int j=0;j<=k;j++){
			long long tar=s-i-j;
			if (tar>=0 && tar<=k) sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int p[100005],y[100005];
vector<int> v[100005];

signed main()
{
    int N,M;
    cin>>N>>M;
    REP(i,M){
        cin>>p[i]>>y[i]; p[i]--;
        v[p[i]].push_back(y[i]);
    }
    REP(i,N) sort(ALL(v[i]));

    REP(i,M){
        int num=lower_bound(ALL(v[p[i]]),y[i])-v[p[i]].begin()+1;
        printf("%06lld%06lld\n",p[i]+1,num);
    }

}


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

// pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
// gp_hash_table<int, int> table;

using namespace std;

#define vec vector
#define ALL(x) begin(x), end(x)

typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1000 * 1000 * 1000;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector< int > a(4);

    for(int i = 0;i < 4;i++) cin >> a[i];

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

    if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
        cout << "YES\n";
    }else {
        cout << "NO\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int h, w;
	std::cin >> h >> w;
	std::string str[100] = {};
	rep(i, h) {
		std::cin >> str[i];
		str[i] = '#' + str[i];
		str[i].push_back('#');
	}
	rep(i, str[0].length()) {
		std::cout << '#';
	}
	std::cout << std::endl;
	rep(i, h) {
		std::cout << str[i] << std::endl;
	}
	rep(i, str[0].length()) {
		std::cout << '#';
	}
	std::cout << std::endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll N_MAX{ 100001 };
ll N, A[N_MAX], B[N_MAX], C[N_MAX], ans;
int main() {
    cin.sync_with_stdio(0), cin.tie(0);
    cin >> N;
    for(int i{}; i < N; ++i) cin >> A[i];
    for(int i{}; i < N; ++i) cin >> B[i];
    for(int i{}; i < N; ++i) cin >> C[i];
    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);
    for(int i{}; i < N; ++i)
        ans += distance(A, lower_bound(A, A + N, B[i]))
            * (N - distance(C, lower_bound(C, C + N, B[i] + 1)));
    cout << ans << endl;
}


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

int a[510][510],H,W,h,w;
int main()
{
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if (!(H%h)&&!(W%w)) return puts("No"),0;
	puts("Yes");
	a[0][0]=(H/h)*(W/w)+1;
	a[h-1][w-1]=-a[0][0]-1;
	for (int i=0;i<H;i++,puts(""))
	for (int j=0;j<W;j++)
		printf("%d ",a[i%h][j%w]);
	return 0;
}


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

int main() {
   int A,B;
   cin >> A >> B;
   int ans = -1;
   rep(i, 10, 1001){
       if(i*2/25 == A &&  i/10 == B){
           ans = i;
           goto end;
       }
   }
   end:
   cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   string s, ans = "WA";
   cin >> s;
   regex partern(R"(A[a-z][a-z]*C[a-z]*[a-z])");
   if (regex_match(s, partern))
      ans = "AC";
   cout << ans << endl;
   return 0;
}


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

int main() {
    int n, p;
    cin >> n >> p;
    int cnt_odd = 0;
    for (int i=0; i<n; ++i) {
        int a; cin >> a;
        if (a%2) cnt_odd++;
    }
    long long ans;
    if (cnt_odd == 0) {
        if (p == 0) ans = pow(2, n);
        else ans = 0;
    }
    else {
        ans = pow(2, n-1);
    }
    cout << ans << endl;
}

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

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

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}


int main() {
    int n; cin >> n;
    vector<int> v;
    for(int i = 0;i < n;i++){
        int x; cin >> x;
        v.push_back(x);
    }
    ll ans = 0;
    sort(v.begin(),v.end(),greater<int>());
    ans += v[0];
    for(int i = 1;i < n/2;i++){
        ans+=v[i]*2;
    }
    if(n % 2 != 0){
        ans += v[n/2];
    }
    cout << ans;
}




Measured memory_bytes: 4228
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	a := nextInt()
	b := nextInt()

	for i := 1; i <= 3; i++ {
		if i != a && i != b {
			fmt.Printf("%d", i)
			return
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
  
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
  
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT
  
#define sz(x) ((int)x.size())
  
const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int MAXN = 1e5;
#define FILENAME ""
const double eps = 1e-6;
const int maxn = 1001;

ll answer = inf;

ll f1 (ll temp) {
	while (temp % 10 != 0) ++temp;
	return temp;
}

void f (vector <pair<ll, bool>>& a, int k, int sum) {
	if (k == sz(a)) {
		answer = min(answer, (ll) sum);
		return;
	}
	for (int i = 0; i < a.size(); i++) {
		if (!a[i].se) {
			a[i].se = true;
			if (sum == 0 || sum % 10 == 0) {
				f(a, k + 1, sum + a[i].fi);
			}
			else {
				f(a, k + 1, f1(sum) + a[i].fi);
			}
			a[i].se = false;
		}
	}
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("unionday.in", "r", stdin);
    //freopen("unionday.out", "w", stdout);
    vector <pair<ll, bool>> a;
    for (int i = 0; i < 5; i++) {
    	ll x;
    	cin >> x;
    	a.pb(mp(x, false));
    }
 	f(a, 0, 0);
 	cout << answer;
    return 0;
}

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

#define MAX 100000

typedef long long llong; //long long型と同じ意味を持つllog型を定義

/*入力値を入れるための変数*/
int n; //荷物の個数
int k; //トラックの台数
llong T[MAX]; //各荷物の重さ, w_(0)からw_(n-1)までが入っている

/*積むことができる荷物の個数を求める関数
最大積載量P, トラックの台数k*/
int Check(llong P){
	int i = 0; //荷物の番号
	/*全てのトラックに荷物を詰めていく*/
	for( int j = 0; j < k; j++ ){
		llong s = 0; //トラックを変える際に積んでいる積載量はリセットする
		/*j台目のトラックに詰めれるだけ荷物を詰めている*/
		while( s + T[i] <= P ){
			s += T[i]; 
			i++;
			if( i == n ) return n; //n個全ての荷物をトラックに詰めるとその時点で終了
		}
	}
	return i; //何番目の荷物まで詰めれたかを返す
}

/*最も最適な最大積載量Pを求める*/
int Solve(){
	llong left = 0;
	llong right = 100000 * 10000; //計算できる全荷物の最大重量
	llong mid;
	/*最大積載量がmidの時, 
	積める荷物の個数が与えられた荷物の個数より大きいということは最適解はleft側にある.
	逆に小さいとき最適解はright側にある.
	最適解の範囲を絞っていくことで最適解を求める.
	*/
	while( right - left > 1 ){
		mid = ( left + right ) / 2;
		int v = Check(mid); 
		if( v >= n ){
			right = mid; 
		}else{
			left = mid;
		}	
	}
	return right;
}


/*与えられた値を用意した変数に代入*/
int main(void){
	scanf("%d %d\n", &n, &k);
	for( int i = 0; i < n; i++ ){
		scanf("%lld\n", &T[i]);
	}
	llong ans = Solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

const ll INF = 1LL << 30;

int main(){
    ll N;
    cin >> N;
    vll x(N), y(N), h(N);
    rep(i, N){
        cin >> x[i] >> y[i] >> h[i];
    }
    vll temph(N, INF), temph_max(N, INF);
    ll ansh;
    bool f;
    rep(i, 101){
        rep(j, 101){
            f = 1;
            rep(k, N){
                if(h[k]){
                    ansh = h[k] + abs(i - x[k]) + abs(j - y[k]);
                    break;
                }
                ansh = 1;
            }
            rep(k, N){
                if(max(ansh - abs(i - x[k]) - abs(j - y[k]), 0LL) != h[k]){
                    f = 0;
                    break;
                }
            }
            if(f){
                cout << i << " " << j << " " << ansh << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	ll x,y; cin >> x >> y;
	if (x == 0 && y > 0) cout << abs(y) << endl;
	else if (x == 0 && y < 0) cout << abs(y) + 1 << endl;
	else if (y == 0 && x < 0) cout << abs(x) << endl;
	else if (y == 0 && x > 0) cout << abs(x)+1 << endl;
	else if (0 < x && x < y) cout << y-x << endl;
	else if (0 < y && y < x) cout << x-y+2 << endl;
	else if (x*y < 0) cout << abs(abs(x) - abs(y)) + 1 << endl;
	else if (x < 0 && y < x) cout << abs(y) - abs(x) + 2 << endl;
	else cout << y - x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>

#define repd(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}
void even(int n){
	repd(i,1,n+1){
		repd(j,1,n+1){
			if(i+j!=n+1 && i<j){
				cout << i << " " << j << endl;
			}
		}
	}
}

void odd(int n){
	repd(i,1,n+1){
		repd(j,1,n+1){
			if(i+j!=n && i<j){
				cout << i<< " "<< j << endl;
			}
		}
	}
}

int main(){
	//source
	int N=inputValue();
	if(N%2==0){
		cout << (N-2)*N/2 << endl;
		even(N);
	}else{
		cout << ((N-2)*N+1)/2 << endl;
		odd(N);
	}
	return 0;
}


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 n; _f64 alpha; vector<_f64> s;
        while(cin >> n && n != 0) {
            s.resize(n, 0); _rep(i, n) { cin >> s[i]; } alpha = 0;
            _rep(i, n) { alpha += pow(s[i] - accumulate(_all(s), 0.0) / _size(s), 2); }
            alpha = sqrt(alpha / n);
            cout << fixed << setprecision(8) << alpha << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3288
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>

#include <math.h>

using namespace std;

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

		if (n == 0)
		{
			break;
		}

		int* a = new int[n];
		double sum = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			sum += a[i];
		}

		double m = sum / n;

		sum = 0;
		for (int i = 0; i < n; i++)
		{
			sum += (a[i] - m) * (a[i] - m);
		}

		cout << fixed << setprecision(8) << sqrt(sum / n) << endl;

		delete[] a;
		a = 0;
	}
}


Measured memory_bytes: 3276
#include<stdio.h>
int main(void)
{
	int mount[10];
	for(int f1=0;f1<10;f1++){
		scanf("%d",&mount[f1]);
	}
	int mem;
	for(int f1=0;f1<10;f1++){
		for(int f2=0;f2<10;f2++){
			if(mount[f1]>mount[f2]){
				mem=mount[f1];
				mount[f1]=mount[f2];
				mount[f2]=mem;
			}
		}
	}
	for(int f1=0;f1<3;f1++){
		printf("%d\n",mount[f1]);
	}
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1e9  //
#define INFLL 4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define PB(a) push_back(a)
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

//------------------------------------------------------

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    Yes(a <= c && c <= b);

    return 0;
}



Measured memory_bytes: 256
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
#show_flg=True

n,m=MI()
t=1<<n
key=[]
for i in range(m):
    a,b=MI()
    c=0
    for j in LI_():
        c+=1<<j
    key.append((a,c))
inf=float('inf')
dp=[[inf]*(m+1) for _ in range(t)]
#dp[stat][m] # min value using up to m and open stat
dp[0][0]=0

for j in range(1,m+1):
    for i in range(t):
        cost,ck=key[j-1]
        show(i,j,'|',dp[ck|i][j],min(dp[ck|i][j-1],dp[i][j-1]+cost))
        dp[ck|i][j]=min(dp[ck|i][j],dp[ck|i][j-1],dp[i][j-1]+cost)
        dp[i][j]=min(dp[i][j],dp[i][j-1])
        
for i in dp:
    show(*i)

ans=dp[t-1][m] if dp[t-1][m]!=inf else -1
print(ans)


Measured memory_bytes: 150872
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] A = sc.next().toCharArray();
	for(int i = 0; i<5 ; i++){
		System.out.print(A[i]);
	}
	System.out.print(" ");
	for(int i = 6; i<13 ; i++){
		System.out.print(A[i]);
	}
	System.out.print(" ");
	for(int i = 14; i<=18 ; i++){
		System.out.print(A[i]);
	}
  }
}

Measured memory_bytes: 10192
def resolve():
    INF = 10 ** 18
    N, K = map(int, input().split())
    P = list(map(lambda x: int(x) - 1, input().split()))
    C = list(map(int, input().split()))

    cycles = []
    ans = -INF
    for n in range(N):
        loop, score = 0, 0
        t = n
        for i in range(min(N, K)):
            n = P[n]
            score += C[n]
            ans = max(ans, score)
            if n == t:
                loop = i + 1
                break
        cycles.append((loop, score))

    for n in range(N):
        loop, score = cycles[n]
        if loop > 0 and score > 0:
            r = (K - 1) // loop
            nscore = r * score
            for i in range(K - r * loop):
                n = P[n]
                nscore += C[n]
                ans = max(nscore, ans)
    print(ans)



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 74648
<?php
 
fscanf(STDIN, '%d %d %d %d %d', $W, $H, $x, $y, $r);
 
//???????????????0??????
if ($x - $r < 0
    //???????????????????????¢???????¶?
    || $x + $r > $W
    //???????????????0??????
    || $y - $r < 0
    //???????????????????????¢??????????¶?
    || $y + $r > $H) {
    echo 'No';
} else {
    echo 'Yes';
}
 
echo PHP_EOL;

Measured memory_bytes: 15232
#include <cstdio>

int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int x;
        scanf("%d",&x);
        if(x&1)
        {
            printf("first");
            return 0;
        }
    }
    printf("second");
    return 0;
}

Measured memory_bytes: 128
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("YES") if fl else print("NO")
import collections
import math
import itertools
import heapq as hq
import sys

x = ni()
f=False
if x in[3,5,7]:
    f=True
yn(f)


Measured memory_bytes: 9368
#include<iostream>

using namespace std;

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

  if (x == (x%10*100 + x/100 + x/10%10*10)) {
    cout << "Yes" << endl;    
  } else {
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
from itertools import permutations
n = int(input())
l = list(permutations(range(1, n + 1))) 
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
first = 0
second = 0
for i in range(len(l)):
  if(p == l[i]):
    first = i
  if(q == l[i]):
    second = i
print(abs(first - second))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

template <int MOD>
struct Fp
{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD)
    {
        if (val < 0)
            val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept
    {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp &operator+=(const Fp &r) noexcept
    {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp &operator-=(const Fp &r) noexcept
    {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator*=(const Fp &r) noexcept
    {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp &operator/=(const Fp &r) noexcept
    {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp &r) const noexcept
    {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp &r) const noexcept
    {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
    {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
    {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }
};

const int MOD = 1'000'000'007;
using mint = Fp<MOD>;

mint dp[710][2010];

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        a[i] = x + y;
        b[i] = x - y;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ans = max(a[n - 1] - a[0], b[n - 1] - b[0]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9524
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
#define ll long long
#define iiMPQ priority_queue<ii,vector<ii>,greater<ii> >
#define MPQ priority_queue<int,vector<int>,greater<int> >
#define PQ priority_queue<int>
#define iiPQ priority_queue<ii>
#define US unordered_set<int>
#define UMS unordered_multiset<int>
#define UM unordered_map<int>
#define ST stack<int>
#define MS multiset<int>
#define scan(n) cin>>n
#define scann(a,b) cin>>a>>b
#define scannn(a,b,c) cin>>a>>b>>c
#define print(n) cout<<n
#define println(n) cout<<n<<"\n"
#define first fi
#define second se
#define REP(i,n) for(int i=0;i<n;++i)
 
void m1(){
  int n; scan(n);
  ll arr[n+5],cnt[100005];
  ll res = 0;
  memset(cnt,0,sizeof cnt);
  REP(i,n) {
    scan(arr[i]);
    ++cnt[arr[i]];
    res += arr[i];
  }
  int q; scan(q);
  ll b,c;
  REP(i,q){
    scann(b,c);
    res -= cnt[b] * b;
    res += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    println(res);
  }
}
/* 
void m2(){
  int t; scan(t);
  while(t--) m1();
}
*/
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //freopen("in.txt","r",stdin);
  m1();
  //m2();
}

Measured memory_bytes: 5132
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<sstream>

using namespace std;

string IntToString(long long  number){
  stringstream ss;
  ss << number;
  return ss.str();
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int ans = 0, n, k;
  cin >> n >> k;
  string az = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int num[26], check = 0;
  vector<int> abc;
  for(int i = 0; i < 26; i++) num[i] = 0;
  for(int i = 0; i < n; i++){
    string tmp;
    cin >> tmp;
    for(int j = 0; j < 26; j++){
      if(tmp[0] == az[j]){
	num[j]++;
	break;
      }
    }
  }
  for(int i = 0; i < 26; i++){
    if(num[i] != 0){
      check++;
      abc.push_back(num[i]);
    }
  }
  sort(abc.begin(), abc.end(), greater<int>());
  int count = 0, memo = 0;
  while(1){
    for(int i = 0; i < abc.size(); i++){
      if(abc[i] != 0){
	abc[i]--;
	count++;
      }
      if(count == k){
	ans++;
	break;
      }
    }
    if(count != k) break;
    sort(abc.begin(), abc.end(), greater<int>());
    count = 0;
  }
  cout << ans << endl;
}


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

int main() {
    ll N;
    string S;
    cin >> N >> S;
    if (S[0] == 'W') {
        cout << 0 << endl;
        return 0;
    }

    constexpr ll MOD = 1e9 + 7;
    ll ans = 1;
    for (ll i = 1; i <= N; i++) {
        (ans *= i) %= MOD;
    }
    ll line_num = 1;
    for (ll i = 1; i < 2 * N; i++) {
        //Bのとき奇数回、Wのとき偶数回反転させなければならない
        //またlineを残りの数以上伸ばすこともできない
        ll rem = 2 * N - i - 1;
        if (line_num >= rem) {
            //強制的にキャッチ
            if (line_num % 2 != (S[i] == 'B')) {
                //色がダメ
                ans = 0;
            } else {
                (ans *= line_num--) %= MOD;
            }
            continue;
        }
        if (line_num % 2 == (S[i] == 'B')) {
            //ここでキャッチ
            (ans *= line_num--) %= MOD;
        } else {
            //ここから伸ばす
            line_num++;
        }
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    int n;
    cin>>n;
    vi h(n);rep(i,n)cin>>h[i];
    int dp[100005];
    dp[0]=0;dp[1]=abs(h[1]-h[0]);
    rep(i,n-2){
        dp[i+2]=min(dp[i+1]+abs(h[i+2]-h[i+1]),dp[i]+abs(h[i+2]-h[i]));
    }
    cout<<dp[n-1];
}

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

int main()
{
	int n, p;
	int member[50];
	while (cin >> n >> p)
	{
		if (n == 0 && p == 0)break;
		int initP = p;
		int index = 0;
		for (int i = 0; i < n; i++)
		{
			member[i] = 0;
		}

		while (true)
		{
			if (p > 0)
			{
				p--;
				member[index % n]++;
				if (member[index % n] == initP)
				{
					break;
				}
			}
			else
			{
				p += member[index % n];
				member[index % n] = 0;
			}
			index++;
		}
		cout << index % n << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
object Main {
  def main(args: Array[String]): Unit = {
    solve2
  }

  def solve(): Unit = {
    import scala.io.StdIn._
    val c = readLine()
    val str = ("abcdefghijklmnopqrstuvwxyz")

    println(str(str.indexOf(c) + 1))
  }

  def solve2(): Unit = {
    import scala.io.StdIn._
    var c = readChar.toInt
    c = c + 1
    println(c.toChar)
  }
}

Measured memory_bytes: 27200
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	// "strings"
	"math"
)

var (
	n int
	scanner = bufio.NewScanner(os.Stdin)
)

const (
	MAX = 1000000000000
)

func main() {
	scanner.Split(bufio.ScanWords)
	n := scanInt()
	xx := scanInts(n)

	ans := MAX
	for p := 1; p <= 100; p++ {
		hp := 0
		for _, x := range xx {
			hp += (x - p) * (x - p)
		}
		ans = Min(ans, hp)
	}
	fmt.Println(ans)
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func min(n []int) (min, idx int) {
	min = math.MaxInt64
	for i := 0; i < len(n); i++ {
		if n[i] < min {
			min = n[i]
			idx = i
		}
	}
	return
}

func max(n []int) (max, idx int) {
	max = math.MinInt64
	for i := 0; i < len(n); i++ {
		if n[i] > max {
			max = n[i]
			idx = i
		}
	}
	return
}



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

int main() {
    int s;
    cin>>s;
    
    int h = 0, m = 0;
    
    if(s >= 3600) {
        h = s / 3600;
        s = s % 3600;
    }
    
    m = s / 60;
    s = s % 60;
    
    cout<<h<<':'<<m<<':'<<s<<endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
int main() {

  std::string N;
  std::cin >> N;

  if (N[0] == '9' || N[1] == '9') {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
group_target = set(map(int, input().split()))

groupa = {1, 3, 5, 7, 8, 9, 10, 12}
groupb = {4, 6, 9, 11}
groupc = {2}

if group_target.issubset(groupa) or group_target.issubset(groupb):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
N,M = map(int,input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]

def match(ofs_x, ofs_y):
    for ar,br in zip(A[ofs_y:], B):
        if ar[ofs_x : ofs_x + M] != br:
            return False
    return True

for y in range(N-M+1):
    for x in range(N-M+1):
        if match(x,y):
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> v(n), gcdasc(n, 0), gcddesc(n, 0);
  rep(i, 0, n) cin >> v[i];

  int b = v[0];
  gcdasc[0]=b;
  rep(i, 1, n) b = gcdasc[i] = __gcd(v[i], b);

  b = v[n-1];
  gcddesc[n-1]=b;
  repr(i, 0, n-1) b = gcddesc[i] = __gcd(v[i], b);

  int ans = max(gcddesc[1], gcdasc[n - 2]);

  rep(i, 1, n - 1) chmax(ans, __gcd(gcdasc[i - 1], gcddesc[i + 1]));

  cout << ans << endl;
}


Measured memory_bytes: 4504
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        long n = long.Parse(Console.ReadLine());
        long[] l = new long[5] {0,0,0,0,0};
       for(long i = 0; i < n; i ++) {
           string s = Console.ReadLine();
           if(s[0]=='M') l[0] ++;
           if(s[0]=='A') l[1] ++;
           if(s[0]=='R') l[2] ++;
           if(s[0]=='C') l[3] ++;
           if(s[0]=='H') l[4] ++;
       }
       Console.WriteLine(solve(l));
    }
    static long solve(long[] l) {
        long count = 0;
        count += l[0] * l[1] * (l[2]+l[3]+l[4]);
        count += l[0] * l[2] * (l[3]+l[4]);
        count += l[0] * l[3] * l[4];
        count += l[1] * l[2] * (l[3]+l[4]);
        count += l[1] * l[3] * l[4];
        count += l[2] * l[3] * l[4];
        return count;
    }
}

Measured memory_bytes: 13140
#include <iostream>

int main(){
   int A, B, C;
   std::cin >> A >> B >> C;

   if(A!=B && B!=C && C!=A) std::cout << "No" << std::endl;
   else if(A==B && B==C) std::cout << "No" << std::endl;
   else std::cout << "Yes" << std::endl;
   return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    string s;
    cin >> s;
    if(s == "BBB" || s == "AAA"){
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
    return 0;
}

Measured memory_bytes: 256