akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#include "string"

int32_t main(){
	boost;
	int n,m,k;
	cin>>n>>m>>k;
	int ans = 0;
	char a[n][m];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	for(int i=0;i<(1<<n);i++){
		for(int j =0;j<(1<<m);j++){
			int cnt = 0;
			for(int l=0;l<n;l++){
				for(int r=0;r<m;r++){
					if(!(i&(1ll<<l)) && !(j&(1ll<<r)) && a[l][r] == '#')
						cnt++;
				}
			}
			if(cnt == k)
				ans++;
		}
	}
	cout<<ans<<endl;		
}



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

using namespace std;

int L,n;

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

vector<string> s{};

	for(int i=0;i<n;i++){
		string str;
		cin>>str;
		s.emplace_back(str);

	}

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

string ans;
  for (int i = 0; i < n; i++) {
	ans +=s[i];
	}
cout<<ans<<endl;

return 0;
}



Measured memory_bytes: 3632
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,m,n,a,b
    integer(8) :: x(26),y(26)
  
    read(*,*) s
    read(*,*) t
    x(:)=0
    y(:)=0
    m=len_trim(s)
    n=len_trim(t)
    do i=1,m
        a=ichar(s(i:i))-96
        x(a)=x(a)+1
    end do
    do i=1,n
        a=ichar(t(i:i))-96
        y(a)=y(a)+1
    end do
    do i=1,26
        if(x(i)/=0)then
            a=i
            exit
        end if
    end do
    do i=26,1,-1
        if(y(i)/=0)then
            b=i
            exit
        end if
    end do
    
    if(a>b)then
        write(*,*)'No'
    else if(a<b)then
        write(*,*)'Yes'
    else if(x(a)/=m .or. y(b)/=n)then
        write(*,*)'No'
    elseif(n>m)then
        write(*,*)'Yes'
    elseif(n<=m)then
        write(*,*)'No'
    end if

  
    stop
end program sample
  



Measured memory_bytes: 2832
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, A, B := sc.nextInt(), sc.nextInt(), sc.nextInt()
	if N*A < B {
		fmt.Fprintln(wtr, N*A)
	} else {
		fmt.Fprintln(wtr, B)
	}

	wtr.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
using namespace std;


unsigned int xor128(){
	static uint x=123456789;
	static uint y=333333333;
	static uint z=555555555;
	static uint w=88888888;
	unsigned int t;
	t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct node{
	node*l,*r;
	int cnt,val,Min;
};
node pool[400000];
int p;

inline int cnt(node*t){return t?t->cnt:0;}
inline int Min(node*t){return t?t->Min:INF;}

inline node*update(node*t){
	t->cnt=cnt(t->l)+cnt(t->r)+1;
	t->Min=min({t->val,Min(t->l),Min(t->r)});
	return t;
}
inline node*merge(node*l,node*r){
	if(!l)return r;
	if(!r)return l;
	if(xor128()%(cnt(l)+cnt(r))<(unsigned int)cnt(l)){
		l->r=merge(l->r,r);
		return update(l);
	}
	else{
		r->l=merge(l,r->l);
		return update(r);
	}
}
inline pair<node*,node*>split(node*t,int k){
	if(!t)return make_pair((node*)NULL,(node*)NULL);
	if(k<=cnt(t->l)){
		auto p=split(t->l,k);
		t->l=p.second;
		return make_pair(p.first,update(t));
	}
	else{
		auto p=split(t->r,k-cnt(t->l)-1);
		t->r=p.first;
		return make_pair(update(t),p.second);
	}
}

int main(){
	int n,q;scanf("%d%d",&n,&q);
	node*root=NULL;
	rep(i,n){
		int a;scanf("%d",&a);
		node*t=&pool[p++];
		*t={NULL,NULL,1,a,a};
		root=merge(root,t);
	}
	rep(i,q){
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		if(x==0){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y-1);
			auto c=split(b.second,1);
			root=merge(merge(merge(a.first,c.first),b.first),c.second);
		}
		else if(x==1){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y);
			printf("%d\n",Min(b.first));
			root=merge(merge(a.first,b.first),b.second);
		}
		else{
			auto a=split(root,y);
			auto b=split(a.second,1);
			b.first->val=z;
			update(b.first);
			root=merge(merge(a.first,b.first),b.second);
		}
	}
}


Measured memory_bytes: 9476
n, k = map(int, input().split())
r, s, p = map(int, input().split())
d = {"r": p, "s": r, "p": s}
t = input()

ans = 0
prev = ["#" for _ in range(k)]
for i, move in enumerate(t):
    if prev[i%k] != move:
        ans += d[move]
        prev[i%k] = move
    else:
        prev[i%k] = "#"
print(ans)    
    

Measured memory_bytes: 3956
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		long result = Math.max(A*B, C*D);
		
		System.out.println(result);
	}
}

Measured memory_bytes: 23892
#include <stdio.h>
#include <math.h>

