akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

mt19937 rng;
clock_t start;

const int D = 365;
const int NTYPE = 26;
array<int, NTYPE> c;
array<array<int, NTYPE>, D> s;

array<int, D> day_order;
array<int, NTYPE> type_order;

void input(){
    int _d;
    cin >> _d;
    REP(i, NTYPE){
        cin >> c.at(i);
    }
    REP(i, D){
        REP(j, NTYPE){
            cin >> s.at(i).at(j);
        }
    }
}

void output(const array<int, D>& sch){
    for(auto x : sch){
        cout << x + 1 << endl;
    }
}

int calc_satisfaction(const array<int, D>& sch){
    int ret = 0;
    array<int, NTYPE> last;
    fill(ALL(last), 0);
    REP(i, D){
        const int cur_d = i + 1;
        const int t = sch.at(i);
        ret += s.at(i).at(t);
        last.at(t) = cur_d;
        REP(j, NTYPE){
            ret -= c.at(j) * (cur_d - last.at(j));
        }
    }
    return ret;
}

void greedy_init(array<int, D>& ans){
    array<int, NTYPE> last;
    fill(ALL(last), 0);
    REP(i, D){
        const int cur_d = i + 1;
        int max_type = -1;
        int max_val = numeric_limits<int>::min();
        REP(j, NTYPE){
            int tmp = s.at(i).at(j) + c.at(j) * (cur_d - last.at(j));
            if(max_val < tmp){
                max_type = j;
                max_val = tmp;
            }
        }
        assert(max_type != -1);
        ans.at(i) = max_type;
        last.at(max_type) = i + 1;
    }
}

void init(){
    REP(i, D){
        day_order.at(i) = i;
    }
    REP(i, NTYPE){
        type_order.at(i) = i;
    }
}

void solve(){
    rng.seed(0);
    array<int, D> ans;
    greedy_init(ans);

    uniform_real_distribution<> ur(0.0, 1.0);

    int cur_score = calc_satisfaction(ans);

    int best_score = cur_score;
    auto best_ans = ans;
    double temp = 2000;
    REP(i, 50){
        bool modified = false;
        shuffle(ALL(day_order), rng);
        shuffle(ALL(type_order), rng);
        for(int j : day_order){
            for(int k : type_order){
                const int cur_k = ans.at(j);
                if(k == cur_k){ continue; }
                ans.at(j) = k;
                const int tmp = calc_satisfaction(ans);
                if(exp(- (double)(cur_score - tmp) / temp) >= ur(rng)){
                    cur_score = tmp;
                    modified = true;
                    if(cur_score > best_score){
                        best_score = cur_score;
                        best_ans = ans;
                    }
                    break;
                }else{
                    ans.at(j) = cur_k;
                }
            }
        }
        const double cur_sec = (double)(clock() - start) / CLOCKS_PER_SEC;
        if(!modified || cur_sec >= 1.9){
            break;
        }
        temp *= 0.9;
    }
    output(best_ans);
}

int main(){
    start = clock();
    input();
    init();
    solve();
    return 0;
}


Measured memory_bytes: 4312
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	ll X;
	cin >> X;
	int a = 0, b = 0;
	rep2(i, -150, 150)
	{
		rep2(j, -150, 150)
		{
			if (pow(i, 5) - pow(j, 5) == X)
			{
				a = i;
				b = j;
				break ;
			}
		}
		if (a != 0 && b != 0) break ;
	}
	cout << a << " " << b << '\n';

	return 0;
}


Measured memory_bytes: 4020
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String x = null;
		while(true){
			x = sc.next();
			if(x.equals("0")){
				break;
			}
			char[] nums = x.toCharArray();
			int sum = 0;
			for(char data: nums){
				sum += Integer.parseInt(String.valueOf(data));
			}
			System.out.println(sum);
		}
	}
}




Measured memory_bytes: 26652
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_D
 * 
 * @author Kyoro
 */
public class Main {

	private int H, W;
	private char ground[][];
	private BufferedReader reader;
	LinkedList<Integer> stack;

	public Main() {
		reader = new BufferedReader(new InputStreamReader(in));
	}

	public void init() {
		ground = new char[102][102];
		for (int i = 0; i < ground.length; i++) {
			Arrays.fill(ground[i], 'x');
		}
		stack = new LinkedList<Integer>();
	}

	public boolean read() throws IOException {
		init();
		String line = reader.readLine();
		String tokens[] = line.trim().split(" ");
		H = Integer.parseInt(tokens[0]);
		W = Integer.parseInt(tokens[1]);
		if (H == 0 || W == 0) {
			return false;
		}
		for (int h = 0; h < H; h++) {
			line = reader.readLine();
			for (int w = 0; w < W; w++) {
				ground[h + 1][w + 1] = line.charAt(w);
			}
		}
		return true;
	}

