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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long a = sc.NextLong();
        long b = sc.NextLong();
        long c = sc.NextLong();
        long k = sc.NextLong();

        long count = 0;
        while (a >= b)
        {
            b *= 2;
            count++;
        }

        while (b >= c)
        {
            c *= 2;
            count++;
        }

        string answer = count <= k ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27540
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
//#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
//    freopen("elect.in", "r", stdin);
//    freopen("elect.out", "w", stdout);
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n + n);
    for (auto &i : a) cin >> i;
    sort(all(a));
    int ans = 0;
    for (int i = 0; i < n + n; i += 2) {
        ans += a[i];
    }
    cout << ans << '\n';
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<long long> x(n);
    vector<long long> y(n);
    vector<long long> z(n);
    long long ans = -1;

    for (auto i = 0; i < n; i++)
    {
        long long xi, yi, zi;
        cin >> xi >> yi >> zi;
        x[i] = xi;
        y[i] = yi;
        z[i] = zi;
    }

    for (auto bit = 0; bit < (1 << 3); bit++)
    {
        vector<bool> is_positive(3, false);
        vector<long long> sol;
        long long part_ans = 0;
        sol.clear();
        for (auto i = 0; i < 3; i++)
        {
            if (bit & (1 << i))
            {
                is_positive[i] = true;
            }
        }

        for (auto i = 0; i < n; i++)
        {
            long long tmp = 0;
            if (is_positive[0])
            {
                tmp += x[i];
            }
            else
            {
                tmp -= x[i];
            }

            if (is_positive[1])
            {
                tmp += y[i];
            }
            else
            {
                tmp -= y[i];
            }

            if (is_positive[2])
            {
                tmp += z[i];
            }
            else
            {
                tmp -= z[i];
            }

            sol.push_back(tmp);
        }

        sort(sol.rbegin(), sol.rend());
        for (auto i = 0; i < m; i++)
        {
            part_ans += sol[i];
        }

        if (ans < part_ans)
        {
            ans = part_ans;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef struct{    
	int num;  
	int col; 
}STONE; 
int main(void){   
	int i,j;         
	int n;   
	int bw,temp;  
	int count;      
	int sum;         
	STONE data[100001]; 
	while(1){      
		scanf("%d", &n);   
		if (n==0){           
			break;     
		}       
		memset(data,0,sizeof(data));
		count=-1;    
		bw=2;         
		for(i=0;i<n;i++){          
			scanf("%d",&temp);        
			if(temp!=bw){            
				count++;             
				data[count].col=temp;         
				data[count].num=1;            
				bw=temp;                
			}else{                      
				data[count].num++;       
			}  
		}                 
		sum=0;           
		for(i=0;i<=count;i++){   
			sum+=data[i].num;    
			if((sum-data[i].num)%2==1){     
				j=i-1;                  
				while(j>=0 && data[j].col != data[i].col){      
					data[j].col^=1;                      
					j--;                              
				}                   
			}               
		}                  
		sum=0;              
		for(i=0;i<=count;i++){ 
			if (data[i].col==0){   
				sum+=data[i].num;      
			}         
		}             
		printf("%d\n",sum);         
	}             
	return 0; 
} 

Measured memory_bytes: 1552
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

#define MAX_N 200000

using namespace std;

int par[MAX_N];
int rnk[MAX_N];
long long int diff[MAX_N];

// 初期化
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		rnk[i] = 0;
		diff[i] = 0;
	}
}

// x の親を返す
P find(int x){
	P p;
	if(par[x] == x){
		p.first = x;
		p.second = 0;
		return p;
	}
	p = find(par[x]);
	diff[x] += p.second;
	p.second = diff[x];
	par[x] = p.first;
	return p;
}

// x と y を併合する
void unite(int x, int y, int z){
	P px = find(x);
	P py = find(y);
	int x_par = px.first;
	int y_par = py.first;
	if(x_par == y_par){
		return;
	}
	
	if(rnk[x_par] < rnk[y_par]){
		par[x_par] = y_par;
		diff[x_par] = diff[y_par] - px.second + py.second + z;
	}else{
		par[y_par] = x_par;
		diff[y_par] = diff[x_par] + px.second - py.second - z;
		if(rnk[x_par] == rnk[y_par]){
			rnk[x_par]++;
		}
	}
}

