akhauriyash/Code-Regression huggingface dataset:
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def input():
    return next(args)
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)

# エントリーポイント
def main():
    N, Q = parse(int, int)
    edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = parse(int1, int1)
        edges[a] += [b]
        edges[b] += [a]
    vals = [0] * N
    for _ in range(Q):
        p, x = parse(int1, int)
        vals[p] += x

    counter = [0] * N
    que = [(0, 0)]
    alr = [False] * N
    while que:
        v, x = que.pop()
        alr[v] = True
        counter[v] += x + vals[v]
        for n in edges[v]:
            if not alr[n]:
                que.append((n, counter[v]))

    for v in counter:
        print(v)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()


Measured memory_bytes: 92616
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define pie 3.14159265358979323846
#define ll long long
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
double min(double x, double y)  
{  
    return (x < y)? x: y;    
}
double calcAngle(double h, double m)  
{
    if (h == 12) h = 0;  
    if (m == 60) m = 0; 
    double hour_angle=0.5*(h*60+m);  
    double minute_angle=6*m;  
    double angle=abs(hour_angle-minute_angle);
    angle=min(double(360)-angle,angle);
    return angle;  
}  
int main()
{
	double a,b,h,m;cin>>a>>b>>h>>m;
	double ang=calcAngle(h,m);
	double x=a*a+b*b-double(2)*a*b*cos(ang*pie/double(180));
	cout<<fixed<<setprecision(25)<<sqrt(x);
}

Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

const int MAX_V = 100010;

struct edge{
   int to, cost;
};

vector<edge> G[MAX_V];