	public String solve() {
		int area;
		char g;
		int w, h;
		int count = 0;
		for (h = 1; h <= H; h++) {
			for (w = 1; w <= W; w++) {
				area = dfs(ground[h][w], h, w);
				if (area > 0) {
					count++;
				}
			}
		}
		return String.format("%d", count);
	}

	public int dfs(char g, int h, int w) {
		stack.push(h);
		stack.push(w);

		int area = 0;
		while (!stack.isEmpty()) {
			w = stack.pop();
			h = stack.pop();
			if (ground[h][w] == 'x' || ground[h][w] != g) {
				continue;
			}
			ground[h][w] = 'x';
			area++;
			stack.push(h + 1);
			stack.push(w);
			stack.push(h);
			stack.push(w + 1);
			stack.push(h - 1);
			stack.push(w);
			stack.push(h);
			stack.push(w - 1);
		}
		return area;
	}

	public static void main(String[] args) {
		Main main = new Main();
		try {
			while (main.read()) {
				out.println(main.solve());
			}
		} catch (IOException e) {
			err.println(e);
		}
	}
}



Measured memory_bytes: 32040
#include <stdio.h>

int main(void) {
  int k, a, b;
  scanf("%d %d %d", &k, &a, &b);
  for(int i = a; i <= b; i++) {
      if(i % k == 0) {
          puts("OK");
          return 0;
      }
  }
  puts("NG");
  return 0;
}

Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;

int prime[1000010];//i??????????´???°
bool is_prime[1000010]; //is_prime[i]???true??????i????´???°

void sieve(int n){ //n??\???????´???°?????????
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
		}
	}
}

int main(){
	int n;
	sieve(1000000);
	int sum[10010]={};
	rep(i,1,10001){
		sum[i]+=sum[i-1]+prime[i-1];
	}
	while(1){
		cin>>n;
		if(n==0) break;
		cout<<sum[n]<<endl;
	}
}

Measured memory_bytes: 2488
import java.util.*;

public class Main {
	public static int a, b;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		
		int sum = 0;
		for(int i = 0; i < 2; i++) {
			if(a >= b) {
				sum+=a;
				a--;
			}else {
				sum+=b;
				b--;
			}
		}
		
		System.out.println(sum);
	  }
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(void){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if(C<A&&C<B){
        printf("No");
        return 0;
    }
    if(C>A&&C>B){
        printf("No");
        return 0;
    }
    printf("Yes");
        
    return 0;
}

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

vector<vector<int> > G;
vector<int> d;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> in(n,0), A(n+m-1), B(n+m-1);
  G.resize(n);
  d.resize(n,0);
  rep(i,n+m-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    A[i] = a;
    B[i] = b;
    in[b]++;
    G[a].push_back(b);
  }
  int s = 0;
  rep(i,n) {
    if (in[i] == 0) {
      s = i;
      break;
    }
  }

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

  while (!que.empty()) {
    int p = que.front(); que.pop();
    for (auto v : G[p]) {
      in[v]--;
      d[v] = max(d[v], d[p] + 1);
      if (in[v] == 0) que.push(v);
    } 
  }

  vector<int> res(n,-1);
  rep(i,n+m-1) {
    int u = A[i];
    int v = B[i];
    if (d[v] - d[u] == 1) res[v] = u;
  }
  rep(i,n) cout << res[i] + 1 << endl;
  return 0;
} 

Measured memory_bytes: 8192
S = input()


word = S

front = S[:2]
back = S[2:]

front_mm = False
if 1 <= int(front)  and int(front) <= 12:
    front_mm = True

back_mm = False
if 1 <= int(back)  and int(back) <= 12:
    back_mm = True

if front_mm and back_mm:
    print('AMBIGUOUS')
if not front_mm and back_mm:
    print('YYMM')
if front_mm and not back_mm:
    print('MMYY')
