akhauriyash/Code-Regression huggingface dataset:
n = int(input())
c = input().split()
c = [int(n) for n in c]

s = dict.fromkeys([int(n) for n in range(1,n+1)], 0)

for i in c:
    s[i] = s[i] + 1

for i in range(1, n+1):
    print(s[i])


Measured memory_bytes: 41172
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

ll gcd(ll a, ll b){
  ll temp;
  while(a%b!=0){
    temp = b;
    b = a % b;
    a = temp;
  }
  return b;
}
int main(){
  ll k, ans=0;
  cin >> k;
  for(ll i=1;i<=k;i++){
    for(ll j=1;j<=k;j++){
      for(ll h=1;h<=k;h++){
        ans += gcd(gcd(i,j),h);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int M = N;
    int X = 10e8;
    int f = 0;
	while(X>=1)
	{
        f += M/X;
        if(M/X!=0) M-=(M/X)*X;
        X /= 10;
	}

	if(N%f==0) cout << "Yes" << endl;
	else cout << "No" << endl;
    
	return 0;
}



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

void maxVal(ll& a, ll b) {
	a = max(a, b);
}

void solve() {
	ll n, w, res = 0; cin >> n >> w;
	vector<ll> dp(w + 1, 0);
	for (int i = 0; i < n; ++i) {
		ll weight, val;
		cin >> weight >> val;
		for (int j = w; j >= weight; --j) {
			maxVal(dp[j], dp[j - weight] + val);
		}
	}
	for (auto d : dp) {
		maxVal(res, d);
	}
	cout << res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}


Measured memory_bytes: 1024
import numpy as np
N , K = map(int,input().split())
S = list(input())
s = np.ones(N)
for i , st in enumerate(S):
    if st == "R":
        s[i] = -1


s_res =s[1:N] - s[:N-1]

s_abs = np.abs(s_res)

non_happy = s_abs.sum()/2 - 2*K

if non_happy <0:
    non_happy =0

ans = (N-1) - non_happy
print(int(ans))



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

typedef long long ll; 

int main() {
	string s;
	int n, se, i;
	cin >> n >> s;
	se = s.length();
	if(n >= se) {
		cout << s << endl;
	} else {
		for(i = 0; i < n; i++) {
			cout << s[i];
		}
		cout << "..." << endl; 
	}
	
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
const int maxn = 2010;
int n, A[maxn];

bitset <maxn * maxn> dp;

void solve() {
  cin >> n;
  int sum = 0;
  rep(i, 1, n) {
    A[i] = read(), sum += A[i];
  }
  dp[0] = 1;
  rep(i, 1, n) dp |= dp << A[i];
  int pos = (sum - 1) / 2 + 1;
  while (pos < sum && !dp[pos]) pos++;
  printf("%d\n", pos);
}

int main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

Measured memory_bytes: 5228
#include <algorithm>
#include <iostream>
// #include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef greater<int> gi;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  int a[n];
  REP(i, n) cin >> a[i];
  int ans = 2000000000;
  for (int y : a) {
    vi vec;
    priority_queue<int, vi, gi> que;
    REP(i, n + 1) {
      if (i == n || a[i] < y) {
        sort(ALL(vec));
        int len = vec.size();
        REP(j, len - k + 1) que.push(vec[j]);
        vec.clear();
      } else {
        vec.push_back(a[i]);
      }
    }
    if (que.size() < q) continue;
    REP(i, q - 1) que.pop();
    int x = que.top();
    ans = min(ans, x - y);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,R;
	cin>>n>>m>>R;
	vi r(R);
	rep(i,R)cin>>r[i];
	vvl dist(n,vl(n,LINF));
	ll a,b,c;
	rep(i,m){
		cin>>a>>b>>c;
		dist[a-1][b-1]=c;
		dist[b-1][a-1]=c;
	}
	rep(k,n){
		rep(i,n){
			rep(j,n){
				chmin(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	vl route(R);
	iota(all(route),0);
	ll ans=LINF;
	do{
		ll tmp=0;
		rep(i,R-1){
			tmp+=dist[r[route[i+1]]-1][r[route[i]]-1];
		}
		chmin(ans,tmp);
	}while(next_permutation(all(route)));
	cout<<ans<<endl;


}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
map<ll, int> prime_factor(ll num) {
	map<ll, int> mp;
	ll k = (ll)sqrt(num);
	mp[1]++;
	rep(i, 2, k + 1) {
		while (num % i == 0) {
			num /= i;
			mp[i]++;
		}
	}
	if (num != 1)mp[num]++;
	return mp;
}
//mpの各要素は(first:素因数, second:指数)
//mp.size()にすれば素因数が何種類かを取得できる
//1が含まれることに注意
int main(void) {
	ll n, ans = 0;
	cin >> n;
	map<ll, int> mp = prime_factor(n);
	for (auto m : mp) {
		if (m.first == 1)continue;
		rep(i, 0, 1000000000) {
			if (i * (i + 1) / 2 > m.second) {
				ans += i - 1;
				//printf("a %d\n", i - 1);
				break;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,n;
  cin>>x>>n;
  unordered_map<int,int> mp;
  for(int i=0;i<n;i++)
  {
    int y;
    cin>>y;
    mp[y]=1;
  }
  int ans;
  for(int i=x;i>=0;i--)
  {
    if(mp.find(i)==mp.end())
    {
      ans=i;
      break;
    }
  }
  for(int i=x;i<=101;i++)
  {
    if(mp.find(i)==mp.end())
    {
      int diff=i-x;
      if(diff<(x-ans))
      {
        ans=i;
        break;
      }
    } 
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3608
N,A,B,C,D = map(int, input().split())
S = list(input())

curval = "x"
cnt = 0
initidx = 0
ngarea = [-1]
triarea = [-1]

for idx,val in enumerate(S):
    if val == curval:
        cnt += 1
    else:
        if cnt >= 2 and curval == '#':
            ngarea.append(initidx + 1)
        elif cnt >= 3 and curval == '.':
            for i in range(3,cnt+1):
                triarea.append(initidx + 1 + i - 3)
        initidx = idx
        cnt = 1
    curval = val
else:
    if cnt >= 2 and curval == '#':
        ngarea.append(initidx + 1)
    elif cnt >= 3 and curval == '.':
        triarea.append(initidx + 1)

if C < D:
    isBflg = True
    isABflg = True
    for ngp in ngarea:
        if ngp > B and ngp < D:
            isBflg = False
        if ngp > A and ngp < B:
            isABflg = False
    if isBflg and isABflg:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
else:
    isChangeFlg = False
    # Changepoint = -1
    for trp in triarea:
        if trp >= A and trp + 1 >= B:
            Changepoint = trp + 1
            isChangeFlg = True
            break
    if isChangeFlg == False or Changepoint >= C or Changepoint > D:
        print('No')
        exit()
    else:
        isBflg = True
        isABflg = True
        isChange2DFlg = True
        for ngp in ngarea:
            if ngp > B and ngp < Changepoint:
                isBflg = False
            if ngp > A and ngp < B:
                isABflg = False
            if ngp > Changepoint and ngp < D:
                isChange2DFlg = False
        if isBflg and isABflg and isChange2DFlg:
            print('Yes')
            exit()
        else:
            print('No')
            exit()







Measured memory_bytes: 5044
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

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

  char prev = s[0];
  string ans = "Good";
  FOR(i, 1, 4) {
    char cur = s[i];
    if(prev == cur) {
      ans = "Bad";
    }
    prev = cur;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int c = 1;
  for (int i = 0;i < a;i++){
    if (c >= b)
      c = c + b;
    else
      c =c * 2;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
def binary_search(input_array, key):
    low = 0
    high = len(input_array) - 1
    while low <= high:
        mid = (low+high)//2
        if input_array[mid] == key:
            return 1
        elif input_array[mid] < key:
            low = mid + 1
        else:
            high = mid -1
    return 0
    



n = int(input())

input_array = raw_input().split(" ")
input_array = map(int, input_array)

q = int(input())

for i in range(q):
    print binary_search(input_array,int(input()))


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

long long powe(long long x,long long y, long long mod) {
    long long res=1;
    long long x1=x;
    while(y>0) {
        if(y%2==1) {
            res=(res*x1)%mod;
        }
        y/=2;
        x1=(x1*x1)%mod;
    }
    return res;
}

int main() {
    long long n;
    long long mod = 1000000000+7;
    cin>>n;
    long long ans=0;
    ans=powe((long long)10,n,mod);
    ans=(ans+powe((long long)8,n,mod)+mod)%mod;
    ans = (ans-powe((long long)9,n,mod)+mod)%mod;
    ans = (ans-powe((long long)9,n,mod)+mod)%mod;
    cout<<ans%mod<<endl;
    
    return 0;
}

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

class Dice {
private:
    int face_top;
    int face_south;
    int face_east;
    int face_west;
    int face_north;
    int face_bottom;

public:
    Dice(int a, int b, int c, int d, int e, int f);
    void Roll(char order);
    int Get_Top();
};

Dice::Dice(int a, int b, int c, int d, int e, int f) {
    face_top = a;
    face_south = b;
    face_east = c;
    face_west = d;
    face_north = e;
    face_bottom = f;
}

void Dice::Roll(char order) {
    int res = face_top;
    if (order == 'E') {
        face_top = face_west;
        face_west = face_bottom;
        face_bottom = face_east;
        face_east = res;
    } else if (order == 'W') {
        face_top = face_east;
        face_east = face_bottom;
        face_bottom = face_west;
        face_west = res;
    } else if (order == 'S') {
        face_top = face_north;
        face_north = face_bottom;
        face_bottom = face_south;
        face_south = res;
    } else if (order = 'N') {
        face_top = face_south;
        face_south = face_bottom;
        face_bottom = face_north;
        face_north = res;
    }
}

int Dice::Get_Top() {
    return face_top;
}

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    Dice dice(a, b, c, d, e, f);
    string orders;
    cin >> orders;
    for (int i = 0; i < orders.size(); ++i) {
        dice.Roll(orders[i]);
    }
    cout << dice.Get_Top() << endl;

    return 0;
}


Measured memory_bytes: 3204
package main

import "fmt"

func main() {
	var n, k, x, y int
	fmt.Scan(&n)
	fmt.Scan(&k)
	fmt.Scan(&x)
	fmt.Scan(&y)

	costs := 0
	for i := 1; i <= n; i++ {
		if i <= k {
			costs += x
		} else {
			costs += y
		}
	}

	fmt.Println(costs)
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn is_prime(x: u64) -> bool {
    if x == 2 {
        return true;
    }

    if x < 2 || x % 2 == 0 {
        return false;
    }

    let mut index: u64 = 3;
    let x_sqrt: u64 = (x as f64).sqrt() as u64;
    while index <= x_sqrt {
        if x % index == 0 {
            return false;
        }
        index += 2;
    }
    return true;
}

fn main() {
    let n: u64 = read();
    let mut count: u64 = 0;
    for _ in 0..n {
        let number: u64 = read();
        if is_prime(number) {
            count += 1;
        }
    }
    println!("{}", count);
}



Measured memory_bytes: 5044
#include <iostream>
using namespace std;
 
 
#define F(i, a) for (int i = 0; i < (a); i++)
#define Fd(i, a) for (ll i = (a)-1; i >= 0; i--)
#define Fs(i, a, j) for (ll i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define ll long long
#define mp make_pair
#define eb emplace_back
#define FastOpen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define int long long
//int power(int x,int p){if(p==0)return 1;if(p==1)return x;if(p%2)return x*power(x,p-1);int y=power(x,p/2);return y*y;}
/*
*/

//const int INF = 1e9+7;

void solve() {
    int n; cin >> n;
    int arr[n];
    F(i,n) cin >> arr[i];
    int res = 0;
    for (int i=0,j=0; i<n; i=j) {
        j = i+1;
        while (j < n && arr[j] < arr[i]) {
//            if (arr[j] > arr[j-1]) res += (arr[j]-arr[j-1]);
//            res += (arr[i]-arr[j]);
            j++;
        }
        for (int k =i; k < j; k++) res += (arr[i] - arr[k]);
    }
    cout << res << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    FastOpen
    int t; t=1;
    while (t--) solve();
}





Measured memory_bytes: 4748
N, X = map(int, input().split())
x_list = list(map(int, input().split()))

import numpy as np
import fractions

a = list(set(abs(np.array(x_list) - X)))
ans = a[0]
for i in range(1, len(a)):
    ans = fractions.gcd(ans, a[i])
print(ans)

Measured memory_bytes: 41512
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
//        int n = int.Parse(input[0]);
//        int m = int.Parse(input[1]);
//        int a = int.Parse(input[2]);
//        int b = int.Parse(input[3]);*/
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
//        int b = int.Parse(ReadLine());
//        int c = int.Parse(ReadLine());
//        int d = int.Parse(ReadLine());
//        string a = ReadLine();
//        string b = ReadLine();
//        string c = ReadLine();
        Array.Sort(input);
            WriteLine(Abs(int.Parse(input[0])-int.Parse(input[2])));
    }
}

Measured memory_bytes: 13408
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>

using namespace std;

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

int main(){
    const long long int INF = 10000000000;
    int N,M;
    cin >> N >> M;
    long long int a[N],b[N];
    REP(i,N){
        cin >> a[i] >> b[i];
    }
    long long int c[M],d[M];
    REP(i,M){
        cin >> c[i] >> d[i];
    }
    long long int e[2][N];
    REP(i,N){
        e[1][i] = INF;
    }
    int m;
    REP(i,N){
        REP(j,M){
            m = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(m<e[1][i]){
                e[0][i] = j+1;
                e[1][i] = m;
            }
        }
    }
    REP(i,N){
        cout << e[0][i];
        if(i!=N-1){
            cout << "\n";
        }
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
ll n,ans = 0;
void dfs(ll a,bool flag7,bool flag5,bool flag3)
{
    if(a > n)
    {
        return;
    }
    if(flag7 && flag5 && flag3)
    {
        ans++;
    }
    dfs(a * 10 + 7,true,flag5,flag3);
    dfs(a * 10 + 5,flag7,true,flag3);
    dfs(a * 10 + 3,flag7,flag5,true);
}
int main()
{
    cin >> n;
    bool flag[3];
    dfs(0,false,false,false);
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
// 2018/07/02 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

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

	// 往路

	int D = 0;				// 現時点の最大距離

	for(int i=0; i<N-1; i++){	// 左端から右端へ
		D = max(D, d[i]);			// 最大距離の更新

		if(D<10){				// 次に跳べないならば
			cout << "no" << endl;
			return 0;
		}

		D -= 10;				// 次に跳んだ
	}

	// 復路

	D = 0;

	for(int i=N-1; i>0; i--){	// 右端から左端へ
		D = max(D, d[i]);

		if(D<10){
			cout << "no" << endl;
			return 0;
		}

		D -= 10;
	}

	cout << "yes" << endl;

	return 0;
}



Measured memory_bytes: 4272
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
    int size;
    scanf("%d\n", &size);
    if(size < 1 || size > 100)
        return (EXIT_FAILURE);
    int array[size];
    
    for(int i = 0; i < size; i++)
        scanf("%d", &array[i]);
    
    int minLoc, temp;
    int count = 0;
    for(int i = 0; i < size; i++){
        minLoc = i;
        for(int j = i; j < size; j++)
            if(array[j] < array[minLoc])
                minLoc = j;
        if(minLoc != i)
            count++;
        temp = array[i];
        array[i] = array[minLoc];
        array[minLoc] = temp;
    }
    
    for(int i = 0; i < size; i++){
        if(i == size - 1)
            printf("%d\n",array[i]);
        else
            printf("%d ", array[i]);
    }
    printf("%d\n",count);
    return (EXIT_SUCCESS);
}




Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,k;
  cin >> n >> k;
  priority_queue<pll> q;
  for(ll i=0;i<n;i++) {
    ll t,d;
    cin >> t >> d;
    q.push(pll(d,t));
  }
  priority_queue<pll,vector<pll>,greater<pll>> q1;
  map<ll,ll> ans;
  map<ll,ll> cnt;
  ll kind=0;
  ll sum=0;
  for(ll i=0;i<k;i++) {
    ll d=q.top().first;
    ll t=q.top().second;
    q.pop();
    sum+=d;
    q1.push(pll(d,t));
    if(cnt[t]==0) {
      kind++;
    }
    cnt[t]++;
  }
  ans[kind]=sum+kind*kind;
  while(q.size()&&q1.size()) {
    ll d=q.top().first;
    ll t=q.top().second;
    q.pop();
    if(cnt[t]) continue;
    cnt[t]++;
    ll f=0;
    sum+=d;
    kind++;
    while(q1.size()) {
      ll d1=q1.top().first;
      ll t1=q1.top().second;
      q1.pop();
      if(cnt[t1]==1) continue;
      cnt[t1]--;
      f=1;
      sum-=d1;
      break;
    }
    if(f) {
      ans[kind]=sum+kind*kind;
    }
  }
  ll res=0;
  for(auto p:ans) {
    res=max(p.second,res);
  }
  cout << res << endl;
}

Measured memory_bytes: 7536
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

L, R, d = map(int, input().split())
cnt = 0
for num in range(L, R+1):
    if num%d==0:
        cnt += 1
print(cnt)


Measured memory_bytes: 65268
#include<stdio.h>

int main(){
  long long int n;
  long long int sum = 1000000000002;
  scanf("%lld",&n);
  for(long long int i = 1;i <= 1000000;i++){
    if(n % i == 0){
      if(i+n/i < sum){sum = i+n/i;}
    }
  }printf("%lld\n",sum-2);
  return 0;
}

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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	
	vector<string> s(h);
	for(int i = 0; i < h; i++)
	{
		cin >> s[i];
	}
	
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if(s[i][j] == '#')
			{
				if(i == 0 && j == 0)
				{
					if(s[i][j + 1] != '#' && s[i + 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else if(i == h - 1 && j == w - 1)
				{
					if(s[i][j - 1] != '#' && s[i - 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else if (i == 0 && j == w - 1)
				{
					if(s[i][j - 1] != '#' && s[i + 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else if (i == h - 1 && j == 0)
				{
					if(s[i][j + 1] != '#' && s[i - 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else if (i == 0)
				{
					if(s[i][j + 1] != '#' && s[i][j - 1] != '#' && s[i + 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else if (j == 0)
				{
					if(s[i][j + 1] != '#' && s[i + 1][j] != '#' && s[i - 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else if (i == h - 1)
				{
					if(s[i][j + 1] != '#' && s[i][j - 1] != '#' && s[i - 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else if (j == w - 1)
				{
					if(s[i][j - 1] != '#' && s[i + 1][j] != '#' && s[i - 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
				else 
				{
					if(s[i][j + 1] != '#' && s[i][j - 1] != '#' && s[i + 1][j] != '#' && s[i - 1][j] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
			}
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] S = new int[n];
        for(int i = 0; i < n; i++){
            S[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] T = new int[q];
        for(int i = 0; i < q; i++){
            T[i] = sc.nextInt();
        }
        int count = 0;
        
        
        for(int i = 0; i < q; i++){
            if(BinarySearch(S, T[i])){
                count++;
            }
        }
        System.out.println(count);
   }
   
   public static boolean BinarySearch(int[] S, int key){
       int left = 0;
       int right = S.length - 1;
       int mid = 0;
       
       while(left <= right){
           //System.out.println(left + " " + right + " " + mid);
           mid = (left + right)/2;
           if(S[mid] == key){
               // System.out.println(key + " " + mid);
                return true;
           }else if (key < S[mid]){
                right = mid-1;
           }else{
                left = mid+1;
           }
       }
       return false;
   }
}


Measured memory_bytes: 67904
M, D = [int(i) for i in input().split()]

count = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        if len(str(d)) == 1:
            continue
        d10, d1 = map(int, list(str(d)))
        if d10 >= 2 and d1 >= 2 and d1 * d10 == m:
            count += 1
print(count)

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec S(N);
    ll sum = 0;
    REP(i,0,N) {
        ll a, b;
        cin >> a >> b;
        S[i] = a + b;
        sum -= b;
    }

    DESC(S);
    REP(i,0,(N+1)/2) sum += S[i*2];
    PR(sum);
    

    return 0;
}

/*



*/

Measured memory_bytes: 4056
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep (i, n) cin >> a[i];
	ll sum = 0;
	rep (i, n) sum += a[i];
	int i;
	for (i = 1; i * i <= sum; i++) {
		if (sum % i != 0) continue;
		int x = sum / i;
		vector<int> b(n);
		ll subsum = 0, check = 0;
		rep (j, n) b[j] = a[j] % x;
		sort(all(b), [](int a, int b) {return a > b;});
		rep (j, n) subsum += b[j];
		rep (j, n) {
			if (subsum == 0) break;
			check += x - b[j];
			subsum -= x;
		}
		if (k >= check) {
			cout << x << "\n";
			return 0;
		}
	}
	for (; i >= 1; i--) {
		if (sum % i != 0) continue;
		int x = i;
		vector<int> b(n);
		ll subsum = 0, check = 0;
		rep (j, n) b[j] = a[j] % x;
		sort(all(b), [](int a, int b) {return a > b;});
		rep (j, n) subsum += b[j];
		rep (j, n) {
			if (subsum == 0) break;
			check += x - b[j];
			subsum -= x;
		}
		if (k >= check) {
			cout << x << "\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b,c;
	
	scanf("%d%d%d",&a,&b,&c);
	if(a<b){
		if(b<c){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

int INF = 1'000'000'000;
typedef tuple<int, int, int> T;

int moved(int z, int m){
    if (m == 0) return z;
    if (m == 1) return (z + 1) % 4;
    if (m == 2) return (z + 2) % 4;
    if (m == 3) return (z + 3) % 4;
    else return 10;
}

void next(int nz, int &nx, int &ny){
    if (nz == 0) nx--;
    else if (nz == 1) ny++;
    else if (nz == 2) nx++;
    else ny--;
}

bool check(int x, int y, int h, int w){
    return (0 <= x && x < h && 0 <= y && y < w);
}

int main(){
    while (1){
        int w, h;
        cin >> w >> h;
        if (!w) break;
        vector<vector<vector<int>>> distance(h, vector<vector<int>>(w, vector<int>(4, INF)));
        vector<vector<int>> command(h, vector<int>(w));
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++) cin >> command[i][j];
        }
        vector<int> c(4);
        for (int i = 0; i < 4; i++) cin >> c[i];
        priority_queue<T, vector<T>, greater<T>> que;
        int a = 0; int b = 0; int q = 1;
        que.push(tie(a, b, q));
        while (que.size()){
            int d = get<0>(que.top());
            int x = get<1>(que.top());
            int y = x % 100; x /= 100;
            int z = get<2>(que.top());
            que.pop();
            if (distance[x][y][z] <= d) continue;
            distance[x][y][z] = d;
            if (x == h - 1 && y == w - 1) break;
            for (int i = 0; i < 4; i++){
                if (i == command[x][y]){
                    int nx = x;
                    int ny = y;
                    int nz;
                    nz = moved(z, i);
                    next(nz, nx, ny);
                    if (check(nx, ny, h, w)){
                        nx *= 100;
                        nx += ny;
                        que.push(tie(d, nx, nz));
                    }
                }
                else {
                    int nx = x;
                    int ny = y;
                    int nz;
                    nz = moved(z, i);
                    next(nz, nx, ny);
                    if (check(nx, ny, h, w)){
                        nx *= 100;
                        nx += ny;
                        int nd = d + c[i];
                        que.push(tie(nd, nx, nz));
                    }
                }
            }
        }
        int ans = INF;
        for (int i = 0; i < 4; i++){
            ans = min(ans, distance[h-1][w-1][i]);
        }
        cout << ans << endl;
    }
}


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

int main()
{
  int n, k;
  int64_t ans = 0;
  cin >> n >> k;
  vector<int64_t> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];
  sort(vec.begin(), vec.end(), greater<int64_t>());

  for (int i = 0; i < n; i++)
  {
    if (i < k)
      continue;
    else
      ans += vec[i];
  }
  cout << ans << endl;
}

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

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{int to;};
using graph = vector<vector<edge>>;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  ll n, x, m;
  cin >> n >> x >> m;

  vi vis(m + 1);
  
  int stage = 0;
  ll init = 0;
  int init_len = 0;
  vector<ll> loop;
  auto curr = x;
  rep(i, 0, n) {
    // cout << "At step : " << i << " with " << curr << endl;
    if (stage == 0 and vis[curr] != 0) {
      stage = 1;
    } else if (stage == 1 and vis[curr] > 1) {
      break;
    }
    // cout << "At stage " << stage << endl;

    vis[curr]++;
    if (stage == 0) init += curr, init_len++;
    else if (stage == 1) loop.PB(curr);

    curr = (curr * curr) % m;
  }
  auto rem = n - init_len;
  auto num_loops = sz(loop) ? rem / sz(loop) : 0;
  auto extra = sz(loop) ? rem % sz(loop) : 0;

  // cout << "Rem: " << rem << " Loops: " << num_loops << " extra: " << extra << endl;

  auto loop_total = accumulate(all(loop), 0LL);

  ll res = init + num_loops * loop_total + accumulate(begin(loop), begin(loop) + extra, 0LL);
  cout << res << '\n';
}


Measured memory_bytes: 4200
S = ['0'] + list(input()) + ['0']
N = len(S)
flag = False

ans = 0

for i in range(N - 1, 0, -1):
    j = int(S[i])
    if flag:
        j += 1
        S[i] = j

    if j <= 5:
        if j == 5 and int(S[i - 1]) >= 5:
            ans += j
            flag = True
        else:
            ans += j
            flag = False

    else:
        ans += 10 - j
        flag = True

if flag:
    ans += 1


# print (ans)
count = 0
for s in S:
    if s == 5:
        count += 1
    else:
        ans -= max(0, count - 2)
        count = 0

print (ans)
            


        
    


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

int main()
{
  int n;
  
  scanf("%d%*c", &n);
  while (n--){
    string str;
    getline(cin, str);
    while (str.find("Hoshino") != -1){
      str.insert(str.find("Hoshino"), "Hoshina");
      str.erase(str.find("Hoshino"), 7);
    }

    cout << str << '\n';
  }

  return (0);
}

Measured memory_bytes: 1252
import java.util.Random;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str;
        Random random = new Random();
        int j,i,res,a;
        str = scan.nextLine();
        a = Integer.valueOf(str);
        int[][] x = new int[a][6];
        for(i = 0; i < a; i++) {
            str = scan.nextLine();
            String[] num = str.split(" ", 0);
            for (j = 0; j < 6; j++) {
                x[i][j] = Integer.valueOf(num[j]);
            }
        }
        res = 0;
        for(i=0;i<10000;i++){
            int r1,r2;
            r1 = r2 = 0;
            while(r1==r2){
                r1 = random.nextInt(a);
                r2 = random.nextInt(a);
            }
            res = check(x[r1],x[r2]);
            if(res == 1){
                break;
            }
        }


        if(res == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

        scan.close();
    }

    static void set(int[] x,int a,int b,int c,int d,int e,int f){
        x[0] = a;
        x[1] = b;
        x[2] = c;
        x[3] = d;
        x[4] = e;
        x[5] = f;
    }
    static void turn(int[] x,int i){
        switch (i){
            case 0:
                set(x,x[4],x[0],x[2],x[3],x[5],x[1]);
                break;
            case 1:
                set(x,x[3],x[1],x[0],x[5],x[4],x[2]);
                break;
            case 2:
                set(x,x[2],x[1],x[5],x[0],x[4],x[3]);
                break;
            case 3:
                set(x,x[1],x[5],x[2],x[3],x[0],x[4]);
                break;
        }
    }
    static int check(int[] x, int[] y){
        Random random = new Random();
        int i,res;
        res = 0;
        for(i = 0; i < 1000; i++){
            if(x[0]==y[0]&&x[1]==y[1]&&x[2]==y[2]&&x[3]==y[3]&&x[4]==y[4]&&x[5]==y[5]){
                res = 1;
                break;
            }
            turn(x,random.nextInt(4));
        }
        return res;
    }
}



Measured memory_bytes: 28828
N = int(input())
a = list(map(int, input().split()))
a_sort = sorted(a)
right = a_sort[N // 2]
left = a_sort[N // 2 - 1]
for i in range(N):
    if a[i] <= left:
        print(right)
    elif a[i] >= right:
        print(left)

Measured memory_bytes: 25556
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
    int i;

    int sum = 0;
    char W[11], T[1001];

    scanf("%s", W);
    for( i = 0; W[i]; ++i ) W[i] = tolower(W[i]);
    while( 1 ){
        scanf("%s", T);
        if( strcmp("END_OF_TEXT", T) == 0 ) break;
        for( i = 0; T[i]; ++i ) T[i] = tolower(T[i]);
        if( strcmp(W, T) == 0 ) ++sum;
    }

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

    return 0;
}


Measured memory_bytes: 2116
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ASum = A.Sum();

        var ans = (N < ASum) ? -1 : N - ASum;

        WriteLine(ans);
    }
}


Measured memory_bytes: 29220
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
using namespace std;

int main(void){
    int H,W; cin>>H>>W;
    char s[51][51];
    for(int i=1;i<=W;i++){
        for(int j=1;j<=H;j++){
            cin>>s[i][j];
        }
    }
    for(int i=1;i<=W;i++){
        for(int j=1;j<=H;j++){
            if((s[i][j]=='#'&&s[i-1][j]=='#')||(s[i][j]=='a'&&s[i-1][j]=='#')||(s[i][j]=='#'&&s[i-1][j]=='a')){
                s[i][j]='a';
                s[i-1][j]='a';
            }
            if((s[i][j]=='#'&&s[i][j-1]=='#')||(s[i][j]=='#'&&s[i][j-1]=='a')||(s[i][j]=='a'&&s[i][j-1]=='#')){
                s[i][j]='a';
                s[i][j-1]='a';
            }
        }
    }
    bool ans=true;
    for(int i=1;i<=W;i++){
        for(int j=1;j<=H;j++){
            if(s[i][j]=='#'){
                ans=false;
            }
        }
    }
    cout<<(ans?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int f[1000006];
long long int a[1000006];
int main()
{

    long long int mod,t,k=0,i,m,n,x,j=0,l,c=0,r=0,w,s,d=0,sum=0,mul,mx1,mx,s1=10000000,s2=0;

    cin>>n>>k;


    for(i=1; i<=n; i++)
    {

        cin>>a[i];
    }


    for(i=n-1; i>=1; i--)
    {
        f[i]=1e9;
        for(j=1; j<=k; j++)
        {
            if(i+j<=n)
            {
                f[i]=min( f[i],f[i+j]+abs(a[i]-a[i+j]));
            }

        }

    }
    cout<<f[1]<<endl;
    return 0;

}


Measured memory_bytes: 5152
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        for (int i = str.length() - 1; i >= 0; i--) {
            System.out.print(str.charAt(i));
        }
        System.out.println();
    }
}


Measured memory_bytes: 26008
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N;
    cin >> S;
    int left_kakko = 0;
    int right_kakko = 0;
    rep(i,0,N){
        if(S[i] == '('){
            left_kakko++;
        }else{
            if(left_kakko != 0){
                left_kakko--;
            }else{
                right_kakko++;
            }
        }
    }
    rep(i,0,right_kakko){
        cout << '(';
    }
    cout << S;
    rep(i,0,left_kakko){
        cout << ')';
    }
    cout << endl;

}


Measured memory_bytes: 256
INF = 10 ** 9
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque
from math import factorial

def main():
    n = int(input())
    B = list(map(int,input().split()))
    flag = True
    ans = []
    for i in range(n):
        idx = -1
        for j in range(n - i):
            if B[j] == j + 1:
                idx = j
        if idx == -1:
            flag = False
            break
        ans.append(idx + 1)
        B = B[:idx] + B[idx + 1:]

        if not flag:
            break
    
    print('\n'.join(map(str,ans[::-1])) if flag else -1)
if __name__=='__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
char s[200010];
int a[200010],st[200010],ed[200010],ans[200010],M,lb;
vector<int>in[200010];
int p[200010],N;
int main(){
	int n,i,j,sum,tmp;
	bool flag;
	scanf("%d%s",&n,s+1);
	a[0]=1;
	for(i=1;s[i];i++)a[i]=s[i]-'0';
	n<<=1;
	for(i=0;i<n;i++){
		if(!a[i]&&a[(i+1)%n]){
			M++;
			st[M]=i;
			for(j=(i+1)%n;a[j];j=(j+1)%n){
				if(a[(j+1)%n])in[M].push_back(j);
			}
			ed[M]=(j-1+n)%n;
		}
	}
	#define wa {puts("No");return 0;}
	if(!M){
		n>>=1;
		if(n&1)wa
		puts("Yes");
		for(i=1;i<=n;i+=2)printf("%d %d %d %d ",i,i+1,i,i+1);
		return 0;
	}
	sum=0;
	for(i=1;i<=M;i++)sum+=in[i].size();
	if(sum&1)wa
	if(sum&2){
		tmp=0;
		for(i=1;i<=M;i++)tmp+=!in[i].empty();
		if(tmp==1)wa
		for(i=1;in[i].empty();i++);
		for(j=i+1;in[j].empty();j++);
		swap(ed[i],ed[j]);
		ans[*in[i].rbegin()]=ans[*in[j].rbegin()]=++lb;
		in[i].pop_back();
		in[j].pop_back();
	}
	for(i=1;i<M;i++)ans[ed[i]]=ans[st[i+1]]=++lb;
	ans[ed[M]]=ans[st[1]]=++lb;
	for(i=1;i<=M;i++){
		for(int x:in[i])p[++N]=x;
	}
	for(i=1;i<=N;i+=4){
		ans[p[i]]=ans[p[i+2]]=++lb;
		ans[p[i+1]]=ans[p[i+3]]=++lb;
	}
	flag=0;
	for(i=0;i<n;i++){
		if(!ans[i]){
			flag=!flag;
			if(flag)lb++;
			ans[i]=lb;
		}
	}
	puts("Yes");
	for(i=0;i<n;i++)printf("%d ",ans[i]);
}

Measured memory_bytes: 11124
package main

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

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	as := make([]int, n+1)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}

	const inf = int(1e14)

	ms := make([]int, n+1)
	k := 1
	for i := range as {
		if k > inf {
			ms[i] = inf
		} else {
			ms[i] = k - as[i]
			if ms[i] < 0 {
				fmt.Println(-1)
				return
			}
			k = ms[i] * 2
		}
	}
	ms2 := make([]int, n+1)
	for i := range ms {
		if i == 0 {
			ms2[i] = 1
		} else {
			ms2[i] = min(ms[i-1]*2, inf)
		}
	}

	ns := make([]int, n+1)
	for i := n; i >= 0; i-- {
		if i == n {
			ns[i] = as[i]
		} else {
			ns[i] = min(ns[i+1]+as[i], ms2[i])
		}
	}
	var ans int
	for i := range ns {
		ans += ns[i]
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 5948
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const a = s[0];
  const b = s[1];

  const ans = a % 3 === 0 || b % 3 === 0 || (a + b) % 3 === 0;

  console.log(ans ? 'Possible' : 'Impossible');
}

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


Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int x;
    cin >> x;
    if(x == 1) cout << 0 << endl;
    else cout << 1 << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  map<int, int> mp;
  for (int a : A) {
    mp[a]++;
  }
  vector<int> B;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    B.emplace_back(it->second);
  }
  sort(B.begin(), B.end());
  int res = 0;
  for (int i = 0; i < (int)B.size(); i++) {
    if ((int)B.size() - i > K) {
      res += B[i];
    } else {
      break;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 11640
#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 ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,t;
  cin >> x >> t;
  cout << max(x-t,0) << endl;
}

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

int n, pos, total=0;
vector<int> x;

int costFun(vector<int> s, int p){
	int ans = 0;
	for(int coor: s){
		ans += pow(coor-p, 2);
	}
	return ans;
}

int main() {
	cin >> n;
	for(int i=0, a; i<n; i++){
		cin >> a;
		x.push_back(a);
		total += a;
	}

	pos = total/n;

	cout << min(costFun(x, pos), costFun(x, pos+1)) << endl;
}

Measured memory_bytes: 256
n = int(input())

t_num=0
h_num=0

for i in range(n):
    tarou, hanako = map(str, input().split())
    
    if tarou > hanako:
        t_num += 3
    elif hanako > tarou:
        h_num +=3
    else:
        t_num += 1
        h_num += 1
print(t_num,h_num)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD 1000000007;
#define INV_10 299473306;
using namespace std;
int GCD(int a, int b)
{
	if(a%b==0)
		return b;
	return GCD(b, a%b);
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r[n], g[n], b[n];
	long long sum=0;
	for(int i = 0; i < n; i++)
	{
		if(i==0)
			r[i]=0;
		else
			r[i]=r[i-1];
		if(s[i]=='R')
			r[i]++;
		if(i==0)
			b[i]=0;
		else
			b[i]=b[i-1];
		if(s[i]=='B')
			b[i]++;
		if(i==0)
			g[i]=0;
		else
			g[i]=g[i-1];
		if(s[i]=='G')
			g[i]++;
		//cout << r[i] << ' ';
	}
	//cout << '\n';
	for(int i = 0; i < n; i++)
	{
		if(s[i]=='G')
		{
			for(int j = i+1; j < n; j++)
			{
				if(s[j]=='B')
				{
					sum+=r[i];
					int pos=i-(j-i);
					if(pos >= 0 && s[pos]=='R')
						sum--;
				}
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		if(s[i]=='G')
		{
			for(int j = i+1; j < n; j++)
			{
				if(s[j]=='R')
				{
					sum+=b[i];
					int pos=i-(j-i);
					if(pos >= 0 && s[pos]=='B')
						sum--;
				}
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		if(s[i]=='R')
		{
			for(int j = i+1; j < n; j++)
			{
				if(s[j]=='G')
				{
					sum+=b[i];
					int pos=i-(j-i);
					if(pos >= 0 && s[pos]=='B')
						sum--;
				}
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		if(s[i]=='R')
		{
			for(int j = i+1; j < n; j++)
			{
				if(s[j]=='B')
				{
					sum+=g[i];
					int pos=i-(j-i);
					if(pos >= 0 && s[pos]=='G')
						sum--;
				}
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		if(s[i]=='B')
		{
			for(int j = i+1; j < n; j++)
			{
				if(s[j]=='R')
				{
					sum+=g[i];
					int pos=i-(j-i);
					if(pos >= 0 && s[pos]=='G')
						sum--;
				}
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		if(s[i]=='B')
		{
			for(int j = i+1; j < n; j++)
			{
				if(s[j]=='G')
				{
					sum+=r[i];
					int pos=i-(j-i);
					if(pos >= 0 && s[pos]=='R')
						sum--;
				}
			}
		}
	}
	cout << sum << '\n';
}

Measured memory_bytes: 3672