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

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//long n = long.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
			long sum = 0;
			Dictionary<long, long> count = new Dictionary<long, long>();
			count.Add(0, 1);
			for (int i = 0; i < n; i++) {
				sum += a[i];
				long key = sum % m;
				if (!count.ContainsKey(key)) {
					count.Add(key, 0);
				}
				count[key]++;
			}
			//foreach (var item in count.OrderBy(p => p.Key)) {
			//	System.Diagnostics.Debug.WriteLine(item);
			//}
			long ans = 0;
			foreach (var c in count.Values) {
				ans += c * (c - 1) / 2;
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 25824
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
	cin>>n;
	ll sum=0;
	map<ll,ll>m;
	for(int i=1;i<=n;i++)
	{
	    ll a;
		cin>>a;
		m[a]++;
		sum+=a;
	}
	int q;
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		ll x,y;
		cin>>x>>y;
		sum+=(y-x)*m[x];
		m[y]+=m[x];
		m[x]=0;
		cout<<sum<<endl;
	}
 }


Measured memory_bytes: 9324
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
vector<vector<llong>> g;
vector<llong> v;

bool bfs(llong s) {
    queue<llong> que;
    que.push(s);
    v[s] = 1;

    while (!que.empty()) {
        llong u = que.front();
        que.pop();

        for (auto w:g[u]) {
            if (v[w] == -1) {
                que.push(w);
                v[w] = v[u] + 1;
            }
        }
        for (auto w:g[u]) {
            if (v[w] - v[u] != 1 && v[u] - v[w] != 1) {
                return false;
            }
        }
    }

    return true;
}

int main() {
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            char ch;
            cin >> ch;

            if (ch == '1') g[i].push_back(j);
        }
    }

    llong ans = -1;
    for (int i = 0; i < n; i++) {
        v.clear();
        v.resize(n, -1);

        if (bfs(i)) {
            for (int j = 0; j < n; j++) ans = max(ans, v[j]);
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int n,k;
    cin >> n >>k;
    vector<int> mark(n);

    rep(i,k) cin >> mark[i];
    rep(i,n-k){
        cin >> mark[i+k];
        if(mark[i+k]>mark[i]) cout << "Yes" << endl;
        else cout <<"No" << endl;
    } 

}

Measured memory_bytes: 4048
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

struct _node_table {
    int* next_node;
    int* cost;
    int size;
    int capacity;
} node_table[100005];

int dp[100005];

void init_node(int x) {
    node_table[x].capacity = 10;
    node_table[x].next_node = (int*)malloc(node_table[x].capacity*sizeof(int));
    node_table[x].cost = (int*)malloc(node_table[x].capacity*sizeof(int));
    node_table[x].size = 0;
}

void free_node(int y) {
    free(node_table[y].next_node);
    free(node_table[y].cost);
}

void grow_node(int z) {
    if(node_table[z].capacity < node_table[z].size+2) {
        int size, i;
        int* next_node = node_table[z].next_node;
        int* cost = node_table[z].cost;
        node_table[z].capacity *= 1.5;
        node_table[z].next_node = (int*)malloc(node_table[z].capacity*sizeof(int));
        node_table[z].cost = (int*)malloc(node_table[z].capacity*sizeof(int));
        for(i=0,size=node_table[z].size;i<size;i++) {
            node_table[z].next_node[i] = next_node[i];
            node_table[z].cost[i] = cost[i];
        }
        free(next_node);
        free(cost);
    }
}

void add_next_node(int s, int t, int u) {
    int size = node_table[s].size;
    node_table[s].next_node[size] = t;
    node_table[s].cost[size] = u;
    node_table[s].size++;

    grow_node(s);
}

void solve(int r, int v) {
    int i, size, from, to, cost;
    int queue[SHRT_MAX];
    int wp, rp;

	dp[0] = 0;
    for(i=1;i<v;i++) dp[i] = INT_MAX;

    wp = rp = 0;
    queue[wp++%SHRT_MAX] = r;

    while(wp>rp) {
        from = queue[rp++%SHRT_MAX];

        for(i=0,size=node_table[from].size;i<size;i++) {
            to = node_table[from].next_node[i];
            cost = node_table[from].cost[i];

            if(cost+dp[from] < dp[to]) {
                queue[wp++%SHRT_MAX] = to;
                dp[to] = cost+dp[from];
            }
        }
    }
}

int main(void) {
	int i, h;
    for(i=0;i<100005;i++) init_node(i);

	scanf("%d\n", &h);
    for(i=0;i<h;i++) {
        int j, u, k, v, c;
        scanf("%d %d", &u, &k);
        for(j=0;j<k;j++) {
	        scanf("%d %d", &v, &c);
	        add_next_node(u, v, c);
        }
    }

    solve(0, h);

    for(i=0;i<h;i++) {
        free_node(i);
        if(dp[i] == INT_MAX) {
            printf("INF\n");
        } else {
            printf("%d %d\n", i, dp[i]);
        }
    }

    return 0;
}



Measured memory_bytes: 17376
#include <iostream>
#include <string>

#define INC(i, a, b) for(int i = a; i < b; ++i)
#define DEC(i, a, b) for(int i = a; i > b; --i)
#define REP(i, n)    for(uint i = 0; i < n; ++i)

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}

