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

#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector<int> 
#define vll vector < long long > 
#define vld vector < long double >
#define vs vector<string> 
#define vb vector<bool> 
#define vin(v, n) for (ll i = 0; i < n; i++) cin >> v[i];
#define vout(v, n) for (ll i = 0; i < n; i++) cout << v[i] << " ";
#define all(x) x.begin(), x.end()
#define sortall(x) sort(x.begin(), x.end())
#define ll long long
#define ld long double
#define sp " "
#define nl "\n"
#define mod 1e9 + 7
#define pb push_back
#define prec(n) fixed<<setprecision(n)
#define llsetBits(x) __builtin_popcountll(x)            //counts number of set bits in ll x
#define setBits(x) __builtin_popcount(x)                //counts number of set bits in int x
#define llcountTz(x) __builtin_ctzll(x)                 //counts trailing zeroes in ll x
#define countTz(x) __builtin_ctz(x)                     //counts trailing zeroes in int x
#define debug(x) cout << #x << " " << x;
#define fo(i, n) for (int i = 0; i < n; i++)
#define foexc(i, a, b) for (int i = a, ; i < b; i++)
#define foinc(i, a, b) for (int i = a, ; i <= b; i++)
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll power(ll x, ll n);

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

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

ll gcd(ll a,ll b)
{
	if(b==0) {return a;}
	else {return gcd(b,a%b);}
}
ll lcm(ll a, ll b)
{
	return (a*b)/(gcd(a,b)) ;
}
ll power(ll x, ll n)
{
	if(n==0) { return 1ll;}
	else if(n%2==0) { return power((x*x),n/2);}
	else { return x*power((x*x),(n-1)/2);}
}

Measured memory_bytes: 3656
#include <cstdio>
#include <utility>
#include <string>
#include <queue>
#include <climits>
#include <vector>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
	_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

struct N {
	int s, n;
};

bool all(int n) {
	int c = n & 3;
	n >>= 2;
	for (; n; n >>= 2)
		if ((n & 3) != c)
			return false;
	return true;
}

int main() {
	for (;;) {
		string s = in;
		if (s == "0")
			return 0;
		vector<bool> m(1 << s.size() * 2);
		int t {};
		for (char c: s)
			t = t << 2 | (c == 'r' ? 1 : c == 'g' ? 2 : 3);
		m[t] = true;
		queue<N> q;
		q.push({t, 0});
		[&] {
			while (!q.empty()) {
				N f {q.front()};
				q.pop();
				if (all(f.s)) {
					outl(f.n);
					return;
				}
				for (int i: range(1, s.size())) {
					int x = (i - 1) * 2,
						m0 = f.s >> x & 3,
						m1 = f.s >> i * 2 & 3;
					if (m0 != m1) {
						int g = m0 ^ m1,
							t = (f.s & ~(15 << x)) | (g | g << 2) << x;
						if (!m[t]) {
							m[t] = true;
							q.push({t, f.n + 1});
						}
					}
				}
			}
			outl("NA");
		}();
	}
}


Measured memory_bytes: 2832
#include<stdio.h>

int main()
{
	int n , h , m, s ;
	scanf("%d", &n);
	h = n / 3600 ;
	m = (n - h * 3600 ) / 60 ;
	s = n- ( h * 3600) - ( m * 60);
	
	printf("%d:%d:%d\n", h , m , s );
	return 0;
} 


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


using namespace std;

