akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }

    int min = *min_element(data.begin(), data.end());
    int left;
    if (min != 1){
        left = (min + k - 2) / (k - 1);
    }
    else{
        left = 0;
    }
    int right;
    if (min != n){
        right  = (n - min + k - 2) / (k - 1);
    }
    else{
        right = 0;
    }

	cout << left + right << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define loopi(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) loopi(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // #define endl "\n"
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/10;

int popcount(unsigned long long x){
    return __builtin_popcount(x);
    static int dp[66000];
    if(dp[1] == 0){
        for(int i = 0; i < 65536; i++) dp[i] = (i&1) + dp[i>>1];
    }
    int res = 0;
    while(x) res += dp[x&0xffff], x >>= 16;
    return res;
}

int solve(ll s, ll d){
    if(s <= 0 && d >= 0) return __builtin_popcount(-s) + __builtin_popcount(d);
    else if(s >= 0 && d >= 0){
        int j = 0;
        int ans = 0;
        while(s < d){
            if((s>>j&1) && (d>>j&1)){
                s += 1LL<<j;
                d -= 1LL<<j;
                ans += 2;
            } else if((s>>j&1) ^ (d>>j&1)){
                s += 1LL<<j;
                ans ++;
            }
            j++;
        }
        return ans;
    } else return solve(-d,-s);
}

signed main(){
    fastios();
    int N;
    cin >> N;
    rep(i,N){
        ll s,d;
        cin >> s >> d;
        cout << solve(s,d) << endl;
    }
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,a,i,k,l;
  cin>>n;
  map<int,int> m;
  for(i=0;i<n;i++){
    cin>>a;
    if(m.count(a)) m.at(a)++;
    else m[a]=1;
  }
  l=m.size();
  vector<int> b(l),s(l);
  i=0;
  for(auto mm:m){
    b.at(i)=mm.second;
    i++;
  }
  sort(b.begin(),b.end());
  s.at(0)=b.at(0);
  for(i=1;i<l;i++) s.at(i)=s.at(i-1)+b.at(i);
  for(k=1;k<=n;k++){
    if(k>l) cout<<0<<endl;
    else if(k==l) cout<<b.at(0)<<endl;
    else{
      int ll=0;
      int rr=n/k+1;
      while(rr-ll>1){
        int mm=(ll+rr)/2;
        int d=distance(b.begin(),lower_bound(b.begin(),b.end(),mm));
        if(d==0 || s.at(d-1)+mm*(l-d)>=k*mm) ll=mm;
        else rr=mm;
      }
      cout<<ll<<endl;
    }
  }
}

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

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

using namespace std;

int main(){
  int N;
  cin>>N;
  if(N==1){
    cout<<"Hello World"<<endl;
  }
  else {
    int a,b;
    cin>>a>>b;
    cout<<(a+b)<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
bool get;
string s, t;
int dp[2][2001][2001];
int main()
{
	cin >> n >> m >> s >> t;
	memset(dp[1], -1, sizeof(dp[1]));
	for(int i = 0; i <= n; ++i)
	{
		for(int j = 0; j <= m; ++j)
		{
			if(i != n)
			{
				get = (s[i] == 'I');
				dp[get][i + 1][j] = max(dp[get][i + 1][j], dp[get ^ 1][i][j] + 1);
			}
			if(j != m)
			{
				get = (t[j] == 'I');
				dp[get][i][j + 1] = max(dp[get][i][j + 1], dp[get ^ 1][i][j] + 1);
			}	
			ans = max(ans, dp[1][i][j]);
		}
	}
	cout << ans << endl;
}

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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	vector<string> c;
	rep (i, 3){
		string s; cin >> s;
		c.push_back(s);
	} // end rep

	string res = "";
	rep (i,3){
		res += c[i][i];
	} // end rep
	
	cout << res << endl;
 	
	return 0;
}

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

#define INF UINT64_C(123456789012345678)

int N;
uint64_t A[114514];

uint64_t saidai[114514];

int main(void) {
	int i;
	uint64_t chotensu = 0;
	uint64_t active = 1;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i <= N; i++) {
		if (scanf("%" SCNu64, &A[i]) != 1) return 1;
	}

	for (i = 0; i <= N; i++) {
		if (A[i] > active) {
			puts("-1");
			return 0;
		}
		saidai[i] = active - A[i];
		active = saidai[i] * 2;
		if (active > INF) active = INF;
	}

	chotensu = A[N];
	active = chotensu;
	for (i = N - 1; i >= 0; i--) {
		if (saidai[i] * 2 < active) {
			puts("-1");
			return 0;
		}
		if (active > saidai[i]) active = saidai[i];
		active += A[i];
		chotensu += active;
	}

	printf("%" PRIu64 "\n", chotensu);
	return 0;
}

/*

頂点数を最大にしたいので、1個から2個生やすより、2個から2個生やした方が有利
制約によって、各深さに置ける最大ノード数が決まる

*/


Measured memory_bytes: 3292
import math
A,B,H,M= list(map(int, input().split()))

bx = B * math.sin(M/60*2*math.pi)
by = B * math.cos(M/60*2*math.pi)
ax = A * math.sin((H/12+M/720)*2*math.pi)
ay = A * math.cos((H/12+M/720)*2*math.pi)

print(math.sqrt((ax-bx)**2+(ay-by)**2))


Measured memory_bytes: 62552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll dp[400][700][700], ndp[700][700]; 

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

    ll n = s.size();
    ll z = 0;
    zep(i, 0, n)if(s[i] == '0')z++;

    ll cnt[500]; memset(cnt, 0, sizeof(cnt));
    ll at = 0;
    zep(i, 0, n){
        if(s[i] == '0'){
            at++;
        }else{
            cnt[at]++;
        }
    }

    dp[0][0][0] = 1;
    ll r = n - z;
    rep(i, 1, z + 1){
        r -= cnt[i - 1];

        if(i < z + 1){
            memset(ndp, 0, sizeof(ndp));
            rep(k, 0, 300){
                rep(j, 0, 300){
                    ndp[j + 1][k] += dp[i - 1][j][k];
                    ndp[j + 1][k] %= MOD;
                }

                rep(j, 0, 300){ndp[j + 1][k] += ndp[j][k]; ndp[j][k] %= MOD;}
                //rep(j, 0, 300){if(j - k > r)ndp[j][k] = 0;}
                rep(j, 0, 300){dp[i][j][k] += ndp[j][k]; dp[i][j][k] %= MOD;}
            }
        }

        memset(ndp, 0, sizeof(ndp));
        rep(j, 0, 300){
            rep(k, 0, 300){
                ndp[j][k] += dp[i - 1][j][k];
                ndp[j][k] %= MOD;
                ndp[j][k + cnt[i - 1] + 1] += MOD - dp[i - 1][j][k];
                ndp[j][k] %= MOD;
            }

            rep(k, 0, 300){ndp[j][k + 1] += ndp[j][k]; ndp[j][k] %= MOD;}
            rep(k, j + 1, 300){ndp[j][k] = 0;}
            rep(k, 0, 300){dp[i][j][k] += ndp[j][k]; dp[i][j][k] %= MOD;}
        }
    }

    /*rep(i, 0, z + 1){
        zep(j, 0, 5){
            zep(k, 0, 5){
                cout << dp[i][j][k] << " ";
            }
            cout << endl;
        }
        cout << endl;
    }*/

    ll ans = 0;
    rep(j, 0, min(K, n - z)){
        ans += dp[z + 1][j][j];
        ans %= MOD;
    }
    print(ans)
    
    return 0;
}

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

