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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const ll MOD = 1e9 + 7;
const int N = 21 + 1;

ll dp[N][(1 << N)];
int a[N][N];
int n;

ll sol(int i, int mask) {
    if(i == n) return 1;

    ll &ret = dp[i][mask];
    if(ret != -1) return ret;

    ret = 0;

    for(int j = 0; j < n; j++) {
        if(a[i][j] == 0) continue;
        if(mask & (1 << j)) {
            ret += sol(i + 1, mask ^ (1 << j));
            ret %= MOD;
        }
    }

    return ret;
}

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    memset(dp, -1, sizeof(dp));
    cin >> n;

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


    cout << sol(0, (1 << n) - 1);
}








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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

int main() {

    int a, b;
    cin >> a >> b;

    int ans = a;
    if(a > b)ans--;

    cout << ans << endl;
    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3592
from operator import itemgetter
n = int(input())

abn = [list(map(int,input().split())) for _ in range(n)]


#abn.sort()
abn.sort(key = itemgetter(1) )


#print(abn)

ts = 0 # time_stamp
enable = True
for abi in abn:
    a, b = abi

    if not ts + a <= b:
        enable = False
        break
    else:
        ts += a

print('Yes' if enable else 'No')

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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;

  char ch = S[K - 1];
  for (int i = 0; i < N; i++) {
    if (S[i] != ch) S[i] = '*';
  }

  cout << S << endl;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> LLLL;

int main(int argc, char *argv[]) {
	LL n, m;
	cin >> n >> m;
	vector<LLLL> v;
	for (LL i = 0; i < n; ++i) {
		LL a, b;
		cin >> a >> b;
		v.push_back(LLLL(a, b));
	}
	sort(v.begin(), v.end());
	LL ans = 0;
	for (auto kv : v) {
		LL a = min(m, kv.second);
		ans += a * kv.first;
		m -= a;
		if (m <= 0) {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2420
//59
#include<iostream>

using namespace std;

int main(){
  for(;;){
    int ma=0;
    char shop;
    for(int i=0;i<5;i++){
      int s,ss;
      cin>>s>>ss;
      if(s==0&&ss==0)return 0;
      if(s+ss>ma){
	ma=s+ss;
	shop=i+'A';
      }
    }
    cout<<shop<<' '<<ma<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	bool ans = true;
	string s; cin >> s;
	int l, r;
	int n = s.size();
	l = 0; r = n - 1;
	for (int i = l; i <= r; i++) {
		if (s[i] != s[r - (i - l)]) ans = false;
	}
	l = 0; r = (n - 1) / 2 - 1;
	for (int i = l; i <= r; i++) {
		if (s[i] != s[r - (i - l)]) ans = false;
	}
	l = (n + 3) / 2 - 1; r = n - 1;
	for (int i = l; i <= r; i++) {
		if (s[i] != s[r - (i - l)]) ans = false;
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	char str[100];
	while(~scanf("%s",str)){
		int l=strlen(str);
		F(i,0,l-8) printf("%c",str[i]);
		puts("");
	}
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

int main(){
    long int n, k;
    cin >> n >> k;
    long int ans = min(n % k, abs(k - n % k));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
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);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    string a,b;
    cin >> a >> b;
    if (a.size() > b.size()) {
        cout << "GREATER" << "\n";
    }
    if (a.size() < b.size()) {
        cout << "LESS" << "\n";
    }
    if (a.size() == b.size()) {
        if (a > b) {
            cout << "GREATER" << "\n";
        }
        if (a<b) {
            cout << "LESS" << "\n";
        }
        if (a==b) {
            cout << "EQUAL" << "\n";
        }
    }
}

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

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

    vector<char> trans(26,'1');
    for(int i=0; i<s.length(); i++){
        if(trans[s[i] - 'a'] == '1') trans[s[i] - 'a'] = t[i];
        else if(trans[s[i] - 'a'] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    sort(trans.begin(),trans.end());
    for(int i=0; i<25; i++){
        if(trans[i] == '1') continue;
        
        if(trans[i] == trans[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		// 街
		int N = Integer.parseInt(scn.next());
		// 徒歩疲労
		long A = Long.parseLong(scn.next());
		// テレポート疲労
		long B = Long.parseLong(scn.next());

		long[] towns = new long[N];

		for (int i = 0; i < N; i++) {
			towns[i] = Long.parseLong(scn.next());
		}

		long sum = 0;
		for (int i = 1; i < N; i++) {
			long toho = (towns[i] - towns[i - 1]) * A;
			if (toho > B) {
				sum += B;
			} else {
				sum += toho;
			}
		}

		System.out.println(sum);

	}

}

Measured memory_bytes: 50692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, M;
  vector<int> road(N);
  
  cin >> N >> M;
  
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    road.at(a-1) += 1;
    road.at(b-1) += 1;
  }
  
  for (int i = 0; i < N; i++)
    cout << road.at(i) << endl; 
}

Measured memory_bytes: 24832
# coding: utf-8
# Your code here!
import numpy as np

def main():
    N, W = map(int, input().split())
    V = 10**3 * N + 1 
    
    dp = np.full(V, W+1)
    # print(len(dp))
    dp[0] = 0
    
    for _ in range(N):
        w, v = map(int, input().split())
        dp[v:] = np.minimum(dp[v:], dp[:-v]+w)

    # print(dp)
    print(np.max(np.where(dp<=W)))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 14880
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>

using namespace std;


int main()
{
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0; i <=a; i++)
	{
		for (int j = 0; j <=b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				if (i * 500 + j * 100 + k * 50==x)
				{
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = []
for i in range(N):
    a,b = list(map(int,input().split()))
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2==1:
    print(B[(N-1)//2] - A[(N-1)//2]+1)
else:
    b1 = B[(N-2)//2]
    b2 = B[N//2]
    a1 = A[(N-2)//2]
    a2 = A[N//2]
    print(b1 + b2 - (a1 + a2) + 1)
    #print(a1,a2,b1,b2)

Measured memory_bytes: 99628
#include <iostream>
#include <vector>
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    
    int M = 0;
    rep(i, N) M = max(M, A[i]);
    vector<int> dp(H + M, INF);
    dp[0] = 0;
    REP(i, H + M) {
        rep(j, N) {
            if (i - A[j] < 0) continue;
            dp[i] = min(dp[i], dp[i - A[j]] + B[j]);
        }
    }
    
    int ans = INF;
    for (int i = H; i < H + M; ++i) ans = min(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    int[] ss,ss1;
    while(true){
	string s = readln();
	if(s == "\n") break;
	if(stdin.eof()) break;
	auto s1 = split(s,',');
	ss ~= to!int(s1[0]);
	ss1 ~= to!int(s1[0]);
    }
    int[] list;
    while(true){
	string s = readln();
	if(s == "\n") break;
	if(stdin.eof()) break;
	auto s1 = split(s,',');
	ss1 ~= to!int(s1[0]);
	for(int i=0;i<ss.length;i++){
	    if(ss[i] == to!int(s1[0])){
		bool flg = true;
		foreach(j;list) if(j == to!int(s1[0])) flg = false;
		if(flg) 
		    list ~= to!int(s1[0]);
	    }
	}
    }

    sort(list);
    foreach(i;list){
	int count = 0;
	foreach(j;ss1){
	    if(i == j) count++;
	}
	writef("%d %d\n",i,count);
    }
}

Measured memory_bytes: 2476
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 140_B
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] A = new int[N+1];
		int[] B = new int[N+1];
		int[] C = new int[N+1];

		int i = 0;
		int ret = 0;

		for(i=1; i<=N; i++) {
			A[i] = sc.nextInt();
		}
		for(i=1; i<=N; i++) {
			B[i] = sc.nextInt();
		}
		for(i=1; i<=N-1; i++) {
			C[i] = sc.nextInt();
		}
	    // Scannerクラスのインスタンスをクローズ
		sc.close();

		ret += B[1];
		for(i=2; i<=N; i++) {
			ret += B[i];
			if(A[i]-A[i-1] == 1) {
				ret += C[A[i-1]];
			}
		}

		System.out.println(ret);

	}
}


Measured memory_bytes: 35500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  cin>>a.at(0);
  int d=0;
  for(int i=1;i<n;i++){
    cin>>a.at(i);
    d=max(d,a.at(i)-a.at(i-1));
  }
  d=max(d,k-(a.at(n-1)-a.at(0)));
  cout<<k-d<<endl;
}

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

long long gcd(long long a, long long b){
  if(a<b)swap(a,b);

  if(a%b==0)return b;
  else gcd(b, a%b);
}

int main(){
  int n;
  cin>>n;
  vector<long long> t(n);
  for(int i=0; i<n; i++)cin>>t.at(i);

  long long ans=1;
  for(int i=0; i<n; i++)ans=ans/gcd(ans, t.at(i))*t.at(i);

  cout<<ans<<endl;
}

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

typedef long long ll;
typedef long double ld;

const int M=1e5+5;
const ll mod=998244353;
ll ct[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int mx=0;
	int n;
	cin>>n;
  for(int i=0;i<n;i++)
	{
		int d;
		cin >> d;
		if(i==0 && d!=0)
		{
			cout<<0;
			return 0;
		}
		if(i>0 && d==0)
		{
			cout<<0;
			return 0;
		}
		ct[d]++;
		mx=max(mx,d);
	}
	ll res=1;
	for(ll i=1;i<=mx;i++)
	{
		if(ct[i]==0)
			res=0;
		for(int j=1;j<=ct[i];j++)
			res=(res*ct[i-1])%mod;
	}
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)













int main(){
    string s;
    cin >> s;
    string a[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    REP(i, 7){
        if(s == a[i]){
            cout << 7 - i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
   public static void main(String args[]){
      int  a,b;
      Scanner reader = new Scanner(System.in);
      String temp[];
      temp = reader.nextLine().split(" ");
      
      a = Integer.parseInt(temp[0]);
      b = Integer.parseInt(temp[1]);
      
      System.out.printf("%d %d\n",a*b,2*(a+b));          
   }//method
}//class

Measured memory_bytes: 26196
s = input()
s = sorted(s)
s = set(s)
alpha = 'a'
flg = 0
for i in range(1,27):
    if (alpha not in s):
        flg = 1
        break
    else : alpha = chr(ord(alpha)+1)
if (flg): print(alpha)
else: print("None")


Measured memory_bytes: 10200
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, long long M, std::vector<long long> A)
{
  for (auto a : A)
    N -= a;
  if (N < 0)
    N = -1;
  cout << N << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(M);
  for (int i = 0; i < M; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(N, M, std::move(A));
  return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;cin >> N;

    vector<ll> p(N);
    rep(i,N) cin >> p[i];

    vector<ll> min_l(N);
    min_l[0] = p[0];

    ll ans = 1;

    REP(i,N-1){
        if(p[i] < min_l[i-1]){
            ans++;
            min_l[i] = p[i];
        }else{
            min_l[i] = min_l[i-1];
        }
    }

    cout << ans << endl;
 }

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    char c;cin >> c;
    if(0 <= c - 'a' && c - 'a' <= 26) puts("a");
    else puts("A");
    return 0;
}


Measured memory_bytes: 3584
N = int(input())
S = [list(input()) for _ in range(N)]

initial_dict = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0,
}

for s in S:
    if s[0] in initial_dict:
        initial_dict[s[0]] += 1

keys = list(initial_dict.keys())
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += initial_dict[keys[i]] * initial_dict[keys[j]] * initial_dict[keys[k]]

print(ans)


Measured memory_bytes: 20260
#include <iostream>

using namespace std;

static const int MAX = 36;

struct Card {
  char suit;
  int value;
};

void bubble (struct Card A[], int N) {

  bool flag = 1;

  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N-1; i < j; j--) {
      if (A[j].value < A[j-1].value) {
        Card a = A[j-1];
        A[j-1] = A[j];
        A[j] = a;
        flag = 1;
      }
    }
  }

}

void selection (struct Card A[], int N) {

  for (int i = 0; i < N; i++) {
    int minj = i;
    Card origin = A[i];
    for (int j = i; j < N; j++) {
      if (A[j].value < A[minj].value) {
        minj = j;
      }
    }

    if (i != minj) {
      A[i] = A[minj];
      A[minj] = origin;
    }
  }

}

void print (struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable (struct Card C1[], struct Card C2[], int N) {
  for (int i = 0; i < N; i++) {
    if (C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main () {

  int N;
  Card C1[MAX], C2[MAX];

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> C1[i].suit >> C1[i].value;
    C2[i] = C1[i];
  }

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1, C2, N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long int>t,a;

int main(){
	cin>>n;
	t.resize(n);
	a.resize(n);
	for(int i=0;i<n;i++)cin>>t[i]>>a[i];
	
	for(int i=1;i<n;i++){
		if(t[i-1]>t[i]||a[i-1]>a[i]){
			long long int p=max((t[i-1]+t[i]-1)/t[i],(a[i-1]+a[i]-1)/a[i]);
			t[i]*=p;
			a[i]*=p;
		}
	}
	cout<<t[n-1]+a[n-1];
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int len = 0;
        for(int j = 0; j < n; j++){
            if(s[i+j] == s[j] && i+j-len != j){
                len++;
            }else{
                ans = max(ans, len);
                len = 0;
            }
        }
    }
    cout << ans << endl;
}

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

namespace AtTest.ABC_139
{
    class F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            List<double[]> xyAngles = new List<double[]>();
            for (int i = 0; i < n; i++)
            {
                long[] xy = ReadLongs();
                xyAngles.Add(new double[3] { xy[0], xy[1], Atan2(xy[1], xy[0]) });
            }
            xyAngles = xyAngles.OrderBy(a => a[2]).ToList();
            for (int i = 0; i < n; i++)
            {
                xyAngles.Add(new double[3]
                { xyAngles[i][0], xyAngles[i][1], xyAngles[i][2] });
            }

            double res = 0;
            for (int i = 0; i < 2 * n; i++)
            {
                for (int j = i; j < Min(2 * n, i + n); j++)
                {
                    double x = 0;
                    double y = 0;
                    for (int k = i; k <= j; k++)
                    {
                        x += xyAngles[k][0];
                        y += xyAngles[k][1];
                    }
                    res = Max(res, Sqrt(x * x + y * y));
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const int INF = 100100100;
int main(){
    int n,m;
    vector<int> to[100005];
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<int> q;
    vector<int> dist(n,INF);
    vector<int> kanban(n,-1);
    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int u:to[v]){
            if(dist[u] != INF) continue;
            dist[u] = dist[v]+1;
            kanban[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    rep(i,n){
        if(i == 0) continue;
        int ans = kanban[i];
        ans++;
        cout << ans <<endl;
    }
    return 0;
}

Measured memory_bytes: 10576
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long K, A, B; cin >> K >> A >> B; 
	if(A >= K){
		cout << 1 << "\n"; return 0;
	}else if(A <= B){
		cout << -1 << "\n"; return 0; 
	}else{
		cout << 1 + (K - B - 1) / (A - B) * 2 << "\n"; return 0; 
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<long long int> a(n+1);
  long long int ans=0;
  long long int a_max=0;
  for(int i=1;i<=n;i++){
    cin >> a.at(i);
    if(a_max < a.at(i)){
      a_max = a.at(i);
    }
    if(a.at(i)<a_max){
      ans += a_max - a.at(i);
    }
  }

  cout << ans <<endl;
  
}

Measured memory_bytes: 4780
n = int(input())

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ans = sum(b)
for i in range(len(a)-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]


print(ans)

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

map<long, long> pf(long n) {
  map<long, long> ma;
  for (long i = 2; i * i <= n; i++) {
    while (n % i == 0) ma[i]++, n /= i;
  }
  if (n != 1) ma[n]++;
  return ma;
}

int main() {
  long N, P;
  cin >> N >> P;
  long ans = 1;
  for (auto [a, b] : pf(P)) {
    while (b - N >= 0) b -= N, ans *= a;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3628
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    a = list(geta(int))
    a.sort()

    ret = 1
    for ai in a:
        ret *= ai
        if ret > 10**18:
            print(-1)
            return

    print(ret)


if __name__ == "__main__":
    main()

Measured memory_bytes: 20500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	int x = n % 10;
	if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
		cout << "hon\n";
	else if (x == 3)
		cout << "bon\n";
	else
		cout << "pon\n";

    return 0;
}

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

int main() {
  vector<int> a(100009);
  int n,ans=0;
  cin>>n;
  for(int i=0;i<n;++i){
    long long p;cin>>p;
    if(p>n) ans++;
    else a[p-1]++;
  }
  
  for(int i=0;i<n;++i){
    ans+=max(a[i]-(i+1),a[i]%(i+1));
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll q;
priority_queue<ll> fr;
priority_queue< ll ,vector<ll>,greater<ll>> bk;
ll mid,s_fr,s_bk;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>q;
    mid = s_fr = s_bk = 0;
    ll b = 0;
    ll in,inp,inpu;
    cin>>in>>inp>>inpu;
    mid = inp;
    b = inpu;
    rep(i,q-1){
        cin>>in;
        if(in==1){
            cin>>inp>>inpu;
            b += inpu;
            if(mid>=inp){
                fr.push(inp);
                s_fr += inp;
                if(fr.size()>bk.size()){
                    bk.push(mid);
                    s_bk += mid;
                    mid = fr.top();
                    fr.pop();
                    s_fr -= mid;
                }
            }else{
                bk.push(inp);
                s_bk += inp;
                if(bk.size()-fr.size()>=2){
                    fr.push(mid);
                    s_fr += mid;
                    mid = bk.top();
                    bk.pop();
                    s_bk -= mid;
                }
            }
        }else{
            ll ans = 0;
            ans += mid*(fr.size()) - s_fr;
            ans += s_bk - mid*bk.size() ;
            princ(mid);
            print(ans + b);
        }
    }
    return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	ll H,N;
	cin>>H>>N;
	ll sum=0;
	ll A;
	rep(i,0,N){
		cin>>A;
		sum+=A;
	}
	if(H<=sum){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

using namespace std;

int W, H, N;

struct Vector2{
	int x;
	int y;
};

bool exist(int map[2000][2000], Vector2 p, int step){
	if(p.x < 0 || p.y < 0 || p.x >= W || p.y >= H){
		return false;
	}
	if(map[p.y][p.x] > step + 1){
		map[p.y][p.x] = step + 1;
		return true;
	}
	return false;
}

int map[2000][2000];

int main(){
	
	string map_[2000];
	
	cin >> H >> W >> N;
	
	for(int i = 0; i < H; i++){
		cin >> map_[i];
	}
	
	int ans = 0;
	
	Vector2 start, goal, punct, p, p1;
	
	punct.x = -1;
	punct.y = -1;
	
	queue<Vector2> que;
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(map_[i][j] == 'S'){
				start.x = j;
				start.y = i;
				map[i][j] = 0;
			}
		}
	}
	
	for(int loop = 0; loop < N; loop++){
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(map_[i][j] == 'X'){
					map[i][j] = -1;
				}else if(map_[i][j] == '0' + loop){
					start.x = j;
					start.y = i;
					map[i][j] = 0;
				}else if(map_[i][j] == '0' + loop + 1){
					goal.x = j;
					goal.y = i;
					map[i][j] = 1 << 30;
				}else{
					map[i][j] = 1 << 30;
				}
			}
		}
		que.push(start);
		que.push(punct);
		
		bool checker = false;
		
		for(int step = 0; step < 10000000; step++){
			while(true){
				p = que.front();
				que.pop();
				if(p.x == punct.x && p.y == punct.y){
					que.push(punct);
					break;
				}else if(p.x == goal.x && p.y == goal.y){
					checker = true;
					break;
				}
				p1.x = p.x - 1;
				p1.y = p.y;
				if(exist(map, p1, step)){
					que.push(p1);
				}
				p1.x = p.x + 1;
				p1.y = p.y;
				if(exist(map, p1, step)){
					que.push(p1);
				}
				p1.x = p.x;
				p1.y = p.y - 1;
				if(exist(map, p1, step)){
					que.push(p1);
				}
				p1.x = p.x;
				p1.y = p.y + 1;
				if(exist(map, p1, step)){
					que.push(p1);
				}
			}
			if(checker){
				ans += step;
				break;
			}
		}
		
		while(!que.empty()){
			que.pop();
		}
		
		/*
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(map[i][j] == 1 << 30){
					printf("0 ");
				}else{
					printf("%d ", map[i][j]);
				}
			}
			printf("\n");
		}
		*/
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 10460
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

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

 

 
int main(){
    int n; cin >> n;
    vector<int> L(n);
    rep(i,n) cin >> L[i];
    
    sort(L.begin(), L.end()); //昇順にソート
    int ans = 0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            int r = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
            int l = j+1;
            ans += r-l;
        }
    }
    
    cout << ans << endl;
}


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

int now,n,k;

int main(){
  cin >> n>>k;
  int x=(n-1)*(n-2)/2;//理論最大
  if (k>x){
    cout<<-1<<endl;
    return 0;
  }
  if (n==2){
    cout<<1<<endl;
    cout<<"1 2"<<endl;
    return 0;
  }
  

  int y=x-k;//つなぐ必要のある辺
  int m=n-1+y;
  vector<vector<int>> vv = vector<vector<int>>(n-2, vector<int>(n-2, 0));
  REP(i,n-2){
    REP(j,n-2){
      if (j>=(i+1))continue;
      if (y==0)break;
      vv[i][j]=1;
      y--;
    }
  }

  //出力
  cout<<m<<endl;
  REP(i,n-1){
    cout<<1<<" "<<(i+2)<<endl;
  }
  
  REP(i,n-2){
    REP(j,n-2){
      if (vv[i][j]==1){
        cout<<(n-i-1)<<" "<<(n-j)<<endl;
      }
    }
  }

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

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

# define ll long long

int main()
{
   ll a,b,c;
   cin>>a>>b>>c;
   set< ll > s;
   s.insert(a);
   s.insert(b);
   s.insert(c);
   if(s.size()==2)
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
   
   
   return 0;
}

Measured memory_bytes: 256
a = []
for i in range(3):
    a.append(map(int, raw_input().split()))

b = []
for i in range(3):
	for j in range(2):
		b.append(a[i][j])

if b.count(1) <= 2 and b.count(2) <= 2 and b.count(3) <= 2 and b.count(4) <= 2:
	print("YES")

else:
	print("NO")

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int64_t i = 0; i < n; ++i)
using namespace std;

int main() {
  int a, b;
  bool c = 1, d = 1;
  string s;
  cin >> s;
  rep(i, s.size()){
    if(c && s[i] == 'A'){
      a = i;
      c = 0;
    }
    if(d && s[s.size()-i-1] == 'Z'){
      b = s.size() - i;
      d = 0;
    }
  }
  cout << b - a << endl;
  return 0;
}

Measured memory_bytes: 640
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
using namespace std;
int n;

int main()
{
	scanf("%d", &n);
	n%=10;
	if(n==2 || n==4 || n==5 || n==7 || n==9)
		printf("hon\n");
	else if(n==0 || n==1 || n==6 || n==8)
		printf("pon\n");
	else printf("bon\n");
	
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

typedef long long ll;

ll op(ll x)
{
	ll nrop=0;
	while (x > 2)
	{
		nrop++;
		x = (x - 1) / 2;
	}
	return nrop;
}

int main()
{
	ll x;

	cin >> x;
	ll st = 0, dr=1e14;

	while (dr - st > 1)
	{
		ll mij = (st + dr) / 2;
		ll ans = op(mij);
		if (ans > x)
			dr = mij;
		else st = mij;
	}
	cout << st << '\n';
	return 0;
}

Measured memory_bytes: 888
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
d=defaultdict(int)
for a in A:
    d[a]+=1
ans=sum(A)
Q=int(input())
for _ in range(Q):
    b,c=map(int,input().split())
    ans+=c*d[b]-b*d[b]
    d[c]+=d[b]
    d[b]=0
    print(ans)

Measured memory_bytes: 95040
#include <iostream>

using namespace std;

int main() {
    string str;
    getline(cin,str);
    int a=str.length();
    int s;
    s = a/2;
    int count=0;
    for(int i=0;i<s;i++)
    {
        if(str[i] != str[a-1-i])
        {
            str[i] == str[a-1-i];
            count++;
        }
    }
    cout << count ;
    
}

Measured memory_bytes: 256
N = int(input())
C = {}
for i in range(N):
    s = input().strip()
    s = "".join(sorted(s))
    if s not in C:
        C[s] = 0
    C[s] += 1
cnt = 0
for x in C:
    n = C[x]
    cnt += (n*(n-1))//2
print(cnt)

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int isPrime(int n){
  if(n<=1) return 0;
  int k;
  for(k=2;k*k<=n;k++) if(n%k==0) return 0;
  return 1;
}

void run(void){
  int n;
  scanf("%d",&n);
  const int mod=1000000007;
  int cnt=1;
  int i;
  for(i=1;i<=n;i++){
    if(!isPrime(i)) continue;
    int local=0;
    int t=n;
    while(t>=i){
      local+=t/i;
      t/=i;
    }
    cnt=(int64)cnt*(local+1)%mod;
  }
  printf("%d\n",cnt);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <queue>

long long C[51][51];


int main()
{
  int n,K;
  scanf("%d%d",&n,&K);
  for(int i=0;i<=n;i++){
    C[i][0]=C[i][i]=1ll;
    for(int j=1;j<i;j++){
      C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
  }
  int S,T;
  scanf("%d%d",&S,&T);
  std::vector<int> A(n);
  for(int i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  std::vector<long long> M(18,0ll);
  for(int j=0;j<18;j++){
    for(int i=0;i<n;i++){
      if((A[i]>>j)&1){
	M[j]|=(1ll<<i);
      }
    }
  }
  std::queue<std::pair<int,long long> > Q;
  long long ans=0ll;
  if((S&T)==S){
    long long BI=(1ll<<n)-1ll;
    std::vector<int> V;
    for(int j=0;j<18;j++){
      if(((S>>j)&1)==0&&((T>>j)&1)==1){
	V.push_back(j);
      }
      else if(((T>>j)&1)==0){
	BI&=~M[j];
      }
      else{
	BI&=M[j];
      }
    }
    int m=V.size();
    for(int s=0;s<n;s++){
      if((A[s]&S)!=S||(A[s]&T)!=A[s]){
	continue;
      }
      for(int J=0;J<(1<<m);J++){
	long long I=BI;
	int sg=1;
	for(int x=0;x<m;x++){
	  if((J>>x)&1){
	    sg=-sg;
	    if((A[s]>>V[x])&1){
	      I&=M[V[x]];
	    }
	    else{
	      I&=~M[V[x]];
	    }
	  }
	}
	//printf("%d %lld\n",J,I);
	int c=0;
	for(int i=s+1;i<n;i++){
	  if((I>>i)&1){
	    c++;
	  }
	}
	for(int x=0;x<K&&x<=c;x++){
	  ans+=sg*C[c][x];
	}
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MAX = 999999999;

int main(){
    int n, d, x;
    cin >> n >> d >> x;

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];

    int sum = x;
    rep(i, n){
        rep(j, 100){
            if(j * nums[i] + 1 <= d) sum ++;
            else break;
        }
    }

    cout << sum << endl;
}

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

const int MOD = 1000000000 + 7;

long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    // 最下位bitが立っていたら x^{2^i}を掛ける
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

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

  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }

  vector<pair<int, int>> v;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    int val = it->first;
    int cnt = it->second;
    v.push_back(make_pair(val, cnt));
  }

  if (n & 1) {
    bool is_ok = true;
    if (v[0].first != 0 || v[0].second != 1 || (int)v.size() != (n + 1) / 2) {
      is_ok = false;
    }
    for (int i = 1; i < (int)v.size(); i++) {
      if (v[i].second != 2 || v[i].first != i * 2) {
        is_ok = false;
      }
    }
    if (is_ok) {
      cout << mod_pow(2, v.size() - 1, MOD) << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    bool is_ok = true;
    if ((int)v.size() != n / 2) {
      is_ok = false;
    }
    for (int i = 0; i < (int)v.size(); i++) {
      if (v[i].second != 2 || i * 2 + 1 != v[i].first) {
        is_ok = false;
      }
    }
    if (is_ok) {
      cout << mod_pow(2, v.size(), MOD) << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3840
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut vec: Vec<usize> = vec![];
    for _ in 0..N {
        vec.push(read());
    }
    let mut ans_rev = vec![];
    for _ in 0..N {
        let mut last = None;
        for (i, &v) in vec.iter().enumerate() {
            let i = i + 1;
            if i == v {
                last = Some(i);
            }
        }
        match last {
            None => {
                println!("-1");
                return;
            }
            Some(a) => {
                ans_rev.push(a);
                vec.remove(a - 1);
            }
        }
    }
    ans_rev.reverse();
    for i in ans_rev {
        println!("{}", i);
    }
}


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

long long dist(long long k,long long s,long long t){
	if(s>t){
		long long temp=s;
		s=t;
		t=temp;
	}
	if(k<s)return t-k;
	if(k>t)return k-s;
	return min(t-k,k-s)*2+max(t-k,k-s);
}

int main(){
	int A,B,Q;
	cin >> A >> B >> Q;
	vector<long long> s;
	vector<long long> t;
	vector<long long> x(Q);
	vector<long long> ans;
	
	s.push_back(-999999999999);
	t.push_back(-999999999999);
	for(int i=0;i<A;i++){
		long long k;
		cin >> k;
		s.push_back(k);
	}
	for(int i=0;i<B;i++){
		long long k;
		cin >> k;
		t.push_back(k);
	}
	s.push_back(999999999999);
	t.push_back(999999999999);
	
	for(auto &k : x)cin >> k;
	
	for(auto &k : x){
		auto s1=lower_bound(s.begin(),s.end(),k)-s.begin()-1;
		auto s2=s1+1;
		auto t1=lower_bound(t.begin(),t.end(),k)-t.begin()-1;
		auto t2=t1+1;
		long long a=99999999999999;
		a=min(a,dist(k,s[s1],t[t1]));
		a=min(a,dist(k,s[s1],t[t2]));
		a=min(a,dist(k,s[s2],t[t1]));
		a=min(a,dist(k,s[s2],t[t2]));
		ans.push_back(a);
	}
	for(auto &k : ans)cout << k << endl;
	return 0;
}

Measured memory_bytes: 4596
import sys

input = sys.stdin.readline


def main():
    X, K, D = map(int, input().split())

    X = abs(X)
    q, r = divmod(X, D)
    if K <= q:
        ans = (q - K) * D + r
    else:
        if (K - q) % 2 == 0:
            ans = r
        else:
            ans = D - r

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
mod = 10 ** 9 + 7
n, a, b = map(int, input().split())

comb = [n] * (b + 1)
inv = [1] * (b + 1)
for i in range(2, b + 1):
  inv[i] = -inv[mod % i] * (mod // i) % mod
  comb[i] = comb[i-1] * (n - i + 1) * inv[i] % mod

count = pow(2, n, mod) - 1 - comb[a] - comb[b]
print(count % mod)

Measured memory_bytes: 18804
program prob6
    implicit none
    integer(8) :: n, i, ans, minsum
    integer(8), allocatable :: a(:), b(:), d(:)
    read(*,*) n
    allocate(a(n))
    allocate(b(n))
    allocate(d(n))
    read(*,*) a
    read(*,*) b

    d = a - b
    if(sum(d) < 0) then
        write(*,*) "-1"
        stop
    end if

    call msort(d)

    minsum = 0

    do i = 1, n
        if(d(i) >= 0) then
            ans = i - 1
            exit
        end if
        minsum = minsum - d(i)
    end do

    do i = n, 1, -1
        if(minsum <= 0) then
            exit
        end if
        minsum = minsum - d(i)
        ans = ans + 1
    end do

    write(*,*) ans

    deallocate(a)
    deallocate(b)
    deallocate(d)
    stop
contains


  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort

end program prob6

Measured memory_bytes: 4276