// x, y が同じグループか判定
bool same(int x, int y){
	P px = find(x);
	P py = find(y);
	int x_par = px.first;
	int y_par = py.first;
	return (x_par == y_par);
}

int main(){
	
	while(true){
		int n, q;
		cin >> n >> q;
		if(n == 0){
			break;
		}
		
		init(n + 1);
		
		for(int i = 0; i < q; i++){
			string str;
			cin >> str;
			int a, b, c;
			
			if(str == "!"){
				cin >> a >> b >> c;
				unite(a, b, c);
			}else{
				cin >> a >> b;
				if(!same(a, b)){
					cout << "UNKNOWN" << endl;
				}else{
					cout << diff[a] - diff[b] << endl;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mem(dp, v) memset(dp, v, sizeof dp);
using namespace std;

const int N = 1e6 + 7, inf = 1e9;
ll ar[N], n, k, t;

int main()
{
    ll n, k, pw = 1, tot = 0;
   // ios_base::sync_with_stdio(false);
    cin>>n>>k;
    for(int i = 0; i < n; i++)
    {
        cin>>ar[i];
    }
    sort(ar, ar+n);
    for(int i = n - k - 1; i >= 0; i--) tot += ar[i];
    cout<<tot<<"\n";
    return 0;
}


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

int main(){
    stack<char> mystack;
    string s;
    cin>>s;
    int cntPop = 0;
    for(int i=0;s[i];i++){
        if(mystack.empty()){
            mystack.push(s[i]);
            continue;
        }
        if((mystack.top()=='1' && s[i]=='0') || (mystack.top()=='0' && s[i]=='1')){
            mystack.pop();
            cntPop++;
        }else{
            mystack.push(s[i]);
        }
    }

    cout<<cntPop*2<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int alice=0,bob=0;
  	int n;
  cin>>n;
  vector<int >v(n,0);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.rbegin(),v.rend());
  for(int i=0;i<n;i++){
  	if(i%2==0)alice+=v[i];
    else bob+=v[i];
  }
  cout<<alice-bob;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var pt []bool

func ptInit(n int) {
	pt = make([]bool, n+1)
	for i := 2; i < n; i++ {
		pt[i] = true
	}
	for i := 2; i*i <= n; i++ {
		for j := i * 2; j <= n; j += i {
			if pt[j] {
				pt[j] = false
			}
		}
	}
}

func main() {
	var X int
	fmt.Scan(&X)
	ptInit(int(1e6))
	for i := X; i <= len(pt); i++ {
		if pt[i] {
			fmt.Println(i)
			return
		}
	}
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){

    string s;
    cin>>s;
    if(s.compare("Sunny")==0){
        cout<<"Cloudy"<<endl;
    }else if (s.compare("Cloudy")==0)
    {
        cout<<"Rainy"<<endl;
    }else{
        cout<<"Sunny"<<endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int a[maxn];

int main(){
	int n = read();
	for(int i=1; i<=n; i++){
		a[i] = read();
	}
	int ans = 0,cnt = 0;
	for(int i=1; i<=n; i++){
		if(a[i]==i) cnt++;
		else {
			ans += (cnt+1)/2;
			cnt = 0;
		}
	}
	ans += (cnt+1)/2;
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
N = int(input())
d = []

A = list(map(int, input().split()))
k = []
ANS = []
for i in range(1, N+1):
  k.append(i)

d = list(zip(k, A))
d.sort(key=lambda x:x[1])

for b in range(N):
  print(d[b][0], end=" \n"[b + 1 == N])

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

int main(){
    
    string str;
    int ans;
    
    while(cin >> str && str != "0"){
        ans = 0;
        
        for(int i = 0, l = str.size(); i < l; i++)
            ans += str[i] - '0';
            cout << ans << endl;
        
    }
    
    return 0;
}



Measured memory_bytes: 3188
n = int(input())
list = []
list.append(input())
c = 0

for i in range(n - 1):
    old = list[-1]
    new = input()
    if old[-1] != new[0]:
        c += 1
    for j in list:
        if j == new:
            c += 1
    list.append(new)

if c == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
	static ArrayList<Integer> xs, ys;
	static int x, y;
	static Boolean[][] mem1, mem2;
	static int offset = 8001;

	static boolean solve(int idx, int sum) {
		if (idx == xs.size())
			return sum == x;
		if (mem1[idx][sum + offset] != null)
			return mem1[idx][sum + offset];
		return mem1[idx][sum + offset] = solve(idx + 1, sum + xs.get(idx)) || solve(idx + 1, sum - xs.get(idx));
	}

	static boolean solve2(int idx, int sum) {
		if (idx == ys.size())
			return sum == y;
		if (mem2[idx][sum + offset] != null)
			return mem2[idx][sum + offset];
		return mem2[idx][sum + offset] = solve2(idx + 1, sum + ys.get(idx)) || solve2(idx + 1, sum - ys.get(idx));
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		x = sc.nextInt();
		y = sc.nextInt();

		xs = new ArrayList<>();
		ys = new ArrayList<>();

		int start = 0;

		while (start < s.length() && s.charAt(start) == 'F') {
			x--;
			start++;
		}

		boolean inX = true;
		for (int i = start; i < s.length(); i++) {
			if (s.charAt(i) == 'T') {
				inX = !inX;
			}
			else {
				int cnt = 0;
				boolean in = false;
				while (i < s.length() && s.charAt(i) == 'F') {
					cnt++;
					i++;
					in = true;
				}
				if (in)
					i--;
				if (inX)
					xs.add(cnt);
				else
					ys.add(cnt);
			}
		}
		mem1 = new Boolean[xs.size() + 1][8002 * 2];
		mem2 = new Boolean[ys.size() + 1][8002 * 2];
		if (solve(0, 0) && solve2(0, 0))
			System.out.println("Yes");
		else
			System.out.println("No");

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}
	}
}


Measured memory_bytes: 287064
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
list_M = [0 for _ in range(n+1)]

for s in list_A:
    list_M[s] += 1
total = 0

for i in range(n+1):
    total += list_M[i]*(list_M[i]-1)//2

for s in list_A:
    ans = total - list_M[s] + 1
    print(ans)

Measured memory_bytes: 26140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, a;
    int tmp;
    
    scanf("%d%d", &n, &a);
    
    tmp=n%500;
    
    if (tmp<=a) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}



Measured memory_bytes: 1692
from operator import mul
n, m, c = map(int, input().split())
b = [int(i) for i in input().split()]
lst = []
for _ in range(n):
    lst.append(input().split())

sumlst = []

for i in lst:
    i = [ int(x) for x in i]
    res = [x * y for (x, y) in zip(i, b)]
    res = sum(res) + c
    if res > 0:
        sumlst.append(res)
    else:
        continue

print(len(sumlst))

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N ((ll)2010)
#define MOD ((ll)1e9+7)
ll tavan(ll x,ll y){ll res=1;while(y){res*=y%2?x:1;res%=MOD;x*=x;x%=MOD;y/=2;}return res;}

ll n,k,fac[N*N],rfac[N*N],dp[N][N];

ll C(ll x,ll y){return (fac[x]*((rfac[y]*rfac[x-y])%MOD))%MOD;}

int main()
{
	cin>>n>>k;
	if(k==1)return cout<<1,0;
	fac[0]=rfac[0]=1;
	for(ll i=1;i<N*N;i++)fac[i]=(fac[i-1]*i)%MOD,rfac[i]=tavan(fac[i],MOD-2);
	dp[0][0]=1;
	for(int i=0;i<=n;i++)
		for(int j=i;j<=n;j++)
		{
			if(i)dp[i][j]=dp[i-1][j];
			if(j>i)dp[i][j]+=dp[i][j-1]*C(j*(k-1)+i-1,k-2);
			dp[i][j]%=MOD;
		}
	cout<<(dp[n][n]*fac[n])%MOD;
	return 0;
}

Measured memory_bytes: 86016
/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;
vector <int> g[N];

int gag , mx;

void dfs(int v,int p,int r){
    if(r > mx){
        mx = r;
        gag = v;
    }
    for(int i=0;i<(int)g[v].size();i++){
        int to = g[v][i];
        if(to == p)continue;
        dfs(to , v , r + 1);
    }
}

int main() {
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a , b;
        scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1 , -1 , 0);
    mx = 0;
    dfs(gag , -1 , 0);
    ++mx;
    if(mx % 3 == 2)
        cout << "Second" << endl;
    else
        cout << "First" << endl;
	return 0;
}


Measured memory_bytes: 26752
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    long long n;
    int i;
    cin>>n;
    int ans,tot;
    for(i=sqrt(n);i>=0;i--){
        if(n%i==0){
            int ans=1,m=n/i;
            while(m>=10)
            {
                m/=10;
                ans++;
            }
            cout<<ans<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

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

struct UnionFind
{
  int n, num;
  vector<int> sz, par;
  UnionFind() {}
  UnionFind(int n_) : n(n_), num(n_), sz(n_, 1), par(n_, 0) { iota(par.begin(), par.end(), 0); }
  int find(int x)
  {
    return (x == par[x] ? x : par[x] = find(par[x]));
  }
  bool same(int x, int y)
  {
    return find(x) == find(y);
  }
  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (sz[x] < sz[y])
      swap(x, y);
    sz[x] += sz[y];
    par[y] = x;
    num--;
  }
  int size(int x)
  {
    return sz[find(x)];
  }
  int count() const
  {
    return num;
  }
};
//

int h, w;
vector<string> in;

int f(int a, int b) {
  return a*w+b;
}

bool check( int a, int b, int c, int d ) {
    return (in[a][b] == '#' && in[c][d] == '.') || (in[a][b] == '.' && in[c][d] == '#');
}

int main() {
  cin >> h >> w;
  in.resize(h);
  UnionFind uf(h*w);
  REP(i,h) cin >> in[i];
  REP(i,h) REP(j,w) {
    if ( i>0 ) {
      if ( check(i,j,i-1,j) )
        uf.unite(f(i, j), f(i - 1, j));
    }
    if ( j>0 ) {
      if (check(i, j, i, j-1))
        uf.unite(f(i,j), f(i,j-1));
    }
  }
  vector<LL> B(h*w),W(h*w);
  REP(i,h) REP(j,w) {
    int p=uf.find(f(i,j));
    if ( in[i][j]=='.' ) W[p]++;
    else B[p]++;
  }
  LL ans=0;
  REP(i,h) REP(j,w) if ( f(i,j)==uf.find(f(i,j)) ) {
    ans+=B[f(i,j)]*W[f(i,j)];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7196
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

signed main()
{
  int N, M;
  int sum = 0;
  
  cin >> N >> M;

  sum += min(N, M / 2);
  
  N -= sum, M -= sum * 2;
  cout << sum + M / 4 << endl;

  return 0;
}


Measured memory_bytes: 256
// Modular Query

// c[i] = i 以下のカードのうち最大のカード
// wrong answer
// 1/5

#include<iostream>
using namespace std;

int main()
{
    int N, Q, q;
    int c[300001] = {0};
    cin>>N>>Q;
    while(N-->0) {
        int i;
        cin>>i;
        c[i]=i;
    }
    for(int i=1; i<300001; i++) {
        if(!c[i]) c[i] = c[i-1];
    }
    while(Q-->0) {
        int res=0;
        cin>>q;
        for(int i=q-1; i<300001; i+=q) {
            res = max(res, c[i]%q);
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 2340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000010;
int n,a[N],w[N],fa[N];
struct data{
	ll w;int s,x;
	bool operator <(const data &p)const{
		if(w*p.s!=p.w*s)return w*p.s<p.w*s;
		return x<p.x;
	}
}p[N];
set<data>Q;
int cnt=0,b[N];
inline int find(int x){return b[x]==x?x:b[x]=find(b[x]);}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		scanf("%d",&fa[i]);
	for(int i=1;i<=n;i++)scanf("%d",&w[i]);
	for(int i=1;i<=n;i++){
		p[i]=(data){w[i],1,i};
		Q.insert(p[i]);b[i]=i;
	}
	cnt=n;
	ll ans=0;
	data t;
	while(!Q.empty()){
      t=*Q.begin();Q.erase(t);
      int y=find(fa[t.x]);
		if(!y)continue;
      ans+=(t.s-t.w)*p[y].w;
		Q.erase(p[y]);
		data e=t;
		e.w+=p[y].w;e.s+=p[y].s;e.x=++cnt;
		b[cnt]=cnt;b[y]=cnt;b[find(t.x)]=cnt;
		fa[cnt]=fa[y];fa[t.x]=cnt;
		p[cnt]=e;
		Q.insert(e);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 28672
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai {
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var K = line[1];
        var list = new List<long>();
        for (int i=0;i<N;++i)
        {
            list.Add(Int64.Parse(Console.ReadLine()));
        }
        var newList=list.OrderBy(x=>x).ToArray();
        var min = long.MaxValue;
        for (int i=0;i<N-(K-1);++i)
        {
            var sa = newList[i+(K-1)]-newList[i];
            if (sa < min) min = sa;
        }
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 23900
#include <stdio.h>
#include <math.h>
typedef long long ll;

int main(void) {
  ll i, n, p, ans = 1;
  scanf("%lld%lld", &n, &p);
  if(n == 1) {
    printf("%lld", p);
    return 0;
  }
  for(i = 2; i <= sqrt(p); ++i) if(!(p % i)){
    ll cnt = 0;
    while(!(p % i)) ++cnt, p /= i;
    if(cnt / n) ans *= (ll)pow(i, cnt / n);
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

int W, H, ppl;
char m[30][30];
string d = "WSEN";
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

bool canMove(int h, int w) {
	if(0 <= h && 0 <= w && h < H && w < W)
		if(m[h][w] == '.' || m[h][w] == 'X')
			return true;
	return false;
}

char decideDirection(int h, int w, char d2) {
	REP(i, 4) {
		int nd = (d.find(d2) + 3 + i) % 4;
		int nh = h + dy[nd], nw = w + dx[nd];
		if(canMove(nh, nw)) return d[nd];
	}
	return d2;
}

int main() {
	while(cin >> W >> H, W|H) {
		ppl = 0;
		REP(i, H) REP(j, W) {
			cin >> m[i][j];
			if(d.find(m[i][j]) != string::npos)
				ppl++;
		}

		int cnt = 0;
		while(ppl) {
			REP(i, H) REP(j, W) {
				if(d.find(m[i][j]) != string::npos) {
					m[i][j] = decideDirection(i, j ,m[i][j]);
				}
			}

			bool chk[30][30];
			memset(chk, true, sizeof(chk));
			REP(i, 4) REP(j, H) REP(k, W) {
				if(m[j][k] == d[i] && chk[j][k]) {
					int nh = j + dy[i], nw = k + dx[i];
					if(m[nh][nw] == '.' && chk[nh][nw]) {
						swap(m[j][k], m[nh][nw]);
						chk[nh][nw] = false;
					}
					else if(m[nh][nw] == 'X' && chk[nh][nw]) {
						m[j][k] = '.';
						chk[nh][nw] = false;
						ppl--;
					}
					chk[j][k] = false;
				}
			}
			cnt++;
			if(cnt > 180) break;
		}
		if(cnt > 180) cout << "NA" << endl;
		else cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

ll N, P;
string S;
vector<ll> s;

ll solve() {
	ll ans = 0;

	if (P == 2 || P == 5) {
		repn(i, N) {
			if (s[i] % P == 0) { ans += i; }
		}

		return ans;
	}

	vector<ll> d(N + 2);
	d[N + 1] = 0;

	ll pow = 1;

	for (ll i = N; i >= 1; i--) {
		d[i] = d[i + 1] + pow * s[i];
		d[i] %= P;
		pow = pow * 10 % P;
		//cout << i << d[i] << endl;
	}

	map<ll, ll> mp;

	repn(i, N + 1) {
		mp[d[i]]++;
	}

	for (auto x : mp) {
		ans += (x.second - 1)*x.second/2;
	}

	return ans;
}




int main() {

	cin >> N >> P;
	cin >> S;

	s.assign(N + 1, 0);
	repn(i, N) s[i] = S[i - 1] - '0';

	cout << solve();
	
	system("PAUSE");

}





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

using i64 = long long;
using u64 = unsigned long long;

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

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

i64 C[2002][2002];
int main()
{
    memset(C, 0, sizeof C);
    for(int i = 0; i <= 2000; i++) {
        for(int j = 0; j <= i; j++) {
            if(j == 0 || j == i) {
                C[i][j] = 1;
            } else {
                C[i][j] = C[i-1][j] + C[i-1][j-1];
                C[i][j] %= mod;
            }
        }
    }
    i64 n, k;
    scanf("%lld%lld", &n, &k);
    for(int i = 1; i <= k; i++) {
        i64 ans = 0;
        if(n == k) {
            if(i == 1) puts("1");
            else puts("0");
            continue;
        }
        if(i > 1)
            ans += C[k-1][i-1]*C[n-k-1][i-2];
        ans %= mod;
        ans += C[k-1][i-1]*C[n-k-1][i];
        ans %= mod;
        ans += 2*C[k-1][i-1]*C[n-k-1][i-1];
        ans %= mod;
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 35128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main(void) {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, n) {
    if (s[i] == s[i + 1]) continue;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

int main() {
  int K, X;
  cin >> K >> X;
  
  int first = X - K + 1, last = X + K - 1;
  for(int i = first; i <= last; i++) {
    cout << i << ' ';
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a,b;
int cnt[100010];
bool t[100010];
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cnt[i]=1;
		t[i]=false;
	}t[0]=true;
	for(int i=0;i<m;i++){
		cin>>a>>b;a--,b--;
		if(t[a]==true){
			t[b]=true;
			if(cnt[a]==1)t[a]=false;
		}
		cnt[a]--,cnt[b]++;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(t[i]==true&&cnt[i]>0){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define IOS cin.tie(0);ios::sync_with_stdio(0)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?' ':'\n'); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);}//最小公倍数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//void print(){}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const int NMAX = 200;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
//    IOS;
    CIN(A,B,K);
    int cnt=0,ans;
    RRepS(i,min(A,B),1){
        if(A%i==0&&B%i==0){
            cnt++;
            ans=i;
        }
        if(cnt==K)break;
    }
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 256
a, b = gets.split.map(&:to_i)

min = (a / 0.08).floor
max = (100 / 0.08).floor

p = -1
min.upto(max) do |n|
  break p = n if (n * 0.08).floor == a && (n * 0.10).floor == b
end

puts p


Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int d[200][200];
int main(){
    int n;
    cin>>n;
    rep(i,200)rep(j,200)d[i][j]=1<<29;
    rep(i,200)d[i][i]=0;
    rep(i,n){
        int src,k;
        cin>>src>>k;
        src--;
        rep(j,k){
            int dst;cin>>dst;
            dst--;
            d[src][dst] = 1;
        }
    }

    rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    int p;cin>>p;
    rep(i,p){
        int s,t,ttl;
        cin>>s>>t>>ttl;--s,--t;
        if(d[s][t] >= ttl) puts("NA");
        else printf("%d\n", d[s][t]+1);
    }
}

Measured memory_bytes: 1296
#include <stdio.h>

int main()
{   
    int n;
    scanf("%d",&n);
    int dig=0,c=n;
    while(c>0){
        c/=10;
        dig++;
    }
    if(dig==6){
        printf("90909");
        return 0;
    }
    if(dig==1){
        printf("%d",n);
    }
    else if(dig==2){
        printf("9");
    }else if(dig==4){
        printf("909");
    }else if(dig==3){
        printf("%d",9+n-99);
    }else {
        printf("%d",909+n-9999);
    }
    return 0;
}


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

int n, m, a, h, p, q, ans;
int g[101][1001];

int dfs(int k, int hgt) {
    int ret = k;

    if (hgt == 0) {
        if (g[k][hgt] == 0) {
            return k;
        }
    }

    for (int i = hgt - 1; i >= 0; i--) {
        if (g[k][i] >= 0) {
            ret = dfs(g[k][i], i);
            break;
        }
    }

    return ret;
}

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


    while (cin >> n >> m >> a, n | m | a) {
        a--;

        fill(g[0], g[100], -1);

        for (int i = 0; i < m; ++i) {
            cin >> h >> p >> q;
            h--;
            p--;
            q--;
            g[p][h] = q;
            g[q][h] = p;
        }

        ans = dfs(a, 1000);

        cout << ans + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;

int main()
{
	int n,d;
	cin>>n>>d;
	int r=0;
	while(n--)
	{
		long long x,y;
		cin>>x>>y;
		double sum;
		sum=sqrt(x*x+y*y);
//		cout<<sum<<endl;
		if(sum<=d)
			r++;
	}
	cout<<r<<endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    cin >> n;
    vector<int64_t> a(n),b(n);
    int64_t ans=0;
    rep(i,0,n) cin >> a[i] >> b[i];
    for(int i=n-1; i>=0; --i){
        a[i]+=ans;
        if(a[i]%b[i]==0) continue;
        ans+=(b[i]-a[i]%b[i]);
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC044 B - 美しい文字列
// 2020.06.16

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  vector<int> alp(26, 0);
  int N = S.size();
  REP(i, N){
    alp[S[i]-'a']++;
  }
  bool flag = true;
  REP(i, 26){
    if(alp[i]%2 == 1) flag = false;
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){

  int n,m;

  while(cin >> n, n){
    int a[100000] = {0};
    for(int i=0;i<n;i++){
      cin >> m;
      a[m]++;
    }

    for(int i=0;i<10;i++){
      for(int j=0;j<a[i];j++) cout << "*";
      if(a[i] == 0) cout << "-";
      cout << endl;
    }
  }

}

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

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

int const MAX = 100005;
int const NIL = -1;
struct Node {
  int parent, left, right;
} T[MAX];

int D[MAX];

void rec(int u, int p) {
  D[u] = p;
  if (T[u].right != NIL) rec(T[u].right, p);
  if (T[u].left != NIL) rec(T[u].left, p+1);
}

int main() {
  int n;
  cin >> n;
  rep(i,n) T[i].parent = T[i].left = T[i].right = NIL;

  int id, k;
  rep(i,n) {
    cin >> id >> k;
    int c, l;
    rep(j,k) {
      cin >> c;
      if (j==0) T[id].left = c;
      else T[l].right = c;
      l = c;
      T[c].parent = id;
    }
  }
  int r;
  rep(i,n) {
    if (T[i].parent == NIL) r = i;
  }
  
  rec(r, 0);

  rep(i,n) {
    string type;
    if (T[i].parent == NIL) type = "root";
    else if (T[i].left == NIL) type = "leaf";
    else type = "internal node";
    
    printf("node %d: parent = %d, depth = %d, %s, [", i, T[i].parent, D[i], type.c_str());
    for (int j=0, c=T[i].left; c!=NIL; j++, c=T[c].right) {
      if (j) cout << ", ";
      cout << c;
    }
    cout << ']' << endl;
  }
  return 0;
}



Measured memory_bytes: 7964
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
string s;
cin >> s;
if (s[0]==s[1]||s[1]==s[2]||s[2]==s[3])
{
    cout << "Bad" << endl;
}else
{
    cout << "Good" << endl;
}















//////////////////////////////////////////////////////
return 0;}

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

int dp[105][4][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int K;
    cin >> K;
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(k,2) {
        int nd = s[i]-'0';
        rep(d,10) {
            int ni = i+1, nj = j, nk = k;
            if (d != 0) nj++;
            if (nj > K) continue;
            if (k == 0) {
                if (d > nd) continue;
                if (d < nd) nk = 1;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
    cout << "Yes";
  } else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
    cout << "Yes";
  } else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 256
import math
from typing import List

a, b, c, d = map(int, input().split())

def gcd(c, d):
    mod = 1
    while mod > 0:
        mod = c % d
        c = d
        d = mod
    return c

def f(x: int, c: int, d: int):
    return x - x // c - x // d + x // (c * d // gcd(c, d))

print(f(b, c, d) - f(a - 1, c, d))


Measured memory_bytes: 10196
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

long a[300000];

int cmp(const void* a, const void* b) {
	return *(long*)b - *(long*)a;
}

int main(void) {
	long n, i;
	long long ans = 0;
	scanf("%ld", &n);
	for (i = 0; i < 3 * n; i++) {
		scanf("%ld", &a[i]);
	}
	qsort(a, 3 * n, sizeof(long), cmp);
	for (i = 0; i < n; i++) {
		ans += (long long)a[i * 2 + 1];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4860
#include<bits/stdc++.h>
using namespace std;
bool ans[100001];
int main(){
  int n,m;
  cin>>n>>m;
  int p[100001];
  for(int i=1;i<=n;i++)p[i]=1;
  ans[1]=1;
  for(int i=0,x,y;i<m;i++){
    cin>>x>>y;
    p[x]--;
    p[y]++;
    if(ans[x])ans[y]=1;
    if(!p[x])ans[x]=0;
  }
  int a=0;
  for(int i=1;i<=n;i++)a+=ans[i];
  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{long long n;long long count=0;
 cin>>n;long long num5=5;
 long long c=n/2;
 if (n%2!=0)
   cout<<0;
 else
   {while (num5 <= n) {
	  count += (n / num5) / 2;
	  num5 *= 5;
	}
     cout<<count;
   }
 return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}






int main() {
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if (k%2==1){
        cout << b-a << endl;
    }
    else cout << a-b << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")


def solve(N: int, a: "List[int]"):
    acc = list(accumulate(a))
    m = INF
    for i in range(N-1):
        buf = abs(acc[i]-(acc[N-1]-acc[i]))
        m = min(m, buf)
    print(m)

    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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33764
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        int ans = 0;
        for (int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        int count = 0;
        while (count<n){
            int instance = count;
            int dis =0;
            while (a[count]==a[instance]){
                dis++;
                instance++;
            }
            ans+=dis/2;
            count=instance;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

void failed() {
  cout << "NA" << endl;
}

int main() {
  
  int Q1, B, C1, C2, Q2;
  
  while(cin >> Q1 >> B >> C1 >> C2 >> Q2) {
    if(Q1 == 0) break;
    
    /*
    if(B/C1 == 0) {
      failed(); continue;
    }
    */
    
    int AizuCh = min(B/C1, Q2);
    if(AizuCh == 0) {
      failed(); continue;
    }
    int NCh = 0;
    for(;;) {
      
      NCh = (B - AizuCh*C1)/C2;
      
      /*
      if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh = (B - AizuCh*C1)/C2;
      }
      */
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      /*
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      */
      else AizuCh --;
      
      if(AizuCh <= 0) { failed(); break; }
    }
    
  }
  
  return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
};


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
 
class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
 
 
    void solve()
    {
        int N = cin.nextint;
        var L = new long[N + 1];
        L[0] = 2;
        L[1] = 1;
        for (int i = 2; i <= N; i++)
        {
            L[i] = L[i - 2] + L[i - 1];
        }
        WriteLine(L[N]);
    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13268
n, m = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
no = []
for i in AB:
    if H[i[0] - 1] > H[i[1] - 1]:
        no.append(i[1] - 1)
    elif H[i[0] - 1] < H[i[1] - 1]:
        no.append(i[0] - 1)
    else:
        no.append(i[1] - 1)
        no.append(i[0] - 1)
print(n - len(set(no)))

Measured memory_bytes: 37960
def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i, root_x = 3, int(pow(x, 0.5))
    while i <= root_x:
        if x % i == 0:
            return False
        i += 2
    return True

primes = [2]
for i in range(3, 104730):
    if isPrime(i):
        primes.append(primes[-1]+i)
while True:
    n = int(input())
    if n == 0:
        break
    print(primes[n-1])

Measured memory_bytes: 8104
def main():
    n=int(input())
    for i in range(1,3501):
        for j in range(1,3501):
            if 4*i*j-n*i-n*j>0 and (n*i*j)%(4*i*j-n*i-n*j)==0:
                print(i,j, (n*i*j)//(4*i*j-n*i-n*j))
                return
if __name__ == "__main__":
    main()

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

using namespace std;

const int max_n = -1, inf = 1000111222;

long long n, p;
long long ans = 1;

void upd(long long x, int cnt) {
    cnt /= n;
    while (cnt--) {
        ans *= x;
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> p;
    for (long long i = 2; i * i <= p; ++i) {
        int cnt = 0;
        while (p % i == 0) {
            ++cnt;
            p /= i;
        }
        upd(i, cnt);
    }
    if (p > 1) {
        upd(p, 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: UTF-8

def Totalsum(i):
    sum = 0
    while(i > 0):
        sum += i % 10
        i = i // 10
    return sum

a = list(map(int, input().split()))
N = a[0]
A = a[1]
B = a[2]
total = 0

for i in range(N+1):
    sum = Totalsum(i)
    if sum >= A and B >= sum:
        total += i

print(total)

Measured memory_bytes: 3064