struct Dijkstra{
    vector<int> d;
    Dijkstra(){}
    Dijkstra(int V){
        d.resize(V, INF);
    }
    void calc(int s){
        d[s] = 1;
        priority_queue<P, vector<P>, greater<P> > q;
        q.push(P(d[s], s));
        while(!q.empty()){
            P p = q.top(); q.pop();
            int from = p.second;
            int cost = p.first;
            if(d[from] < cost) continue;
            rep(i, 0, G[from].size()){
                int next = G[from][i].to;
                int newCost = cost + G[from][i].cost;
                if(d[next] > newCost){
                    d[next] = newCost;
                    q.push(P(newCost, next));
                }
            }
        }
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    Dijkstra d(n);
    rep(i, 0, n){
        G[i].push_back({(i + 1) % n, 1});
        G[i].push_back({(i * 10) % n, 0});
    }
    d.calc(1);
    cout << d.d[0] << endl;
}

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

#define ll long long
#define MOD 1000000007


void solve(){
    int t;
    cin >> t;
    if (t >= 30) cout << "Yes";
    else cout << "No";
}

int main()
{   
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    {
        solve();
        }
    return 0;
}

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

int main() {
    int N,m=3e5,P,r=0;
    cin >> N;

    rep(i,N) {
        cin >> P;
        if(P <= m)
            r++;
        m = min(m,P);
    }

    cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

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

typedef complex<double> P;
typedef pair<P, P> L;

const double EPS = 1e-9;
const int INF = 1e9 + 10;

#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)

#define S first
#define T second
#define EX P(INF,INF)

bool operator < (const P& a, const P& b) {
	return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}

double cross(P a, P b) {
	return (conj(a) * b).Y;
}
double dot(P a, P b) {
	return (conj(a) * b).X;
}
double dist(P a, P b) {
	return (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y);
}

//??????(a,b)??????c????????¨????????? isPointOnLine
bool isPOL(P a, P b, P c) {
	return abs(a - c) + abs(c - b) < abs(a - b) + EPS;
}

//????????¨?????????????????????
P crosspointLL(P a1, P a2, P b1, P b2) {
	double d1 = cross(b2 - b1, b1 - a1);
	double d2 = cross(b2 - b1, a2 - a1);
	if (EQ(d2, 0)) {
		return EX; //??????
	}
	P ret = a1 + d1 / d2 * (a2 - a1);
	if (isPOL(b1, b2, ret) && isPOL(a1, a2, ret)) {
		return ret;
	}
	else {
		return EX; //????????????????????????
	}
}
typedef tuple<P, bool, bool> pbb;

int dp[102][2];

signed main() {

	int T;
	cin >> T;
	rep(_, T) {
		int xa, ya, xb, yb, n;
		cin >> xa >> ya >> xb >> yb;
		P A(xa, ya), B(xb, yb);
		cin >> n;
		vector<pbb> vp;
		rep(i, n) {
			int xs, ys, xt, yt, o, l;
			cin >> xs >> ys >> xt >> yt >> o >> l;
			P s(xs, ys), t(xt, yt);
			if (crosspointLL(s, t, A, B) != P(INF, INF)) {
				vp.push_back(pbb(crosspointLL(s, t, A, B), o, l));
			}
		}
		sort(vp.begin(), vp.end(), [&](pbb &t0, pbb &t1) {
			return dist(A, get<0>(t0)) < dist(A, get<0>(t1));
		});
		rep(i, 102)rep(j, 2)dp[i][j] = INF;
		dp[0][0] = dp[0][1] = 0;
		rep(i, vp.size()) {
			int o = get<1>(vp[i]), l = get<2>(vp[i]);
			rep(j, 2) {
				if (o == 1) {
					if (j == l) {
						dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
					}else{
						dp[i + 1][1 - j] = min(dp[i + 1][1 - j], dp[i][j] + 1);
					}
				}else
				if (o == 0) {
					if (j == l) {
						dp[i + 1][1 - j] = min(dp[i + 1][1 - j], dp[i][j] + 1);
					}
					else {
						dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
					}
				}
			}
		}
		int ans = INF;
		rep(j, 2) {
			ans = min(dp[vp.size()][j], ans);
		}
		cout << ans << endl;
	}

	return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  if(S == "SAT"){
    cout << 1 << endl;
  } else if(S=="FRI"){
    cout << 2 << endl;
  } else if (S=="THU"){
    cout << 3 << endl;
  } else if (S=="WED"){
    cout << 4 << endl;
  } else if (S == "TUE"){
    cout << 5 << endl;
  } else if (S == "MON"){
    cout << 6 << endl;
  } else {
    cout << 7 << endl;
  }
}


Measured memory_bytes: 256
nl = []
n = int(input())
for i in range(n):
    nl.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(6):
            for l in range(4):
                nl[i] = [nl[i][0],nl[i][3],nl[i][1],nl[i][4],nl[i][2],nl[i][5]]
                if nl[i] == nl[j]:
                    print("No")
                    exit()
            if k % 2 == 0:
                nl[i] = [nl[i][4],nl[i][0],nl[i][2],nl[i][3],nl[i][5],nl[i][1]]
            else:
                nl[i] = [nl[i][2],nl[i][1],nl[i][5],nl[i][0],nl[i][4],nl[i][3]]
print("Yes")


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

using namespace std;

typedef long long  ll;

int main()
{
    int n, now, min_v, ans;

    scanf("%d", &n);
    scanf("%d", &min_v);
    scanf("%d", &now);
    ans = now - min_v;
    for (int i = 2; i < n; ++i) {
        min_v = min(min_v, now);
        scanf("%d", &now);
        ans = max(ans, now - min_v);
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
//static const int INF = 1000010000;
//static const int NIL = -1;
//static const int MOD = 1000000007;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
//#define int ll

signed main(){
    int n,a=0,b=0,c=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int tmp;
        scanf("%d",&tmp);
        if(tmp%4==0) a++;
        else if(tmp%2==0) b++;
        else c++;
    }
    if(b==0){
        a+1>=c ? printf("Yes\n") : printf("No\n");
        return 0;
    }
    n -= b;
    if((n+1)/2<=a) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>

long r(long list[6], long dis[5], long i, long n) {
  if (i == 5) {
    return i;
  }
  /* for (int j = 0; j < 6; j++) { */
  /*   std::cout << list[j] << ' '; */
  /* } */
  /* std::cout << std::endl; */

  for (int j = 4; j >= 0; j--) {
    if (list[j] == 0) {
      continue;
    }
    long a = list[j] - dis[j] >= 0 ? dis[j] : list[j];
    list[j] -= a;
    list[j + 1] += a;
  }

  /* std::cout << i << std::endl; */
  /* for (int j = 0; j < 6; j++) { */
  /*   std::cout << list[j] << ' '; */
  /* } */
  /* std::cout << std::endl; */
  return r(list, dis, i + 1, n);
}

int main(int argc, const char *argv[]) {
  long n;
  long a, b, c, d, e;
  std::cin >> n >> a >> b >> c >> d >> e;
  long dis[5] = {a, b, c, d, e};
  long min = dis[0];
  for (int j = 0; j < 5; j++) {
    min = std::min(min, dis[j]);
  }
  long list[6] = {n, 0};
  long re = r(list, dis, 0, n);
  long remaind = 0;
  for (int j = 0; j < 5; j++) {
    remaind += list[j];
    /* std::cout << list[j] << ' '; */
  }
  /* std::cout << std::endl; */
  /* std::cout << "min " << min << std::endl; */
  /* std::cout << "remaind " << remaind << std::endl; */
  /* std::cout << "re " << re << std::endl; */

  std::cout << re + ((remaind + (min - 1)) / min) << std::endl;
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; ++i)
#define X first
#define Y second
#define all(x) x.begin(), x.end()
using namespace std;
using PII=pair<int,int>;

//g -> index, dist
vector<PII> g[200000];

// Tree
class Node{
  public:
    int value;
    int parent;
    Node(){value=0;};
    Node(int d){value=d;};
};

Node nodes[200000];
int used[20000];
int a, b, c, n;
int ans;
const int INF = 1000000000;

PII B1, B2;


// dist, index
PII dfs(int from, int to){
  PII mx(0,to);
//   cout << "index: " << to<< endl;
  rep(i, g[to].size()){
    if(from == g[to][i].X)continue;
    PII val = dfs(to, g[to][i].X);
    val.X += g[to][i].Y;
    if(mx.X <  val.X){
      mx = val;
    }
  }
  return mx;

//   cout << "mx.X " << mx.X << " " << mx.Y << endl;
//   cout << endl;
}

PII diameter(){
  B1 = dfs(-1,0);
  B2 = dfs(-1, B1.Y);
  return B2;
}

void dijkstra(int from, int to, vector<int>& d){
  vector<int> used;
  used.resize(n, 0);
  priority_queue<PII, vector<PII>, greater<PII> > pq;
  pq.push(PII(0, from));
  d[from] = 0;

  while(!pq.empty()){
    int current = pq.top().Y;
    int d_sum = pq.top().X;pq.pop();

    if(d[current] < d_sum)continue;
//     cout << "current " << current << endl;

    rep(i, g[current].size()){
      //g -> index, dist
      int next = g[current][i].X;
      int cost = g[current][i].Y;

      if( d[next] > cost + d[current]){
        d[next] = cost + d[current];
        pq.push(PII(d[next] ,next));
      }
    }
  }
//   cout << "end" << endl;
}


int main(void){

  cin >> n;

  rep(i,n-1){
    cin >> a >> b >> c;
    if(a>b) swap(a,b);
    g[a].push_back(PII(b,c));
    g[b].push_back(PII(a,c));

    nodes[b].parent = a;
    nodes[b].value = c;
  }
//   cout << "end for" << endl;

  diameter();
//   cout << "dia" << endl;
  vector<int> d1, d2;
  d1.resize(n, INF);
  d2.resize(n, INF);
  dijkstra(B1.Y, B2.Y, d1);
  dijkstra(B2.Y, B1.Y, d2);

  rep(i,n){
     cout << max(d1[i], d2[i]) << endl;
  }

//   PII r = dfs(-1, 0);
//   cout << r.X << " " << r.Y << endl;
//   cout << endl;
//   PII t = dfs(-1, r.Y);
//   cout << t.X << " " << t.Y << endl;
//   cout << t.X << endl;
  

  return 0;
}

Measured memory_bytes: 10688
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int mm[100005];
int cnt[100005];

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

// #ifndef ONLINE_JUDGE
//     if(fopen("INPUT.txt","r"))
//     {
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//     }
// #endif  

    int n,l;
    cin>>n>>l;

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

    for(int i=1;i<n;i++)
    {
        if(a[i]+a[i-1]>=l)
        {
            vector<int>ans;
            for(int j=1;j<i;j++)
                ans.push_back(j);
            for(int j=n-1;j>i;j--)
                ans.push_back(j);
            ans.push_back(i);
            cout<<"Possible\n";
            for(auto j:ans)
                cout<<j<<'\n';
            return 0;
        }
    }
    cout<<"Impossible";
} 
    
 


Measured memory_bytes: 5072
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = 1000000007;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

void solve(){
	ll n,q;
	cin >> n;
	ll a[n+5];
	mem(a, 0);
	f0(n-1) cin >> q , a[q]++;
	f1(n) cout << a[i] << '\n';
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;A
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 5208
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	double v[n];
	for (int i = 0; i < n; i++) cin >> v[i];
	
	sort(v, &v[n]);
	for(int i = 0; i < n - 1; i++) {
		v[i+1] = (v[i]+v[i+1])/2.0;
	}
	
	cout << v[n-1] << endl;
}


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

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int y;
		double sum;
		int num=0;
		double max=0.0;

		cin >> y;

		for(int i=0 ;i<n ;i++){
			int b,r,t;
			cin >> b >> r >> t;

			if(t==1){
				sum = 1.0+(double)y*(double)r/100.0;
			}
			else{
				sum = 1.0;
				for(int j=0 ;j<y ;j++){
					sum *= 1.0+(double)r/100.0;
				}
			}

			if(max < sum){
				max = sum;
				num = b;
			}
		}
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string S;cin >> S;
  set<char>st;
  for(const char& c: S) st.insert(c);
  string s = "NS";
  string t = "WE";
  int count = 0;
  if(st.count(s[0])^st.count(s[1])){
    cout <<"No" << endl;
    return 0;
  }
  if(st.count(t[0])^st.count(t[1])){
    cout <<"No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#define inf1 1000000009
#define inf -1
using namespace std;
long long A,B,N;
long long s[100006];
bool cool(int a){
long long t=a;long long s1[100006];
 for(int i=1;i<=N;i++)
    s1[i]=s[i];
 for(int i=1;i<=N;i++)
   { s1[i]-=a*B;
    if(s1[i]<=0)continue;
      int y;
      if(s1[i]%(A-B)==0)y=s1[i]/(A-B);
      else y=s1[i]/(A-B)+1;
       t-=y;
   }//cout<<endl;
 if(t>=0)return true;
 return false;
}
int main(){

 cin>>N>>A>>B;
  for(int i=1;i<=N;i++)
  cin>>s[i];
  long long l=0,L=inf1,s1;s1=inf1;
  while(l<L){
   long long man=(l+L)/2;
    if(cool(man)) L=man,s1=min(s1,man);
    else l=man+1;
    //cout<<L<<" "<<l<<endl;
  }
  cout<<s1<<endl;
}

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


def get_input() -> list:
    """
    標準入力を取得する.

    Returns:
        list: 標準入力
    """
    x = list(map(int, input().split()))
    return x


def main(x: list) -> None:
    """
    求解処理を行う.

    Args:
        x (list): 数列
    """
    # 求解処理
    ans = x.index(0) + 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    x = get_input()
    main(x)


Measured memory_bytes: 9096
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, m, p;
    while(1){
        cin >> n >> m >> p;
        if(n + m + p == 0) break;
        m--;
        vector<int> x(n);
        int sum = 0;
        rep(i, 0, n){
            cin >> x[i];
            sum += x[i];
        }
        sum = sum * (100 - p);
        if(x[m] == 0) cout << 0 << endl;
        else cout << sum / x[m] << endl;
    }
}

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

const int MOD = (int)1e9+7;

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

	char x=S.at(K-1);
	for(int i=0;i<N;i++){
		if(S.at(i)==x)	cout << S.at(i);
		else	cout << "*";
	}
	cout << endl;

	return 0;
}


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

int main(){
  string s;
    
  int a ,b,c,d;
  cin >> s ;
  
    a = atoi(s.c_str());
    //cout << a << endl;
    b = a/100;
    c = (a-b*100)/10;
    d = a-b*100-c*10;
    
    //cout << a << ' ' << b << ' ' << c << ' ' << d << endl;
    cout << b+c+d << endl;
}

Measured memory_bytes: 256
import time

N, M, K = map(int, input().split())
rlt = 0
# ①nCrの各項のmod(10^9+7)を事前計算
p = 998244353
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

# ②事前計算した項を掛け合わせ
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

Mp = [0]*N
Mp[-1] = M 
for i in range(1, N):
  Mp[-i-1] = Mp[-i]*(M-1) % p
#print(Mp)
for k in range(K+1):
  #print(cmb(N-1,k,p), Mp[k])
  rlt += cmb(N-1,k,p)*Mp[k]
  rlt %= p

print(rlt)

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

int main(){
	int n, a[100010];
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	int cnt = 0;
	for (int i = 0; i < n; ++i)
	{
		if(i+1 == a[a[i]-1]) cnt++;
	}
	cout << cnt/2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
// const int N = ;

ll n, d, x, y, ans;

void solve() {
    cin >> n >> d;
    for(int i = 1; i <= n; i++) {
        cin >> x >> y;
        if(x * x + y * y <= d * d) ans++;
    }
    cout << ans << '\n';
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3628
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
for i in range(N):
    if a[i] == 1:
        if x_min < x[i]:
            x_min = x[i]
    elif a[i] == 2:
        if x_max > x[i]:
            x_max = x[i]
    elif a[i] == 3:
        if y_min < y[i]:
            y_min = y[i]
    elif a[i] == 4:
        if y_max > y[i]:
            y_max = y[i]
if x_max <= x_min or y_max <= y_min:
    print(0)
else:
    print((x_max - x_min)*(y_max - y_min))


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int f[1100000];
int p[11],c[11];
int main()
{
	int n,G;
	scanf("%d%d",&n,&G);G/=100;
	int ans=0,sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&p[i],&c[i]);c[i]/=100;
		ans+=p[i];sum+=p[i]*i+c[i];
	}
	memset(f,-1,sizeof(f));f[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=sum;j>=i;j--)
		{
			for(int k=p[i];k>=1;k--)
			{
				int w=i*k;
				if(k==p[i]) w+=c[i];
				if(w>j) continue;
				if(f[j-w]!=-1)
				{
					if(f[j]==-1) f[j]=f[j-w]+k;
					else f[j]=min(f[j],f[j-w]+k);
					if(j>=G) ans=min(ans,f[j]);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4480
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var input = fs.readFileSync('/dev/stdin', 'utf8').split('\n');
var n = input[0];
console.log("" + 2 * 3.14 * parseInt(n, 10));


Measured memory_bytes: 29768
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
q = []
ans = 0
for a in A:
  heapq.heappush(q, -a)

for i in range(M):
  num = heapq.heappop(q)
  num = -num // 2
  heapq.heappush(q, -num)

for i in range(N):
  ans += -heapq.heappop(q)

print(ans)

Measured memory_bytes: 14180
MOD = 10**9 + 7

N, M = map(int, input().split())
Ss = list(map(int, input().split()))
Ts = list(map(int, input().split()))

dp = [[1]*(M+1) for _ in range(N+1)]
for i, S in enumerate(Ss, 1):
    for j, T in enumerate(Ts, 1):
        dp[i][j] = dp[i-1][j] + dp[i][j-1]
        if S != T:
            dp[i][j] -= dp[i-1][j-1]
        dp[i][j] %= MOD

print(dp[-1][-1])


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

using namespace std;
typedef long long ll;
typedef double d;


int main()
{
	ll sum=0,k;
	cin>>k;
	for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int n=1;n<=k;n++){
                sum+=__gcd(n,__gcd(i,j));
            }
        }
	}
	cout<<sum;
	return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){
	ll r;
	cin>>r;
	double ans=(double)3.141592653*2*r;
	cout<<setprecision(10)<<fixed<<ans<<endl;




	

}

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

int main() {
  long long N,S,T,ans;
  cin>>N;
  vector<pair<long long,long long>>x(N);
  for(int i=0;i<N;i++){
    cin>>S>>T;
    x[i]=make_pair(S,T);
  }
  ans=0;
  sort(x.begin(),x.end());
S=x[0].first+x[0].second;
    for(int i=1;i<N;i++){
   T=x[i].first-x[i].second;
if(S<=T){
   S=x[i].first+x[i].second;
  continue;
}
      T=x[i].first+x[i].second;
      S=min(S,T);
      ans++;
  }
  cout<<N-ans<<endl;
}

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

int main(){
    int n, k;
    if (scanf("%d %d", &n, &k) < 2) exit(1);
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        if (scanf("%d", &h[i]) < 1) exit(1);
    }
    vector<int> a = h;
    sort(a.begin(), a.end());
    //座圧 -> id 復元 -> res
    map<int, int> id;
    map<int, int> res;
    int now = 1;
    for (int i = 0; i < n; i++){
        if (id[a[i]] == 0) {
            id[a[i]] = now;
            res[now] = a[i];
            now++;
        }
    }
    long long INF = ((long long)1 << 40);
    vector<vector<long long>> dp(n - k + 1, vector<long long>(n + 1, INF));
    vector<vector<long long>> pd = dp;
    dp[0][0] = 0;
    for (int i = 0; i < n; i++){
        pd = dp;
        for (int j = 0; j < n - k; j++){
            for (int m = 0; m <= n; m++){
                if (dp[j][m] == INF) continue;
                pd[j + 1][id[h[i]]] = min(pd[j + 1][id[h[i]]], dp[j][m] + max(0, h[i] - res[m]));
            }
        }
        dp = pd;
    }
    long long ans = INF;
    for (int i = 0; i <= n; i++) ans = min(ans, dp[n - k][i]);
    printf("%lld\n", ans);
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

int m = 998244353;
int dp[4010][4010];
int cs[2010];
signed main() {
  string s;
  cin >> s;
  int n = s.size();
  REP(i, n) {
    cs[i] += s[i] - '0';
    cs[i + 1] = cs[i];
  }
  dp[0][0] = 1;
  for (int k = 1; k <= 2 * n; ++k) {
    for (int i = 0; i <= k; ++i) {
      if (i > 0 && cs[min(k - 1, n - 1)] >= i) {
        dp[k][i] += dp[k - 1][i - 1];
      }
      if (2 * (1 + min(k - 1, n - 1)) - cs[min(k - 1, n - 1)] >= k - i) {
        dp[k][i] += dp[k - 1][i];
      }
      dp[k][i] %= m;
      // cout << dp[k][i] << " ";
    }
    // cout << "\n";
  }
  cout << dp[2 * n][cs[n - 1]] << endl;
}


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

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

    vector<int> A(N);
    vector<int> C(N);

    int ans = 0;
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < N; i++){
        int  t;
        cin >> t;
        ans += t;
    }
    for(int i = 0; i < N-1; i++){
        cin >> C.at(i);
    }
    for(int i = 0; i < N-1; i++){
        if(A.at(i+1) - A.at(i) == 1){
            ans += C.at(A.at(i)-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import queue

n = int(input())
v = [[]]
for _ in range(n):
    edges = sorted([int(x) for x in input().split()][2:])
    v.append(edges)
answers = [[idx, -1] for idx in range(n + 1)]
q = queue.Queue()
q.put(1)

answers[1][1] = 0
while not q.empty():
    node = q.get()
    for next_node in v[node]:
        if answers[next_node][1] != -1:
            continue
        q.put(next_node)
        answers[next_node][1] = answers[node][1] + 1

for idx, time in answers[1:]:
    print(idx, time)



Measured memory_bytes: 6876
var
s,astr,bstr:ansistring;
sign:char;
a,b,lens,p:longint;
begin
   readln(s);
   lens:=length(s);
   if pos('+',s)<>0 then 
   begin
      p := pos('+',s);
	  sign:='+';
   end;
   if pos('-',s)<>0 then 
   begin
      p := pos('-',s);
	   sign:='-';
   end;
   astr:=copy(s,1,p-2);
   bstr:=copy(s,p+2,lens-p-1);
   val(astr,a);
   val(bstr,b);
   if sign='+' then writeln(a+b);
   if sign='-' then writeln(a-b);
end.

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

using ret_type = double;
constexpr ret_type eps = 1e-8;

ret_type expr(string const& s, int& p);
ret_type term(string const& s, int& p);
ret_type factor(string const& s, int& p);
ret_type number(string const& s, int& p);

ret_type expr(string const& s, int& p) {
    ret_type val = term(s, p);
    while(p < (int)s.size() && (s[p] == '+' || s[p] == '-')) {
        if(s[p] == '-') {
            val -= term(s, ++p);
        } else {
            val += term(s, ++p);
        }
    }
    return val;
}

ret_type term(string const& s, int& p) {
    ret_type val = factor(s, p);
    while(p < (int)s.size() && s[p] == '*') {
        val *= factor(s, ++p);
    }
    return val;
}

ret_type factor(string const& s, int& p) {
    if(s[p] == '-') {
        return -factor(s, ++p);
    } else if(s[p] == '(') {
        ret_type res = expr(s, ++p);
        if(p >= (int)s.size() || s[p] != ')') throw std::logic_error("");
        ++p;
        return res;
    } else if(isdigit(s[p])) {
        return number(s, p);
    } else {
        throw std::logic_error("");
    }
}

ret_type number(string const& s, int& p) {
    if(s[p] != '0' && s[p] != '1') throw std::logic_error("");
    if(p + 1 < (int)s.size() && s[p] == '0' && isdigit(s[p + 1])) throw std::logic_error("");

    ret_type res = 0;
    while(p < (int)s.size() && isdigit(s[p])) {
        res *= 2;
        res += (s[p++] == '1');
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    const int n = s.size();
    vector<char> cs;
    for(auto c : s) {
        if(isalpha(c)) {
            cs.push_back(c);
        }
    }
    sort(begin(cs), end(cs));
    cs.erase(unique(begin(cs), end(cs)), end(cs));

    vector<char> v = {'0', '1', '+', '-', '*', '=', '(', ')'};
    sort(begin(v), end(v));

    if(cs.size() > v.size()) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    set<string> checked;
    do {
        string t;
        for(auto c : s) {
            if(isalpha(c)) {
                t += v[find(begin(cs), end(cs), c) - begin(cs)];
            } else {
                t += c;
            }
        }
        if(count(begin(t), end(t), '=') != 1) continue;
        int lp = 0, rp = find(begin(t), end(t), '=') - begin(t) + 1;
        if(rp == 1 || rp == n || checked.count(t) == 1) continue;

        checked.insert(t);

        try {
            auto lval = expr(t, lp), rval = expr(t, rp);
            if(t[lp] == '=' && rp == n && abs(lval - rval) < eps) {
                ans += 1;
            }
        } catch(...) {
            continue;
        }
    } while(next_permutation(begin(v), end(v)));

    cout << ans << endl;
}


Measured memory_bytes: 7160
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  vector<long long> a(n);
  for(long long i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  cout<<a[n-1]-a[0]<<endl;
}

Measured memory_bytes: 256
import java.util.*;

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();
        int t_hit = a;
        int a_hit = c;

        while (true) {
            a_hit = a_hit - b;
            t_hit = t_hit - d; //後
            if (a_hit <= 0) {
                System.out.println("Yes");
                break;
            }else if (t_hit <= 0) {
                System.out.println("No");
                break;
            }
        }
    }
}

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

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

int main() {
    int n;
    cin >> n;
    ll a[n], b[n];
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll sum = 0;

    rep(k, 32) { //k-bitを求める
        ll cnt = 0;

        ll k_pow = (1 << k);
        ll k_mod = (1 << (k + 1));

        ll b_mod[n];
        rep(i, n) b_mod[i] = b[i] % k_mod;
        sort(b_mod, b_mod + n);

        rep(i, n) {
            ll ai_mod = a[i] % k_mod;

            cnt += lower_bound(b_mod, b_mod + n, 2 * k_pow - ai_mod)
                    - lower_bound(b_mod, b_mod + n, k_pow - ai_mod);
            cnt += lower_bound(b_mod, b_mod + n, 4 * k_pow - ai_mod)
                    - lower_bound(b_mod, b_mod + n, 3 * k_pow - ai_mod);
        }
        sum += (cnt % 2) * k_pow;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  __float128 x=0;
  int N;
  cin>>N;
  bool lg=false;
  bool neg;
  bool u;
  while(N--){
    int o,Y;
    cin>>o>>Y;
    if(o==1){
      if(!lg){
	x+=Y;
      }else{
	if(u){
	  x=Y;
	  lg=false;
	}
      }
    }else if(o==2){
      if(!lg){
	x-=Y;
      }else{
	if(u){
	  x=-Y;
	  lg=false;
	}
      }
    }else if(o==3){
      if(Y==0){
	x=0;
	lg=false;
      }else{
	if(lg){
	  neg^=Y<0;
	  x+=log(fabs(Y));
	}else{
	  x*=Y;
	}
      }
    }else{
      if(lg){
	neg^=Y<0;
	x-=log(fabs(Y));
      }else{
	x/=Y;
      }
    }
    const double th=1e20;
    const double thl=log(th);
    const double uth=1/th;
    const double uthl=log(uth);
    if(lg){
      if(uthl<=x&&x<=thl){
	x=(neg?-1:1)*exp(double(x));
	lg=false;
      }
    }else{
      if(x&&(x<-th||-uth<x&&x<uth||th<x)){
	u=-uth<x&&x<uth;
	neg=x<0;
	x=log(fabs(double(x)));
	lg=true;
      }
    }
    //    cout<<(double)x<<endl;
  }
  cout<<lrint(double(x))<<endl;
}

Measured memory_bytes: 1264
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main{
	//for(Map.Entry<Object, Object> e: map.entrySet()){ ...
	public static void main(String[] args){
		try{
//-*-*- tp start -*-*-
			final int INF = Integer.MAX_VALUE, MINF = Integer.MIN_VALUE;
			SpecialComparator scomparator = new SpecialComparator();
			Scanner s = new Scanner(System.in);
//-*-*- tp end -*-*-
			//write a program...
			while(s.hasNext()){
				int a = s.nextInt(), b = s.nextInt();
				debugl(String.valueOf(a+b).length());
			}
//-*-*- tp start -*-*-
		}catch(Exception e){
			e.printStackTrace();
		}
	}
//-*-*- tp end -*-*-
	//functions
//-*-*- tp start -*-*-
	private static void debugl(Object obj){
		System.out.println(obj);
	}
	private static void debug(Object obj){
		System.out.print(obj);
	}
	private static String toStrmd(Object[] obj){
		return Arrays.deepToString(obj);
	}
}

class SpecialComparator implements Comparator{
	private int index = 0;
	public void setIndex(int index){
		this.index = index;
	}
	public int compare(Object a, Object b){
		String[] sa = (String[])a;
		String[] sb = (String[])b;
		return (sa[index].compareTo(sb[index]));
	}
}
//-*-*- tp end -*-*-

Measured memory_bytes: 12000
package main

import "fmt"

var dp [10001]int

func dynamicPlanning(damage int, a []int, b []int) int {
	if damage <= 0 {
		return 0
	}
	//fmt.Println("Remains damage : ",damage)
	if dp[damage] > 0 {
		//fmt.Println("Already searched : ",dp[damage])
		return dp[damage]
	}
	var min = -1
	//var min_num int
	for i := 0 ; i < len(a) ; i++ {
		/*if damage <= a[i] {
			fmt.Println("Attacked one : ",b[i])
			dp[damage] = b[i]
			return b[i]
		}*/
		temp := dynamicPlanning(damage-a[i],a,b) + b[i]
		if min < 0 || min > temp {
			min = temp
			//min_num = i
		}
	}
	//fmt.Println("Attacked many times : ",min)
	dp[damage] = min
	return min
}

func main(){
	var h,n int
	fmt.Scan(&h, &n)
	a := make([]int,n)
	b := make([]int,n)
	for i := 0 ; i < n ; i++ {
		fmt.Scan(&a[i],&b[i])
	}
	answer := dynamicPlanning(h,a,b)
	fmt.Println(answer)
}


Measured memory_bytes: 2560
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-B: Merge Sort

#include <climits>
#include <cstdio>
#include <cstring>

static void print_ints(const int as[], const unsigned int n, const char* sep = " ") {
  const char* out_sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::printf("%s%d", out_sep, as[i]);
    out_sep = sep;
  }
  std::printf("\n");
}

static void print_int(const unsigned int n) {
  std::printf("%d\n", n);
}

static unsigned int comparison_count = 0u;

static void merge(int* /*const*/ begin, int* const middle, int* /*const*/ end) {
  while (*begin < *middle) {
    ++begin;
    ++comparison_count;
  }
  while (*(middle-1) < *(end-1)) {
    --end;
    ++comparison_count;
  }
  auto size = middle - begin;
  int tmp[size+1]; // size+1(sentinel)
  std::memcpy(tmp, begin, sizeof(tmp[0])*size);
  tmp[size] = INT_MAX; // > 10**9
  auto ss0 = begin, ss1 = tmp, ss2 = middle;
  const auto end1 = ss1+size, end2 = end;
  while (ss2 < end2) {
    while (*ss1 <= *ss2) {
      *ss0++ = *ss1++;
      ++comparison_count;
    }
    *ss0++ = *ss2++;
    ++comparison_count;
  }
  while (ss1 < end1) {
    *ss0++ = *ss1++;
    ++comparison_count;
  }
}

void merge_sort(int* const begin, int* const end) {
  auto size = end - begin;
  if (size > 1) {
    auto middle = begin + size/2;
    merge_sort(begin, middle);
    merge_sort(middle, end);
    merge(begin, middle, end);
  }
}

int main(void) {
  unsigned int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  merge_sort(ss, ss+n);

  print_ints(ss, n);
  print_int(comparison_count);

  return 0;
}

// eof

Measured memory_bytes: 5660
N ,K = map(int,input().split())

A = list(map(int,input().split()))
MAX = max(max(A),K)
l = len(str(bin(MAX)))-2

AB = []
for i in range(N):
  s = str(bin(A[i]))
  temp = s[2:]
  lendif = l - len(temp)
  while lendif > 0:
    temp = "0"+temp
    lendif -= 1
  AB.append(temp)
#print(AB,l)

ans = 0
now = 0 #Kを超えていないかチェックする用。
for i in range(l): #桁数で回す。l-i桁から順にみていく。
  #cは0の数。dは1の数。
  c = 0; d = 0
  for j in range(N):
    if AB[j][i] == "0":
      c += 1
    else:
      d += 1
  if c > d: #0の方が多いので1にしたい。l-i桁目が1の時はKを超えてないか確認。
    if pow(2,l-1-i)+now > K:
      m = d
    else:
      now += pow(2,l-1-i)
      m = c
  else:
    m = d
  #print(m, now, pow(2,l-1-i))
  ans += pow(2,l-1-i)*m
print(ans)

Measured memory_bytes: 17820
#!/usr/bin/env python3
import sys


def solve(x: int):
    q, r = divmod(x, 11)
    ans = q * 2
    if r > 0:
        ans += 1
        r -= 6
    if r > 0:
        ans += 1
        r -= 5
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    solve(x)


if __name__ == '__main__':
    main()


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

int main() {
    int n;
    string str;
    cin >> n >> str;
    
    long long ans = 0;
    map<pair<string, string>, long long> mp;
    
    for (int s = 0; s < (1<<n); s++) {
        string r = "", b = "";
        for (int i = 0; i < n; i++) {
            if (s & (1<<i)) r.push_back(str[i]);
            else b.push_back(str[i]);
        }
        reverse(b.begin(), b.end());
        mp[make_pair(r, b)]++;
    }
    
    for (int s = 0; s < (1<<n); s++) {
        string r = "", b = "";
        for (int i = 0; i < n; i++) {
            if (s & (1<<i)) r.push_back(str[i + n]);
            else b.push_back(str[i + n]);
        }
        reverse(b.begin(), b.end());
        ans += mp[make_pair(b, r)];
    }
    
    cout << ans << endl;
    return 0;
}

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


void solve(std::string S){
    string ans;
    if(S == "ABC") ans = "ARC";
    else ans = "ABC";
    cout << ans << endl;
    return;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main(){
    string s; cin >> s;
    int sz = s.size();
    int mid = s.size()/2;
    int count = 0;
    for(int i = 0, j = sz-1; i < sz/2 && j>= sz-mid; i++, j--){
    	if(s[i] != s[j]) count++;
    }
    cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
 int N;
 cin >> N;
 
 int mon;
 int ans;
 for(int i = 0; i < 10; i++){
   mon += 1000;
   if(mon >= N){
     ans = mon - N;
     break;
   }
 }
 cout << ans << endl;
}

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

#define N 1010

int c[N][N];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1,x1,x2,y1,y2;i<=n;i++)
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2),x1++,x2++,y1++,y2++,c[x1][y1]++,c[x2][y2]++,c[x1][y2]--,c[x2][y1]--;
	int ans=0;
	for(int i=1;i<N;i++)
		for(int j=1;j<N;j++)
			c[i][j]+=c[i-1][j]+c[i][j-1]-c[i-1][j-1],ans=ans<c[i][j]? c[i][j]:ans;
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 7212
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[100010];
int B[100010];
int C[100010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		cin>>B[i];
	}
	REP(i,N){
		cin>>C[i];
	}
	sort(A,A+N);
	sort(B,B+N);
	sort(C,C+N);
	int ans=0;
	REP(i,N){
		int ok=-1,ng=N;
		while(abs(ng-ok)>1){
			int mid=(ok+ng)/2;
			if(A[mid]<B[i]){
				ok=mid;
			}
			else{
				ng=mid;
			}
		}
		int res=ok+1;
		DEB(ok)DEB(ng)END
		ok=N,ng=-1;
		while(abs(ng-ok)>1){
			int mid=(ok+ng)/2;
			if(C[mid]>B[i]){
				ok=mid;
			}
			else{
				ng=mid;
			}
		}
		DEB(ok)DEB(ng)END
		res*=((N-1)-ok)+1;
		ans+=res;
	}
	cout<<ans<<endl;
	return 0;
}


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

template<typename T>
T get_value(std::istream& is);

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

  const auto tar {get_value<int>(cin)};
  for (auto i {tar / 7}; i != -1; --i)
    if (!((tar - i*7) % 4)) {
      cout << "Yes\n";
      return 0;
    }
  cout << "No\n";
  return 0;
}

template<typename T>
inline T get_value(std::istream& is)
{
  T v;
  is >> v;
  return v;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

string s;
int k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s >> k;
    char ans = '1';
    rep(i, 0, k) {
      if (s[i] != '1') {
        ans = s[i];
        break;
      }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 380