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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

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

void Main() {
    int x,a,b;
    cin>>x>>a>>b;
    if (b-a>0) {
        if ((b-a) <= x) {
            cout << "safe" << endl;
        } else {
            cout << "dangerous" << endl;
        }
    } else {
        cout << "delicious" << endl;
    }
    
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define M 1000000007LL
long long k[1000006];
inline long long qm(long long a,long long x)
{
    long long s,c;
    s=1;
    c=a;
    while(x){
        if(x&1)s=(s*c)%M;
        c=(c*c)%M;
        x>>=1;
    }
    return s;
}
int main()
{
    long long n;
    cin>>n;
    k[0]=1;
    for(long long i=1;i<1000001LL;++i){k[i]=(k[i-1]*i)%M;}
    long long x=(n+1)/2,y;
    long long s=0,s1=0;
    for(;x<n;++x){
        y=(k[x-1]*qm(k[x*2-n],M-2)%M*qm(k[n-x-1],M-2)%M*k[x]%M*k[n-x-1]%M-s1+M)%M;
        s1=(s1+y)%M;
        s=(s+y*x%M)%M;
        //cout<<x<<' '<<y<<' '<<s1<<' '<<s<<endl;
    }
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 8192
#include<stdio.h>

int main(void){

int a,b,c;

int count=0;

int i;

scanf("%d %d %d",&a,&b,&c);

for(i=a;i<=b;i++){ 

if(c%i==00)

count++;

}

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

return 0 ; 

}

Measured memory_bytes: 596
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;

class Main {

    static final int modnum = 1000000000 + 7;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            list.add(sc.nextInt());
        }
        ArrayList<Integer> copy = new ArrayList<Integer>(list);

        Collections.sort(copy, Comparator.naturalOrder());

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if (list.get(i) != copy.get(i))
                cnt++;
        }

        if (cnt == 0 || cnt == 2)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 23252
s = input()
k = int(input())
n = len(s)
a = []
for i in range(k):
    if n - i > 0:
        for j in range(n - i):
            a.append(s[j:j + i + 1])
a = list(set(a))
a.sort()
print(a[k-1])



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

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

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

  int A[N];

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

  int ans = A[0];
  for (int i = 1; i < N; i++) {
    ans = gcd(ans, A[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
K = int(input())


def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret


dp = [[[0 for _ in range(2)] for _ in range(K+1)] for _ in range(len(str(N))+1)]
# 頭から0桁目まで決めて、0以外の数が0個既に使われている時、i桁目までの部分がNより小さいのは0の一通り
dp[0][0][0] = 1


for i in range(len(str(N))):
    digit = int(str(N)[i])
    for j in range(K+1):
        # i桁目までがNのそこまでより小さい場合、i-1桁目までもNのi-1桁目までより小さいことが確定するから、
        # i-1 -> iへの派生を入れる（from 厳密に小さい to 厳密に小さい）
        dp[i+1][j][1] += dp[i][j][1]

        # i-1桁目までがNのi-1桁目までより小さくなく（一致し）、Nのi桁目が０であれば、作っている数字のi桁目が０になる
        if digit == 0:
            # 厳密に小さくされないので（from 厳密に小さくない to 厳密に小さくない）
            dp[i+1][j][0] += dp[i][j][0]
        else:
            """
            314159で、31OXXXかつNの3桁目までより小さいパターンは、31XXXXから派生
            """
            # （from 厳密に小さくない（一致する） to 厳密に小さい）
            dp[i+1][j][1] += dp[i][j][0]
        
        # 先頭になんか0以外の数字を入れて、残りがまだ0以外の数字を入れる必要があるとき
        if j-1 >= 0:
            # 0以外のなんかの値を使ったので j-1 -> j かつ  * 9（０以外をいれる）
            dp[i+1][j][1] += dp[i][j-1][1] * 9
            if digit != 0:
                # i桁目が一致する（Nのiまでより小さくならない）パターンについて、直前の場合の数を足す
                dp[i+1][j][0] += dp[i][j-1][0]
                # i桁目までが、Nのそれまでより小さくなるパターンについて、i桁目ではdより小さい値をとれる
                dp[i+1][j][1] += dp[i][j-1][0] * (digit-1)

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

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

int main() {

  int64_t N, K;
  cin >> N >> K;

  if(N < K){
    if(N > K - N){
      cout << K - N << endl;
    }else{
      cout << N << endl;
    }
  }else if(N == K){
    cout << 0 << endl;
  }else{
    N = N % K;
    if(N > K - N){
      cout << K - N << endl;
    }else{
      cout << N << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=307,oo=1000000007;
int n,m,s,A[N][N],ans[N][N],V[N];
struct W {
	int x,y;
	bool operator < (const W &_) const {
		if(x==_.x) return y>_.y;
		return x<_.x;
	}
	W operator + (int t) {
		if(y>=t) return (W){x,y-t};
		return (W){x+1,s-t};
	}
}D[N];
void fly(int x) {
	For(i,1,n) D[i]=(W){oo,0},V[i]=0;
	D[x]=(W){0,s};
	For(i,1,n) {
		int u=-1;
		For(j,1,n)
		if(!V[j]&&(u==-1||D[j]<D[u])) u=j;
		V[u]=1;
		For(j,1,n)
		if(A[u][j]!=oo) D[j]=min(D[j],D[u]+A[u][j]);
	}
	For(i,1,n)
	if(D[i].x==oo) ans[x][i]=-1;
	else ans[x][i]=D[i].x;
}
int main() {
	scanf("%d%d%d",&n,&m,&s);
	For(i,1,n) For(j,1,n) A[i][j]=oo;
	For(i,1,m) {
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		if(z>s) continue;
		A[x][y]=A[y][x]=min(A[x][y],z);
	}
	For(i,1,n) fly(i);
	int q;
	scanf("%d",&q);
	while(q--) {
		int x,y; 
		scanf("%d%d",&x,&y);
		printf("%d\n",ans[x][y]);
	}
	return 0;
}

Measured memory_bytes: 1280
def resolve():
    N = int(input())
    R=set()
    G=set()
    B=set()
    S = input()
    for index,i in enumerate(S):
        if i == "R":
            R.add(index)
        elif i == "G":
            G.add(index)
        else:
            B.add(index)
    count = len(R)* len(G)* len(B)

    for red in R:
        for blue in B:
            mx = max(red,blue)
            mn = min(blue,red)
            step = mx - mn


            if (mx + step) in G:
                count -= 1
            
            if (mn - step) in G:
                count -= 1
            if step % 2 ==0 and (mn + step // 2) in G:
                count -=1

    print(count)



                

            







if __name__ == "__main__":
    resolve()

Measured memory_bytes: 68828
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  if(n%k==0){
    std::cout << 0 << '\n';
    return 0;
  }
  n = n % k;
  std::cout << min(n, abs(n-k)) << '\n';
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int n;

void dfs(string s,int mx){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    int k=s.back()-'a';
    for(int i=0;i<=mx;i++){
        string t=s;
        t.push_back('a'+i);
        dfs(t,mx);
    }
    s.push_back('a'+mx+1);
    dfs(s,mx+1);
}

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

    cin>>n;
    dfs("a",0);
    return 0;
}


Measured memory_bytes: 1536
while True:
    h,w = map(int, input().split())
    if w==0 and h==0:
        break
    
    s = '#'
    d = '.'

    str = ''

    for i1 in range(h):
        if i1%2 == 0:
            for i2 in range(w):
                if i2%2 == 0:
                    str = str + s
                else:
                    str = str + d
            
            print(str)
            str=''

        else:
            for i2 in range(w):
                if i2%2 == 0:
                    str = str + d
                else:
                    str = str + s
            
            print(str)
            str=''
    
    print()

    



Measured memory_bytes: 5612
N = int(input())
A = list(map(int, input().split()))

exec_count = 0

while True:
  exist_odd = False
  
  for i in range(N):
    if A[i]%2 == 1:
      exist_odd = True
  if exist_odd == True:
    break
  else:
    exec_count += 1
    for i in range(N):
      A[i] = A[i]/2
      
print(exec_count)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += sc.nextInt() - 1;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 40420
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

int dfs(vvi vec,int n,vector<bool> visited,int v)
{
	bool all_visited=true;
	
	rep(i,0,n){
		if(!visited[i]) all_visited=false;
	}
	if(all_visited) return 1;
	
	int ret=0;
	
	for(int c:vec[v]){
		if(visited[c]) continue;
		visited[c]=true;
		ret+=dfs(vec,n,visited,c);
		visited[c]=false;
	}
	return ret;
}

signed main(){
	int n,m; cin>>n>>m;
	vvi vec(n,vi(0));
	rep(i,0,m){
		int a,b; cin>>a>>b;
		--a; --b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	vector<bool> visited(n,false);
	visited[0]=true;
	cout<<dfs(vec,n,visited,0);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	cout<<max(0,a-b*2);
	re 0;
}


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

import sys
input = sys.stdin.readline

def io_generator():
	return input()

def iil(a_io):
	return map(int, a_io().split())


#+++++++++++++++++++


def main(io):
	a,b=iil(io)
	if a <= 5:
		return 0
	elif a <= 12:
		return b//2
	return b

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	ret = main(io)
	if ret is not None:
		print(ret)

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

int main() {
  long long N;
  cin >> N;
  vector <long long> p(N);
  rep(i, N) cin >> p[i];
  int count = 0;
  rep(i, N) if (p[i] != i + 1) count++;
  string result;
  if (count <= 2) {
    result = "YES";
  } else {
    result = "NO";
  }
  cout << result << endl;
  return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N;
    cin >> N;
    lli ans = 0;
    REP(i, 0, N) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll>Q;

ll ans[200010];

vector<int>g[200010];

int main(void){
    string s;
    cin>>s;
    int n = s.length();
    if(s[n-1]=='1'){
        cout<<-1<<endl;
        return 0;
    }
    if(s[0]!='1' || s[n-2]!='1'){
        cout<<-1<<endl;
        return 0;
    }
    if(n==2){
        if(s!="10")cout<<-1<<endl;
        else{
            cout<<1<<" "<<2<<endl;
        }
        return 0;
    }
    if(n==3){
        if(s!="110")cout<<-1<<endl;
        else{
            cout<<1<<" "<<2<<endl;
            cout<<2<<" "<<3<<endl;
        }
        return 0;
    }
    if(n%2==0){
        int m = n/2;
        for(int i=0;i<m-1;i++){
            if(s[i]!=s[n-2-i]){
                cout<<-1<<endl;
                return 0;
            }
        }
        int l = 0,r = 0;
        for(int i=m-1;i>=0;i--){
            if(l==0){
                if(s[i]=='1'){
                    l=i+1;
                    r=l+1;
                    g[l].push_back(r);
                }
            }
            else{
                if(s[i]=='1'){
                    g[i+1].push_back(l);
                    l=i+1;
                }
                else g[i+1].push_back(l);
            }
        }
        for(int i=r;i<n;i++)g[r].push_back(i+1);
    }
    else{
        int m=(n-1)/2;
        for(int i=0;i<m;i++){
            if(s[i]!=s[n-2-i]){
                cout<<-1<<endl;
                return 0;
            }
        }
        int l=0,r=0;
        for(int i=m-1;i>=0;i--){
            if(l==0){
                if(s[i]=='1'){
                    l=i+1;
                    r=l+1;
                    g[l].push_back(r);
                }
            }
            else{
                if(s[i]=='1'){
                    g[i+1].push_back(l);
                    l=i+1;
                }
                else g[i+1].push_back(l);
            }
        }
        for(int i=r;i<n;i++)g[r].push_back(i+1);
    }
    for(int i=1;i<=n;i++){
        if(g[i].size()){
            for(int j=0;j<g[i].size();j++){
                cout<<i<<" "<<g[i][j]<<endl;
            }
        }
    }
    return 0;
}

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


def solve(N: int, K: int):
    b1 = math.log2(K)

    p = 0
    for n in range(1,N+1):
        b2 = math.log2(n)
        c  = max(math.ceil(b1-b2),0)
        p  += 0.5**c

    print(p/N)
        


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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



int N, A, B;
string S;
//-----------------------------------------------------------------
int main() {
	cin >> N >> A >> B >> S;

	int ac = 0;
	int bc = 0;

	rep(i, 0, S.length()) {
		if (S[i] == 'a') {
			if (ac + bc < A + B) {
				ac++;
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else if (S[i] == 'b') {
			if (ac + bc < A + B && bc < B) {
				bc++;
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else
		{
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,cnt,fa[404*404],sh[404*404],sb[404*404],id[404][404],vis[404][404];
ll ans;
char mp[404][404];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",mp[i]+1);
		for(int j=1;j<=m;j++)id[i][j]=++cnt,fa[cnt]=cnt;
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	if(mp[i][j]=='.')sb[id[i][j]]=1;
	else sh[id[i][j]]=1;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		if(i<n&&mp[i+1][j]!=mp[i][j])
		{
			int u=find(id[i][j]),v=find(id[i+1][j]);
			if(u!=v)
			{
				fa[u]=v;
				sh[v]+=sh[u],sb[v]+=sb[u];
				sh[u]=sb[u]=0;
			}
		}
		if(j<m&&mp[i][j+1]!=mp[i][j])
		{
			int u=find(id[i][j]),v=find(id[i][j+1]);
			if(u!=v)
			{
				fa[u]=v;
				sh[v]+=sh[u],sb[v]+=sb[u];
				sh[u]=sb[u]=0;
			}
		}
	}
	for(int i=1;i<=n*m;i++)if(sh[i]&&sb[i])ans+=1ll*sh[i]*sb[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(x,n) for(int i=x;i<n;i++)
#define REP(y,n) for(int j=y;j<n;j++)
#define vi vector<int>
#define vvi vector<vector<int>>
signed main(){
  char c;
  int alp[26]={};
  while((c = getchar()) != EOF){
    if(65<=c&&c<=90)alp[c-65]+=1;
    else if(97<=c&&c<=122)alp[c-97]+=1;
  }
  rep(0,26){
    c=i+97;
    cout<<c<<' '<<':'<<' '<<alp[i]<<endl;
  }
}



Measured memory_bytes: 3080
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;
function PriorityQueue(t,i){this._pq=[null].concat(t),this._cf=i||function(t,i){return t>i};for(let t=Math.floor(this._pq.length/2);t>=1;t--)this._maxHeapify(t)}PriorityQueue.prototype._parent=function(t){return Math.floor(t/2)},PriorityQueue.prototype._left=function(t){return 2*t},PriorityQueue.prototype._right=function(t){return 2*t+1},PriorityQueue.prototype._maxHeapify=function(t){(function t(i){let e=this._left(i),p=this._right(i),r=i;if(e<this._pq.length&&this._cf(this._pq[e],this._pq[i])&&(r=e),p<this._pq.length&&this._cf(this._pq[p],this._pq[r])&&(r=p),r!==i){let e=this._pq[i];this._pq[i]=this._pq[r],this._pq[r]=e,t.call(this,r)}}).call(this,t)},PriorityQueue.prototype.maximum=function(){return this._pq[1]},PriorityQueue.prototype.extractMax=function(){if(this._pq.length<=1)return;let t=this._pq[1];return this._pq[1]=this._pq[this._pq.length-1],this._pq.pop(),this._maxHeapify(1),t},PriorityQueue.prototype.increaseKey=function(t,i){let e=t;if(!this._pq[e]||this._cf(i,this._pq[e]))for(this._pq[e]=i;e>1&&!this._cf(this._pq[this._parent(e)],this._pq[e]);){let t=this._pq[e];this._pq[e]=this._pq[this._parent(e)],this._pq[this._parent(e)]=t,e=this._parent(e)}},PriorityQueue.prototype.insert=function(t){this._pq.push(null),this.increaseKey(this._pq.length-1,t)},PriorityQueue.prototype.size=function(t){return this._pq.length-1};

function main(input) {
  var o = new I(input);

  var n = o.a();
  var adj = [];
  for (var i = 1; i <= n; i++) {
    adj[i] = [];
  }

  for (var i = 0; i < n - 1; i++) {
    var a = o.a();
    var b = o.a();
    adj[a].push(b);
    adj[b].push(a);
  }

  var c = o.l();
  c.sort((a, b) => b - a);

  var maxLength = 0;
  var maxNode;
  for (var i = 1; i <= n; i++) {
    if (adj[i].length > maxLength) {
      maxLength = adj[i].length;
      maxNode = i;
    }
  }

  var color = [];
  var mark = [];
  var currentCIndex = 0;
  var pq = new PriorityQueue([], (a, b) => a.size > b.size);
  pq.insert({ value: maxNode, size: adj[maxNode].length });
  color[maxNode] = 1;

  while (pq.size() > 0) {
    var v = pq.extractMax();
    mark[v.value] = c[currentCIndex];
    currentCIndex += 1;

    adj[v.value].forEach(u => {
      if (color[u] === undefined) {
        color[u] = 1;
        pq.insert({value: u, size: adj[u].length});
      }
    });
  }

  var total = c.slice(1).reduce((a, b) => a + b);
  console.log(total);
  console.log(mark.slice(1).join(" "));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17340
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;

ll M = 1000000007;

int main(){
    ll N, C; cin >> N >> C;
    vvll p(N, vll(3));
    rep(i, 0, N){
        cin >> p[i][0] >> p[i][1] >> p[i][2];
    }
    sort(p.begin(),p.end());
    vector<vector<P>> cp(C+1, vector<P>(0));
    rep(i, 0, N){
        ll a = p[i][0], b = p[i][1], c = p[i][2];
        P x = mp(a,b);
        cp[c].emplace_back(x);
    }
    vvll Q(0, vll(2));
    rep(i, 1, C+1){
        ll n = sz(cp[i]);
        if(n == 0){continue;}
        P m = cp[i][0];
        ll b = m.first, e = m.second;
        if(n == 1){
            vll t(2); t[0] = b; t[1] = e;
            Q.emplace_back(t);
        }
        rep(j, 1, n){
            P v = cp[i][j];
            ll g = v.first, h = v.second;
            if(j == n-1){
                if(g == e){
                    e = h;
                    vll r(2);
                    r[0] = b; r[1] = e;
                    Q.emplace_back(r);
                }else{
                    vll r(2);
                    r[0] = b; r[1] = e;
                    Q.emplace_back(r);
                    vll u(2);
                    u[0] = g; u[1] = h;
                    Q.emplace_back(u);
                }
            }
            else{
                if(g == e){
                    e = h; continue;
                }else{
                    vll r(2);
                    r[0] = b; r[1] = e;
                    Q.emplace_back(r);
                    b = g; e = h;
                }
            }
        }
    }
    sort(Q.begin(),Q.end());
    priority_queue<ll, vector<ll>, greater<ll>> E;
    ll ma = 1;
    E.push(Q[0][1]);
    ll n = sz(Q);
    rep(i, 1, n){
        ll x = Q[i][0], y = Q[i][1];
        ll z = E.top();
        if(z < x){
            E.pop();
            E.push(y);
        }else{
            E.push(y);
        }
        ma = max(ma, sz(E));
    }
    prt(ma);
}

Measured memory_bytes: 13876
n = gets.to_i
datas = gets.split(" ").map{|n|n.to_i}
allrain = datas.inject(:+)
lastrain = allrain
#まず一つ解く
((n-1) / 2).times do|idx|
  lastrain -= datas[idx*2+1]*2
end

rains = []

#頭が分かる
rains << datas[0]*2 - lastrain

for idx in 0..(n-3) do
  rains << datas[idx+1]*2 - rains[idx]
end

rains.unshift(lastrain)

puts rains.join(" ")

Measured memory_bytes: 14340
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long L, M;
	scanf("%lld%lld", &L, &M);
	if (M % 2 == 1)
	{
		long long  tmp = L / M;
		long long res = tmp * tmp * tmp;
		cout << res << endl;
	}
	else
	{
		long long tmp, tmq;
		tmq=tmp = L / M;
		tmq = tmp + ((M / 2 <= L % M) ? 1 : 0);
		long long res = tmp * tmp * tmp + tmq * tmq * tmq;
		cout << res << endl;
	}
}

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

int main(){
	int n, k;
	int ans = 1;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		if(i == 0) ans *= k;
		else ans *= (k - 1);
	}
	cout << ans;
	return 0;
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int32_t main()
{   fastio;

    int n , d;
    cin>>n>>d;

    vii arr(n);
    int cnt=0;
    vii brr(n);
    for(int i=0; i<n; i++) {
        cin>>arr[i]>>brr[i];
        if(arr[i]*arr[i]+brr[i]*brr[i] <= d*d) cnt++;
    }
    cout<<cnt<<"\n";


}

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

long n;
set<long long> s;

int main(){
  cin >> n;
  long long first = 0, second = 0;
  
  for(long i=0;i<n;i++){
    long long a;
    cin >> a;
    if(s.find(a) == s.end()){
      s.insert(a);
    }else{
      s.erase(s.find(a));
      if(a > first){
	second = first;
	first = a;
      }else if(a > second){
	second = a;
      }
    }
  }

  cout << first * second << endl;
}

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

int main(){
	int n, r, p, c;
	vector<int> v;
	while(scanf("%d%d", &n, &r), n){
		v.resize(n);
		for(int i = 0; i < n; ++i){
			v[i] = n - i;
		}

		for(int i = 0; i < r; ++i){
			scanf("%d%d", &p, &c);
			--p;
			rotate(v.begin(), v.begin() + p, v.begin() + (p + c));
		}
		printf("%d\n", v[0]);
	}
}

Measured memory_bytes: 1056
import sys

sys.setrecursionlimit(1000000)


def z(changeable: [], cc: [], ans_set):
    for nums, limit_c in changeable:
        # 最新のもの
        num = nums[-1]
        next_ls = []
        target = cc[num]
        limit = limit_c

        if target[1] < limit:
            limit = target[1]
            sub = target[1]
            for i in range(len(nums)-1):
                sub += cc[nums[i]][nums[i+1]]
            ans_set.add(sub)

        for i in range(10):
            if i in nums:
                continue
            x = target[i]
            if x < limit:
                nums_cp = nums[:]
                nums_cp.append(i)
                next_ls.append((nums_cp, limit - x))
        z(next_ls, cc, ans_set)


def main():
    h, w = map(int, input().split())
    cc = []
    for i in range(10):
        ls = list(map(int, input().split()))
        cc.append(ls)

    wall = []
    for i in range(h):
        ls = list(map(int, input().split()))
        wall.append(ls)

    # 1になるまでの最小値
    to1dic = {}
    for i in range(10):
        if i == 1:
            continue
        target = cc[i]
        # 初期値は直接変換。これよりも小さい数でいけたらそれにする
        limit = target[1]
        changeables = []
        ans_set = {limit}
        for j in range(10):
            if j == i:
                continue
            x = target[j]
            if x < limit - 1:
                changeables.append(([i, j], limit - x))

        z(changeables, cc, ans_set)

        min_v = min(ans_set)

        to1dic.setdefault(i, min_v)

    total = 0
    for i in range(h):
        for j in range(w):
            num = wall[i][j]
            if num == -1 or num == 1:
                continue
            total += to1dic[num]
    # print(to1dic)
    print(total)


main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int long long

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

void out(set<int> &ans){
  for(auto itr : ans){
    cout << itr << ' ';
  }
  cout << endl;
}

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

  int N; cin >> N;
  set<int> ans;
  if(N <= 5){
    if(N == 3) ans = {2,5,63};
    if(N == 4) ans = {2,5,20,63};
    if(N == 5) ans = {2,3,4,6,9};
    out(ans);
    return 0;
  }
  int k = 0, plus[] = {2,3,4,6};
  int sum = 0;
  while(N > 0){
    REP(i, 4){
      if(N <= 0) continue;
      ans.insert(6*k + plus[i]);
      sum += 6*k + plus[i];
      N--;
    }
    k++;
  }
  if(sum % 6 == 2){
    ans.erase(8); ans.insert(30000);
  }
  if(sum % 6 == 3){
    ans.erase(9); ans.insert(30000);
  }
  if(sum % 6 == 5){
    ans.erase(9); ans.insert(29998);
  }
  out(ans);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000
#define N 1000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  vector<ll> check(N + 1, 0); // 0 : 関係なし, 1 : セーフかも, 2 : アウト
  vector<ll> num(N + 1, 0);
  for (int i = 0; i < n; i++){
    cin >> a[i];

    num[a[i]]++;
  }

  if (num[0] == 1){
    cout << 1 << endl;
  }
  else if (num[2] >= 2){
    cout << 0 << endl;
  }
  else {
    for (ll i = 0; i < n; i++){
      if (check[a[i]] == 0){
        check[a[i]] = 1;
        for (ll j = a[i]*2; j <= N; j += a[i]){
          check[j] = 2;
        }
      }
      else if (check[a[i]] == 1)
        check[a[i]] = 2;
    }
    ll ans = 0;
    for (ll i = 0; i <= N; i++){
      ans += (check[i] == 1 ? 1 : 0);
    }
    cout << ans << endl;
  }
 

  return 0;
}


Measured memory_bytes: 20412
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;
typedef long long Int;
#define REP(i , x) for(int i = 1 ; i < x ; ++i)


int main()
{
	REP(i, 10){
		REP(j, 10){
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1116
import java.util.*;
import java.io.*;


class Main {

    public static void main(String[] args) throws IOException
    {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st1 = new StringTokenizer(br.readLine());
        int h = Integer.parseInt(st1.nextToken());
        int w = Integer.parseInt(st1.nextToken());
        int k = Integer.parseInt(st1.nextToken());

        char grid[][] = new char[h][w];

        for(int i = 0 ; i < h ; i++)
        {
            grid[i] = br.readLine().toCharArray();
        }
        int cnt = 0;
        for(int i = 0 ; i < Math.pow(2 , h) ; i++)
        {

            for(int j = 0 ; j < Math.pow(2 , w) ; j++)
            {
                int sum = 0;
                for(int x = 0 ; x < h ; x++)
                {
                    if((i & 1 << x) != 0) {
                        for (int y = 0; y < w; y++) {
                            if((j & 1 << y) != 0) {
                                if(grid[x][y] == '#')
                                {
                                    sum++;
                            }
                            }
                        }
                    }
                }
                if(sum == k)
                    cnt++;
            }
        }
        out.println(cnt);

        out.flush();
        out.close();

    }

    static class pair{
        long x1;
        long x2;

        public pair(long x1 , long x2)
        {
            this.x1 = x1;
            this.x2 = x2;
        }

    }

}


Measured memory_bytes: 32900
import re,sys
a,b=map(int, input().split())
s=input()


try:
    s1,s2=s.split("-")
except Exception as e:
    print('No')
    sys.exit()

if(not s1.isdigit() or not s2.isdigit()):
    print('No')
    sys.exit()

if(len(s1)!=a or len(s2)!=b or len(s2)>5):
    print('No')
    sys.exit()

print('Yes')

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

int main(){
  int x,i=0,j,sq,n,TorF,s=0;

  scanf("%d",&x);

  while(i<x){

    i++;
    TorF=0;    
    scanf("%d",&n);    

    if(n==2){ s++; continue;}
    else if(n<2 || n%2==0) continue;        
    else {
      j=3;
      sq=sqrt(n);
      
      while(j<=sq){
	
	if(n%j==0){TorF=1; break;}	
	else j+=2;
      }
      
    }
    if(TorF==0) s++;
  }
  
  printf("%d\n",s);
  return 0;
}
    
  



Measured memory_bytes: 2072
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S, T;
	std::cin >> S >> T;
	if (T.substr(0, S.size()) == S)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


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

using namespace std;

int main() {
    vector<vector<int> > A(3, vector<int>(3));
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> A.at(i).at(j);
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);
    vector<vector<bool> > bingo(3, vector<bool>(3, false));
    for(int i = 0; i < N; i++) {
        cin >> b.at(i);
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(b.at(i) == A.at(j).at(k)) {
                    bingo.at(j).at(k) = true;
                }
            }
        }
    }
    bool flag = false;
    for(int i = 0; i < 3; i++) {
        if(bingo.at(i).at(0) && bingo.at(i).at(1) && bingo.at(i).at(2)) {
            flag = true;
        }
        if(bingo.at(0).at(i) && bingo.at(1).at(i) && bingo.at(2).at(i)) {
            flag = true;
        }
    }
    if(bingo.at(0).at(0) && bingo.at(1).at(1) && bingo.at(2).at(2)) {
        flag = true;
    }
    if(bingo.at(0).at(2) && bingo.at(1).at(1) && bingo.at(2).at(0)) {
        flag = true;
    }
    
    cout << (flag == true ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
def main():

    n = input()
    if n[-1] in ["2", "4", "5", "7", "9"]:
        print("hon")
    elif n[-1] in ["0", "1", "6", "8"]:
        print("pon")
    else:
        print("bon")



if __name__ == '__main__':
    main()


Measured memory_bytes: 9032
n,m=map(int,input().split())
l=[0]*m
r=[0]*m
for i in range(m):
    l[i],r[i]=map(int,input().split())
mi=1
ma=n
for i in range(m):
    if l[i]>mi:
        mi=l[i]
    if ma>r[i]:
        ma=r[i]
if ma>=mi:
    ans=ma-mi+1
else:
    ans=0
print(ans)

Measured memory_bytes: 10868
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		sc.close();

		switch (S) {
		case "Sunny":
			System.out.println("Cloudy");
			break;
		case "Cloudy":
			System.out.println("Rainy");
			break;
		case "Rainy":
			System.out.println("Sunny");
			break;
		}
	}
}


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

#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define MAXSZ 1400

int main(void){
  int fld[MAXSZ][MAXSZ];
  int dp[MAXSZ][MAXSZ];
  int h,w,ans=0;
  
  cin >> h >> w;
  for (int i=0; i<h; i++){
    for (int j=0; j<w; j++){
      cin >> fld[j][i];
      dp[j][i] = (i==0||j==0)?1-fld[j][i]:0;
      ans = MAX(ans,dp[j][i]);
    }
  }
  for (int i=1; i<h; i++){
    for (int j=1; j<w; j++){
      if (fld[j][i]){
        dp[j][i]=0;
      } else {
        dp[j][i] = MIN(dp[j-1][i-1], MIN(dp[j][i-1],dp[j-1][i]))+1;
      }
      ans = MAX(ans, dp[j][i]);
    } 
  }
/*
  for (int i=0; i<h; i++){
    cout << dp[0][i];
    for (int j=1; j<w; j++){
      cout << " " << dp[j][i];
    } cout << endl;
  }
*/
  cout << (ans*ans) << endl;
  return 0;
}


Measured memory_bytes: 18416
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int count_z = 0;
int count_o = 0;
for(int i = 0; i < S.size(); i++){
  if(S.at(i)=='0') count_z++;
  else count_o ++;
}
if(count_z > count_o) cout <<count_o*2 <<endl;
else cout << count_z*2 <<endl;
}

Measured memory_bytes: 512
def read():
    N = int(input().strip())
    X = list(map(int, input().strip().split()))
    return N, X

def solve(N, X):
    smin = 1000000000
    for p in range(1, 101):
        s = sum([(x - p) ** 2 for x in X])
        smin = min(smin, s)
    return smin


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 3060
a = gets.chomp.to_i
n = gets.chomp.split(" ").map(&:to_i)
flag = 1
count = 0
for i in 0..(a-1) do 
  minj = i
  for j in i..(a-1) do 
    if(n[j] < n[minj])
      minj = j
    end
  end
  count += 1 unless n[minj] == n[i]
  n[minj],n[i] = n[i],n[minj]
  
end
n[0,a-1].each do |d|
  print("#{d} ")
end
puts("#{n[a-1]}")
puts count

Measured memory_bytes: 8720
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 998244353

def check(mid, points, origin, rotate):
    height = origin * math.cos(math.radians(rotate))
    # print(height)
    cs = math.cos(math.radians(rotate))
    sn = math.sin(math.radians(rotate))
    for px, py in points:
        py = py - origin
        rx, ry = px*cs - py * sn, px * sn + py * cs
        if abs(rx) > height + 0.0000001 or abs(ry) > height + 0.0000001:
            # print("FALSE", rotate)
            return False

    return True


class Segtree_op():
    def __init__(self, n):
        self.size = 1
        while (n >= 1):
            self.size = self.size << 1
            n = n // 2

        self.arr = [self.unit() for i in range(self.size * 2)]

    def op(self, lch, rch):
        return lch + rch

    def unit(self):
        return 0

    def update(self, k, val):
        k += self.size - 1
        self.arr[k] = val
        while (k):
            k = (k - 1) // 2
            self.arr[k] = self.op(self.arr[k * 2 + 1], self.arr[k * 2 + 2])

    def query(self, l, r):
        L = l + self.size
        R = r + self.size
        s = self.unit()
        while L < R:
            if R & 1:
                R -= 1
                s = self.op(s, self.arr[R - 1])

            if L & 1:
                s = self.op(s, self.arr[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def show(self):
        idx = 1
        while (idx <= self.size):
            print(self.arr[idx - 1:idx * 2 - 1])
            idx *= 2


def solve():
    n, m = getList()
    graph = [[] for i in range(n)]
    michi = [-1  for i in range(n)]
    det = [INF for i in range(n)]
    det[0] = 0

    for _ in range(m):
        a, b = getList()
        a, b = a-1, b-1
        graph[a].append(b)
        graph[b].append(a)

    h = []
    for nx in graph[0]:
        heappush(h, (1, nx))
        det[nx] = 1
        michi[nx] = 1

    while(h):
        # print(h)
        _, tgt = heappop(h)
        for nx in graph[tgt]:
            if det[nx] == INF:
                michi[nx] = tgt+1
                det[nx] = det[tgt] + 1
                heappush(h, (det[nx], nx))

    # print(det)
    for d in det:
        if d == INF:
            print("No")
            return
    print("Yes")
    for m in michi[1:]:
        print(m)
def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    solve()



Measured memory_bytes: 105000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register
#define maxn 230000
#define inf 0x7f7f7f7f
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
int n;
int a[maxn],b[maxn];
ll maxx,maxxx;
int main()
{
	n=read();
	for(rg int i=1;i<=n;++i)
	{
		a[i]=read();
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	maxx=b[n],maxxx=b[n-1];
	if(maxx==maxxx)
	{
		for(rg int i=1;i<=n;++i)
		{
			cout<<maxx<<endl;
		}
	}
	else
	{
		for(rg int i=1;i<=n;++i)
		{
			if(a[i]!=maxx)
			{
				cout<<maxx<<endl;
			}
			else
			{
				cout<<maxxx<<endl;
			}
		}
	}
	
}

Measured memory_bytes: 3200
<?php
$input = STDIN;

$N = trim(fgets($input));

$cnt = 0;
for ($i = 0; $i < $N; $i++) {
    $x = trim(fgets($input));
    if ($x == 2) {
        $cnt++;
    } else if ($x % 2 == 1) {
        $limit = sqrt($x);
        for ($f = 3; $f <= $limit; $f += 2) {
            if ($x % $f == 0) {
                break;
            }
        }
        if ($f > $limit) {
            $cnt++;
        }
    }
}

print $cnt . "\n";


Measured memory_bytes: 9236
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <iterator>
#include <limits>
#include <cmath>

using namespace std;

typedef struct {
    double x, y;
} pt;

typedef pair<pt, pt> seg;

seg mkseg(double ax, double ay, double bx, double by) {
    pt a = {ax, ay};
    pt b = {bx, by};
    return seg(a, b);
}

double inf = numeric_limits<double>::infinity();
double eps = pow(10, -9);

pt seg_cross(seg a, seg b) {
    double A = (a.second.x - a.first.x) / (a.second.y - a.first.y);
    double B = (b.second.x - b.first.x) / (b.second.y - b.first.y);

    // cerr << "A=" << A << " B=" << B << endl;

    if (A == inf || A == -inf) {
        double y = a.first.y;
        double x = B * (y - b.first.y) + b.first.x;
        pt p = {x, y};
        return p;
    }

    if (B == inf || B == -inf) {
        double y = b.first.y;
        double x = A * (y - a.first.y) + a.first.x;
        pt p = {x, y};
        return p;
    }

    double y = (A * a.first.y - B * b.first.y + b.first.x - a.first.x) / (A - B);
    double x_ = A * (y - a.first.y) + a.first.x;
    double x = B * (y - b.first.y) + b.first.x;
    pt p = {x, y};
    return p;
}

void solve() {
    int ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;

    seg new_seg = mkseg(ax, ay, bx, by);
    double nminx = min(ax, bx);
    double nmaxx = max(ax, bx);
    double nminy = min(ay, by);
    double nmaxy = max(ay, by);

    int n;
    cin >> n;

    vector< pair<pt, bool> > pts;

    while (n--) {
        int ax_, ay_, bx_, by_;
        int pos, owner;
        cin >> ax_ >> ay_ >> bx_ >> by_ >> pos >> owner;

        seg s = mkseg(ax_, ay_, bx_, by_);

        double minx = max(nminx, double(min(ax_, bx_))) - eps;
        double maxx = min(nmaxx, double(max(ax_, bx_))) + eps;
        double miny = max(nminy, double(min(ay_, by_))) - eps;
        double maxy = min(nmaxy, double(max(ay_, by_))) + eps;

        pt c = seg_cross(new_seg, s);
        // cerr << "CROSS AT " << c.x << "," << c.y << endl;

        bool flag = (pos == 1) ^ (owner == 1);
        if (minx <= c.x && c.x <= maxx && miny <= c.y && c.y <= maxy) {
            // cerr << "PUSH " << c.x << "," << c.y << endl;
            pts.push_back(make_pair(c, flag));
        }
    }

    struct {
        bool operator()(pair<pt, bool> a, pair<pt, bool> b) {
            return a.first.x == b.first.x
                       ? a.first.y < b.first.y
                       : a.first.x < b.first.x;
        }
    } by_x;

    sort(pts.begin(), pts.end(), by_x);

    int curr_pos = -1;
    int cnt = 0;
    for (vector< pair<pt, bool> >::iterator it = pts.begin(); it != pts.end(); ++it) {
        pair<pt, bool> p = *it;
        // cerr << "FOUND " << p.first.x << " " << p.first.y << " " << p.second << endl;
        if (curr_pos != -1) {
            if (curr_pos != p.second) {
                cnt++;
            }
        }
        curr_pos = p.second;
    }
    cout << cnt << endl;
}

int main() {
    int N;
    cin >> N;
    while (N--) {
        solve();
    }
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll target;
    cin >> target;

    if (m < n)
        swap(n, m);

    ll ans = 0;
    ll curr = 0;
    while (curr < target)
    {
        ans++;
        curr += m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256