if not front_mm and not back_mm:
    print('NA')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    //int a=0,b=0,N=0,S=0;
    int N=0,M=0,ans=0;
    string tmp;
    vector<string> AKA;
    vector<string> AO;
    map<string,int> saidai;

    cin>>N;
    for(int i=0;i<N;i++){
        cin>>tmp;
        saidai[tmp]++;
    }
    cin>>M;
    for(int i=0;i<M;i++){
        cin>>tmp;
        saidai[tmp]--;
    }


    for(auto itr=saidai.begin();itr != saidai.end();++itr){
        if(itr==saidai.begin())ans=itr->second;
        if(itr->second>ans)ans=itr->second;
    }

    if(ans<0)ans=0;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split();
        int[] P = new int[N];
        for(int i = 0; i < N; i++)
        {
            P[i] = int.Parse(input[i]);
        }
        int min = int.MaxValue;
        int ans = 0;
        for(int i=0; i < N; i++)
        {
            if (min >= P[i]) { min = P[i];ans++; }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 33116
#include<stdio.h>
#include<string.h>
int main(void){
 char moji[1001],comm[100],kari[1001];
 int i,j,q,a,b;
 scanf("%s%d",moji,&q);
  for(i=0;i<q;i++){
   scanf("%s%d%d",comm,&a,&b);
   if(strcmp(comm,"print")==0) {
    for(j=a;j<b+1;j++){
     printf("%c",moji[j]);
    }
    printf("\n");
   }
   if(strcmp(comm,"reverse")==0) {
       strcpy(kari,moji);
    for(j=a;j<b+1;j++){
     moji[j]=kari[b-(j-a)];
    }
   }
   if(strcmp(comm,"replace")==0) {
    scanf("%s",kari);
     for(j=a;j<=b;j++){
      moji[j]=kari[j-a];
     }
  }
 }
 return 0;
}



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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, m;
    bool a[30][30] = {};
    /*
    for (int i = 0; i < 30; i++)
    {
        for (int j = 0; j < 30; j++)
        {
            if (a[i][j])
                cout << i << "," << j << endl;
        }
    }
    */
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int tmp;
            cin >> tmp;
            a[i][tmp - 1] = true;
        }
    }

    int cnt = 0;
    for (int i = 0; i < m; i++)
    {
        bool f = true;
        for (int j = 0; j < n; j++)
        {
            if (a[j][i] == false)
                f = false;
        }
        if (f)
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
#define pb push_back
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    vector<long long>v;
    pair<string, long long> n;
    set<string> y;
    long long a,b,c,d=0,e=0,i,f=0,g=0,j,k=1,l=0,r=0,z,m,h,p;
    string t,s,x;
    double q,u;
    cin>>a>>b;
    if(b%2==1||a*2>b||a*4<b){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}

Measured memory_bytes: 3592
#include<cstdio>
#include<iostream>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    if(a>0)
    {
    	cout<<"Positive"<<endl;
    }
    else if(b>=0)
	{
		cout<<"Zero"<<endl;
	}
    else if((a&1)^(b&1))
	{
		cout<<"Positive"<<endl;
	}
    else
	{
		cout<<"Negative"<<endl;
	}
    return 0;
}

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

using namespace std;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    for (int i = 0; i < M; ++i) cin >> A[i];

    int i = 0;
    for (; i < M; ++i)
        if (A[i] > X) break;
    cout << min(i, M - i) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int