int main(){
    int N; cin >> N;
    int a;
    int div4 = 0, div2 = 0, odd = 0;
    REP(i, N){
        cin >> a;
        if(a % 2 != 0){
            odd++;
        }else if(a % 4 != 0){
            div2++;
        }else{
            div4++;
        }
    }
    TFprint((odd <= div4 || (div2 == 0 && odd <= div4 + 1)), "Yes", "No");
    return 0;
}

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

int main(){
    
    ll n;
    cin >> n;
    ll n2 = n;
    ll a = sqrt(n);
    vector<ll> p(a+1,0);
    ll ans = 0;
    ll ch = 0;
    for(ll i = 2;i <= a;i++){
        if(n%i == 0){
            while(n%i == 0){
                p[ch]++;
                n /= i;
            }
        ch++;
        }
        if(n == 1){
            break;
        }
    }
    if(n != 1){
        ans++;
    }
    for(ll i = 0;i <= ch;i++){
        if(p[i] != 0){
            int count = 1;
            while(count <= p[i]){
                p[i] -= count;
                count++;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

vector <vector<ll>> dp;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
   ll n,m,k;
   cin >> n >> m >> k;
   dp.resize(n,vector<ll>(m,LLONG_MAX));
   ll x1,x2,y1,y2;
   cin >> x1 >> y1 >> x2 >> y2;
   x1--;y1--;x2--;y2--;
   vector <string> arr(n);
   for (int z=0;z<n;z++){
      cin >> arr[z];
   }
   queue<ii> que;
   que.push({x1,y1});
      vector <vector<bool>> visited(n,vector<bool>(m,false));

   dp[x1][y1] = 0;
   visited[x1][y1] = true;
   while (!que.empty()){
      ll ox = que.front().fi;
      ll oy = que.front().se;
      que.pop();
      for (int x=ox+1,i = 0;x<n && i<k;x++,i++){
         if (arr[x][oy] == '@') break;
         if (dp[ox][oy] >= dp[x][oy]) break;
         dp[x][oy] = dp[ox][oy]+1;
         if (!visited[x][oy])
         que.push({x,oy});
         visited[x][oy] = true;
      }
      for (int x=ox-1,i = 0;x>=0 && i<k;x--,i++){
         if (arr[x][oy] == '@') break;
         if (dp[ox][oy] >= dp[x][oy]) break;
         dp[x][oy] = dp[ox][oy]+1;
         if (!visited[x][oy])
         que.push({x,oy});
         visited[x][oy] = true;
      }
      for (int y=oy+1,i=0;y<m && i<k;y++,i++){
         if (arr[ox][y] == '@') break;
         if (dp[ox][oy] >= dp[ox][y]) break;
         dp[ox][y] = dp[ox][oy]+1;
         if (!visited[ox][y])
         que.push({ox,y});
         visited[ox][y] = true;
      }
      for (int y=oy-1,i=0;y>=0 && i<k;y--,i++){
         if (arr[ox][y] == '@') break;
         if (dp[ox][oy] >= dp[ox][y]) break;
         dp[ox][y] = dp[ox][oy]+1;
         if (!visited[ox][y])
         que.push({ox,y});
         visited[ox][y] = true;
      }
   }
   if (dp[x2][y2] == LLONG_MAX) cout << -1 << endl;
   else cout << dp[x2][y2] << endl;
} 

Measured memory_bytes: 18700
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, M, R;
    cin >> n >> M >> R;

    vector<ll> r(R);
    rep(i, R) cin >> r[i];
    vector<ll> A(M), B(M), C(M);
    rep(i, M) cin >> A[i] >> B[i] >> C[i];
    
    
    // Warshall–Floyd 
    ll INF = 1e18;
    vector<vector<ll> > d(n, vector<ll>(n, INF));
    rep(i, M) {
        d[A[i]-1][B[i]-1] = C[i];
        d[B[i]-1][A[i]-1] = C[i];
    }
    rep(k, n) {
        rep (i, n) {
            rep (j, n) {
                if (d[i][k] < INF && d[k][j] < INF) {
                    d[i][j] = min(
                        d[i][j], d[i][k] + d[k][j]);
                }
            }
        }        
    }

    
    auto nums = r;
    // 事前にソートしないと全部列挙できない
    sort(all(nums));
    ll res = INF;
    do {
        ll dist = 0;
        rep(i, nums.size() - 1) {
            dist += d[nums[i]-1][nums[i+1]-1];
            dist = min(dist, INF);
        }
        res = min(res, dist);
    } while (next_permutation(nums.begin(), nums.end()));

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 4004
from scipy.sparse import*
f=csgraph.floyd_warshall
I=9e9
n,m,l,*t=map(int,open(0).read().split())
d=eval('[I]*-~n,'*-~n)
for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=d[b][a]=c
d=f(d)
d[d>l]=I
d[d<I]=1
d=f(d)
d[d>I]=I
for i in zip(*[iter(t[m*3+1:])]*2):print(int(d[i]%I-1))

Measured memory_bytes: 40764
import math
 
[a, b, h, m] = [int(x) for x in input().split(" ")]
short = ((h) * 60 + m) / (12 * 60) * 360
long = (m) / (60) * 360
theta = abs(long - short)
inte = math.cos(math.radians(theta))
print(math.sqrt(a ** 2 + b ** 2- 2*a * b * inte))

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	
	ll N, K;
	cin >> N >> K;
	double Ans = 0;

	std::vector<ll> v(N);

	for (int i = 1; i <= N; ++i)
	{
		int count = 0;
		int num = i;
		
		while(num < K){
			++count;
			num = num * 2;
		}

		v[i - 1] = count;
	}

	/////////compute///////
	for (int i = 0; i < N; ++i)
	{
		Ans = Ans + pow( 0.5, v[i]);
	}

	Ans = Ans / N;

	cout << setprecision(15) << Ans << endl;



}










Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;


int main() {
	ll a, b;
	cin >> a;
	cin >> b;
	if (a + b == 5) {
		cout << 1 << endl;
	}
	if (a + b == 4) {
		cout << 2 << endl;
	}
	if (a + b == 3) {
		cout << 3 << endl;
	}

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		char c = sc.next().charAt(0);
	    
	    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
	      System.out.println("vowel");
	    } else {
	      System.out.println("consonant");
	    }
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21204
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define p push
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {

	string s;
	scans(s);
	string st = s.substr(0, s.length() / 2), r = s.substr(s.length() / 2);
	reverse(all(r));
	int ans = 0;
	rep(i, st.length()) {
		if (st[i] != r[i])++ans;
	}
	printf("%d\n", ans);

	Please AC;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
bitset<2000009> dp;
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    dp[0] = 1;

    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    for (int& i : a) cin >> i, sum += i;

    for (int i = 0; i < n; i++) {
        dp |= (dp << a[i]);
    }
    for (int i = sum / 2; i >= 0; i--) {
        if (dp[i]) {
            cout << sum - i << endl;
            break;
        }
    }
}



Measured memory_bytes: 4368
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:i64,
        k:i64,
    }
    let diff = (k - n).abs();
    if diff % 2 != 0 {
        println!("IMPOSSIBLE");
    }else {
        println!("{}",if n < k { n + diff/2} else {k + diff/2});
    }
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4352
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let (s, ) = input!(String);

    let mut accum_whites = vec![];
    let mut accum_blacks = vec![];

    let mut whites = 0;
    let mut blacks = 0;

    accum_blacks.push(0);
    accum_whites.push(0);
    for (i, c) in s.char_indices() {
        if c == '.' {
            whites += 1;
        } else {
            blacks += 1;
        }

        accum_blacks.push(blacks);
        accum_whites.push(whites);
    }

    let mut min = std::u32::MAX;

    for i in 0..(n+1) {
        let reverse = accum_blacks[i] - accum_blacks[0] + accum_whites[n] - accum_whites[i];
        min = std::cmp::min(min, reverse);
    }

    println!("{}", min);
}