int main() {
    int n; cin>>n;
    vector<int>dp(n + 1);
    for(int i = 1;  i <= n; ++i){
        for(int j = i ; j <= n ; j += i){
            dp[j]++;
        }
    }
    long long ans =0 ;
    for(int i = 1 ; i <= n; ++i){
        ans += (long long)i * dp[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 42324
#include <iostream>
#include <string>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

const int QMAX = 200000;
char T[QMAX], D[QMAX];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, Q;
  cin >> N >> Q;
  cin.ignore();
  string board;
  getline(cin, board);
  REP(i, Q) { cin >> T[i] >> D[i]; }
  int head = -1, tail = N;
  for (int i = Q - 1; i >= 0; --i) {
    char t = T[i];
    if (D[i] == 'L') {
      if (head + 1 < N && t == board[head + 1]) ++head;
      if (tail < N && t == board[tail]) ++tail;
    } else {
      if (tail - 1 >= 0 && t == board[tail - 1]) --tail;
      if (head >= 0 && t == board[head]) --head;
    }
  }
  cout << (tail - head - 1) << endl;
}


Measured memory_bytes: 976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		int anser;

		if (n == 0) {
			anser = m * (m - 1) / 2;
		} else if (m == 0) {
			anser = n * (n - 1) / 2;
		} else {
			anser = (n * (n - 1) + m * (m - 1)) / 2;
		}

		System.out.println(anser);
	}

}


Measured memory_bytes: 22612
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m,max=Integer.MIN_VALUE,count=0;
		int[][] ans=new int[15][15];//入力を15*15の2次元配列で受け取る。ans[i]にはi番目の人の15人に対する意見が格納される。
		boolean flag=true;
		for(int[]buff:ans) {
			Arrays.fill(buff, -1);//ansの初期値を全て-1にする
		}

		/*入力受け取り*/
		for(int i=0;i<n;i++) {
			m=sc.nextInt();//i番目の人の意見の数
			for(int j=0;j<m;j++) {
				ans[i][sc.nextInt()-1]=sc.nextInt();//xをans[i][x-1]とすることで、i番目の人のxに対する意見yをans[i][x]に格納できる。
			}
		}
		/*bit演算*/
		for(int i=0;i<Math.pow(2, n);i++) {
			int[] status = new int[n];
			for(int j=0;j<n;j++) {//iを2進数にした場合にどこの桁が1になっているか判定し、1の場合はstatusに代入
				if((1&i>>j)==1) {
					status[j]=1;//statusが1である==正直者である==status[i]が1だった場合、i番目の人の意見は全て正しくないと行けない。
					count++;
				}
			}
			for(int j=0;j<n;j++) {
				if(status[j]==1) {
					for(int k=0;k<n;k++) {
						if(ans[j][k]==-1)continue;//kの人に対して発言していない。
						if(ans[j][k]!=status[k])flag=false;
					}
				}
			}
			if(flag)max=Math.max(max, count);
			flag=true;
			count=0;
		}
		System.out.println(max);


	}

}



Measured memory_bytes: 24916
x,k,d = map(int, input().split())
x = abs(x)
if x<k*d:
	ans = abs(k*d-x) % (2*d)
	print(min(ans, 2*d-ans))
else:
	print(x-k*d)
# eval("eval(\"print(\"hello\")\")")

# # a = "1234"
# # al = list(a)
# # al.insert(1,".")
# # print(al)


# str = input()
# l = list(str)
# n = len(str)
# i = 0;
# while i<n:
# 	if(l[i]=="("):
# 		l.insert(i,"*")
# 		l.insert(i,"*")
# 		n = n+2
# 		i=i+2
# 	i = i+1
# # print(l)
# print(eval("".join(l)))


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

int n, k, r, len;
set <int> s;

int main() {
	ios::sync_with_stdio(0);
	n = 7;
	cin >> k;
	r = n % k;
	len = 1;
	while(r != 0) {
		if(s.find(r) != s.end()) {
			cout << -1 << endl;
			return 0;
		}
		s.insert(r);
		n = r * 10 + 7;
		r = n % k;
		len++;
	}
	cout << len << endl;
	return 0;
}