main(void)
{
  int count, i;
  scanf("%d", &count);
  int data[count];

  for (i = 0; i < count; i++) {
    scanf("%d", &data[i]);
  }

  for (i = count - 1; i >= 0; i--) {
    if (i == 0) {
      printf("%d", data[i]);
    } else {
      printf("%d ", data[i]);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1828
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int x,y,s;
  while(cin >> x >> y >> s,x){
    int i,j,x2,y2,ans=-1;
    for(i=1;i<s;i++){
      for(j=1;j<s;j++){
        x2=i*(100+x)/100;
        y2=j*(100+x)/100;
        if(x2+y2==s)ans = max(ans,i*(100+y)/100+j*(100+y)/100);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer cout<<endl<<"answer : ";
#define maxn 100005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0;string s;bool flag=false;
        cin>>n; lld a[n]; for(i=0;i<n;i++) cin>>a[i];
        x=a[0];
        vec v;
        for(i=1;i<n;i++)
            x=x^a[i];
        for(i=0;i<n;i++)
            v.pb(x^a[i]);
        for(auto u:v)
            cout<<u<<" ";
        cout<<endl;
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|
 
*/

Measured memory_bytes: 6816
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    int ans = N;
    for (int i = 1; i < N; i++)
    {
        for (int j = i; j >= 0; j--)
        {
            if (H[i] < H[j])
            {
                ans--;
                break;
            }
        }
        
    }
    cout << ans;
    return 0;
}

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

int main()
{
    string s;
    int n,k,a;
    cin>>n;
    cin>>s;
    cin>>k;

    for(a=0;a<n;a++){
        if(s[k-1]==s[a]){
            cout<<s[a];
        }
        else{
            cout<<"*";
        }

    }

    return 0;

}

Measured memory_bytes: 256
# copy
n = int(input())
a = list(map(int, input().split()))

result = 1
d = 0
for i in range(1, n):
    diff = a[i] - a[i - 1]
    if d == 0:
        d = diff
    elif d * diff < 0:
        result += 1
        d = 0

print(result)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#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 FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll a, b, c;
int main() {
	cin >> a >> b >> c;
	ll d = min(a, c);
	a -= d; c -= d;
	b -= min(b, c);
	cout << a << " " << b << endl;
}





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

int main() {
    int N;
    cin >> N;
    vector<pair<pair<string, int>, int>> vec;
    string S;
    int P;
    for (int i = 0; i < N; i++) {
        cin >> S >> P;
        vec.push_back(make_pair(make_pair(S, -P), i + 1));
    }

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

    for (int i = 0; i < N; i++) {
        cout << vec[i].second << endl;
    }
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int> cnt(n,0);
  for(int i=0;i<n;i++){
    cnt[a[i]]++;
  }
  int m=*max_element(a.begin(),a.end());
  bool isok=true;
  if(m%2==0){
    for(int l=0;l<n;l++){
      if(m>=l && l>m/2){
	isok=isok&&(cnt[l]>=2);
      }
      else if(l==m/2){
	isok=isok&&(cnt[l]==1);
      }
      else{
	isok=isok&&(cnt[l]==0);
      }
    }
  }
  else{
    for(int l=0;l<n;l++){
      if(m>=l && l>(m+1)/2){
	isok=isok&&(cnt[l]>=2);
      }
      else if(l==(m+1)/2){
	isok=isok&&(cnt[l]==2);
      }
      else{
	isok=isok&&(cnt[l]==0);
      }
    }
  }
  cout<<(isok ? "Possible" :"Impossible")<<endl;
  return 0;

}


Measured memory_bytes: 256
#create date: 2020-08-07 07:56

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    h, w = na()
    n = ni()
    a = na()
    g = [0] * (h*w)
    gi = 0; ai = 0
    while gi != h * w:
        anow = a[ai]
        for i in range(gi, gi+anow):
            g[i] = (ai+1)
        gi = gi + anow
        ai += 1
    g_rev = g[::-1]
    for i in range(h):
        l = i*w
        r = i*w + w
        if i % 2 == 0:
            print(*g[l:r])
        else:
            l_rev = h*w - r
            r_rev = h*w - l
            print(*g_rev[l_rev:r_rev])
if __name__ == "__main__":
    main()

Measured memory_bytes: 9352
# Author: cr4zjh0bp
# Created: Thu Mar 12 19:34:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

A, B, C, D = nin(4)

print(min(A, B) + min(C, D))

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

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[] id, size;
    long mod = 1000000000+7;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
//        System.out.println(main.solve());
    }
    void solve() throws IOException {
        int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
        id = new int[n+1]; size = new int[n+1];
        for(int i=1;i<=n;i++) id[i] = i;
        Arrays.fill(size,1);
        List<Integer>[] block = new List[n+1];
        for(int i=0;i<=n;i++) block[i] = new ArrayList<>();
        int[] friends = new int[n+1];
        for(int _i=0;_i<m;_i++){
            int a = sc.nextInt(), b = sc.nextInt();
            friends[a] += 1; friends[b] += 1;
            union(a,b);
        }
        for(int _i=0; _i<k; _i++){
            int c = sc.nextInt(), d = sc.nextInt();
            block[c].add(d); block[d].add(c);
        }
        for(int i=1;i<=n;i++){
            int root = find(i);
            int base= size[root]-1; // -1 is self
            base -= friends[i];
            for(int a:block[i]){
                int p = find(a);
                if(p==root) base -= 1;
            }
            out.print(base); out.print(" ");
        }
        out.flush();
    }
    int find(int p){
        while(id[p]!=p){
            id[p] = id[id[p]];
            p = id[p];
        }
        return p;
    }
    void union(int p, int q){
        int i = find(p), j = find(q);
        if(i==j) return;
        id[j] = i;
        size[i] += size[j];
    }


}



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

using ll=long long;
#define int ll
#define upto(a,b,i) for(int i=(a),b_=(b);i<=b_;++i)
#define uptil(a,b,i) for(int i=(a),b_=(b);i<b_;++i)
#define downto(a,b,i) for(int i=(a),b_=(b);i>=b_;--i)
#define downtil(a,b,i) for(int i=(a),b_=(b);i>b_;--i)
#define times(n,i) uptil(0,n,i)
#define rtimes(n,i) downto((n)-1,0,i)
#define size(v) ((int)(v).size())
#define sp << " "
#define ln << endl
template<class T> using vec = vector<T>;

struct uf{
  int n;
  vec<int> par,rank;
  uf(int n):n(n),par(n,-1),rank(n,0){}

  int root(int i) {
    if(par[i]==-1) return i;
    return par[i] = root(par[i]);
  }
  bool merge(int a,int b) {
    a=root(a);
    b=root(b);
    if(a==b) return 0;
    if(rank[a] > rank[b]) swap(a,b);
    par[a] = b;
    ++rank[b];
    return 1;
  }
};

void solve() {
  int N; cin >> N;

  vec<int> xs(N), ys(N);
  vec<pair<int,int>> xis(N), yis(N);
  times(N,i) {
    cin >> xs[i] >> ys[i];
    xis[i] = {xs[i], i};
    yis[i] = {ys[i], i};
  }
  sort(begin(xis), end(xis));
  sort(begin(yis), end(yis));
  uf uf(N);
  times(N-1,i) {
    if(xis[i].first == xis[i+1].first) {
      uf.merge(xis[i].second, xis[i+1].second);
    }
    if(yis[i].first == yis[i+1].first) {
      uf.merge(yis[i].second, yis[i+1].second);
    }
  }

  map<int, set<int>> xset;
  map<int, set<int>> yset;

  times(N,i) {
    xset[uf.root(i)].insert(xs[i]);
    yset[uf.root(i)].insert(ys[i]);
  }

  int ans = -N;
  for(auto &p : xset) {
    ans += size(p.second) * size(yset[p.first]);
  }

  cout << ans ln;

  next_case:;
}

signed main() {
  cout << fixed << setprecision(20);
  cerr << fixed << setprecision(10);
  solve();
return 0;
}


Measured memory_bytes: 11264
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	var S string
	fmt.Scan(&S)
	s := make([]int, 1)
	s[0] = 0
	cnt := 1
	prev, _ := strconv.Atoi(string(S[0]))
	for i := 1; i < N; i++ {
		tmp, _ := strconv.Atoi(string(S[i]))
		if i != N-1 {
			if tmp == prev {
				cnt++
			} else {
				if prev == 1 {
					s = append(s, cnt)
				} else {
					s = append(s, -cnt)
				}
				cnt = 1
				prev = tmp
			}
		} else {
			if prev == tmp {
				cnt++
				if prev == 1 {
					s = append(s, cnt)
				} else {
					s = append(s, -cnt)
				}
			} else {
				if prev == 1 {
					s = append(s, cnt)
					s = append(s, -1)
				} else {
					s = append(s, -cnt)
					s = append(s, 1)
				}
			}
		}
	}
	cnt0 := 0
	for i := 1; i < len(s); i++ {
		if s[i] < 0 {
			cnt0++
		}
	}
	var max int
	s = append(s, 0)
	prev = 0
	if cnt0 <= K {
		fmt.Println(N)
	} else {
		for i := 0; i < len(s)-2*K; i++ {
			if i == 0 {
				cnt = 0
				for _, x := range s {
					if x >= 0 {
						max += x
						if cnt == K {
							break
						}
					} else {
						max += (-1 * x)
						cnt++
					}
				}
				prev = max
			} else if s[i] > 0 && i != 1 {
				tmp := prev - s[i-2] + s[i-1] - s[i+2*K-1] + s[i+2*K]
				if tmp > max {
					max = tmp
				}
				prev = tmp
			}
		}
		fmt.Println(max)
	}
}


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

const int UNDEFINED = -1;
int used[1010];

struct BipartiteGraph {
	struct Edge {
		const int from;
		const int to;
		Edge(const int from, const int to) :
			from(from),
			to(to)
			{}
	};
	const int V;
	vector<vector<Edge>> G;
	vector<int> color;
	BipartiteGraph(const int V) :
		V(V),
		G(vector<vector<Edge>>(V, vector<Edge>())),
		color(vector<int>(V, -1))
		{}
	void addEdge(const int from, const int to) {
		G[from].emplace_back(from, to);
		G[to].emplace_back(to, from);
	}
	bool dfs(const int from, const int col) {
		color[from] = col;
		bool ret = true;
		for(Edge e : G[from]) {
			if(color[e.to] == -1) {
				ret &= dfs(e.to, col ^ 1);
			}
			if(color[e.to] == col) {
				return false;
			}
		}
		return ret;
	}
	int bipart() {
		if(not dfs(0, 0)) throw "NOT Bipartite Graph";
		int ret = 0;
		for(int i : color) ret += i;
		return ret;
	}
};

int main() {
	int n, m;
	while(cin >> n >> m and n > 0) {
		BipartiteGraph bg(n);
		for(int i = 0; i < m; ++i) {
			int u, v; cin >> u >> v;
			u--; v--;
			bg.addEdge(u, v);
		}
		set<int> ans;
		try {
			int cnt = bg.bipart();
			if(cnt % 2 == 0) ans.insert(cnt / 2);
			if((n - cnt) % 2 == 0) ans.insert((n - cnt) / 2);
			cout << ans.size() << "\n";
			for(int i : ans) cout << i << "\n";
		}
		catch(...) {
			cout << 0 << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3240
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
      // 位置 i を st1 にプッシュ(write your code)
    	push(i, &st1);
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      // 水たまりの総水量 sum を更新(write your code)
    	int j=pop(&st1);
    	sum+=i-j;
    	
      
      // st2_j と st2_a を用いて水たまりの水量を更新 
      int a = i - j;   // 更新する水たまりの水量を a に格納していく
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        // 水たまりの水量を求めていく (write your code)
      	pop(&st2_j);
      	a+=pop(&st2_a);
      }
      // 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    	push(j,&st2_j);
    	push(a,&st2_a);
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}



Measured memory_bytes: 2144
import math
def ccw(p1,p2,p3):
#    print (p2[0]-p1[0])*(p3[1]-p1[1])-(p2[1]-p1[1])*(p3[0]-p1[0])
    return (p2[0]-p1[0])*(p3[1]-p1[1])-(p2[1]-p1[1])*(p3[0]-p1[0])
while True:
    n=input()
    if n==0:
        #print 0
        break
    p=[0]*n
    for i in xrange(n):
        p[i]=map(float,raw_input().strip().split(","))
    P=min(p,key=lambda a:(a[1],a[0]))
    p.sort(key=lambda x:math.atan2(x[1]-P[1],x[0]-P[0]))
    #print len(p)
    #print "\n".join(map(lambda x:"{},{}".format(x[0],x[1]),p))
    M=0
    ans=0
    for i in xrange(1,n):
        while ccw(p[M-1],p[M],p[i])<=0:
            if M>0:
                M-=1
                ans+=1
            elif i==n:
                break
            else:
                i+=1
                
        M+=1
        p[M],p[i]=p[i],p[M]
    print ans
    #print len(p)
    #print "\n".join(map(lambda x:"{},{}".format(x[0],x[1]),p))

Measured memory_bytes: 4488
N, M = map(int, input().split())

A = []
for _ in range(N):
  a = input()
  A.append(a)

B = []
for _ in range(M):
  b = input()
  B.append(b)

existed = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    match = True
    for mi in range(M):
      for mj in range(M):
        x = i + mi
        y = j + mj

        if (A[y][x] != B[mj][mi]):
          match = False
          break
      
      if (match == False):
        break

    if (match):
      existed = True
      break
  
  if (existed):
    break

result = 'Yes' if (existed) else 'No'
print(result)


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;
ll P[51];
ll T[51];

ll solve(ll n, ll X){
  if(n==0){
    if(X<=0) return 0;
    else return 1;
  }
  if (X<=1+T[n-1]){
    return solve(n-1,X-1);
  }
  return P[n-1]+1+solve(n-1,X-2-T[n-1]);
}

int main(){
  ll N,X;
  cin>>N>>X;
  P[0]=1;
  T[0]=1;
  for (int i = 0; i < N; i++) {
    P[i+1]=2*P[i]+1;
    T[i+1]=2*T[i]+3;
  }
  cout<<solve(N,X)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
    int a,b,t,count;
    cin>>a>>b;
    int c,n=10;
    c=b;
    while(c/10>0){
        n*=10;
        c/=10;
    }
    n*=a;
    n+=b;
    t=1;
	count=1;
    while(t<n){
        t=count*count;
        count+=1;
    }
    if(n==t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main(){
int a,d; 
cin>>a;
vector<int> b(a),c;
for(int i=0;i<a;i++)
cin>>b.at(i);
c=b;
sort(b.begin(),b.end());
for(int i=0;i<a;i++){
if(c.at(i)==b.at(a-1)){
d=i;
break;
}
}
for(int i=0;i<a;i++){
if(d==i)
cout<<b.at(a-2)<<endl;
else
cout<<b.at(a-1)<<endl;
}
}

Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include<algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};

int main() {
  int tmp;
  cin >> tmp;
  const int n = tmp;
  int a[n],b[n],c[n-1];
  for(int i=0;i<n;i++)
    cin >> a[i];
  for(int i=0;i<n;i++)
    cin >> b[i];
  for(int i=0;i<n-1;i++)
    cin >> c[i];
  
  int ans = 0;
  for(int i=0;i<n;i++){
      ans += b[a[i]-1];
      if(i>0 && a[i-1]+1 == a[i])
      	ans+= c[a[i-1]-1];
        
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
fn main(){
  let nq: Vec<usize> = read_vec();
  let n = nq[0];
  let q = nq[1];

  let s: String = read();
  let sv: Vec<char> = s.chars().collect();
  let mut ac: Vec<usize> = vec![0;n+1];

  for i in 1 .. n {
   if sv[i-1] == 'A' && sv[i] == 'C' {
     ac[i+1] = ac[i] + 1;
   } else {
     ac[i+1] = ac[i];
   }
  }
  
  for _ in 0 .. q {
    let lr: Vec<usize> = read_vec();
    let l = lr[0];
    let r = lr[1];

    println!("{}", ac[r] - ac[l]);
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}


Measured memory_bytes: 4860
import math

n = int(input())
array = [int(x) for x in input().split()]

tmp = math.ceil(sum(array)/n)
tmp2 = math.floor(sum(array)/n)

print(min(sum([pow(abs(x-tmp2),2) for x in array]), sum([pow(abs(x-tmp),2) for x in array])))

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

int main() {
    long int N;
    std::cin >> N;
    std::vector<long int> d(N);
    for(int i = 0; i < N; ++i) {
        std::cin >> d[i];
    }
    std::sort(d.begin(),d.end());
    int half = N/2;
    std::cout << d[half] - d[half - 1] << std::endl;
    }


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

int main() {
    long a, b, k;
    cin >> a >> b >> k;
    if(a > k) {
        a -= k;
    } else {
        k -= a;
        a = 0;
        b = max(0l, b - k);
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String S = scan.nextLine();
        int N=S.length();
        if(N==6){
            if(S.charAt(2)==S.charAt(3)&&S.charAt(4)==S.charAt(5)){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 25172
<?php
fscanf(STDIN, "%s", $s);
$weatherArray = array( 'Sunny', 'Cloudy', 'Rainy' );
$weatherIndex = array_search($s, $weatherArray) + 1;
if(!array_key_exists($weatherIndex, $weatherArray)){
    $weatherIndex = 0;
}
$tomorrowWeather = $weatherArray[$weatherIndex];
echo $tomorrowWeather;
?>

Measured memory_bytes: 4728
s = input()

d = s.count("dream")
dr = s.count("dreamer")
e = s.count("erase")
er = s.count("eraser")
de = s.count("dreamerase")
der = s.count("dreameraser")

l = (d + e) * 5 + (dr - de) * 2 + er
print("YES" if l == len(s) else "NO")

Measured memory_bytes: 3188
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
#flg:反転してるときtrue,してないときFalse
flg = False

for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        if flg:
            flg = False
        else:
            flg = True
    else:
        if t[1] == "1" and flg == False:
            s.appendleft(t[2])
        elif t[1] == "1" and flg == True:
            s.append(t[2])
        elif t[1] == "2" and flg == False:
            s.append(t[2])
        else:
            s.appendleft(t[2])
 
    
if flg:
    s.reverse()
print("".join(s))



Measured memory_bytes: 8684
#define KAKUSUKO
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 50;
int N;
int d[MAX_N];

int main() {
    cin >> N;
    rep(i, N) cin >> d[i];

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;

    return 0;
}


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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		long[][] ab = new long[N][2];
		for (int i = 0; i < N; i++) {
			ab[i][0] = sc.nextLong();
			ab[i][1] = sc.nextLong();
		}
		Arrays.sort(ab, (x, y) -> Long.compare(x[0], y[0]));
		for (int i = 0; i < ab.length; i++) {
			if (ab[i][1] >= K) {
				System.out.println(ab[i][0]);
				return;
			} else {
				K -= ab[i][1];
			}
		}
	}
}


Measured memory_bytes: 92808
#include <iostream> 
#include <cstdio> 
#include <cstdlib>  
#include <algorithm> 
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    string s;
    cin >> s;
    if (s.size() == 2) cout << s << endl;
    else {
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
}


Measured memory_bytes: 3564
import Control.Applicative

data Dice = Dice { diceTop    :: String
                 , diceFront  :: String
                 , diceRight  :: String
                 , diceLeft   :: String
                 , diceBack   :: String
                 , diceBottom :: String
                 } deriving (Show, Eq)

makeDice :: [String] -> Dice
makeDice (t:f:r:l:b:bo:[]) = Dice t f r l b bo

diceToN :: Dice -> Dice
diceToN dice = dice { diceTop    = diceFront dice
                    , diceFront  = diceBottom dice
                    , diceBottom = diceBack dice
                    , diceBack   = diceTop dice
                    }

diceToS :: Dice -> Dice
diceToS dice = dice { diceTop    = diceBack dice
                    , diceFront  = diceTop dice
                    , diceBottom = diceFront dice
                    , diceBack   = diceBottom dice
                    }

diceToE :: Dice -> Dice
diceToE dice = dice { diceTop    = diceLeft dice
                    , diceLeft   = diceBottom dice
                    , diceBottom = diceRight dice
                    , diceRight  = diceTop dice
                    }

diceToW :: Dice -> Dice
diceToW dice = dice { diceTop    = diceRight dice
                    , diceLeft   = diceTop dice
                    , diceBottom = diceLeft dice
                    , diceRight  = diceBottom dice
                    }

diceMoveTo :: Char -> Dice -> Dice
diceMoveTo 'N' = diceToN
diceMoveTo 'S' = diceToS
diceMoveTo 'E' = diceToE
diceMoveTo 'W' = diceToW

diceMoves :: String -> Dice -> Dice
diceMoves []     dice = dice
diceMoves (s:ss) dice = diceMoves ss $ diceMoveTo s dice

diceMoveToTopFront :: String -> String -> Dice -> Dice
diceMoveToTopFront top front = moveToTop top . moveToFront front
  where
      moveToTop top dice
        | top == diceTop dice    = dice
        | top == diceBottom dice = diceMoves "EE" dice
        | top == diceLeft dice   = diceMoves "E"  dice
        | top == diceRight dice  = diceMoves "W"  dice
        | otherwise = dice
      moveToFront front dice
        | front == diceTop dice    = diceMoves "S"  dice
        | front == diceBottom dice = diceMoves "N"  dice
        | front == diceFront dice  = dice
        | front == diceBack dice   = diceMoves "NN" dice
        | front == diceLeft dice   = diceMoves "ES" dice
        | front == diceRight dice  = diceMoves "WS" dice
        | otherwise = dice

main :: IO ()
main = do
    n <- (\n -> read n :: Int) <$> getLine
    dice <- makeDice.words <$> getLine
    ans  <- compareDices (n - 1) dice

    if ans
       then putStrLn "Yes"
       else putStrLn "No"
  where
      compareDices :: Int -> Dice -> IO Bool
      compareDices 0 _    = return True
      compareDices n dice1 = do
          dice2 <- makeDice.words <$> getLine

          if dice1 == diceMoveToTopFront (diceTop dice1) (diceFront dice1) dice2
             then return False
             else compareDices (n - 1) dice1



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



int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll m = -10000000000;
  m = max(max(a * c, a * d),max(b * c, b * d));
  cout << m << endl;

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#define ALL(a) (a).begin(),(a).end()

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

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

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

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

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};




long long fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  // 前処理
  //COMinit();

  ll N,K;
  cin>>N>>K;
  string S;
  cin>>S;

  if(S[K-1]=='A')S[K-1]='a';
  if(S[K-1]=='B')S[K-1]='b';
  if(S[K-1]=='C')S[K-1]='c';

  cout<<S<<endl;
  return 0;
 
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char kekka[20];
    int i,lose;
    lose=0;

    scanf("%s",kekka);

    for(i=0;i<15;i++){
        if(kekka[i] =='x'){
            lose++;
        }
    }

    if(lose>=8){
        printf("NO\n");
    }else{
        printf("YES\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
import math
import heapq
n, ticket = map(int, input().split())
L = list(map(int, input().split()))
h = []
for num in L:
    heapq.heappush(h, -num)
for _ in range(ticket):
    top = heapq.heappop(h)
    top /= 2
    heapq.heappush(h, top)
print(sum(map(lambda x: math.floor(-x), h)))

Measured memory_bytes: 14380
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{

    int n;
    cin >> n;
  
    unsigned long long int p = 1;
    vector<long long int>t(n);
    int r = 0;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        if (t[i] == 0)r++;
    }
    if (r) {
        cout << 0 << endl;
        return 0;
    }
    sort(t.begin(), t.end());
    for (int i = 0; i < n; i++) {
        if (p<= 1000000000000000000/t[i])p *= t[i];
        else {
            cout << -1 << endl;
            return 0;
        }
        //cout << p << endl;
    }
    
   cout << p << endl;

    return 0;

}

Measured memory_bytes: 4052
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
using namespace std;
#define ull unsigned long long
#define llong long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()

string akiba(string s) {
	vector<string> can = {
		"KIHBR",
		"KIHBRA",
		"KIHBAR",
		"KIHBARA",
		"KIHABR",
		"KIHABRA",
		"KIHABARA",
		"AKIHBR",
		"AKIHBRA",
		"AKIHBAR",
		"AKIHABR",
		"AKIHABRA",
		"AKIHABAR",
		"AKIHABARA" };
	auto it = find(all(can), s);
	if (it != can.end())return "YES";
	else return "NO";
}
string akiba2(string s) {
	string s2(s);
	s2 = string(s2.begin(), remove(all(s2), 'A'));
	if (s2 != "KIHBR") return "NO";
	if (s.find("KIH") == string::npos) return "NO";
	int n = s.length();
	rep(i, n - 1) { if (s[i] == s[i + 1])return "NO"; }

	return "YES";

}
int main() {

	string s;
	cin >> s;
	cout << akiba2(s) << endl;
	return 0;
}





Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
ls = [int(input()) for _ in range(n)]

s_ls = sorted([w for w in ls if w % 10 != 0])
ans = sum(s_ls)

if ans == 0:
    print(0)
    exit()

if ans % 10 == 0:
    ans -= s_ls[0]

ans += sum([w for w in ls if w % 10 == 0])
print(ans)


Measured memory_bytes: 9172
#include <iostream>

int main()
{
    int arr[] {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    std::cin >> k;
    std::cout << arr[k - 1];

    return 0;
}

Measured memory_bytes: 256