fn main() {
    solve();
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

enum COLOR {
  WHITE,
  GRAY,
  BLACK,
};

static const int INFTY = INT_MAX;
static const int N = 100;

static int M[N][N] = {};
static vector<COLOR> color(N, WHITE);
static vector<int> d(N, INFTY);

static void bfs(int n, int s) {
  color[s] = GRAY;
  d[s] = 0;

  queue<int> Q;
  Q.push(s);

  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v = 0; v < n; v++) {
      if (M[u][v] && color[v] == WHITE) {
          color[v] = GRAY;
          d[v] = d[u] + 1;
          Q.push(v);
      }
      color[u] = BLACK;
    }
  }
}

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

  int number, count, value;
  for (int i = 0; i < n; i++) {
    cin >> number >> count;
    number--;
    for (int j = 0; j < count; j++) {
     cin >> value;
     value--;
     M[number][value] = 1; 
    }
  }
  
  bfs(n, 0);
  
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << ((d[i] == INFTY) ? -1 : d[i]) << endl; 
  }

  return 0;
}



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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    a, b, c, k = input_to_int_map()

    if a - k  >= 0:
        return 1 * k

    if a + b - k >= 0:
        return 1 * a

    return 1 * a + (-1 * (k - a - b))


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, L;
  std::cin >> N >> L;
  int ans=1000000007, ss=0, minus;
  for(int i=0;i<N;i++){
    ss+=i+L;
    if(ans>abs(i+L)){
      ans = abs(i+L);
      minus=i+L;
    }
  }
  std::cout << ss-minus << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;