int main(int argc, char const *argv[]) {
    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;
    for (int i = 1; i <= n; i++) {
        int x = i;
        int temp = 0;
        while (x != 0) {
            temp += x % 10;
            x /= 10;
        }
        if (temp >= a && temp <= b) {
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
}


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

//B
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf(" %d %d", &n, &k);
  int x;
  for(i=0; i < n; i++){
    scanf(" %d", &x);
    cou+=x > k - x ? k - x : x;
  }
  printf("%d", cou*2);
}


Measured memory_bytes: 128
import java.io.*;
import java.io.InputStreamReader;
import java.util.*;
public class Main
{

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        HashSet<Integer>set = new HashSet<>();
        long ans = 0;
        for(int i = 1;i <= n;i++) {
            st = new StringTokenizer(br.readLine());
            int l = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            ans += r - l + 1;
        }
        System.out.println(ans);

    }

}

Measured memory_bytes: 21716
def ARC064D():
    s = list(input())
    if s[0] == s[-1]:
        key = 1
    else:
        key = -1

    if len(s) % 2 != 0:
        key *= -1

    if key == 1:
        print("First")
    else:
        print("Second")

ARC064D()

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

int main(){
  ll N;cin>>N;
  vll table(1e7+100,1);
  rep(i,1e7+5){
    if(i==0 || i==1)continue;
    for(ll j=i;j<=1e7+5;j+=i){
      table[j]++;
    }
  }
  ll ans=0;
  rep(i,N+1){
    ans += i*table[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 81404
#include <iostream>

using namespace std;

int N;
int main()
{
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;

    } else {
        int A, B;
        cin >> A;
        cin >> B;
        cout << A+B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.shift();
  const MAX = 1000;
  const c = Array.from(Array(MAX + 1), () => []);

  let i, j, X, Y, xlen, ylen, maxlen;
  while ((X = lines.shift()) && (Y = lines.shift())) {
    xlen = X.length;
    ylen = Y.length;
    for (i = 0; i <= xlen; i++) c[i][0] = 0;
    for (j = 0; j <= ylen; j++) c[0][j] = 0;

    for (i = 1; i <= xlen; i++) {
      for (j = 1; j <= ylen; j++) {
        if (X[i-1] === Y[j-1]) c[i][j] = c[i - 1][j - 1] + 1;
        else c[i][j] = Math.max(c[i - 1][j], c[i][j - 1]);
      }
    }
    console.log(c[xlen][ylen]);
  }
})();



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

int n, n0, n2, t;

int main(){
	while (cin >> n && n) {
		n0 = n2 = 0;
		for (int i = 0; i < n; i++) {
			cin >> t;
			if (t) {
				if (t > 1) n2++;
			}
			else {
				n0++;
			}
		}
		if (n2) {
			cout << n - n0 + 1 << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3076
# coding: utf-8
# Your code here!

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

ll.sort()
ans = 0
for i in range(n - 2):
    for j in range(i+1, n - 1):
        lb = j + 1
        ub = n - 1
        b = ll[i] + ll[j]
        if ll[lb] >= b:
            continue
        if ll[ub] < b:
            ans += ub - lb + 1
            continue
        while True:
            if ub == lb:
                ans += ub - j
                break
            t = (lb + ub) // 2 + 1
            if ll[t] < b:
                lb = t
            else:
                ub = t - 1
print(ans)

Measured memory_bytes: 43612
#include<bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> a(3, vector<int>(3));
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j ++){
      cin >> a.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for (int k = 0; k < N; k++){
    cin >> b.at(k);
    for (int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j ++){
        if (a.at(i).at(j)==b.at(k))
            a.at(i).at(j) = 0;
      }
    }
  }
  for (int i = 0; i < 3; i++){
    if (a.at(i).at(0) == 0 && a.at(i).at(1) == 0 && a.at(i).at(2) == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int j = 0; j < 3; j++){
    if (a.at(0).at(j) == 0 && a.at(1).at(j) == 0 && a.at(2).at(j) == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (a.at(0).at(0) == 0 && a.at(1).at(1) == 0 && a.at(2).at(2) == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  if (a.at(2).at(0) == 0 && a.at(1).at(1) == 0 && a.at(0).at(2) == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  for (int k=0; k<K; ++k) {
    if (k%2==0) { // Takahashi
      if (A%2==1)
	--A;
      B += A/2;
      A -= A/2;
    } else { // Aoki
      if (B%2==1)
	--B;
      A += B/2;
      B -= B/2;
    }
  }

  cout << A << ' ' << B << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    double R;
    cin >> R;
    printf("%.20f\n", 2 * PI * R);
    return 0;
}


Measured memory_bytes: 3776
import sys

def div(n):
    if n == 1: return [1]
    d = [1]
    for k in range(2, n):
        if k ** 2 > n: break
        if n % k == 0:
            if k ** 2 == n: d.append(k)
            else: 
                d.append(k)
                d.append(n // k)
    return d

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    SumB = [0] * N
    Ans = []
    count = 0

    for i in reversed(range(N)):
        if SumB[i] % 2 == A[i]: continue
        elif (SumB[i] + 1) % 2 == A[i]:
            Ans.append(i + 1)
            count += 1
            d = div(i + 1)
            for j in d: SumB[j - 1] += 1
        else:
            print(-1)
            break
    else: 
        Ans.sort()
        print(count)
        print(" ".join(map(str, Ans)))
        

    return 0
if __name__ == "__main__":
    solve()

Measured memory_bytes: 87672
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    set<string> st;
    while(N--) {
        string S;
        cin >> S;
        st.insert(S);
    }
    cout << st.size() << endl;
    return 0;
}


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

int main() {
    int64_t x = 0;
    cin >> x;

    int64_t balance = 100;
    int64_t year = 0;
    while (true) {
        year++;
        balance *= 1.01;
        if (balance >= x) break;
    }
    cout << year << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

int main(void){
  string s;
  int n;
  map<string,int>m;
  
  cin >> n;
  cin.ignore();
  
  while(n--){
    getline(cin,s);
    
    m[s]=1;
    string rev1,rev2;
    
    for(int i=0;i<s.size();i++){
      
      rev1=s.substr(0,i);
      rev2=s.substr(i,s.size());
      
      m[rev1+rev2]=1;
      m[rev2+rev1]=1;
      
      reverse(rev1.begin(),rev1.end());
      reverse(rev2.begin(),rev2.end());
      
      m[rev1+s.substr(i,s.size())]=1;
      m[s.substr(i,s.size())+rev1]=1;
      m[s.substr(0,i)+rev2]=1;     
      m[rev2+s.substr(0,i)]=1;     
      
      m[rev1+rev2]=1;
      m[rev2+rev1]=1;
    }
    
    cout << m.size() << endl;
    m.clear();
  }
  
  return 0;
}

Measured memory_bytes: 1008
#include <stdio.h>
int main(void)
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b && b<c && a<c){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
long n,m=1e9,b,r,i,a;
int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		r+=abs(a);
		m=min(m,abs(a));
		b^=a<0;
	}
	cout<<r-b*m*2<<endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>){
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    var divisible = 0L
    var remainderHalf = 0L
    for(i in 1..N){
        if(i % K == 0){
            divisible++
        }
        if(i % K == K / 2){
            remainderHalf++
        }
    }
    if(K % 2 == 1){
        println(divisible * divisible * divisible)
    }else{
        println(divisible * divisible * divisible + remainderHalf * remainderHalf * remainderHalf)
    }
}

Measured memory_bytes: 37780
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const ll MAX_N=20;
ll N,val[MAX_N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    REP(i,N)cin>>val[i];
    REP(i,N){
        ll c;
        cin>>c;
        val[i]-=c;
    }
    sort(val,val+N);
    ll ans=0;
    REP(i,N){
        ans+=max(val[i],0ll);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		
		int max = Math.max(h, w);
		int ans = 0;
		
		for (int i = 1;; i++) {
			if (max * i >= n) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aeroui
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public static int MOD = 1_000_000_007;
        public long[] fact = new long[100005];

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();

            init();
            if (Math.abs(N - M) >= 2)
                out.println(0);
            else if (Math.abs(N - M) == 1)
                out.println((fact[N] * fact[M]) % MOD);
            else
                out.println((((fact[N] * fact[M]) % MOD) * 2) % MOD);
        }

        public void init() {
            fact[0] = 1;
            for (int i = 1; i < fact.length; ++i)
                fact[i] = (fact[i - 1] * i) % MOD;
        }

    }
}



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

#define    ll     long long int

int main( )
{
    ll s = 0, a, b, c, x, y, mn;
    cin >> a >> b >> c >> x >> y;
    mn = min(x, y);
    if (2 * c <= (a + b)) {
        s += ((2 * c) * mn);
        x -= mn;
        y -= mn;
    }
    s += min(a * x + b * y, 2 * c * x + 2 * c * y);
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	io := NewIo()
	defer io.Flush()

	N := io.NextInt()
	var A [200000]int
	var comb [200000]int
	for i := 0; i < N; i++ {
		A[i] = io.NextInt()
		comb[A[i]-1]++
	}

	count := 0
	for j := 0; j < N; j++ {
		if comb[j] <= 1 {
			continue
		}
		count += combination(comb[j], 2)
	}

	// fmt.Printf("%d %v, %v\n", N, A[0:N], comb[0:N])
	for i := 0; i < N; i++ {
		io.Printf("%v\n", count-comb[A[i]-1]+1)
	}
	// fmt.Printf("Lucas %d %d\n", combMod(N, M, 13), combination(N, M))

	// write your own code here
}

// Libraries

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// direct calculation of combination
// n, m should be "small"
func combination(n, m int) int {
	if m > n {
		return 0
	} else if m == n || m == 0 {
		return 1
	} else {
		res := 1
		for i := 0; i < m; i++ {
			res *= (n - i)
		}
		for i := 1; i <= m; i++ {
			res /= i
		}
		return res
	}
}

// caluclate combination modulo based on Lucas theorem
func lucas(n, m, p int) int {
	ntemp := n
	mtemp := m
	res := 1
	for i := 0; i < 100; i++ {
		// fmt.Printf("ntemp: %d\n", ntemp)
		nreminder := ntemp % p
		ntemp = ntemp / p
		mreminder := mtemp % p
		mtemp = mtemp / p
		res = res * (combination(nreminder, mreminder) % p)
		if ntemp == 0 {
			break
		}
	}
	return res % p
}

func combMod(n, m, p int) int {
	return lucas(n, m, p)
}


Measured memory_bytes: 15104
def isPrime(n):
    p = 2
    while p * p <= val:
        if val % p == 0 :
            return False
    
        p +=1
    return True    
t = int(input())
cnt = 0
for i in range(t):
    val = int(input())
    if isPrime(val):
        cnt +=1

print(cnt)


Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }






int main() {
  cout<<fixed<<setprecision(10);

  ll N;cin>>N;
  // vstring S(N);
  // vint P(N);
  vector<tuple<string,ll,ll>> spi(N);
  rep(i,N){
    string s;
    ll p;
    cin>>s>>p;
    p*=-1;
    spi[i] = make_tuple(s,p,i);
  }


  vsort(spi);

  rep(i,N){
    cout << get<2>(spi[i])+1 << endl;
  }



  // cout << ans << endl;

}

















//


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>S;

    a = 0;
    b = 0;

    for(int i=0;S[i];i++){
        if(S[i]=='S')a++;
        else {
            if(a)a--;
            else b++;
        }
    }

    cout<<a+b<<"\n";

    return 0;
}


Measured memory_bytes: 512
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

int dp[45][2][1<<18];

void solve(){  
	dp[0][0][1]=1;
	int n,x,y,z;
	cin>>n>>x>>y>>z;
	int reqd_mask = 1|(1<<z)|(1<<(y+z))|(1<<(x+y+z));
	rep(i,0,n){
		rep(j,0,2){
			rep(k,0,1<<18){
				rep(d,1,11){
					int new_mask = ((k<<d)|1)&((1<<18)-1);
					int new_j = j;
					if((new_mask&reqd_mask)==reqd_mask) new_j=1;
					dp[i+1][new_j][new_mask]+=dp[i][j][k];
					dp[i+1][new_j][new_mask]%=hell;
				}
			}
		}
	}  
	int ans=0;
	rep(i,0,1<<18){
		ans+=dp[n][1][i];
		ans%=hell;
	}
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 166144
N = int(input())
t = [0 for _ in range(N)]
x = [0 for _ in range(N)]
y = [0 for _ in range(N)]
for i in range(N):
    t[i], x[i], y[i] = list(map(int,input().split()))

def manhat_dis(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

ans = "Yes"
t0, sx, sy = 0, 0, 0
for i in range(N):
    dis = manhat_dis(sx, sy, x[i], y[i])
    dt = t[i] - t0
    if dt < dis or (dis - dt) % 2:
        ans = "No"
        break
    t0, sx, sy = t[i], x[i], y[i]
print(ans)

Measured memory_bytes: 48176
#include<stdio.h>
  
#define AMAX 20
#define MMAX 200
 
int A[AMAX+1];
int n, q;

int solve_loop( int p, int t, int res )
{
	return  ( n < p ) ? res: solve_loop( p+1, t-A[p],  !t ) || solve_loop( p+1, t,  !t  );
}
int solve( int p, int t )
{
	return  solve_loop( p, t, 0 );
}
 
int main( void ) 
{
    int i;
    int num;
     
    scanf( "%d", &n );  
    for( i=0; i<n; i++ ) {
        scanf( "%d", &A[i] );
    }   
    scanf( "%d", &q );
    for( i=0; i<q; i++ ) {
        scanf( "%d", &num );
        if( solve( 0, num ) ) {
            printf( "yes\n" );      
        } else {
            printf( "no\n" );
        }
    }
    return 0;
}

Measured memory_bytes: 580
#include <stdio.h>
#include <string.h>
 
int main(void){
  int N, i, j, P[105], rank[105], tmp1;
  char S[105][15], p[105][3], str[105][15], tmp2[15];
  scanf("%d\n", &N);
  for(i=1; i<=N; i++){
    scanf("%s %d", S[i], &P[i]);
    rank[i]=i;
    P[i]=100-P[i];
    
    
    
    if(P[i]/100==0){
      p[i][0]='0';
    }
    else p[i][0]='1';
    
    
    
    if((P[i]/10)%10==0){
      p[i][1]='0';
    }
    else if((P[i]/10)%10==1){
      p[i][1]='1';
    }
    else if((P[i]/10)%10==2){
      p[i][1]='2';
    }
    else if((P[i]/10)%10==3){
      p[i][1]='3';
    }
    else if((P[i]/10)%10==4){
      p[i][1]='4';
    }
    else if((P[i]/10)%10==5){
      p[i][1]='5';
    }
    else if((P[i]/10)%10==6){
      p[i][1]='6';
    }
    else if((P[i]/10)%10==7){
      p[i][1]='7';
    }
    else if((P[i]/10)%10==8){
      p[i][1]='8';
    }
    else if((P[i]/10)%10==9){
      p[i][1]='9';
    }
    
    
    
    if(P[i]%10==0){
      p[i][2]='0';
    }
    else if(P[i]%10==1){
      p[i][2]='1';
    }
    else if(P[i]%10==2){
      p[i][2]='2';
    }
    else if(P[i]%10==3){
      p[i][2]='3';
    }
    else if(P[i]%10==4){
      p[i][2]='4';
    }
    else if(P[i]%10==5){
      p[i][2]='5';
    }
    else if(P[i]%10==6){
      p[i][2]='6';
    }
    else if(P[i]%10==7){
      p[i][2]='7';
    }
    else if(P[i]%10==8){
      p[i][2]='8';
    }
    else if(P[i]%10==9){
      p[i][2]='9';
    }
  }
  
  for(i=1; i<=N; i++){
    sprintf(str[i], "%s%c%c%c", S[i], p[i][0], p[i][1], p[i][2]);
  }
  
  for (i=1; i<=N; ++i) {
    for (j=i+1; j<=N; ++j) {
      if (strcmp(str[i], str[j]) > 0) {
        tmp1 =  rank[i];
        rank[i] = rank[j];
        rank[j] = tmp1;
        strcpy(tmp2, str[i]);
        strcpy(str[i], str[j]);
        strcpy(str[j], tmp2);
      }
    }
  }
  
  for(i=1; i<=N; i++){
    printf("%d\n", rank[i]);
  }
  return(0);
}
 
 
/*
for (i=1; i<=N; ++i) {
    for (j=i+1; j<=N; ++j) {
      if (str[i] > str[j]) {
        tmp1 =  rank[i];
        rank[i] = rank[j];
        rank[j] = tmp1;
        strcpy(tmp2, str[i]);
        strcpy(str[i], str[j]);
        strcpy(str[j], tmp2);
      }
    }
  }
*/

Measured memory_bytes: 128
BASE = 9973
MOD = 2 ** 61 - 1


class RollingHash:
    # 文字列Sのローリングハッシュを構築
    # 計算量: O(N)
    def __init__(self, S):
        # acc[i]はS[0:i]のハッシュ値となる
        self.acc = [0]
        a = 0
        # 累積和を計算するイメージ
        for i, c in enumerate(S):
            h = ord(c) - ord("a") + 1
            offset = pow(BASE, i, MOD)
            a = (a + (h * offset)) % MOD
            self.acc.append(a)

    # S[i:j]のハッシュ値を返す
    # 計算量: O(1)
    def hash(self, i, j):
        # 累積和を用いて部分区間の和を計算するイメージ
        # 注意: 基数によるオフセットをキャンセルする必要がある
        offset = pow(BASE, i, MOD)
        # 素数MODを法とする剰余類における除算は逆元を乗算することで計算できる
        # 素数MODを法とする剰余類におけるxの逆元はx^(MOD - 2)に等しい
        offset_inv = pow(offset, MOD - 2, MOD)
        return ((self.acc[j] - self.acc[i]) * offset_inv) % MOD


N = int(input())
S = input()

# Sのローリングハッシュを計算しておく
rolling = RollingHash(S)

# 長さmのダジャレがSに含まれるならば、長さm-1のダジャレも含まれる
# つまり、長さmのダジャレがSに含まれるならば真となる述語をP(m)とすると、以下を満たす整数cが存在する:
#   - 0以上c以下の整数mについてP(m)は真
#   - cより大きい整数mについてP(m)は偽
# ※ Pは単調関数ということ
# このcを二分探索で発見すれば高速化できる！

# P(ok)は真
ok = 0
# P(ng)は偽
ng = N
while ng - ok > 1:
    # 区間[ok, ng)の中央値をmとする
    m = (ok + ng) // 2

    # 長さmのダジャレが存在するか判定する
    # 長さmのformerのハッシュ値のキャッシュ
    former_cache = set()
    p = False
    # latterに着目してループを回す
    for i in range(m, N):
        # ダジャレ長を決め打ちしているのでjを直接計算できる
        j = i + m
        # S[i:j]がSをはみ出したらループ終了
        if j > N:
            break
        # formerのハッシュ値をキャッシュする
        former_cache.add(rolling.hash(i - m, i))
        # キャッシャに同一のハッシュ値が存在する場合（ハッシュ値が衝突した場合）、ダジャレになっていると判定できる
        if rolling.hash(i, j) in former_cache:
            p = True
        # ハッシュ値の計算、キャッシュ存在判定は共にO(1)で処理できる！
    # 区間[ok, ng) を更新
    if p:
        ok = m
    else:
        ng = m
# whileループを抜けると区間[ok, ng)は[c, c + 1) になっている
ans = ok

print(ans)


Measured memory_bytes: 50676
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define PI      	        2*acos(0.0)
#define INF     	        1e9
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; 

//int dx[] = {1, -1, 0, 0},                  dy[] = {0, 0, 1, -1};                  // 4 Direction
//int dx[] = {1, -1, 0, 0, 1, 1, -1, -1},    dy[] = {0, 0, 1, -1, 1, -1, 1, -1};    // 8 Direction
//int dx[] = {1, -1, 1, -1, 2, 2, -2, -2},   dy[] = {2, 2, -2, -2, 1, -1, 1, -1};   // Knight Direction

inline ll gcd(ll a, ll b){
    a = abs(a);
    b = abs(b);
    while (b){
        a = a % b;
        swap (a, b);
    }
    return a;
}
inline ll power(ll a, ll p){
    ll res = 1, x = a;
    while (p){
        if (p & 1){
            res = (res * x);
        }
        x = (x * x);
        p >>= 1;
    }
    return res;
}
inline ll bigmod(ll a, ll p, ll m){
    ll res = 1 % m, x = a % m;
    while (p){
        if (p & 1){
            res = (res * x) % m;
        }
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}

int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    int ara[n];
    for (int i = 0; i<n; i++){
        cin >> ara[i];
    }
    sort(ara, ara+n);
    int sum = 0;
    for (int i = 0; i<n-1; i++){
        sum += ara[i];
    }
    if (sum > ara[n-1]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define endl '\n'

map <ll,ll > visited;
ll dp[ll(1e5+7)];


vector < vector<ll> > graph(1e5+7);

void dfs(ll a){
    visited[a]++;
    for(ll j=0;j<graph[a].size();j++)
    {
        if(visited[graph[a][j]]==0)
          {
             // cout<<graph[a][j]<<endl;
              dfs(graph[a][j]);

          }
        dp[a]=max(dp[a],dp[graph[a][j]]+1);
    }


}

int main()
{
    ll n,m;
    cin>>n>>m;
   // for(ll j=1;j<=n;j++)dp[j]=0;
    for(ll j=0;j<m;j++)
    {
        ll a,b;
        cin>>a>>b;
        graph[a].push_back(b);
       // cout<<"Bey"<<endl;

    }
    for(ll j=1;j<=n;j++)
    {
        if(visited[j]==0)
        dfs(j);


        //cout<<"Hi"<<endl;
    }
   // cout<<"Hi"<<endl;
    ll *it;
    it=max_element(dp+1,dp+n+1);
    ll ans=ll(*it);
   // for(ll j=1;j<=n;j++)cout<<dp[j]<<" ";
   // cout<<endl;
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 16128
// https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N; string S;
    cin >> N >> S;
    int wtot = 0;
    REP(i, N)
    {
        if ('.' == S[i])
        {
            ++wtot;
        }
    }

    int ans = wtot;
    int wnum = 0, bnum = 0;
    REP(i, N)
    {
        if ('.' == S[i])
        {
            ++wnum;
        }
        else
        {
            ++bnum;
        }
        // i 番目より右側にある白石の数を算出
        int rightcnt = wtot - wnum;
        ans = min(ans, bnum + rightcnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3724
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

vector<int> as;

int main(void) {
    int N, M;
    cin >> N >> M;

    int sum = 0;
    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
        sum += as[i];
    }

    double border = double(sum) / (4.0 * double(M));
    // printf("border: %.6f\n", border);

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (double(as[i]) >= border) {
            count++;
        }
    }

    if (count >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int s1,s2;
  while(cin >> s1 >> s2,s1||s2){
    int ans = 0, val = s1+s2;
 
    for(int i=1;i<5;i++){
      cin >> s1 >> s2;
      if(val < s1 + s2){
    ans = i;
    val = s1 + s2;
      }
    }
    cout << (char)('A'+ans) << " " << val << endl;
  }
}


Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int k,s;
	scanf("%d %d", &k, &s);
	getchar();

	int ans = 0;
	for (int x = 0; x <= k; x++)
	{
		for (int y = 0; y <= k; y++)
		{
			int z = s - y - x;
			if (z >= 0 && z <= k)
			{
				ans++;
			}
		}
	}

	printf("%d\n", ans);
#ifdef _DEBUG
	printf("Press enter to exit\n");
	getchar();
#endif
	return 0;
}


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

long long euclidean_gcd(long long a, long long b) {
  if(a < b) return euclidean_gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}




int main() {
	long long A, B, C, D,counter=0;
	cin >> A >> B >> C >> D;
	counter=(B-A+1)-(B/C-(A-1)/C+B/D-(A-1)/D-B/(C*D/euclidean_gcd(C,D))+(A-1)/(C*D/euclidean_gcd(C,D)));
//（総数）-(Cで割り切れるやつ)-(Dで割り切れるやつ)+(CトDで割り切れるやつ)
    //  cout <<euclidean_gcd(C,D)<<endl;
        cout <<counter;
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int k;
double l, r, p, e, t;

double ans = 0.0;

void dfs(double l, double r, double prob, int remain) {
	double h = (l + r) / 2;

	//printf("%.3lf %.3lf; P=%.3lf; R=%d\n", l, r, prob, remain);

	if (r < t - e || l > t + e) {
		return;
	}
	if (t - e <= l && r <= t + e) {
		ans += prob;
		return;
	}

	if (remain == 0) {
		if (abs(t - h) <= e) {
			ans += prob;
		}
		return;
	}

	if (h < t) {
		dfs(l, h, prob * p, remain - 1);
		dfs(h, r, prob * (1 - p), remain - 1);
	} else {
		dfs(l, h, prob * (1 - p), remain - 1);
		dfs(h, r, prob * p, remain - 1);
	}
}

int main() {
	cin >> k >> l >> r >> p >> e >> t;
	dfs(l, r, 1.0, k);

	cout << fixed << setprecision(12) << ans << endl;
}



Measured memory_bytes: 3280
a=str(input())
b=str(input())
c=str(input())
d=str(input())
e=str(input())
box=[a,b,c,d,e]
li_0=[]
li= []
for i in box:
    if i[-1] == "0":
        li_0.append([i,i[-1]])
    else:
        li.append([i,i[-1]])
#print(li)
li.sort(key = lambda x :x[1], reverse=True)
li_0[len(li_0):len(li_0)] = li
#print(li_0)

ans = 0
count = 0
for i in li_0:
    if i[-1]=="0":
        ans += int(i[0])
    elif count==len(box)-1:
      ans += int(i[0])
    else:
        ans += int(i[0]) + 10 -int(i[-1])
        
    count+=1
print(ans)
        

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

//約数列挙 O(n**1/2)
set<ll> divisor(ll n){
    set<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.insert(i);
            if(i != n/i) res.insert(n/i);
        }
    }
    return res;
}

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

    //set<ll> X;

    auto X = divisor(A);

    //if(B < A) swap(A, B);
    //for(ll i = 1; i*i <= B; i++){
    //    if(B % i == 0 && A % i == 0){
    //        X.insert(i);
    //        if(i != B/i && A % (B/i) == 0) X.insert(B/i);
    //    }
    //}

    vector<ll> Y;
    for(auto&& x : X){
        if(B % x != 0) continue;
        bool valid = true;
        for(auto&& y : Y){
            if(y == 1) continue;
            if(x % y == 0){
                valid = false;
                break;
            }
        }
        if(valid) Y.push_back(x);
    }
    

    ll ans = Y.size();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _xx ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long LL;
const int mod=1e9+7;
const int MAXN=1e3+100;
int main()
{
    int n,d,x;
    cin>>n>>d>>x;
    int ans=x;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        ans+=((d-1)/a+1);
    }
    cout<<ans<<endl;
}


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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
	int N;
	scin(N);
	int A[N],ans[N];
	rep(i,0,N){
		scin(A[i])
		ans[A[i] - 1] = i + 1;
	}
	rep(i,0,N){
		anin(ans[i])
	}
	return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int n;
VVI edge(201010,VI());
bool visited[201010];
ll width;
ll dfs(int node){
  visited[node] = true;

  priority_queue<ll> que;
  que.push(0);
  que.push(0);
  rep(i,edge[node].size()){
    if(visited[edge[node][i]] == true) continue;
    que.push( dfs(edge[node][i]) );
  }
  ll first = que.top();
  que.pop();
  ll second = que.top();
  width = max(width,first+second);

  return first+1;

}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  dfs(0);
  if(width % 3 != 1){
    cout << "First" << "\n";
  }else{
    cout << "Second" << "\n";
  }
  return 0;
}


Measured memory_bytes: 32384
def bubble_sort(A):
    a = list(A)
    swap_count = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(len(a)-1, 0, -1):
            if a[j-1] > a[j]:
                a[j-1], a[j] = a[j], a[j-1]
                swap_count += 1
                flag = 1
    print(' '.join(map(str, a)))
    print(swap_count)

input()
bubble_sort(list(map(int, input().split())))


Measured memory_bytes: 5600
#include <iostream>

int main (){
  int a[3];
  std::cin >> a[0] >> a[1] >> a[2];

  for (int n=0; n<2; n++){
  for (int i=0; i<2; i++){
    if (a[i] > a[i+1]){
      auto temp = a[i];
      a[i] = a[i+1];
      a[i+1] = temp;
    }
  }
  }

  for (int i=0; i<2; i++){
    std::cout << a[i] << " ";
  }
  std::cout << a[2] << std::endl;

}



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

typedef struct Node{
    int key;
    struct Node *prev, *next;
}Node;

Node *nil;
void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key) cur = cur->next;
    return cur;
}

void insert(int key){
    Node *x;
    x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

void deleteNode(Node *t){
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void delete(int key){
    deleteNode(listSearch(key));
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main(){
    int key, n, i;
    int size = 0;
    char command[20];
    scanf("%d", &n);
    init();
    
    for(i = 0; i<n; i++){
            scanf("%s%d", command, &key);
            if(command[0] == 'i'){insert(key); size++;}
            else if(command[0] == 'd'){
                if(strlen(command) == 6) delete(key);
                else if(command[6] == 'F') deleteFirst();
                else if(command[6] == 'L') deleteLast();
                size--;
            }
    }

    printList();

    return 0;
}



Measured memory_bytes: 32952