int main(void){
	int n;
	double x1, y1, x2, y2, x3, y3;
	double r, xp, yp;

	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);

		xp = (1/2.0) * ((x1*x1 + y1*y1)*(y3 - y2) + (x2*x2 + y2*y2)*(y1 - y3) + (x3*x3 + y3*y3)*(y2 - y1)) / (x1*(y3 - y1) + x2*(y1 - y3) + x3*(y2 - y1));
		yp = -(x3 - x2)/(y3 - y2) * xp + (1/2.0) * (x3*x3 - x2*x2 + y3*y3 - y2*y2) / (y3 - y2);
		r = sqrt((x1 - xp)*(x1 - xp) + (y1 - yp)*(y1 - yp));

		printf("%.3f %.3f %.3f\n", xp, yp, r);
	}

	return 0;
}

Measured memory_bytes: 0
import collections

num = int(input())
s = sorted(list(map(int, input().split())))
if num == 1:
    print(1)
else:
    c = collections.Counter(s)
    max_ans = 0
    for i in range(num):
        start = s[i]
        current_ans = c[start]+c[start+1]+c[start+2]
        max_ans = max(current_ans,max_ans)
        i += c[start]
    print(max_ans) 

Measured memory_bytes: 14548
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

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

    const int INF = 2 * n;
    vector<int> d(n, INF);

    vector<int> v;
    int ct = 0;
    int now = 0;
    while (d[now] == INF) {
        v.pb(now);
        d[now] = ct++;
        now = a[now];
    }

    int ans;
    if (k < ct)
        ans = v[k];
    else {
        int loop = ct - d[now];

        k -= ct;
        k %= loop;
        ans = v[d[now] + k];
    }
    cout << ans + 1 << "\n";
    return 0;
}


Measured memory_bytes: 5784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  vector<int> n(5);
  rep(i,5){
    cin >> n.at(i);
  }
  rep(i,5){
    if(n.at(i)==0){
      cout << i+1;
      return 0;
    }
  }
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	long double r;
	cin >> r;
	printf("%.10Lf %.10Lf\n", M_PI * r * r, M_PI * r * 2);

	return 0;
}


Measured memory_bytes: 3300
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
ll id(char C) {
	if (C >= 'A') return (ll)C - 'A' + 26;
	else return (ll) C - 'a';
}
int main() {
	cin >> N;
	string S, T;
	cin >> S >> T;
	vll A(52, vl(52,0));
	ll mode = 0;
	ans = 1;
	for (i = 0; i < N; i++) {
		if (S[i] == T[i]) {
			if (mode == 0) {
				(ans *= 3) %= MOD;
			}
			else if (mode == 1) {
				(ans *= 2) %= MOD;
			}
			mode = 1;
		}
		else {
			if (mode == 0) {
				(ans *= 6) %= MOD;
			}
			else if (mode == 1) {
				(ans *= 2) %= MOD;
			}
			else {
				(ans *= 3) %= MOD;
			}
			mode = 2;
			i++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < n; ++i)
#define out(x) cout << x << endl;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;


int main() {

	int N;
	cin >> N;

	int right = 0;
	vector<pair<int, int>> A(N);
	

	rep(i, N) {
		int tmp;
		cin >> tmp;
		A[i].F = tmp;   //value
		A[i].S = i; //index
	}
	sort(all(A));

	//out("-----")
	//for (int i = 0; i < N; i++)
	//{
	//	cout << A[i].F << " : " << A[i].S << endl;
	//out("-----")

	rep(i, N) {

		if (i != A[N-1].S) {
			out(A[N-1].F);
		}
		else {
			out(A[N - 2].F);
		}
	}

	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
 int ans=n%1000;
  if(ans==0)
  cout<<ans<<endl;
  else{
    int ans1=1000-ans;
    cout<<ans1<<endl;
  }
  return 0;
}
  


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

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

  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max({a*c,a*d,b*c,b*d})<<endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    
    rep2(i,1,10)
        rep2(j,1,10)
            if(i*j == n)
            {
                cout << "Yes" << endl;
                return 0;
            }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

int main(){	
	long long N;
	scanf("%lld",&N);
	ll A;
	multiset<ll> st;
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A);
		st.insert(A);
	}
	ll res = 0;
	while(!st.empty()) {
		ll maxA = *st.rbegin();
		// cout << maxA << endl;
		ll two = 2;
		while (two <= maxA) two *= 2;
		// cout << *st.find(maxA) << endl;
		st.erase(st.find(maxA));
		// cout << two-maxA << " " << *st.find(two-maxA) << endl;
		if (st.find(two-maxA) != st.end()) {
			res++;
			st.erase(st.find(two-maxA));
		}
	}
	cout << res << endl;	

	return 0;
}



Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
const int N = 1e5 + 5;
//const int INF = 1e9 + 5;
int a[N];
void solve_test_case(){
	string s,t;
	cin>>s>>t;
	int c = 0;
	for(int i = 0;s[i];){
		
		for(int j = 0;t[j];++j){
			if(s[i] != t[j])
				c++;
			i++;
		}
	}		
	cout<<c<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	// cin>>t;
	for(int i = 0;i < t;++i){
		solve_test_case();
	}
}