int main(int argc, char const *argv[]) {
int H,W;
cin>>H>>W;
int h,w;
cin>>h>>w;
cout<<H*W-h*W-w*H+h*w<<endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[int(_) for _ in input().split()]
b=[int(_) for _ in input().split()]

d_a={}
d_b={}

for i in range(-1,n):
    d_a[i]=0
    d_b[i]=0

for i in range(n):
    d_a[a[i]-1]+=1
    d_b[b[i]-1]+=1

diff=0
c,d=0,0
for i in range(n):
    if d_a[i]+d_b[i]>n:
        print("No")
        exit()
    c+=d_a[i]
    d+=d_b[i-1]
    diff = max(diff,c-d)
print("Yes")
# for i in range(n):
#     print(a[i],end=" ")
# print()
for i in range(n):
    print(b[(i-diff)%n],end=" ")
print()

Measured memory_bytes: 60756
#include <stdio.h>
#include <stdlib.h>
void merge(signed long arr[], signed long l, signed long m, signed long r) 
{ 
    signed long i, j, k; 
    signed long n1 = m - l + 1; 
    signed long n2 =  r - m; 
  
    /* create temp arrays */
    signed long L[n1], R[n2]; 
  
    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++) 
        L[i] = arr[l + i]; 
    for (j = 0; j < n2; j++) 
        R[j] = arr[m + 1+ j]; 
  
    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray 
    j = 0; // Initial index of second subarray 
    k = l; // Initial index of merged subarray 
    while (i < n1 && j < n2) 
    { 
        if (L[i] <= R[j]) 
        { 
            arr[k] = L[i]; 
            i++; 
        } 
        else
        { 
            arr[k] = R[j]; 
            j++; 
        } 
        k++; 
    } 
  
    /* Copy the remaining elements of L[], if there 
       are any */
    while (i < n1) 
    { 
        arr[k] = L[i]; 
        i++; 
        k++; 
    } 
  
    /* Copy the remaining elements of R[], if there 
       are any */
    while (j < n2) 
    { 
        arr[k] = R[j]; 
        j++; 
        k++; 
    } 
} 
  
