akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _018_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            int[] array = ReadInts();
            Array.Sort(array);
            if (array[n - 1] < k)
            {
                Console.WriteLine("IMPOSSIBLE");
                return;
            }
            long gcd = array[0];
            for(int i = 1; i < n; i++)
            {
                gcd = GCD(gcd, array[i]);
            }
            if (k % gcd == 0)
            {
                Console.WriteLine("POSSIBLE");
            }
            else
            {
                Console.WriteLine("IMPOSSIBLE");
            }
        }
        
        static long GCD(long a, long b)
        {
            long c = b;
            do
            {
                c = a % b;
                a = b;
                b = c;
            } while (c > 0);
            return a;
        }

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


Measured memory_bytes: 18400
/* ***********************************************
Author        :devil
************************************************ */
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <time.h>
#include <cmath>
#include <stdlib.h>
#define LL long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ou(a) printf("%d\n",a)
#define pb push_back
#define pii pair<int,int>
#define mkp make_pair
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
using namespace std;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int N=5e3+10;
int main()
{
    int a[3];
    for(int i =0;i<3;++i)scanf("%d",&a[i]);
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

int main(void) {
    int num;
    cin >> num;
    vector<int> vec(num);
    int ans = 0;
    for (int i=0; i < num; i++) {
        cin >> vec[i];
        ans ^= vec[i];
    }

    for (int i=0; i < num; i++) {
        vec[i] = ans ^ vec[i];
        cout << vec[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
map<string,int> book;
vector<string>ans;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int n,Max=0;
	cin>>n;
	rep(i,1,n) {
		string a;
		cin>>a;
		book[a]++;
		Max=max(book[a],Max);
	}
	for(auto x:book) {
		if(x.se==Max) {
			ans.pb(x.fi);
		}
	}
	sort(ans.begin(),ans.end());
	rep(i,0,ans.size()-1) cout<<ans[i]<<'\n';
    return 0;
}


Measured memory_bytes: 25584
#include <cstdio>
#include <vector>
#include <cmath>

int n;
int x[50];
int y[50];

long long cover(double cx, double cy, double r)
{
	long long res = 0;
	for (int i = 0; i < n; ++i)
	{
		double dx = cx - x[i], dy = cy - y[i];
		if (dx * dx + dy * dy <= r * r)
		{
			res |= 1LL << (long long)i;
		}
	}
	return res;
}

bool check(double r)
{
	std::vector<long long> cand;
	cand.emplace_back(0);

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			double x1 = x[i], y1 = y[i];
			double x2 = x[j], y2 = y[j];
			double dx = x2 - x1, dy = y2 - y1;
			double a = dx * dx + dy * dy;
			double b = .5;
			double d = r * r / a - b * b;
			if (d >= 0)
			{
				d = std::sqrt(d);
				double x3 = x1 + dx * b;
				double y3 = y1 + dy * b;
				double x4 = -dy * d;
				double y4 = dx * d;
				long long ij = 1LL << (long long)i | 1LL << (long long)j;
				cand.emplace_back(cover(x3 - x4, y3 - y4, r) | ij);
				cand.emplace_back(cover(x3 + x4, y3 + y4, r) | ij);
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cand.emplace_back(cover(x[i], y[i], r) | 1LL << i);
	}
	for (int i = 0; i < cand.size(); ++i)
	{
		if (cand[i] == (1LL << n) - 1) return true;
	}
	return false;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d", x + i, y + i);
	}
	double l = 0;
	double r = 100000;
	for (int i = 0; i < 100; ++i)
	{
		double mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid;
	}
	printf("%.9f", l);
	return 0;
}


Measured memory_bytes: 256
S = input()
tmplen = 0
atclen = 0
for i in range(len(S)):
  if S[i]== "A" or S[i]=="T" or S[i]=="G" or S[i]=="C":
    tmplen = tmplen + 1
  else:
    if(atclen < tmplen):
      atclen = tmplen
    tmplen = 0
if(atclen<tmplen):
    atclen = tmplen
print(atclen)

Measured memory_bytes: 3060
from sys import exit

A, B = map(int, input().split())


def get_xor(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return 1 + x
    elif x % 4 == 3:
        return 0


ans = get_xor(A - 1) ^ get_xor(B)

print(ans)


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

using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, taka, aoki, pa[N], dpst[N], depth[N];
vector<int> adj[N];

void dfs(int u) {
	dpst[u] = 0;
	for (int v : adj[u])
		if (v != pa[u]) {
			pa[v] = u;
			depth[v] = depth[u] + 1;
			dfs(v);
			dpst[u] = max(dpst[u], dpst[v] + 1);
		}
}
int finaltag(int dist) {
	if (dist < 2) return 0;
	return dist - 1;
}

int main() {
	cin >> n >> taka >> aoki;
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);
	}
	pa[aoki] = -1; depth[aoki] = 0;
	dfs(aoki);
	int dist = depth[taka];
	int ans = 0, aokiApproach = 0;
	for (int u = taka; dist > 0; dist -= 2, u = pa[u], aokiApproach++) {
		ans = max(ans, finaltag(dist) + dpst[u] + aokiApproach);
	}
	cout << ans << endl;
}

Measured memory_bytes: 10752
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n,m; cin>>n>>m;
    vector<vector<int>> g(n+1);
    for(int i = 0 ; i < m; i++){
        int a,b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> p(n+1);
    vector<int> d(n+1, 1e9);
    set<pair<int,int>> q;
    q.insert({0,1});
    for(int i = 2; i <= n; i++){
        q.insert({INT_MAX,i});
    }
    d[1] = 0;
    d[0] = 0;
    while(!q.empty()){
        int v = q.begin()->ss;
        q.erase(q.begin());
        for(int next : g[v]){
            if(d[next] > d[v] + 1){
                q.erase({d[next],next});
                d[next] = d[v] + 1;
                p[next] = v;
                q.insert({d[next],next});
            }
        }
    }
    if(*max_element(all(d))== INT_MAX) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        for(int i = 2; i <=n; i++)
            cout<<p[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 19520
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 123456789
#define MAX 100001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
vector<vector<ll> >g(MAX);
ll n,m,u,v,ans,used[MAX];
void dfs(ll s){
	used[s]=1;
	for(int i=0;i<g[s].size();i++){
		if(!used[g[s][i]]){
			dfs(g[s][i]);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	while(m--){
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i=1;i<=n;i++){
		if(!used[i]){
			dfs(i);
			ans++;
		}
	}
	cout<<ans-1;
}

Measured memory_bytes: 11124
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;


//int V;
//
//
//bool dfs(int v, int c) {
//    color[v] = c;
//    for (int i = 0; i < G[v].size(); i++) {
//        if (color[G[v][i]] == c) return false;
//        if (color[G[v][i]] == 0 && !dfs(G[v][i], -c )) return false;
//    }
//
//    return true;
//}
//
//void solve() {
//    for (int i = 0; i < V; i++) {
//        if (color[i] == 0) {
//            if (!dfs(i, 1)) {
//                printf("No\n");
//                return ;
//            }
//        }
//    }
//
//    printf("Yes\n");
//}

vector<vector<pair<int, int>>> G;

int color[100004];

void dfs(int v, int c) {
    color[v] = c;
    for (int i = 0; i < G[v].size(); i++) {
        if (color[G[v][i].first] == 0 && G[v][i].second % 2 == 0) {
            dfs(G[v][i].first, c);
        } else if (color[G[v][i].first] == 0 && G[v][i].second % 2 != 0) {
            dfs(G[v][i].first, -c);
        }

    }

}
int main(){
    int N;
    cin >> N;
    ll u[N], v[N], w[N];
    ll a, b, c;
    G.resize(N);
    rep(i, N-1){
        cin >> a >> b >> c;
        G[a-1].push_back(make_pair(b-1, c));
        G[b-1].push_back(make_pair(a-1, c));
    }

    dfs(0, 1);

    rep(i, N){
        if (color[i] == 1){
            cout << 1 << endl;
        }  else {
            cout << 0 << endl;
        }
    }





}

Measured memory_bytes: 8192
#include<stdio.h>
#define MAX 100000
int P[MAX],F[MAX]={0},i,j,p=0,r,M,A,B,rp,rq;

int main()
{
	for(i=2;i<MAX;i++)
		if(!F[i])
		{
			P[p++]=i;
			for(j=i*2;j<MAX;j+=i)
				F[j]=1;
		}
	for(;scanf("%d%d%d",&M,&A,&B),M;)
	{
		for(i=rp=rq=r=0;i<p;i++)
			for(j=0;j<=i&&P[i]*P[j]<=M;j++)
			{
				if(((double)A/B)<=((double)P[j]/P[i])&&P[i]*P[j]>r)
				{
					rp=P[j];rq=P[i];r=rp*rq;
				}
			}
		printf("%d %d\n",rp,rq);
	}
	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint x, y; std::cin >> x >> y;
  lint z = x - y;
  if (z<0) z=-z;
  bool ans = 1 < z;
  std::cout << (ans ? "Alice" : "Brown") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;

int main(){
	LL N, M;
	cin >> N >> M;
	vLL b(M), c(M), a(N);
	vector<P>	vp;
	for(int i = 0;i < N;i++)	cin >> a[i];
	sort(a.rbegin(), a.rend());
	for(int i = 0;i < M;i++)	cin >> b[i] >> c[i];
	for(int i = 0;i < M;i++)	vp.push_back({c[i], b[i]});
	sort(vp.rbegin(), vp.rend());
	for(int i = 0;i < M;i++)	tie(c[i], b[i]) = vp[i];
	int aid = 0;
	int cid = 0;
	int sid = 0;
	LL ans = 0;
	while(sid < N){
		if(a[aid] >= c[cid]){
			ans += a[aid++];
			sid++;
		}else{
			ans += c[cid];
			sid++;
			b[cid]--;
			if(b[cid] == 0)	cid++;
			if(cid == M && sid < N){
				for(int i = aid;;i++){
					ans += a[i];
					sid++;
					if(sid == N)	break;
				}
			}
		}
	}
	cout << ans << endl;
}

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

using namespace std;

const int max_n = 18, inf = 1000111222;

int n, a[1 << max_n + 5];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < (1 << n); ++i) {
        scanf("%d", &a[i]);
    }
    int ans = 0;
    for (int mask = 1; mask < (1 << n); ++mask) {
        int mx1 = a[0], mx2 = -1;
        for (int i = mask; i > 0; i = mask & (i - 1)) {
            if (a[i] >= mx1) {
                mx2 = mx1;
                mx1 = a[i];
            } else if (a[i] >= mx2) {
                mx2 = a[i];
            }
        }
        ans = max(ans, mx1 + mx2);
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 4096
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct
{
  int idx, read, x1, y1, x2, y2;
} Rec;

void solve(vector<Rec*> rem, int& reader)
{
  int minIndex = 0;
  for (unsigned int i = 1; i < rem.size(); ++i) {
    if (rem[minIndex]->x1 > rem[i]->x1) {
      minIndex = i;
    } else if (rem[minIndex]->x1 == rem[i]->x1) {
      if (rem[minIndex]->y1 > rem[i]->y1)
	minIndex = i;
    }
  }

  rem[minIndex]->read = reader++;
  int x = 501, y = rem[minIndex]->y2;
  vector<Rec*> rem1, rem2;
  for (unsigned int i = 0; i < rem.size(); ++i) {
    if (i == minIndex)
      continue;
    if (rem[i]->x1 < x && rem[i]->y1 < y && y < rem[i]->y2)
      x = min(x, rem[i]->x1);
  }

  for (unsigned int i = 0; i < rem.size(); ++i) {
    if (i == minIndex)
      continue;
    if (rem[i]->x2 <= x && rem[i]->y2 <= y)
      rem1.push_back(rem[i]);
    else
      rem2.push_back(rem[i]);
  }

  if (!rem1.empty())
    solve(rem1, reader);
  if (!rem2.empty())
    solve(rem2, reader);
}

int main()
{
  int n;
  bool first = true;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;

    if (!first)
      puts("");

    vector<Rec> rec(n);
    for (int i = 0; i < n; ++i) {
      rec[i].idx = i;
      scanf("%d %d %d %d", &rec[i].x1, &rec[i].y1, &rec[i].x2, &rec[i].y2);
      if (rec[i].x1 > rec[i].x2)
	swap(rec[i].x1, rec[i].x2);
      if (rec[i].y1 > rec[i].y2)
	swap(rec[i].y1, rec[i].y2);
    }

    vector<Rec*> rem;
    for (unsigned int i = 0; i < rec.size(); ++i)
      rem.push_back(&rec[i]);

    int cnt = 1;
    solve(rem, cnt);

    for (unsigned int i = 0; i < rec.size(); ++i)
      printf("%d\n", rec[i].read);
    first = false;
  }
  return 0;
}

Measured memory_bytes: 0
import math
x=int(input())

def get_sieve_of_eratosthenes(n):
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

data = get_sieve_of_eratosthenes(x*2)
for i in data:
  if i>=x:
    print(i)
    break
#print(data)

Measured memory_bytes: 17536
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	runeMap := make(map[rune]int)
	var s string
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		localRuneMap := make(map[rune]int)
		for _, r := range s {
			localRuneMap[r]++
		}
		for r := 'a'; r <= 'z'; r++ {
			if i == 0 || localRuneMap[r] < runeMap[r] {
				runeMap[r] = localRuneMap[r]
			}
		}
	}

	for r := 'a'; r <= 'z'; r++ {
		for j := 0; j < runeMap[r]; j++ {
			fmt.Printf("%c", r)
		}
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s;
  in(s);
  rep(i, s.size()){
    if(s[i] != ',')
      out(s[i]);
    else
      hina;
  }
  memi;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll x[100010];
ll dp[22][100010];
//dp[i][j]=x[j]から2^i日以内で到達可能な最大のindex

void f(int a,int b){
	if(a>b){int t=a;a=b;b=t;}
	//aからbまで移動
	ll l=0,r=1<<20,d=19;//lはNG,rはOK
	while(r-l>1){
		if(dp[d][a]>=b)r=l+(1<<d);
		else{
			l=l+(1<<d);
			a=dp[d][a];
		}
		d--;
	}
	printf("%lld\n",r);
}

int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",x+i);
	ll L;
	scanf("%lld",&L);
	
	rep(i,0,n){
		//にぶたん
		ll X=x[i]+L;
		ll l=i,r=n;//lはOK,rはNG
		while(r-l>1){
			ll m=(l+r)/2;
			if(x[m]<=X)l=m;
			else r=m;
		}
		dp[0][i]=l;
	}
	
	rep(i,0,20)rep(j,0,n)dp[i+1][j]=dp[i][dp[i][j]];
	
	int q;
	scanf("%d",&q);
	while(q--){
		int a,b;
		scanf("%d %d",&a,&b);
		f(a-1,b-1);
	}
	return 0;
}

Measured memory_bytes: 17920
import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(lambda x:-int(x), sys.stdin.readline().split()))
heapq.heapify(A)

for j in range(m):
    heapq.heappush(A ,int(A[0]/2))
    heapq.heappop(A)

print(-sum(A))

Measured memory_bytes: 14204
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem0555 : Ring **/
int main()
{
	int n;
	string t;
	cin>>t>>n;
	vector<string> s(n);
	rep(i, n) {
		cin>>s[i];
	}
	int ans = 0;
	rep(i, n) {
		rep(j, s[i].size()) {
			string ss;
			rep(k, s[i].size()) {
				ss += s[i][(j+k)%s[i].size()];
			}
			if (ss.find(t, 0) != string::npos) {
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
#define NIL -1

struct Node{int p=NIL,l=NIL,r=NIL;};

void preOrder(Node T[], int id){
	if(id==NIL) return;
	cout << " " << id;
	preOrder(T,T[id].l);
	preOrder(T,T[id].r);
}

void inOrder(Node T[], int id){
	if(id==NIL) return;
	inOrder(T,T[id].l);
	cout << " " << id;
	inOrder(T,T[id].r);
}

void postOrder(Node T[], int id){
	if(id==NIL) return;
	postOrder(T,T[id].l);
	postOrder(T,T[id].r);
	cout << " " << id;
}

int main(){
	int n;
	cin >> n;
	Node T[n];
	for(int i=0;i<n;i++){
		int id,l,r;
		cin>>id>>l>>r;
		T[id].l=l;
		T[id].r=r;
		if(l!=NIL)T[l].p=id;
		if(r!=NIL)T[r].p=id;
	}
	
	int root;
	for(int i=0;i<n;i++){
		if(T[i].p==NIL){
			root=i;
			break;
		}
	}
	
	cout << "Preorder" << endl;
	preOrder(T,root);
	cout << endl;

	cout << "Inorder" << endl;
	inOrder(T,root);
	cout << endl;

	cout << "Postorder" << endl;
	postOrder(T,root);
	cout << endl;

	return 0;
}



Measured memory_bytes: 3052
require 'pp'

n = gets.chomp!.to_i
a_n = gets.chomp!.split(" ").map(&:to_i).sort

counter = {}
a_n.each do |a|
    counter[a] ||= 0
    counter[a] += 1
end
# 番兵(counterが3つ以上あることを保証する)
counter[10 ** 8] = 0
counter[10 ** 9] = 0

max = 0
counter.each_cons(3) do |x, y, z|
    count = x[1]
    if x[0] + 1 == y[0]
        count += y[1]
        if y[0] + 1 == z[0]
            count += z[1]
        end
    end

    if max < count
        max = count
    end
end

puts max



Measured memory_bytes: 15720
#python3
from operator import itemgetter
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    s = []
    for i,j in zip(a,range(n)):
        s.append((i,j+1))
    for i in sorted(s, key=itemgetter(0)):
        print(i[1],end=" ")
main()


Measured memory_bytes: 20880
#096_D
n = int(input())
prime_5 = []
for i in range(2, 55556):
    flg = (i % 5 == 1)
    if flg:
        for j in range(2, int(i**0.5)+1):
            if i % j == 0:
                flg = False
                break
    if flg:
        prime_5.append(i)
print(*prime_5[:n])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;  
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
 
const int MOD = 1e9 + 7; 
const int N = 1e5+10; 
const int INF = 1e9 + 5; 
 
int main(void) 
{
 
	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	#endif
 
	string s; 
	cin >> s; 
	for (char c : s) 
		if (c == '7') 
		{
			cout << "Yes\n"; 
			return false; 
		}
 
	cout << "No\n"; 
 
 
	return false; 
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 100001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int main(){
	int a[4];
	rep(i, 4)scanf("%d", &a[i]);
	if(a[0]+a[1] > a[2]+a[3])printf("Left");
	else if(a[0]+a[1] < a[2]+a[3])printf("Right");
	else printf("Balanced");
	printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
#include <numeric>
using namespace std;

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

    stack<int> st1;
    stack<pair<int, int>> st2;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '\\')
        {
            st1.push(i);
        }
        else if (s[i] == '/' && !st1.empty())
        {
            int j = st1.top();
            st1.pop();
            int tmp = i - j;
            while (st2.size() > 0 && st2.top().first > j)
            {
                tmp += st2.top().second;
                st2.pop();
            }
            st2.push(make_pair(i, tmp));
        }
    }

    vector<int> ans;
    while (!st2.empty())
    {
        ans.push_back(st2.top().second);
        st2.pop();
    }

    cout << accumulate(ans.begin(), ans.end(), 0) << endl;
    cout << ans.size();
    for (int i = ans.size() - 1; i >= 0; i--)
    {
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}


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

def breadth_first_search(graph, root): 
    visited, queue = set([root]), collections.deque([root])
    color = [0] * len(graph)
    # root is always 0
    while queue: 
        vertex = queue.popleft()
        for neighbour in graph[vertex]: 
            if neighbour[0] not in visited: 
                visited.add(neighbour[0]) 
                queue.append(neighbour[0])
                color[neighbour[0]] = (color[vertex] + neighbour[1] % 2) % 2
    return color 

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    graph = [[] for i in range(N)]
    for i in range(len(u)):
        graph[u[i]-1] += [[v[i]-1, w[i]]]
        graph[v[i]-1] += [[u[i]-1, w[i]]]
    color = breadth_first_search(graph, 0)
    print("\n".join(list(map(str, color))))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
//ranker
using namespace std;

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

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


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

  int M, min, max;

  while(1){
    cin >> M >> min >> max;

    if(M == 0 && min == 0 && max == 0) break;

    int P[M];
    REP(i, M) cin >> P[i];

    int gomi = 0;
    int cnt = 0;
    REPS(i, min-1, max){
      if(gomi <= P[i]-P[i+1]){
      gomi = P[i]-P[i+1];
      cnt = i+1;
    }
  }
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n,a[100010];
    int ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    a[0]=a[n+1]=0;
    for(int i=0;i<=n;i++){
        ans+=abs(a[i]-a[i+1]);
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",ans-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]));
    }
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

/* エラトステネスの篩 */
const int SIZE = 1000000;
vector<int> primes;
bool isPrime[SIZE];

void make_primes() {
  if (primes.size() > 0) return;
  memset(isPrime, true, sizeof(isPrime));
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < SIZE; i++) 
    if (isPrime[i])
      for (int j = i * i; j < SIZE; j += i)
        isPrime[j] = false;
  REP(i, SIZE) if (isPrime[i]) primes.push_back(i);
}


int main2() {
  
  int N = nextInt();

  vector<int> ans;
  for (int n = 1; ans.size() < N; n++) {
    if (isPrime[5*n + 1]) {
      ans.push_back(5*n+1);
    }
  }
  
  REP(i, ans.size()) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}

int main() {
  make_primes();
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1916
<?php
# 入力部
// fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%d %d", $n, $m);
// $s1 = fgets(STDIN); //"\n"の2文字
// $s2 = fgets(STDIN);
// fscanf(STDIN, "%d", $n);
// fscanf(STDIN, "%s", $s);
// fscanf(STDIN, "%s", $s2);

# 処理部
// $arr = str_split($s);
// $arr2 = str_split($s2);
// $arr1 = explode(" ", $s1);
// $arr2 = explode(" ", $s2);
// for ($i = 0; $n > $x * $i; $i++) {
// }
// if (strpos($s, 'RRR') !== false) {
//   $r = 3;
// } elseif (strpos($s, 'RR') !== false) {
//   $r = 2;
// } elseif (strpos($s, 'R') !== false) {
//   $r = 1;
// } else {
//   $r = 0;
// }
// $s = "No";
// if ($x >= 30) {
//   $s = "Yes";
// }
// for ($i = 0; $i * 1000 < $n; $i++) {
// }
// $c = "a";
// if (ctype_upper($a)) {
//   $c = "A";
// }
// $s = "Yes";
// echo count($arr1);
// for ($i = 0; $i < strlen($s1); $i++) {
//   if ($arr1[$i] != $arr2[$i]) {
//     $s = "No";
//   }
// }
// $unit;
// switch ($n % 10) {
//   case 0:
//   case 1:
//   case 6:
//   case 8:
//     $unit = "pon";
//     break;
//   case 3:
//     $unit = "bon";
//     break;
//   default:
//     $unit = "hon";
//     break;
// }
// if ($s == "ABC") {
//   $r = "ARC";
// } else {
//   $r = "ABC";
// }
// $r = "NG";
// for ($i = $a; $i <= $b; $i++) {
//   if ($i % $k == 0) {
//     $r = "OK";
//   }
// }
// $r = "safe";
// if ($s <= $w) {
//   $r = "unsafe";
// }
// $r = "No";
// if (strpos($n, "7") !== false) {
//   $r = "Yes";
// }
// $r = "No";
// if ($arr[2] == $arr[3] && $arr[4] == $arr[5]) {
//   $r = "Yes";
// }

# 出力部
echo ($n * ($n - 1) / 2) + ($m * ($m - 1) / 2) . "\n";
// echo $z . " " . $x . " " . $y . "\n";
// echo ($i * 1000) - $n . "\n";

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

#define ll              long long
#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define scan(a)         scanf("%d", &a)
#define scanl(a)        scanf("%lld", &a)
#define scand(a)        scanf("%lf", &a)
#define scan2(a, b)     scanf("%d %d", &a, &b)
#define scanl2(a, b)    scanf("%lld %lld", &a, &b)
#define scand2(a, b)    scanf("%lf %lf", &a, &b)

#define yes             cout << "yes\n"
#define no              cout << "no\n"
#define Case(i)         cout << "Case " << int(i) << ": "

#define lop(n)          for(int i = 0; i < n; i++)
#define lopj(n)         for(int j = 0; j < n; j++)
#define lopr(a, n)      for(int k = a; k < n; k++)
#define lrev(n, a)      for(int i = n; i >= a; i--)

#define all(x)          x.begin(), x.end()
#define mem(a, b)       memset(a, b, sizeof(a))

#define vin             vector <int>
#define vll             vector <ll>
#define vst             vector <string>
#define pll             pair <int, int>
#define pss             pair <string, string>
#define vpll            vector <pll>

#define fread           freopen("input.txt", "r", stdin)
#define fwrite          freopen("output.txt", "w", stdout)
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define mod             1000000007
#define PI              acos(-1.0)
#define inf             999999999999


using namespace std;


int main()
{
    fastio;

    int n;
    string s;

    cin >> n >> s;

    pll lst[n + 1], pp = {0, 0};

    //lst[0] = pp;

    lop(n)
    {
        pp.ff += s[i] == 'W';
        pp.ss += s[i] == 'R';

        lst[i] = pp;
    }

    int dr = 0;

    lrev(n - 1, 0)
    {
        if(lst[i].ff - dr <= 0 or lst[i].ff == 0)
            break;

        if(s[i] == 'R')
        {
            dr++;
        }
    }

    if(lst[n - 1].ff == 0)
        cout << 0 << endl;

    else if(lst[n - 1].ss == 0)
        cout << 0 << endl;

    else
        cout << dr << endl;

//    int w = 0, r = 0, rr = 0, ww = 0;
//
//    lop(n)
//    {
//        w += s[i] == 'W';
//        r += s[i] == 'R';
//
//        if(r and i < n - 1 and s[i + 1] == 'W')
//        {
//            rr = ww = 0;
//            lopr(i + 1, n) {
//                ww += s[k] == 'W';
//                rr += s[k] == 'R';
//            }
//
//            break;
//        }
//    }

   // cout << r << ' ' << rr << ' ' << w << ' ' << ww << '\n';

//    if(w + ww == 0)
//        cout << 0 << endl;
//
//    else if(r == 0)
//        cout << 1 << endl;
//
//    else if(w <= rr)
//        cout << rr << endl;
//
//    else
//        cout << min(w, r + rr) << endl;
//main();
    return 0;
}



Measured memory_bytes: 5304
//
//  main.cpp
//  ABC165C
//


#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;


int n,m,q; //dfsで使いたいのでグローバル変数にしている
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if(A.size() == n+1){
        int now = 0;
        rep(i,q){
            if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans,now);
        return;
    }
    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}
int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q); //長さqで初期化
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1)); //長さ１、中身１のvector
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n,x,count = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		if (i % 2 == 0) continue;
		if (x % 2 == 1) count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3640
import math
n=int(input())
k=int(input())
strn=str(n)

ans1=9*(len(strn)-1)+int(strn[0])
#print(ans1)

def fuc1(x):
    strn=str(x)
    return 9*(len(strn)-1)+int(strn[0])

def fuc2(x):
    if x<10:
        return 0
    strn=str(x)
    ans2=fuc1(int(strn[1:]))
    ans2+=(int(strn[0])-1)*(9*(len(strn)-1))
    #print(ans2,"q")
    for i in range(1,len(strn)-1):
        ans2+=9*(9*(len(strn)-i-1))
    return ans2

def fuc3(x):
    if x<100:
        return 0
    ans3=fuc2(int(strn[1:]))
    ans3+=(int(strn[0])-1)*(81*(len(strn)-1)*(len(strn)-2)//2)
    #print(ans3,"z")
    for i in range(1,len(strn)-2):
        ans3+=9*(81*(len(strn)-i-1)*(len(strn)-i-2)//2)
    #print(ans3)
    return ans3

if k==1:
    print(fuc1(n))
if k==2:
    print(fuc2(n))
if k==3:
    print(fuc3(n))

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll MOD = 1e9+7;

bool seen[200100];

int dfs(const vector<vector<int>> &G, vector<vector<int>> &order, int v){
  seen[v] = true;

  int N = G.size();

  int sum_num = 0;
  for(auto next_v : G[v]){
    if(seen[next_v]) continue;
    
    int num = dfs(G, order, next_v);
    order[v].push_back(num);
    sum_num += num;
  }

  if(N-sum_num-1 > 0)  order[v].push_back(N-sum_num-1);

  return sum_num+1;
}


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

  int N;
  cin >> N;
  vector<vector<int>> G(N), order(N);
  int a, b;
  for(int i = 0; i < N-1; i++){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  for(int i = 0; i < N; i++) seen[i] = false;

  dfs(G, order, 0);

  // for(int i = 0; i < N; i++){
  //   for(int v = 0; v < order[i].size(); v++){
  //     cout << order[i][v] << " ";
  //   }
  //   cout << endl;
  // }

  // 2個以上黒である確率
  ll ans = 0;
  for(int i = 0; i < N; i++){

    if(order[i].size() > 1){
      int sum = 0;
      for(int j = 0; j < order[i].size(); j++){
        sum += order[i][j];
      }
      ll p = 1;
      p = (1 + MOD - modinv(modpow(2, sum, MOD), MOD))%MOD;  
      
      for(int j = 0; j < order[i].size(); j++){
        ll tp = (1 + MOD - modinv(modpow(2, order[i][j], MOD), MOD)) % MOD;
        ll mp = modinv(modpow(2, sum-order[i][j], MOD), MOD);
        p = (p + MOD - (tp * mp) % MOD) % MOD;
      }
      p = (p * modinv(2, MOD)) % MOD;
      ans = (ans + p) % MOD;
    }

  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 35712
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;

int main()
{
    int n;
    cin >> n;
    int k, h, cnt = 0;
    cin >> k;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) cnt++;
    }
    cout << cnt << '\n';
}


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

int main()
{
    string S, be, en;
    int sw=1;
    cin >> S;
    int q;
    cin >> q;
    for(;q--;){
        int t;
        cin >> t;
        if(t==1){ sw *= -1; }
        else{
            int f; char c;
            cin >> f >> c;
            if((f==1 && sw==1) || (f==2 && sw==-1)) be = c + be;
            else en += c;
        }
    }
    S = be + S + en;
    if(sw==-1) reverse(S.begin(), S.end());
    cout << S << "\n";
}

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

int main() {
	int a,b;
	cin>>a>>b;
	for(int i=0;i<=10000;i++) {
		if(i*8/100==a && i*10/100==b) {
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
count=[0]*N
for i in range(1,N+1):
  SHOU=i
  while True:
    AMARI=SHOU%2
    SHOU=SHOU//2
    if AMARI==0:
      count[i-1]+=1
    else:
      break
print(1+count.index(max(count)))

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author houghstc
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <cstring>

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

const int MOD = 1e9+7;

class ATakoyaki {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n, x, t;
        in >> n >> x >> t;
        out << (n/x + (n%x == 0 ? 0 : 1) ) * t << endl;
    }
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ATakoyaki solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,a,b,mi,ma;
    cin>>n>>a>>b;
    if (a<b){
        ma=a;
    }
    else{
        ma=b;
    }
    if(a+b-n>0){
        mi=a+b-n;
    }
    else{
        mi=0;
    }
    cout<<ma<<" "<<mi<<endl;
}

Measured memory_bytes: 256
#計算時間が足りない　何がダメなのか　工夫が足りない　研究が必要
from collections import deque


N, M, K = map(int, input().split())
friend = [list(map(int,input().split())) for _ in range(M)]
block = [list(map(int, input().split())) for _ in range(K)]
#sys.setrecursionlimit(2*N)
#print(friend)
#print(block)
graph = [[] for _ in range(N)]
bgraph = [[] for _ in range(N)]
cnt = [0]*N
for i in range(M):
    ii, jj = friend[i]
    graph[ii-1].append(jj-1)
    graph[jj-1].append(ii-1)

for i in range(K):
    ii, jj = block[i]
    bgraph[ii-1].append(jj-1)
    bgraph[jj-1].append(ii-1)

#print(graph)
#print(bgraph)

seen = [False for _ in range(N)]
seenb = [False for _ in range(N)]
def dfs():
    labelb = 1
    #while False in seen:
    for i in range(N):
        if seen[i] != False: continue
        label = 1
        #i = seen.index(False)
        seen[i] = label
        seenb[i] = labelb
        que = deque([i])
        seg = deque([i])
        while que:
            #print(que)
            neci = que.pop()
            for nec in graph[neci]:
                if seen[nec]== False:
                    seen[nec]=label
                    seenb[nec]=labelb
                    que.append(nec)
                    seg.append(nec)
                    label += 1
        for iii in seg:
            seen[iii] = label

        labelb += 1

dfs()
for i in range(N):
    count = seen[i] - 1 -len(graph[i])
    if bgraph[i] and seen[i]>=2:
          for j in bgraph[i]:
                if seenb[i] == seenb[j]:
                    count -= 1
    cnt[i]=count
print(*cnt)


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

using ll = long long;

using namespace std;

int main() {
    string s;
    cin >> s;
    ll cnt[2019] = {0}, ans = 0;
    int r = 0, d = 1;
    cnt[0] = 1;
    reverse(s.begin(), s.end());
    for (auto &c:s) {
        r = (r + (c - '0') * d) % 2019;
        d = d * 10 % 2019;
        ans += cnt[r];
        cnt[r]++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3740
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	int n,m,num;
	while (scanf("%d %d",&n,&m) && n != 0 && m != 0) {
		pair<int, int> place[m];
		for (int i=0; i<m; i++) {
			place[i].first = 0;
			place[i].second = i+1;
		}
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				scanf("%d",&num);
				if (num == 1) place[j].first++;
			}
		}
		for (int i=0; i<m-1; i++) {
			for (int j=m-1; j>i; j--) {
				if (place[j].first>place[j-1].first) {
					swap(place[j], place[j-1]);
				}
			}
		}
		for (int i=0; i<m; i++) {
			if (i!=0) printf(" ");
			printf("%d",place[i].second);
		}
		printf("\n");
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int calc(vector<int> c, vector<int> s, vector<int> f, int p) {
  int t = 0;
  for(int i=p; i<c.size()-1; i++){
    if( t <= s[i] ){
      t = s[i] + c[i];
    } else {
      int tmp = s[i];
      while(t > tmp) tmp += f[i];
      t = tmp + c[i];
    }
  }
  return t;
}

int main(){

  int n; cin >> n;
  vector<int> c(n, 0);
  vector<int> s(n, 0);
  vector<int> f(n, 0);
  for(int i=0; i<n-1; i++) cin >> c[i] >> s[i] >> f[i];
  for(int i=0; i<n; i++){
    cout << calc(c, s, f, i) << endl;
  }

  return 0;
}

//


Measured memory_bytes: 256
from collections import Counter
n = int(input())
num_l = sorted(map(int, input().split()),reverse=True)
s = sorted(set(num_l), reverse=True)
d = Counter(num_l) # {i:num_l.count(i) for i in s}
res = []
it = 0
lim=len(s)
# c = max()
for i in range(n):
    if d[s[it]] >= 2:
        d[s[it]]-=2
        res.append(s[it])
    else:
        it+=1#pass
        
    if len(res) == 2:
        print(res[0] * res[1])
        break
    if lim==it:
        print(0)
    

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

using namespace std; 

long _mergeSort(long arr[], long temp[], int left, int right); 
long merge(long arr[], long temp[], int left, int mid, int right); 

long mergeSort(long arr[], int array_size) 
{ 
	long temp[array_size]; 
	return _mergeSort(arr, temp, 0, array_size - 1); 
} 

long _mergeSort(long arr[], long temp[], int left, int right) 
{ 
	long mid, inv_count = 0; 
	
	if (right > left) 
	{
		mid = (right + left) / 2; 

		inv_count += _mergeSort(arr, temp, left, mid); 
		inv_count += _mergeSort(arr, temp, mid + 1, right); 

		inv_count += merge(arr, temp, left, mid + 1, right); 
	} 
	
	return inv_count; 
} 

long merge(long arr[], long temp[], int left, int mid, int right) 
{ 
	int i, j, k; 
	long inv_count = 0; 

	i = left;
	j = mid; 
	k = left; 
	
	while ((i <= mid - 1) && (j <= right)) 
	{ 
		if (arr[i] <= arr[j]) 
		{ 
			temp[k++] = arr[i++]; 
		} 
		else 
		{ 
			temp[k++] = arr[j++]; 
			inv_count = inv_count + (mid - i); 
		} 
	} 

	while (i <= mid - 1) 
		temp[k++] = arr[i++]; 

	while (j <= right) 
		temp[k++] = arr[j++]; 

	for (i = left; i <= right; i++) 
		arr[i] = temp[i]; 

	return inv_count; 
} 

int main()
{
	int n; 
	scanf("%d", &n);
	
	long arr[n];
	
	for(int i = 0; i < n; i++)
		scanf("%ld", &arr[i]);
	
			
	printf("%ld\n", mergeSort(arr, n));
	
	return 0;
}


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

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

	map<int, int> m;
	for(int i=0; i<N; i++){
		int a; cin >> a;
		m[a-1]++;
		m[a]++;
		m[a+1]++;
	}

	int ans = 0;
	for(auto p: m)
		ans = max(ans, p.second);

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

Measured memory_bytes: 4736
from fractions import gcd

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    current_brick = 1
    break_count = 0
    for i in range(N):
        if current_brick == A[i]:
            current_brick += 1
        else:
            break_count += 1
    if break_count == N:
        return -1
    return break_count


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 28196
#include<bits/stdc++.h>
using namespace std;
int a[2];
bool t[4];
int main() {
	scanf("%d%d",&a[0],&a[1]);
	sort(a,a+2);
	t[a[0]]=1;t[a[1]]=1;
	for(int i=1;i<=3;i++)
		if(!t[i]) printf("%d",i);
	return 0;
}

Measured memory_bytes: 256