Measured memory_bytes: 3832
#!python3

def LI():
    return list(map(int, input().split()))

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


def judge(v):
    x = 0
    for b, l in v:
        if x + b < 0:
            return False
        x += l
    return True


def main():
    pl, ml = [], []
    t = 0
    for i in range(N):
        l = 0
        b = 0
        for s in S[i]:
            if s == "(":
                l += 1
            else:
                l -= 1
                b = min(b, l)
        t += l
        if l > 0:
            pl.append((b, l))
        else:
            ml.append((b - l, -l))

    pl.sort(reverse=True)
    ml.sort(reverse=True)

    if judge(pl) and judge(ml) and t == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 88140
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[300010], dp[300010], b[300010];
map<int, ll> mp[2048];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=1; i<=n; ++i){
            scanf("%d%d",b+i, a+i);
        }
        mp[0][0]=0;
        for(int i=1; i<=n; ++i){
        	dp[i]=dp[i/2]+1;
        	int tmp=a[i], tmp1=b[i];
        	if(dp[i]<=11){
        		mp[i]=mp[i/2];
        		for(auto it:mp[i/2]){
        			if(it.fs+tmp<=100000)
	        			mp[i][it.fs+tmp]=max(mp[i][it.fs+tmp], it.sc+tmp1);
        		}
	        	ll tmp2=0, tmp3;
	        	for(auto it:mp[i]){
	        		tmp3=it.sc;
	        		mp[i][it.fs]=max(tmp3, tmp2);
	        		tmp2=mp[i][it.fs];
	        	}
        	}
        }
        int q;
        scanf("%d", &q);
        int x, l;
        vector<pair<int, int> > v;
        for(int i=0; i<q; ++i){
        	scanf("%d%d",&x,&l);
        	v.clear();
        	while(dp[x]>11){
        		v.push_back(mk(a[x], b[x]));
        		x/=2;
        	}
        	ans=0;
        	for(int i=0; i<(1<<v.size()); ++i){
        		int tmp=0; ll tmp1=0, tmp2;
        		for(int j=0; j<v.size(); ++j){
        			if(i&(1<<j)){
        				tmp+=v[j].fs;
        				tmp1+=v[j].sc;
        				if(tmp>l){
        					break;
        				}
        			}
        		}
        		if(tmp>l){
        			continue;
        		}
        		tmp2=(--mp[x].upper_bound(l-tmp))->sc;
        		ans=max(ans, tmp2+tmp1);
        	}
        	printf("%lld\n",ans);
        }
    }
  return 0;
}




Measured memory_bytes: 178472
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		br.close();
		StringBuffer sb = new StringBuffer();
		int len = s.length();
		for(int i = 0;i<len;i++) {
			sb.append('x');
		}
		System.out.println(sb.toString());
	}

}


Measured memory_bytes: 21204
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
std::vector<std::pair<int, int> > to[100005];
std::vector<int > ans(100005);

void dfs(int start, int p=-1, int color=0){
  for (int i=0; i<to[start].size(); i++){
    if (to[start][i].first==p){
      continue;
    }
    int thiscolor= (color+to[start][i].second)%2;
    ans[to[start][i].first] = thiscolor;
    dfs(to[start][i].first, start,thiscolor);
  }
  return;
}