Measured memory_bytes: 50416
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define MOD 1000000007
#define PI acos(-1)
int main()
{
	IOS
	ll n;
	cin>>n;
	ll a[n+1],i;
	for(i=1;i<=n;i++)
	cin>>a[i];
	map<ll,ll> mp1,mp2;
	ll ans=0;
	for(i=1;i<=n;i++)
	{
	mp1[i+a[i]]++;
	mp2[i-a[i]]++;
	}
	map<ll,ll>::iterator it;
	for(it=mp1.begin();it!=mp1.end();it++)
	{
		if(mp2.find(it->F)!=mp2.end())
		ans=ans+it->second * mp2[it->first];
	}
	
	cout<<ans;
}

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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

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

    ll N, A, B;
    std::cin >> N >> A >> B;

    ll prev;
    std::cin >> prev;

    ll ans = 0;
    REP(i, N - 1) {
        ll x;
        std::cin >> x;
        ll a_cost = (x - prev) * A;
        ans += min(a_cost, B);
        prev = x;
    }

    std::cout << ans << std::endl;

    return 0;
}


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

void Main() {
  string N;
  cin >> N;
  if (N[0] == '7' || N[1] == '7' || N[2] == '7') cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >>S;
  int last = S.size() - 1;
  int ans = 0;
  for(int i = 0; i <= last/2; i++){
    if(S[i] != S[last - i]){
      S[last - i] = S[i];
      ans++;
    }
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

H = [ i for i in range(1,1000) ]
S = []
for i in H:
    X = sum(H[0:i])
    S.append(X)
#print(S)


for j in range(999):
    if (S[j-1] - A)==(S[j] - B):
         print(S[j-1]- A)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		map<string,int>in;
		rep(i,n){
			string s;int a;
			cin>>s>>a;
			in[s]=a;
		}
		cin>>n;
		rep(i,n){
			string s;
			int a;
			cin>>s>>a;
			int sum=0;
			rep(j,a){
				string tmp;
				cin>>tmp;
				sum+=in[tmp];
			}
			in[s]=min(in[s],sum);
		}
		string s;cin>>s;
		cout<<in[s]<<endl;
	}
	
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> v(N), p(N), q(N);

    REP(i, N) { cin >> p.at(i); }
    REP(i, N) { cin >> q.at(i); }

    int p_num;
    int q_num;

    iota(v.begin(), v.end(), 1);
    int num = 0;
    do {
        num++;
        bool flug = true;
        REP(i, N) {
            if (p[i] != v[i]) {
                flug = false;
            }
        }
        if (flug) {
            p_num = num;
            break;
        }
    } while (next_permutation(v.begin(), v.end()));

    iota(v.begin(), v.end(), 1);
    num = 0;
    do {
        num++;
        bool flug = true;
        REP(i, N) {
            if (q[i] != v[i]) {
                flug = false;
            }
        }
        if (flug) {
            q_num = num;
            break;
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(p_num - q_num) << endl;

    return 0;
}


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

using namespace std;

const int mod = 1'000'000'007;

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

int pw(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return res;
}

int get(int b) {
  int res = pw(10, b);
  add(res, mod - pw(10, b - 1));
  return res;
}

int main() {
  int s;
  scanf("%d", &s);
  int ans = 0;
  for (int i = 1; i * i <= s; ++i) {
    if (s % i == 0) {
      {
        int cnt = get(i);
        if (i >= 9 || cnt >= s / i) {
          add(ans, cnt);
          add(ans, mod - s / i + 1);
        }
      }
      if (s / i != i) {
        int cnt = get(s / i);
        if (s / i >= 9 || cnt >= i) {
          add(ans, cnt);
          add(ans, mod - i + 1);
        }
      }
    }
  }
  for (int i = 1; i <= 8; ++i) {
    int cnt_i = get(i);
    long long v = 0;
    for (int j = i + 1; j <= 9; ++j) {
      int cnt_j = get(j);
      for (int k = 1; k <= cnt_i; ++k) {
        if (v + i * k >= s) {
          break;
        }
        if ((s - v - i * k) % j == 0 && (s - v - i * k) / j <= cnt_j) {
          add(ans, 1);
        }
      }
      v += j * cnt_j;
      if (v >= s) {
        break;
      }
    }
  }
  for (int i = 9; i <= s / 2; ++i) {
    int v = s / (i + 1);
    if (s % (i + 1) == 0) {
      --v;
    }
    int r = s % i;
    if (v >= r) {
      add(ans, (v - r) / i + (r != 0));
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

import string
s = v()

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

lis =list(string.ascii_lowercase)
nlis = [0]*26

for i in s:
    t = lis.index(i)
    nlis[t] += 1

if sum(nlis) != 26:
    for i in range(26):
        if nlis[i] == 0:
            print(s+lis[i])
            break
else:
    for i in range(25, -1, -1):
        for j in lis:
            if s[i] < j and j not in s[:i]:
                print(s[:i] + j)
                exit()


Measured memory_bytes: 10528
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for(ll i=0;i<(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll a,b,c;cin>>a>>b>>c;
    cout<<mmin(a,mmin(b,c))<<" "<<mmax(a,mmax(b,c))<<Endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------













































Measured memory_bytes: 3228
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt(),b=stdIn.nextInt(),c=stdIn.nextInt(),d=stdIn.nextInt();
		if(c>a) a=c;
		if(b>d) b=d;
		if(b-a>0) System.out.print(b-a);
		else System.out.print(0);
	}
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

ll f(ll x, vector<int> &p, vector<int> &n) {
    ll res = 0;
    
    for (int m : p) {
        int l = -1, r = n.size();
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if ((ll)m * n[mid] < x) l = mid;
            else r = mid;
        }
        res += r;
    }

    return res;
}

ll g(ll x, vector<int> &p, vector<int> &n) {
    ll res = 0;

    rep(i, p.size()) {
        int l = i, r = p.size();
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if ((ll)p[i] * p[mid] < x) l = mid;
            else r = mid;
        }
        res += l - i;
    }

    rep(i, n.size()) {
        int l = i, r = n.size();
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if ((ll)n[i] * n[mid] < x) l = mid;
            else r = mid;
        }
        res += l - i;
    }

    return res;
}

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int n, p, z;
    n = p = z = 0;
    rep(i, N) {
        if (A[i] < 0) n++;
        if (0 < A[i]) p++;
        if (A[i] == 0) z++;
    }

    ll nega = (ll)n*p, posi = (ll)n*(n-1) + (ll)p*(p-1), zero = 0;
    rep(i, z) zero += N-1-i;

    vector<int> positive, negative;
    rep(i, N) {
        if (A[i] < 0) negative.push_back(A[i]);
        if (0 < A[i]) positive.push_back(A[i]);
    }
    if (K <= nega) {
        sort(positive.begin(), positive.end());
        sort(negative.begin(), negative.end());

        ll l = (ll)-INF*INF, r = (ll)INF*INF;
        while (r - l > 1) {
            ll mid = (l + r) / 2;
            if (f(mid, positive, negative) < K) l = mid;
            else r = mid;
        }
        cout << l << endl;
    } else if(K <= nega + zero) {
        puts("0");
    } else {
        K -= nega + zero;
        sort(positive.begin(), positive.end());
        sort(negative.begin(), negative.end(), greater<int>());

        ll l = (ll)-INF*INF, r = (ll)INF*INF;
        while (r - l > 1) {
            ll mid = (l + r) / 2;
            if (g(mid, positive, negative) < K) l = mid;
            else r = mid;
        }
        cout << l << endl;
    }
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b=0,d,e=0;
  cin>>a;
 map<int,int>c;
  rep(i,a){
    cin>>d;
    if(c.count(d)){
          c[d]++;
    }
    else c[d]=1;
  }
  auto f=c.begin(),g=c.end();
  for(auto i=f;i!=g;i++){
    if(i->second%2==1)b++;
  }
  cout<<b;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main()
{
    int i, j, k;
    int n, t, m;
    string s;
    ll x;
    cin >> x;
    ll sum = 1000*(x/500);
    x = x%500;
    sum += 5*(x/5);
    cout << sum << endl;
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
    int n;
    int b, f, r, v;
    vector<vector<vector<int>>> x(4, vector<vector<int>>(3, vector<int>(10)));
    cin >> n;
    REP(i,n) {
        cin >> b >> f >> r >> v;
        x.at(b-1).at(f-1).at(r-1) += v;
    }
    REP(i,4) {
        if(i) {
            REP(l,20) cout << '#';
            cout << endl;
        }
        REP(j,3) {
            REP(k,10) {
                cout << ' ';
                cout << x.at(i).at(j).at(k);
            }
            cout << endl;
        }
    }
    return 0;
}



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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

int RMaxQ(int a, int b) {
    return max(a, b);
}
int MaxE() { return -1; }

int target;
bool f(int v) {
    return v < target;
}

signed main() {
    IOS;

    int N, Q;
    cin >> N >> Q;
    V<> A(N);
    REP(i, N) {
        cin >> A[i];
    }

    segtree<int, RMaxQ, MaxE> segmax(A);

    REP(i, Q) {
        int q;
        cin >> q;
        if(q == 1) {
            int x, v;
            cin >> x >> v;
            x--;
            segmax.set(x, v);
        }
        else if(q == 2) {
            int l, r;
            cin >> l >> r;
            l--;
            print(segmax.prod(l, r));
        }
        else {
            int x, v;
            cin >> x >> v;
            x--;
#if 0
            if(v > segmax.prod(x, N)) {
                print(N + 1);
                continue;
            }
            int lb = x, ub = N - 1;
            while(ub - lb > 1) {
                int mid = (lb + ub) / 2;
                int val = segmax.prod(x, mid + 1);
                if(v <= val) { ub = mid; }
                else { lb = mid; }
            }
            if(v <= segmax.prod(x, lb + 1)) {
                print(lb + 1);
            }
            else {
                print(ub + 1);
            }
#else
            target = v;
            print(segmax.max_right<f>(x) + 1);
#endif
        }
    }

    return 0;
}


Measured memory_bytes: 8992
#include <iostream>
#include <string>
using namespace std;
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 = 1LL<<60;

// 入力
string s, t;

// DPテーブル
int dp[3100][3100] = {0}; // 初期値も初期条件も 0

int main() {
    cin >> s >> t;
    
    // DPループ
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }
    
    // 復元
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }
        
        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }
        
        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、res + t[j-1] でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 37120
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 ANS = 0;
	cin >> N;

	vector<SINT32> DATA(N);
	vector<SINT32> PDATA(N);
	vector<SINT32> MDATA(N);
	
	rep(i,0,N) {
		cin >> DATA[i];
	}

	PDATA[0] = DATA[0];
	rep(i,1,N) {
		PDATA[i] = __gcd(DATA[i],PDATA[i-1]);
	}

	MDATA[N-1] = DATA[N-1];
	rep(i,1,N) {
		MDATA[N-i-1] = __gcd(DATA[N-i-1],MDATA[N-i]);
	}



	ANS = MAX(MDATA[1],PDATA[N-2]);

	rep(i,1,N-1) {
		ANS = MAX(ANS,__gcd(PDATA[i-1],MDATA[i+1]));
	}



	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int A[3];
	rep(i, 3) cin >> A[i];
	int K; cin >> K;
	sort(A, A + 3);
	int ans = A[0] + A[1];
	rep(i, K) A[2] *= 2;

	cout << ans + A[2] << endl;

	

    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
if s[0] == 'A':
    counter = 0
    for i in range(2,n-1):
        if s[i] == 'C':
            counter += 1
    if counter == 1:
        check = True
        for i in range(n):
            if s[i] != 'A' and s[i] !='C':
                if s[i].isupper():
                    check = False
                    break
        if check:
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; ++i) {
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(ll j = i * i; j <= n; j += i) {
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while(x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for(int p : fl) {
      if(res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  int q;
  int n = 100010;
  cin >> q;
  vi l(q), r(q);
  rep(i, q) cin >> l[i] >> r[i];
  vi sum(n, 0);
  Sieve s(n);
  rep2(i, 1, n) {
    sum[i] = sum[i - 1];
    if(s.isPrime(i) && s.isPrime((i + 1) / 2)) sum[i]++;
  }
  rep(i, q) cout << sum[r[i]] - sum[l[i] - 1] << endl;
}

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

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; i++) {
    char S;
    cin >> S;
    if(S == 'Y') {
      cout << "Four" << endl;
      break;
    }
    else if(i == N - 1)
      cout << "Three" << endl;
  }
  return 0;
}

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

struct RMQ {
	using type = ll;
	static type id() { return LLONG_MIN; }
	static type op(const type& l, const type & r) { return max(l, r); }
};

template <typename M>
class segment_tree {
	using T = typename M::type;
	const int n;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
public:
	segment_tree(int n_) : n(size(n_)), data(n * 2, M::id()) {}
	segment_tree(int n_, T val) : n(size(n_)), data(n * 2, val) {}
	void init(const vector<T>& data_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = M::op(data[i * 2], data[i * 2 + 1]);
	}
	T find(int l, int r) {
		l += n; r += n + 1;
		T res1 = M::id(), res2 = M::id();
		while (l < r) {
			if (l & 1) res1 = M::op(res1, data[l++]);
			if (r & 1) res2 = M::op(data[--r], res2);
			l >>= 1; r >>= 1;
		}
		return M::op(res1, res2);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	ll N, C;
	cin >> N >> C;
	vector<ll> x(N), v(N), base(N);
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> v[i];
		sum += v[i];
		base[i] = sum - x[i];
	}
	segment_tree<RMQ> st(N);
	st.init(base);
	ll res = max(st.find(0, N - 1), 0LL), tmp = 0;
	for (int i = N - 1; i > 0; i--) {
		tmp += v[i];
		res = max(res, st.find(0, i - 1) + tmp - (C - x[i]) * 2);
	}
	sum = 0;
	for (int i = N - 1; i >= 0; i--) {
		sum += v[i];
		base[i] = sum - (C - x[i]);
	}
	st.init(base);
	res = max(res, st.find(0, N - 1));
	tmp = 0;
	for (int i = 0; i < N - 1; i++) {
		tmp += v[i];
		res = max(res, st.find(i + 1, N - 1) + tmp - x[i] * 2);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
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 fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

ll n,m;
vector<pair<int,int>> v;

class union_find{//rank無しunion_find木
	int par[100002]={-1};
	
public:
	union_find(int num){ 
		for(int i=0;i<=num;i++)par[i]=-1;
	}
	int root(int x){//再帰
		if(par[x]<0){
			return x;
		}else{
			return par[x] = root(par[x]);
		}
	}
	int size(int x){return -1*par[root(x)];}
	bool same(int x,int y){ return root(x)==root(y); }//同じunionにいるか？
	void unite(int x,int y){//unionの結合
		x = root(x);y = root(y);
		if(x==y)return ;
		par[x] += par[y];
		par[y] = x;
	}
};

int main(){
	cin>>n>>m;ll aa,bb;
	rep(i,m){
		cin>>aa>>bb;
		v.pb(mp(aa,bb));
	}
	union_find u(n+1);
	stack<ll> ans;ll tmp =0;
	tmp = n*(n-1)/2;
	for(int i = m-1;i>=0;i--){
		ans.push(tmp);
		if(!u.same(v[i].first,v[i].second))tmp -= u.size(v[i].first)*u.size(v[i].second);
		u.unite(v[i].first,v[i].second);
	}
	rep(i,m){
		cout<<ans.top()<<endl;
		ans.pop();
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

void solve(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a * c;
    if(ans < b * d)
        ans = b * d;
    if(ans < a * d)
        ans = a * d;
    if(ans < b * c)
        ans = b * c;
    cout << ans << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>

#define ll          int
#define F           first
#define S           second
#define pb          push_back
#define mp          make_pair
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define ld             long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

//vector use mat kiya kr
const ll N = 21;
ll dp[N][1<<N];

ll dfs(ll wom ,ll mask, ll n , vector<vector<ll>> &v)
{
    if(wom>=n)
    {
        //suhagraat ka din sab set xD
        if(mask==0)
            return 1;
        return 0;
    }
    if(dp[wom][mask]!=-1)
        return dp[wom][mask];
    ll ans=0;
    for (int i = 0; i <n; ++i)
    {
        if(((mask & (1<<i))) && (v[wom][i]==1))
            ans=(ans+dfs(wom+1,(mask-(1<<i)), n, v))%hell;

    }
    dp[wom][mask]=ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);
    #endif
    ll t = 1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<vector<ll>> v(n,vector<ll> (n,0));
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                cin>>v[i][j];
            }

        }
       
        ll mask=(1<<n)-1;
        memset(dp,-1,sizeof(dp));
        ll ans=dfs(0,mask, n , v);

        cout<<ans;
    }

    
    time
    return 0;
} 

Measured memory_bytes: 175668
main=do
 getLine
 d<-map read.words<$>getLine
 let k=length d
 interact$unlines.map(\[n,x,m]->show$n-1-div(x`mod`m+sum[(m-(-e)`mod`m)*div(n-i+k)k|(e,i)<-zip d[2..]])m).map(map read.words).lines

Measured memory_bytes: 7548
from collections import defaultdict
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*(n+1)
d=defaultdict(int)
for i in range(1,n+1):
  b[i]=b[i-1]+a[i-1]
for i in range(n+1):
  d[b[i]%m]+=1
ans=0
for i in d.items():
  ans+=d[i[0]]*(d[i[0]]-1)//2
print(ans)

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

// author: Seong Yong-ju ( @sei40kr )

#define DEBUG(x) cout << #x << ": " << x << endl

#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); --i)

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i =  (n) - 1; i >= 0; --i)

#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

  string str;
  cin >> str;
  size_t l = str.length();
  int cs['z' - 'a' + 1] = {};

  for (const char &c : str) {
    ++cs[c - 'a'];
  }

  long ans = 0;
  for (const char &c : str) {
    ans += l - cs[c - 'a'];
  }
  ans /= 2;
  ++ans;

  cout << ans << endl;
}


Measured memory_bytes: 720
N,K=map(int,input().split())
A=list(map(int,input().split()))
s=sum(A)
dp=[[-1]*2 for i in range(42)]
dp[0][0]=0
bit=[0]*41
for i in range(41):
    mask=1<<(40-i)
    cnt0,cnt1=0,0
    for j in range(N):
        if A[j]&mask:
            cnt1+=1
        else:
            cnt0+=1
    cost0,cost1=cnt1*mask,cnt0*mask
    if dp[i][1]!=-1:
        dp[i+1][1]=max(dp[i+1][1],dp[i][1]+max(cost0,cost1))
    if K&mask:
        dp[i+1][1]=max(dp[i+1][1],dp[i][0]+cost0)
        dp[i+1][0]=max(dp[i+1][0],dp[i][0]+cost1)
    else:
        dp[i+1][0]=dp[i][0]+cost0
print(max(dp[-1]))

Measured memory_bytes: 86540
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(Math.abs(n-a)>Math.abs(n-b)){
            System.out.println("B");
        }
        else{
            System.out.println("A");
        }
        }
    }



Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> dp(n+2, 0);
    vector<int> ng(n+2);
    rep(i, m) {
        int a;
        cin >> a;
        ng[a]=1;
    }
    dp[0] = 1;
    rep(i, n) {
        if(ng[i+1] == 0) (dp[i+1] += dp[i]) %= MOD;
        if(ng[i+2] == 0) (dp[i+2] += dp[i]) %= MOD;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

ll n, x;

ll f(ll len, ll h) {
    if (h == 0 || len == 0) {
        return 0ll;
    }

    if (len % h == 0) {
        return h * ((len / h) * 2 - 1);
    }
    else {
        return f(h, len % h) + h * (len / h) * 2;
    }
}

void solve() {
    scanf("%lld %lld", &n, &x);
    printf("%lld\n", n + f(n - x, x));
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t = list(input())

ans = 0

for i in range(n):
    valian = t[i]
    if valian == 'r':
        ans += p
    elif valian == 's':
        ans += r
    else:
        ans += s
        
for i in range(k):
    check = ''
    for j in range(i, n, k):
        if check == '':
            check = t[j]
            continue
        
        if check == t[j]:
            if t[j] == 'r':
                ans -= p
            elif t[j] == 's':
                ans -= r
            else:
                ans -= s
            check = ''
        else:
            check = t[j]
        
print(ans)

Measured memory_bytes: 9924
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

N,M=MAP()
nodes1=[[] for i in range(N)]
nodes2=[[] for i in range(N)]
for i in range(M):
    u,v=MAP()
    nodes1[u].append(v)
    nodes2[v].append(u)

T=[]
visited=[False]*N
def rec1(cur):
    visited[cur]=True
    for nxt in nodes1[cur]:
        if not visited[nxt]:
            rec1(nxt)
    # 行き止まったところから順にTに入れていく
    T.append(cur)

# グラフが連結とは限らないので全頂点やる
for u in range(N):
    if not visited[u]:
        rec1(u)

visited=[False]*N
group=[0]*N
grpnum=1
def rec2(cur):
    global grpnum
    group[cur]=grpnum
    visited[cur]=True
    for nxt in nodes2[cur]:
        if not visited[nxt]:
            rec2(nxt)

# 逆順で進めるところまで行く
for u in reversed(T):
    if not visited[u]:
        rec2(u)
        grpnum+=1

Q=INT()
for _ in range(Q):
    u,v=MAP()
    if group[u]==group[v]:
        print(1)
    else:
        print(0)



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

using namespace std;

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

  int ans;
  if (A >= 13) {
    ans = B;
  } else if (A >= 6) {
    ans = B / 2;
  } else {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all int i=0; i<n; i++
#define pb push_back
typedef long long int ll;

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define mod 1000000007

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
}
int main(){
	int m,d,ans=0;
	cin>>m>>d;
	for(int i=1; i<=m; i++){
		for(int j=1; j<=d; j++){
			if(j/10 >=2 && j%10>=2 && (j/10) * (j%10) == i)ans++;
		}
	}
	cout<<ans<<endl;
}


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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    ll x = min(a, k);
    a -= x; k -= x;
    x = min(b, k);
    b -= x; k -= x;
    cout << a << " " << b << "\n";
    return 0;
}

Measured memory_bytes: 256
code = r"""
# distutils: language=c++
# distutils: include_dirs=/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder" nogil:
    cdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()

from cython.parallel cimport prange
from libc.stdio cimport scanf, printf
cdef int i
cdef int N, Q
cdef int t, u, v
scanf("%d%d", &N, &Q)
cdef dsu *d = new dsu(N)
for i in prange(Q, nogil=1):
    scanf("%d%d%d", &t, &u, &v)
    if t == 0:
        d.merge(u, v)
    else:
        printf("%d\n", d.same(u, v))
"""
import os
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b -j 36 solve.pyx')
import solve

Measured memory_bytes: 10748
using System;
using System.Text;

namespace abc148_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            string[] ST = Console.ReadLine().Split(" ");
            string S = ST[0];
            string T = ST[1];

            StringBuilder ansBuild = new StringBuilder();
            for(int i = 0; i < N; i++)
            {
                ansBuild.Append(S[i]);
                ansBuild.Append(T[i]);
            }
            Console.WriteLine(ansBuild.ToString());
        }
    }
}


Measured memory_bytes: 27400
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

lst = list(itertools.permutations(range(1,N+1)))
#print(lst)
Pi = lst.index(P)
Qi = lst.index(Q)
print(abs(Pi-Qi))

Measured memory_bytes: 8052