/* l is for left index and r is right index of the 
   sub-array of arr to be sorted */
void mergeSort(signed long arr[], signed long l, signed long r) 
{ 
    if (l < r) 
    { 
        // Same as (l+r)/2, but avoids overflow for 
        // large l and h 
        signed long m = l+(r-l)/2; 
  
        // Sort first and second halves 
        mergeSort(arr, l, m); 
        mergeSort(arr, m+1, r); 
  
        merge(arr, l, m, r); 
    } 
} 

int main()
{
    signed long n,k;
    signed long long result=0;
    scanf("%ld%ld",&n,&k);
    signed long* arr = (signed long*) malloc(n * sizeof(signed long));
    signed long count = n;
    for(count = 0;count<n;count++)
    {
        scanf("%ld",arr+count);
        result = result + arr[count];
    }
    if(k>=n)
     result = 0;
    else if(k!=0)
    {
    mergeSort(arr,0,n-1);
    for(count = 0;count<k;count++)
    {
        result = result - arr[n-1-count];
    }
    }
    printf("%lld",result);

    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int y, m, d;
	string g;
	while(cin >> g && g != "#"){
		cin >> y >> m >> d;
		if(y == 31){
			if(m < 5){
				cout << "HEISEI" << " " << y << " " << m << " " << d << endl;
			} else {
				cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
			}
		} else if(y < 31){
			cout << "HEISEI" << " " << y << " " << m << " " << d << endl;
		} else {
			cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3160
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws Exception
	{
		int x[]=new int[6];
		for(int i=1;i<=5;i++)
			x[i]=nextInt();
		for(int i=1;i<=5;i++)
			if(x[i]==0)
			{
				out.println(i);
				return;
			}
	}

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

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 32884
#include<cstdio>
#include<cstring>
using namespace std;
int n,mx;
char s[105];
int cnt(int k)
{
	int sum=0;
	bool b[26][2];
	memset(b,false,sizeof(b));
	for(int i=0;i<=k;i++)b[s[i]-'a'][0]=true;
	for(int i=k+1;i<n;i++)
	  if(b[s[i]-'a'][0]&&!b[s[i]-'a'][1])
		{sum++;b[s[i]-'a'][1]=true;}
	return sum;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0,tmp;i<n;i++)
	{
		tmp=cnt(i);
		if(tmp>mx)mx=tmp;
	}
	printf("%d",mx);
}

Measured memory_bytes: 128
import bisect
N = int(input())
T, A = map(int, input().split())
H = [0]*N
H = list(map(int, input().split()))

TL = [0]*N
for i in range(N):
    TL[i] = abs(T - H[i]*0.006 - A)

ansVal = min(TL)
ans = TL.index(ansVal) + 1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define SIZE 100005
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

using namespace std;


int main()
{	
	

	char S[SIZE];
	ll N, K;
	scanf("%lld %lld", &N, &K);
	scanf("%s",&S);
	ll happy=0;
	
	for(ll i=0;i<N-1;i++){
		if((S[i]=='L')&&(S[i+1]=='L'))
		{
			happy++;
		}
		if((S[i]=='R')&&(S[i+1]=='R'))
		{
			happy++;
		}
	}
	
	ll answer;
	answer=min(happy+2*K, N-1);
	
	printf("%lld", answer);
}


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


public class Main {

    int N,T,A;
    int[] H;

    private void solve() {
        N = nextInt();
        T = nextInt();
        A = nextInt();

        H = new int[N];
        for(int i = 0;i < N;i++) {
            H[i] = nextInt();
        }

        double closest = Double.MAX_VALUE;
        int ans = -1;
        for(int i = 0;i < N;i++) {
            double avg = T - H[i] * 0.006;
            double abs = Math.abs(A - avg);
            if (closest > abs) {
                closest = abs;
                ans = i + 1;
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23252
import numpy as np

A = [int(x) for x in input().split()]
A = np.array(A)
t = 0

if A[0] == A[1]:
  t += 1
else:
  pass

if A[0] == A[2]:
  t += 1
else:
  pass

if A[1] == A[2]:
  t += 1
else:
  pass

if t == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 21420
#include<stdio.h>

int main(void)
{
    int N,D,X,A[100],i,j,s=0;
    scanf("%d %d %d",&N ,&D ,&X);
    for(i=0;i<N;i++)
    scanf("%d",&A[i]);
    for(i=0;i<N;i++){
        for(j=1;j<=D; j=j+A[i]) s++;
    }
    printf("%d\n",s+X);
   return 0;
}

Measured memory_bytes: 128
from math import floor
import heapq
def main():
    n,m = map(int,input().split())
    a  = [ -int(x) for x in input().split()]
    heapq.heapify(a)
    for i in range(m):
        now = -heapq.heappop(a)
        now = floor(now/2)
        heapq.heappush(a,-now)
    print(-sum(a))
if __name__ == "__main__":
    main()

Measured memory_bytes: 97560
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;
 
int main() {
    char ch = ' ';

    while(1){
        scanf("%c", &ch);
        if (islower(ch))
        {
            cout << (char)toupper(ch);
        }
        else if (isupper(ch))
        {
            cout << (char)tolower(ch);
        }
        else cout << ch;

        if (ch == '\n') break;
    }
    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


// 素因数が何乗かをmapで返却する
map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void solve() {
    ll N, p; cin >> N >> p;
    ll res = 1;
    auto m = prime_factor(p);
    for(auto a: m){
        ll tmp = a.second / N;
        if(tmp > 0);
        res *= (ll)pow(a.first, tmp);
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main()
{
int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  int c=0;
  for(int i=0;i<n-1;i++)
  {if(a[i]==a[i+1]){cout<<"NO";return 0;}}
  cout<<"YES";
return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg



int main()
{
	int a, b;

	cin >> a >> b;

	cout << a * b << endl;

	return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    int counter;
    counter=0;
    cin>>n;
    int l[n],r[n];
    for(i=0;i<n;i++)
    {
        cin>>l[i]>>r[i];
        counter+=r[i]+1-l[i];
    }
    cout<<counter<<endl;
    return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n, k; cin >> n >> k;

    map<int, int> mp;

    for (int i = 0; i < n; ++i) {
        int a; cin >> a;

        mp[a]++;
    }

    vector<int> v;

    for (auto x : mp) {
        v.push_back(x.second);
    }

    sort(v.begin(), v.end());

    int ans = 0;

    int t = mp.size();

    for (int i = 0; i < t-k; ++i) {
        ans += v[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 10748
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
     
int main() {
  string S;
  long long K;
  long long endCnt;
  
  /* S, K取得 */
  cin >> S >> K;
  
  endCnt = min((long long)S.size(), K);
  for (int i = 0; i < endCnt; i++) {
    if ('1' < S[i]) {
      cout << S[i] << endl;
      return 0;
    }
  }
  cout << '1' << endl;
  return 0;
}

Measured memory_bytes: 256
import bisect
n=int(input())
A=list(map(int,input().split()))
A.sort()

l=bisect.bisect_left(A,A[-1]/2)

if l==n:
    print(A[-1],A[-2])
else:
    if abs(A[-1]/2-A[l])>=abs(A[-1]/2-A[l-1]):
        print(A[-1],A[l-1])
    else:
        print(A[-1],A[l])

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int N,K;
    cin >> N >> K;
    set<int> sunukeS;
    rep(i,N){
      sunukeS.insert(i+1);
    }
    rep(i,K){
      int tgt;
      cin >> tgt;
      rep(g,tgt){
        int sunu;
        cin >> sunu;
        if(sunukeS.count(sunu)){
          sunukeS.erase(sunu);
        }
      }
    }
    printl(sunukeS.size());
}


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

int main(){
  long long A,B,C;
  long long tempA,tempB,tempC;
  cin>>A>>B>>C;
  if(((A==B)&&(B==C))&&(A%2==0)){
    cout<<-1<<endl;
    return 0;
  }
  int n=0;
  bool flag=1;
  while(flag){
    tempA=A;
    tempB=B;
    tempC=C;
    if((A%2==1)||(B%2==1)||(C%2==1)){
      flag=0;
      cout<<n<<endl;
      return 0;
    }
    A=tempB/2+tempC/2;
    B=tempA/2+tempC/2;
    C=tempA/2+tempB/2;
    n++;
  }
  return 0;
}

  
    
    
    
   
  

Measured memory_bytes: 256
n,m=gets.split.map(&:to_i)
l=[]
n.times do
  l << []
end
m.times do |i|
  p,y=gets.split.map(&:to_i)
  l[p-1] << [y,i]
end
a=[]
n.times do |i|
  j=1
  l[i].sort.each do |y,k|
    a[k]=format("%06d%06d",i+1,j)
    j+=1
  end
end
puts a


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

int main(void) {
	int N, K;
	scanf("%d %d", &N, &K);
	int x[100];
	int ans = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &x[i]);
		ans += min(x[i], abs(x[i] - K)) * 2;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3660
object Main extends App {
  import scala.io.StdIn._
  for (_ ← 0 until readInt()) {
    val Array(x0, y0, x1, y1, x2, y2, x3, y3) = readLine.trim.split(' ').map(_.toInt)
    val a = Line(Coordinate(x0, y0), Coordinate(x1, y1))
    val b = Line(Coordinate(x2, y2), Coordinate(x3, y3))
    println(f"${a.distance(b)}%.10f")
  }
}

case class Coordinate(x: Double, y: Double) {
  def distance(that: Coordinate): Double = (this - that).length
  def -(that: Coordinate): Vector = Vector(x - that.x, y - that.y)
}
case class Vector(x: Double, y: Double) {
  def length: Double = math.sqrt(x * x + y * y)
  def dot(that: Vector): Double = x * that.x + y * that.y
  def cross(that: Vector): Double = x * that.y - y * that.x
  def sin(that: Vector): Double = cross(that) / length / that.length
  def cos(that: Vector): Double = dot(that) / length / that.length
}
case class Line(a: Coordinate, b: Coordinate) {
  def distance(that: Line): Double = {
    if ((a - b).sin(that.a - b) * (a - b).sin(that.b - b) < 0 && (that.a - that.b).sin(a - that.b) * (that.a - that.b).sin(b - that.b) < 0) {
      0.0
    }else {
      List(distance(that.a), distance(that.b), that.distance(a), that.distance(b)).min
    }
  }
  def distance(that: Coordinate): Double = {
    if ((a - b).cos(that - b) >= 0 && (b - a).cos(that - a) >= 0) a.distance(that) * (b - a).sin(that - a).abs
    else List(a.distance(that), b.distance(that)).min
  }
}


Measured memory_bytes: 53192
N=int(input())
x=list(map(int,input().split()))
sort_dict={}
count=0
from collections import deque

_x = deque()
for i in sorted(enumerate(x), key=lambda x:x[1]):
    sort_dict[i[0]]=count#昔のインデックスi[0]=count(新しいインデックス)
    _x.append(i[1])#並び替えの要素を追加
    count+=1
_x=list(_x)

cut=N//2-1

for i in range(N):
    #抜く数字はx[i].x[i]の_xにおけるインデックスが分かれば、答えは出る
    #i:ソート前のインデックス
    #sorted_dict[i]:ソートあとインデックス=
    sort_idx=sort_dict[i]
    if sort_idx<=cut:
        print(_x[cut+1])
    else:
        print(_x[cut])


Measured memory_bytes: 144540
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
    int n;
    cin >> n;
    
    if(n%1000 == 0) cout << "0" << endl;
    else cout << 1000 - n%1000 << endl;
  
}


Measured memory_bytes: 3632
class UnionFind():
    # 作りたい要素数nで初期化
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズ
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N, M = map(int, input().split())
uni = UnionFind(N+1)
for _ in range(M):
    a, b = map(int, input().split())
    uni.Unite(a, b)

R = set()
for i in range(1, N+1):
    R.add(uni.Find_Root(i))

print(len(R)-1)

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

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

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

    string t = s.substr(0, s.size() / 2);

    if ( s == t + t) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200050
using namespace std;
typedef long long LL;

int A,B,C;

int main()
{
    cin>>A>>B>>C;
    if (A+B>=C)
        cout<<B+C<<endl;
    else
        cout<<B+(A+B)+1<<endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include<string>
using namespace std;
const int maxn = 1e6+5;

using ll = long long;


int main() {

    string s; cin>>s;

    int n = s.length();
    int cnt = 0;
    for(int i = 0 , j = n-1; i < j; i++, j--){
        if(s[i] != s[j])
            cnt++;
    }

    cout<<cnt<<"\n";

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<List<Integer>> A = new ArrayList<>();
		for (int i = 0; i <= n; i++) {
			List<Integer> a = new ArrayList<>();
			A.add(a);
		}
		int z = sc.nextInt();
		for (int i = 0; i < z; i++) {
			int q = sc.nextInt();
			if (q == 0) {
				int x = sc.nextInt();
				int t = sc.nextInt();
				List<Integer> a = A.get(x);
				a.add(t);
			}
			if (q == 1) {
				int x = sc.nextInt();
				for(int j=0;j<A.get(x).size();j++) {
					System.out.print(A.get(x).get(j));
				if(j!=A.get(x).size()-1)
				System.out.print(" ");
			}
				System.out.println();
			}
			if (q == 2) {
				int x = sc.nextInt();
				A.get(x).clear();
			}
		}
		sc.close();
	}
}




Measured memory_bytes: 310116
n, a, b = map(int, input().split())
s = input()
dome = 0
fore = 0
for t in s:
    if t == "a":
        if dome + fore < a+b:
            print("Yes")
            dome += 1
        else:
            print("No")
    elif t == "b":
        if dome + fore < a+b and fore < b:
            print("Yes")
            fore += 1
        else:
            print("No")
    elif t == "c":
        print("No")

Measured memory_bytes: 4016
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  string s;cin>>s;
  int n = (int)s.size();
  int m = n/2;
  bool ans = true;
  rep(i, n/2){
    if(s[i]!=s[n-i-1])ans=false;
  }
  string t;t=s.substr(0, m);
  rep(i, m/2){
    if(t[i]!=t[m-i-1])ans=false;
  }
  cout<<(ans?"Yes":"No")<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

int main(){
	int n, m;
	vector<string> s, t;
	vector<int> count;

	cin >> n;
	s = vector<string>(n);
	for(int i=0; i < n; i++) {
		cin >> s.at(i);
	}
	cin >> m;
	t = vector<string>(m);
	for(int i=0; i < m; i++) {
		cin >> t.at(i);
	}

	count = vector<int>(n);
	for(int i=0; i < n; i++) {
		for(int j=0; j < max(n, m); j++) {
			if(j < m && s.at(i) == t.at(j))
				count.at(i)--;
			if(j < n && s.at(i) == s.at(j))
				count.at(i)++;
		}
	}
	count.at(0) = max(0, count.at(0));
	for(int i =1; i < n; i++) {
		count.at(0) = max(count.at(0), count.at(i));
	}
	cout << count.at(0) << endl;
}


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

struct st {
	char a;
	int b, c;
};
int main() {
	int n;
	while (cin >> n, n) {
		vector<st>v;
		rep(i, n) {
			char t; int a = 0, b = 0;
			cin >> t;
			rep(j, n - 1) {
				int r; cin >> r;
				if (!r)a++;
				if (r == 1)b++;
			}
			v.push_back({ t,a,b });
		}
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.c < b.c; });
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.b > b.b; });
		for (st i : v) {
			cout << i.a << endl;
		}
	}
}

Measured memory_bytes: 3120
#include<stdio.h>

int main(){

    int n,k,x,y;
    scanf("%d\n%d\n%d\n%d",&n, &k, &x, &y);

    int i,ans=0;
    for(i=0;i<n;i++){
        if(i<k)ans = ans + x;
        else ans = ans + y;
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 128