int main(){
  int N;
  scanf("%d",&N);
  int u, v;
  long long w;
  for (int i=0; i<N-1; i++){
    scanf("%d",&u);
    scanf("%d",&v);
    scanf("%lld",&w);
    u--;
    v--;
    to[u].push_back(std::make_pair(v,w%2));
    to[v].push_back(std::make_pair(u,w%2));
  }
  ans[0]=0;
  dfs(0,-1,0);
  
  for (int i=0; i<N; i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
int main(){
 int K;
  int a[10000001];
 
  cin>>K;
   a[1]=7%K;
  if(a[1]==0){
  cout<<1<<endl;
    return 0;
  }
  else{
  for(int i=2;i<=K;i++){
    a[i]=(a[i-1]*10+7)%K;
    if(a[i]==0){
      
    cout<<i<<endl;
    return 0;
    }
    
  }
  }
  cout<<"-1"<<endl;
  
}


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

#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define per(i, b, a) for(int i = b; i >= (a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (1000*1000*1000+7)
#define inf (2*1000*1000*1000+9)
#define infl ((ll)2*1000*1000*1000*1000*1000*1000+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc; 
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

/* -------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------*/

ll pow(ll a, ll b){
	ll ret=1; 
	while(b--) ret*=a; return ret; 
}
void solve(){ 
	ll n,p; cin>>n>>p; 
	ll ans=1; 
	for(ll i=2;i*i<=p;i++){
		int cnt=0; 
		while(p%i==0){
			cnt++; 
			p/=i; 
		}		
		cnt/=n; 
		ans*=pow(i,cnt); 
	}	
	if(n==1 && p>1) ans*=p; 
	cout<<ans<<endl; 
}


int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


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



int64_t fiftycalc(int64_t n){
  if(n == 0){
   return 0;
  }
  else{
  return n/5 + fiftycalc(n/5);
  }
}


int main() {
int64_t N;
  cin >> N;
  if(N%2 == 1){
  	cout << 0 << endl;
  }
  else{
  	cout << fiftycalc(N/2)<< endl;
  }
  
}

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

using namespace std;
using ll = long long;

#define MOD 1000000007
template<int mod>
struct ModInt{
   int x;
   ModInt():x(0){}
   ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
   ModInt &operator+=(const ModInt &p){
       if((x+=p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator-=(const ModInt &p){
       if((x+=mod-p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator*=(const ModInt &p){
       x=(int)(1LL*x*p.x%mod);
       return *this;
   }
   ModInt &operator/=(const ModInt &p){
       *this*=p.inverse();
       return *this;
   }
   ModInt &operator^=(long long p){
       ModInt res = 1;
       for (; p; p >>= 1) {
           if (p & 1) res *= *this;
           *this *= *this;
       }
       return *this = res;
   }
   ModInt operator-()const{return ModInt(-x);}
   ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
   ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
   ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
   ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
   ModInt operator^(long long p)const{return ModInt(*this)^=p;}
   bool operator==(const ModInt &p)const{return x==p.x;}
   bool operator!=(const ModInt &p)const{return x!=p.x;}
   explicit operator int() const { return x; }
   ModInt operator=(const int p) {x = p; return ModInt(*this);}
   ModInt inverse()const{
       int a=x,b=mod,u=1,v=0,t;
       while(b>0){
           t=a/b;
           a-=t*b;
           std::swap(a,b);
           u-=t*v;
           std::swap(u,v);
       }
       return ModInt(u);
   }
   friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
       return os<<p.x;
   }
   friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
       long long x;
       is>>x;
       a=ModInt<mod>(x);
       return (is);
   }
};
typedef ModInt<MOD> mint;
 

int main()
{
    int h, w; cin >> h >> w;
    vector<int> a(h), b(w);
    for(int i = 0; i < h; i++)cin >> a[i];
    for(int i = 0; i < w; i++)cin >> b[i];
    sort(a.begin(), a.end()), sort(b.begin(), b.end());
    mint ans = 1;

    for(int i = h * w; i > 0; i--) {
        auto hf = lower_bound(a.begin(), a.end(), i), wf = lower_bound(b.begin(), b.end(), i);
        if(*hf == i && *wf == i)continue;
        if(*hf == i) {
            ans *= b.end() - wf;
        } else if(*wf == i) {
            ans *= a.end() - hf;
        } else {
            ans *= (ll)(b.end() - wf) * (a.end() - hf) - (h * w - i);
        }
    }
    ans *= (unique(a.begin(), a.end()) == a.end() && unique(b.begin(), b.end()) == b.end());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>









ll a,b,c,d,e,f,rw,rs,w,w2,s;





void solve()
{
	cin>>a>>b>>c>>d>>e>>f;
	rw=0;
	rs=0;
	for(int i=0;i*a*100<=f;i++)
	{
		for(int j=0;j*b*100<=f;j++)
		{
			w2=(i*a)+(j*b);
			w=w2*100;
			if(w>f)break;
			for(int x=0;x*c<=w2*e;x++)
			{
				for(int y=0;y*d<=w2*e;y++)
				{
					s=min((x*c)+(y*d),f-w);
					if(s>w2*e)break;
					if((rs==0&&rw==0)||s*(rw+rs)>=rs*(w+s))
					{
						rs=s;
						rw=w;
					}
				}
			}
		}
	}
	cout<<rw+rs<<" "<<rs<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
int joseph(int n,int diff,int initial){
	int r=0,i=1;
	for(;i<n;i++)r=(r+diff)%i;
	return (r+1+initial)%n+1;
}
int main(){
	int n,k;
	for(;scanf("%d%d",&n,&k),n;)printf("%d\n",joseph(n,k,k-1));
	return 0;
}

Measured memory_bytes: 600
#include<algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
using namespace std;
int main(void){
	long long int n,l[86]={2,1},i;
	cin>>n;
	for(i=2;i<=86;i++)l[i]=l[i-1]+l[i-2];
	cout<<l[n]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
//解説
int main() {
    int n; cin >> n;
    vector<tuple<string, int, int> > a;
    for (int i = 1; i <= n; ++i) {
        string s;
        int p;
        cin >> s >> p; p = -p;
        a.push_back(tie(s, p, i));
    }
    sort(a.begin(), a.end());
    rep(i, n) {
        string s;
        int p;
        int id;
        tie(s, p, id) = a[i];
        cout << id << endl;
    }
}


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

#define BR "\n"
#define SP " "

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

  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < N; i++) {
    ll temp = A[i];
    for (int j = 0; j < i; j++) {
      if (A[j] > temp) {
        for (int k = i; k > j; k--) {
          A[k] = A[k - 1];
        }
        A[j] = temp;
        break;
      }
    }
    for (int j = 0; j < N - 1; j++) {
      cout << A[j] << SP;
    }
    cout << A[N - 1] << BR;
  }
  return 0;
}


Measured memory_bytes: 3092
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,m;
	
	while(cin >> n >> m && n!=0 && m!=0)
	{
		int men = n*n + m*m;
		int min(0),max(0);
		for(int i=n+1;i<men;i++)
		{
			for(int j=i+1;j<men;j++)
			{
				if(i*i+j*j==men){min=i;max=j;break;}
			}
			if(min!=0 && max!=0){break;}
		}
		
		if(min!=0 && max!=0){cout << min << " " << max << endl;}
		else
		{
			for(int i=men+1;i<22501;i++)
			{
				for(int j=1;j<151;j++)
				{
					for(int k=j+1;k<151;k++)
					{
						if(j*j+k*k == i){min=j;max=k;break;}
					}
				if(min!=0 && max!=0){break;}
				}
			if(min!=0 && max!=0){break;}
			}
			cout << min << " " << max << endl;
		}
	}
	return 0 ;
}

Measured memory_bytes: 1160
def func(x):
    c = 0
    n = x
    while True:
        if n < 100:
            break
        if n % 100 != 0:
            break
        n = n // 100
        c += 1
    return c


def main():
    d, n = map(int, input().split())

    i = 1
    count = 0
    # while True:
    #     if i % 100 != 0:
    #         count += 1
    #     if count == n:
    #         break
    #     i += 1
    while True:
        if func(i) == d:
            count += 1
        if count == n:
            break
        i += 1
    print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>

#define ASIZE 1048576
#define GSIZE 524288

int m, cnt = 0;
int insertionSort(int *A, int n, int g){
  int i, j, v;
  for (i = g; i < n; i++) {
    v = A[i];
    j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
  return cnt;
}

int shellSort(int *A, int n){
  int i, j, g, tmp;
  int G[GSIZE] = {0};
  for (m = 0, g = 1; g <= n; m++, g = g * 3 + 1)
    G[m] = g;
  
  // descending sort
  for (i = 0, j = m - 1; i < j; i++, j--) {
    tmp = G[i];
    G[i] = G[j];
    G[j] = tmp;
  }

  printf("%d\n", m);
  for (i = 0; i < m; i++) {
    if (i)
      printf(" ");
    printf("%d", G[i]);
  }
  puts("");

  for (i = 0; i < m; i++)
    insertionSort(A, n, G[i]);
  return cnt;
}

int main(void){
  int i, n, A[ASIZE] = {0};
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &A[i]);
  shellSort(A, n);

  printf("%d\n", cnt);
  for (i = 0; i < n; i++)
    printf("%d\n", A[i]);

  return 0;
}

Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n;
  cin >> n;

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

  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] == -1) continue;

    if (a[i - 1] == a[i]) {
      a[i] = -1;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int visit[100001];
int cnt;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> btn(n + 1);
    
    for (int i = 1; i <= n; ++i)
        cin >> btn[i];
    
    int idx = 1;
    visit[idx] = 1;
    
    while (1)
    {
        int next = btn[idx];
        if (visit[next])
        {
            cout << -1;
            return 0;
        }
        
        visit[next] = 1;
        ++cnt;
        idx = next;
        if (idx == 2)
            break;
    }
    
    cout << cnt;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int A,B;
  in(A,B);
  out(max(A-2*B,0));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> P;

const int INF = 100000000;

template <typename T>
struct Edge
{
    int to;
    T cost;
};

template <typename T>
struct WeightedGraph
{
    int n;
    vector<vector<Edge<T>>> g;
    
    WeightedGraph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to, T cost){
        g[from].push_back((Edge<T>){to, cost});
    }
};

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

int d[100002];
bool used[200003];
queue<int> que[100002];

int main()
{
    int n, m;
    cin >> n >> m;
    WeightedGraph<P> g(n);
    map<P, vector<P>> mp;
    for(int i = 0; i < m; i++){
        int p, q, c;
        cin >> p >> q >> c;
        p--; q--; c--;
        g.add_edge(p, q, P(c, i));
        g.add_edge(q, p, P(c, i));
        mp[P(p, c)].push_back(P(q, i));
        mp[P(q, c)].push_back(P(p, i));
    }
    fill(d, d + n, INF);
    int k = 0;
    d[0] = 0;
    que[0].push(0);
    while(true){
        while(que[k].size()){
            int u = que[k].front();
            que[k].pop();
            for(Edge<P> e : g.g[u]){
                if(used[e.cost.second]) continue;
                used[e.cost.second] = true;
                int v = e.to;
                if(d[v] <= k) continue;
                if(d[v] == INF){
                    d[v] = k + 1;
                    que[k + 1].push(v);
                }
                queue<int> q;
                q.push(v);
                while(q.size()){
                    int w = q.front();
                    q.pop();
                    for(P p : mp[P(w, e.cost.first)]){
                        if(used[p.second]) continue;
                        used[p.second] = true;
                        int x = p.first;
                        if(d[x] <= k) continue;
                        if(d[x] == INF){
                            d[x] = k + 1;
                            que[k + 1].push(x);
                        }
                        q.push(x);
                    }
                }
            }
        }
        k++;
        if(que[k].empty()) break;
    }
    if(d[n - 1] == INF) cout << -1 << endl;
    else cout << d[n - 1] << endl;
}


Measured memory_bytes: 121728
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = input()
# n = int(input())
# a,b = map(int, input().split())
# a = list(map(int,input().split()))
# w = [int(input()) for i in range(n)]

# ab=[]
# for i in range(m):
#     a,b = map(int, input().split())
#     ab.append((a,b))
     
def main():
    a,b = map(int, input().split())
    ans = 0
    while a <=b:
        ans+=1
        a*=2
    print(ans)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s =new Scanner(System.in);
        int n=s.nextInt();
        for(int i=0;i<n;i++){
            fun(s.nextInt(),s.nextInt(),s.nextInt());
        }
    }
    
    static void fun(int a,int b,int c){
        int x=0,y=Math.min(a,b)*Math.min(a,b),ma=Math.max(a,b);
        x+=Math.max(ma,c)*Math.max(ma,c);
        y+=Math.min(ma,c)*Math.min(ma,c);
        if(x==y)System.out.println("YES");
        if(x!=y)System.out.println("NO");
        
    }
}


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

int main() {
  int x,y,z;
  string nyu1,nyu2,nyu3;
  cin >> x>>nyu1>>y;
  
  if(nyu1 == "+"){z = x + y;}
  if(nyu1 == "-"){z = x - y;}
 
 cout << z <<endl;
   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>

int main(){
  int button,bulb;
  cin >> button >> bulb;
  vector<vint> A(bulb,vint(button));
  rep(i,bulb){
    int number;
    cin >> number;
    rep(j,number) cin >> A[i][j];
  }
  vint B(bulb);
  rep(i,bulb) cin >> B[i];
  int count = 0; 
  rep(i,1<<button){
    //cout << "Q" << endl;
    bool ok = true;
    vint bit(10);
    rep(j,button){
      if(i>>j&1) bit[j] = 1;
    }
    rep(s,bulb){
      int sum = 0;
      for(auto q:A[s]){
        sum += bit[q-1];
      }
      //cout << sum << endl;
      if(!(sum%2 == B[s])) ok = false;
    }
    if(ok) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int n, i, j, m, k, p, q, o, l, s, tt = 1;
        Double x,y,z;
        int ar[],br[];
        char ch;
        BigInteger an, su, u, v;
        String a,b="",c="",d;
        Scanner sc = new Scanner(System.in);
        Scanner scc = new Scanner(System.in);
        ar=new int[200001];
        br=new int[200001];
        n=sc.nextInt();
        m=sc.nextInt();
        sc.nextLine();
        p=0;
        q=0;
       for(i=0;i<m;i++)
       {
           a=sc.nextLine();
          o=0;
          for(j=0; ;j++)
          {
              ch=a.charAt(j);
              if(ch==' ')
              {
                  break;
              }
              o*=10;
              o+=(int)(ch-'0');
          }
          j++;
          ch=a.charAt(j);
           if(ch=='W')
           {
               if(ar[o]==0)
               {
                   br[o]++;
               }
           }
           else
           {
               if(ar[o]==0)
               {
                   p++;
                   q+=br[o];
               }
               ar[o]=1;
           }

       }
        System.out.println(p+" "+q);


    }
}



Measured memory_bytes: 51436
#include<cstdio>
int main(){
	int q;
	scanf("%d",&q);
	for(int x=0;x<q;x++){
		long long int a,b;
		scanf("%lld%lld",&a,&b);
		if(a>b){
			long long int c=b;
			b=a;
			a=c;
		}
		//a<=b
		long long int ans=0;
		ans+=a-1;
		if(a==b){
			ans+=a-1;
		}else{
		for(long long int i=a;0==0;i++){
			if(i*i>=a*b-1){
				int x=i-1;
				if(i*i==a*b-1)x++;
				if((a*b-1)/x==x){
					ans+=(2*x-a-1);
				}else{
					ans+=(2*x-a);
				}
				break;
			}
			if((i+100)*(i+100)<a*b-1){
				i+=100;
			}
		}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;

int main() {
    #ifndef LOCAL
        fastIO;
    #endif
    int x,a;
    cin >> x >> a;
    if(x<a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
int tree[1000100],n,a[100100],val[100100],maxn=-1e9,minn=1e9;
void build(int t,int l,int r){
	tree[t]=0;
	if(l==r)return;
	int mid=(l+r)/2;
	build(t*2,l,mid);
	build(t*2+1,mid+1,r);
}
void modify(int t,int l,int r,int pos){
	if(l==r){
		tree[t]++;
		return;
	}
	int mid=(l+r)/2;
	if(pos<=mid)modify(t*2,l,mid,pos);
	else modify(t*2+1,mid+1,r,pos);
	tree[t]=tree[t*2]+tree[t*2+1];
}
int query(int t,int l,int r,int L,int R){
	if(L>r||l>R)return 0;
	if(L<=l&&r<=R)return tree[t];
	int mid=(l+r)/2;
	return query(t*2,l,mid,L,R)+query(t*2+1,mid+1,r,L,R);
}
bool check(int now){
	build(1,0,n+n);
	for(int i=1;i<=n;i++)
		if(a[i]<now)val[i]=-1;else val[i]=1;
	for(int i=1;i<=n;i++)val[i]+=val[i-1];
	int res=0;
	modify(1,0,n+n,n);
	for(int i=1;i<=n;i++){
		res+=query(1,0,n+n,0,val[i]+n);
		modify(1,0,n+n,val[i]+n);
	}
	return res>=(int)((n*(n+1)/2)/2);
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]),maxn=max(maxn,a[i]),minn=min(minn,a[i]);
	int L=minn,R=maxn,ans;
	while(L<=R){
		int mid=(L+R)/2;
		if(check(mid))ans=mid,L=mid+1;
		else R=mid-1;
	}
	printf("%lld\n",ans);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a.at(i);
  
  int alice=0;
  int bob=0;
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0; i<N; i++){
    if(i%2==0) alice += a.at(i);
    else bob += a.at(i);
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
from math import floor,ceil
import sys
sys.setrecursionlimit(10**7)
def solve():
    N,A,B,C,D=map(int,input().split())
    memo={}
    def dist(n):
        if n in memo:
            return memo[n]
        if n==1:
            return D
        if n==0:
            return 0
        res = min(
            D * n,
            D * abs(n - n//5*5) + C + dist(n//5),
            D * abs(n - (n+4)//5*5) + C + dist((n+4)//5),
            D * abs(n - n//3*3) + B + dist(n//3),
            D * abs(n - (n+2)//3*3) + B + dist((n+2)//3),
            D * abs(n - n//2*2) + A + dist(n//2),
            D * abs(n - (n+1)//2*2) + A + dist((n+1)//2)
        )
        memo[n]=res
        return res
    print(dist(N))

T=int(input())
for i in range(T):
    solve()

Measured memory_bytes: 19984
using System;
using System.Collections.Generic;

namespace cs
{
    public class Program
    {
        public static void Main(string[] args)
        {
            
            var input = Console.ReadLine().ToCharArray();

            char a;
            char b = '\0';
            int aC = 1;
            int bC = 0;

            a = input[0];

            for(int i = 1; i< 4; i++){
                if(a == input[i]){
                    aC++;
                } 
                else if (b == '\0'){
                    b = input[i];
                    bC++;
                }else if( b == input[i]){
                    bC++;
                }
            }

            Console.WriteLine((aC == 2 && aC == bC) ? "Yes" : "No");
            
            
            
/*
            Console.WriteLine();
            Console.WriteLine("続行するにはアレ");*/
            //Console.ReadKey();
           
        }

        public static long GCD(long n, long m){
            
            if(m % n == 0) return n;
            else return GCD(m%n, n);

        }

        public static long LCD(long n, long m){

            return m * n / GCD(n,m);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Repi(i, a, b) for(int i = int(a); i < (int)(b); i++)
#define Repl(i, list) for(int i : list)
#define Sort(v) sort(v.begin(), v.end())
template<typename _T> void Out(_T x) { cout << x << endl; }
template<typename _T> void PrintVec(vector<_T> vec) { Rep(i, vec.size()) { cout << vec.at(i) << " "; } cout << endl; }

int main()
{
    // input
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    // output
    string str = "";
    Rep(i, N){
        str.push_back(S.at(i));
        str.push_back(T.at(i));
    }

    Out(str);
    return 0;
}

Measured memory_bytes: 256
from collections import deque

n=int(input())

tree=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    tree[a].append([b,c])
    tree[b].append([a,c])

q,k=map(int,input().split())
k-=1

dist=[-1 for i in range(n)]
dist[k]=0
que=deque()
que.append(k)
while que:
    x=que.popleft()
    for p in tree[x]:
        if dist[p[0]]==-1:
            que.append(p[0])
            dist[p[0]]=dist[x]+p[1]
ans=[]
for i in range(q):
    x,y=map(int,input().split())
    x-=1;y-=1
    ans.append(dist[x]+dist[y])

for i in ans:
    print(i)

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

int main() {
	string a;
	unsigned long long b,h=0;
	unsigned long long c = 0, d = 0, e = 0, f = 0, g = 0;
	cin >> b;
	for (int i = 0;i < b;i++)
	{
		cin >> a;
		if (a[0] == 'M')c++;
		if (a[0] == 'A')d++;
		if (a[0] == 'R')e++;
		if (a[0] == 'C')f++;
		if (a[0] == 'H')g++;

	}

	h = c * d * e + c * d * f + c * d*g + c * e*f + c * e*g + c * f*g + d * e*f + d * e*g + d * f*g + e * f*g;
	cout << h << endl;
	return 0;
}



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

int main()
{
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> a(n, vector<int>(3));
  for (int i = 0; i < n; i++)
  {
    for (int k = 0; k < 3; k++)
    {
      cin >> a.at(i).at(k);
    }
  }
  int x_max, x_min, y_max, y_min;
  x_max = w;
  x_min = 0;
  y_max = h;
  y_min = 0;

  for (int i = 0; i < n; i++)
  {
    if (a.at(i).at(2) == 1 && x_min < a.at(i).at(0))
    {
      x_min = a.at(i).at(0);
    }
    if (a.at(i).at(2) == 2 && x_max > a.at(i).at(0))
    {
      x_max = a.at(i).at(0);
    }
    if (a.at(i).at(2) == 3 && y_min < a.at(i).at(1))
    {
      y_min = a.at(i).at(1);
    }
    if (a.at(i).at(2) == 4 && y_max > a.at(i).at(1))
    {
      y_max = a.at(i).at(1);
    }
  }
  if (x_max > x_min && y_max > y_min)
  {
    int ans = abs(x_max - x_min) * abs(y_max - y_min);
    cout << ans << endl;
  }
  else
  {
    cout << 0 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
using DataStructures
using Primes
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    mm = 2500
    N,M,S = parseMap(split(readline()))
    S = min(S, mm)
    g = [[] for _ in 1:N]
    for i in 1:M
        u,v,a,b = parseMap(split(readline()))
        push!(g[u], [v, a, b])
        push!(g[v], [u, a, b])
    end
    cd = []
    for i in 1:N
        c, d = parseMap(split(readline()))
        push!(cd, [c, d])
    end
    h = BinaryMinHeap{Array{Int}}()
    push!(h, [0, S*-1, 1])

    dp = Dict()
    for i in 1:N
        for j in 0:mm
            dp[(i,j)] = INF
        end
    end
    dp[(1,S)] = 0
    while(length(h) != 0)
        t = pop!(h)
        u = t[3]
        d = t[1]
        s = t[2]*-1
        if dp[(u, s)] < d
            continue
        end
        for i in g[u]
            v = i[1]
            dist = d+i[3]
            money = s-i[2]
            if money>=0
                if dp[(v, money)]>dist
                    dp[(v, money)] = dist
                    push!(h, [dist, -money, v])
                end
            end   
        end
        s+=cd[u][1]
        s = min(mm, s)
        d+=cd[u][2]
        if s>=0 && dp[(u, s)]>d
            dp[(u, s)] = d
            push!(h, [d, -s, u])
        end
    end
    for i in 2:N
        res = INF
        for j in 0:mm
            res = min(res, dp[(i, j)])
        end
        println(res)
    end
end
INF = 1<<60
main()





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

int main() {
	long long int n;
	cin>>n;
	long long int ABC[3][n];
	for(int i=0;i<n;i++){
		cin>>ABC[0][i]>>ABC[1][i]>>ABC[2][i];
	}
	long long int dp[n][3];
	long long int m=0;
	int abc;
	dp[0][0]=ABC[0][0];
	dp[0][1]=ABC[1][0];
	dp[0][2]=ABC[2][0];
	dp[1][0]=max(dp[0][1],dp[0][2])+ABC[0][1];
	dp[1][1]=max(dp[0][0],dp[0][2])+ABC[1][1];
	dp[1][2]=max(dp[0][1],dp[0][0])+ABC[2][1];
	for(int i=2;i<n;i++){
		for(int j=0;j<3;j++){
			m=0;
			for(int k=0;k<3;k++){
				if(k==j)continue;
				if(m<dp[i-1][k]){
					m=dp[i-1][k];
				}
			}
			dp[i][j]=m+ABC[j][i];
		}
	}
	int x=dp[n-1][0];
	if(x<dp[n-1][1])x=dp[n-1][1];
	if(x<dp[n-1][2])x=dp[n-1][2];
	cout<<x<<endl;
	return 0;
}

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

const int N = 310;

typedef long long LL;

int dp[N][N], C[N][N], sum[N][N];

int main() {
    int n, k, mod; scanf("%d%d%d", &n, &k, &mod), n++;
    for (int i = 0; i <= n; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
    }
    for (int i = 0; i <= k; i++) sum[1][i] = k - i + 1, dp[1][i] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= k; j++) {
            for (int t = 1; t < i; t++) 
                dp[i][j] = (dp[i][j] + (LL)dp[i - t][j] * C[i - 2][t - 1] % mod * sum[t][j + 1]) % mod;
        }
        for (int j = k; j >= 1; j--) sum[i][j] = (sum[i][j + 1] + dp[i][j]) % mod;
    }
    printf("%d\n", dp[n][0]);
    return 0;
}


Measured memory_bytes: 1408