akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int table[3];

string s;
int p;

inline int opnot(int x) {
    return 2-x;
}

inline int opand(int x, int y) {
    if (x == 0 || y == 0) return 0;
    if (x == 1 || y == 1) return 1;
    return 2;
}

inline int opor(int x, int y) {
    if (x == 2 || y == 2) return 2;
    if (x == 1 || y == 1) return 1;
    return 0;
}

int formula() {
    switch (s[p]) {
        case '0': case '1': case '2':
            return s[p++] - '0';
            break;
        case 'P': case 'Q': case 'R':
            return table[s[p++] - 'P'];
            break;
        case '-':
            p++;
            return opnot(formula());
            break;
        case '(':
            p++;
            int a = formula();
            if (s[p] == '*') {
                p++; // for '*'
                int res = opand(a, formula());
                p++; // for ')'
                return res;
            } else {
                p++; // for '+'
                int res = opor(a, formula());
                p++; // for ')'
                return res;
            }
            break;
    }
}

int main() {
    while (getline(cin, s)) {
        if (s == ".") break;
        int cnt = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    table[0] = i;
                    table[1] = j;
                    table[2] = k;
                    p = 0;
                    if (formula() == 2) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,d;
    	char x;
        cin>>x;
        x++;
        cout<<x;
    	
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main(int argc, char const* argv[])
{
  int table_size;
  while(cin >> table_size) {
    if (table_size == 0) break;

    map<char, char> table; 
    char key, val;
    for (int i = 0; i < table_size; i++) {
      cin >> key >> val;
      table.insert( map<char, char>::value_type( key, val ) );
    }

    int input_size;
    cin >> input_size;

    char c;
    for (int i = 0; i < input_size; i++) {
      cin >> c;
      if (table.find(c) == table.end()) {
        cout << c;
      } else {
        cout << table[c];
      }
    }

    cout << endl;
  }
  return 0;
}

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

int main()
{
  int a, b, c, d, p;
  int x, y;
  
  cin >> a >> b >> c >> d >> p;

  x = p * a;
  y = b;

  if (p - c > 0){
    y += (p - c) * d;
  }

  if (x > y){
    x = y;
  }

  cout << x << endl;

  return 0;
}

Measured memory_bytes: 1164
import java.io.*;
import java.lang.StringBuilder;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    char[] ch = br.readLine().toCharArray();
    for(char c : ch){
      String s = String.valueOf(c);
      if (c < 'a')
      sb.append(s.toLowerCase());
      else if(c >= 'a')
      sb.append(s.toUpperCase());
    }
    System.out.println(sb);
  }
}

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

typedef __int128 ll;
const int P = 998244353;
int n; ll pw[110];
char s[110];
map<pair<int, ll>, int> mp;

int main() {
    scanf("%s", s), n = strlen(s);
    for (int i = pw[0] = 1; i < n; i++) {
        pw[i] = pw[i - 1] << 1;
    }
    function<int(int, ll)> solve = [&](int len, ll mask) {
        if (!len) return 1;
        if (mp.count({len, mask})) return mp[{len, mask}];
        int sum = 1LL * solve(len - 1, mask >> 1) * ((mask & 1) + 1) % P;
        ll cur = 0;
        for (int i = 0; i < len; i++) {
            cur |= (mask & pw[i]);
            ll tmp = cur;
            for (int j = 2; (i + 1) * j <= len; j++) {
                int t = (i + 1) * (j - 1); ll all = 0;
                for (int k = t; k < (i + 1) * j; k++) all |= (mask & pw[k]);
                tmp &= (all >> t);
                (sum += 1LL * solve(i + 1, tmp) * solve(len - (i + 1) * j,
                    mask >> ((i + 1) * j)) % P) %= P;
            }
        }
        return mp[{len, mask}] = sum;
    };
    ll mask = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') mask |= pw[i];
    }
    printf("%d\n", solve(n, mask));
    return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    
    rep(i, n) {
        if (a[i] != b[i]) {
            ans++;
        }
        
        if ((a[i] != c[i]) && (b[i] != c[i])) {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

typedef pair<int, int> PII;

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
 
int main(){
  int H,W;
  cin >> H >> W ;
  vector<vector<char> > mat(H, vector<char>(W));
  vector<vector<int> > ans(H, vector<int>(W, -1));

  int cnt_black = 0;
  for(int i=0; i < H; i++){
    for(int j=0; j < W; j++){
      cin >> mat.at(i).at(j);
      if(mat.at(i).at(j) == '#'){
        cnt_black += 1;
      }
    }
  }

  queue<PII> q;
  q.push(make_pair(0,0));
  ans.at(0).at(0) = 0;
  

  int x,y,nx,ny;
  while(!q.empty()){
    cerr << q.front().first << endl;
    cerr << q.front().second << endl;
    x = q.front().first;
    y = q.front().second;
    q.pop();

    for(int k=0;k<4;k++){
      nx = x + dx[k];
      ny = y + dy[k];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W){
        continue;
      }
      if(mat.at(nx).at(ny) == '#' || ans.at(nx).at(ny) != -1){
        continue;
      }
      ans.at(nx).at(ny) = ans.at(x).at(y) + 1;
      q.push(make_pair(nx,ny));

    }
  }


  cerr << "cnt_black " <<  cnt_black << endl;
  cerr << "ans " << ans.at(H-1).at(W-1) << endl;
  if(ans.at(H-1).at(W-1) != -1){
    cout << H*W - ans.at(H-1).at(W-1) - cnt_black - 1 << endl;
  } else {
    cout << ans.at(H-1).at(W-1) << endl;
  }
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define MAXI 1000001

ll MAX = 1e10;

vector<vll> grid;
vb vis;

void dfs(ll u){
    vis[u] = true;
    for(auto x:grid[u]){
        if(!vis[x]) dfs(x);
    }
}

void solve(){
    ll n,m;
    cin >> n >> m;
    grid.resize(n + 1);
    vis.assign(n + 1,false);
    rep(i,0,m){
        ll a,b;
        cin >> a >> b;
        grid[a].pb(b);
        grid[b].pb(a);
    }
    ll ans = 0;
    rep(i,1,n + 1){
        if(!vis[i]){
            ans++;
            dfs(i);
        }
    }
    cout << ans - 1;
}
	
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
 
	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}	

Measured memory_bytes: 10036
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, M;
  cin >> N >> M;
  v(bool) B(N, false);
  B[0] = true;

  vi A(N, 1);

  i64 x, y;
  rep(i, M){
    cin >> x >> y;
    x--, y--;
    if(B[x]) B[y] = true;
    A[x]--;
    A[y]++;
    if(A[x]==0) B[x] = false;
  }
  cout << accumulate(rng(B), 0LL) << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		int N = nextInt();
		long[] A = new long[N];
		long[] B = new long[N];
		for(int i=0;i<N;i++){
			A[i]=nextLong();
			B[i]=nextLong();
		}

		long ans = 0;
		for(int i=N-1;i>=0;i--){
			ans+=(B[i]-(A[i]+ans+B[i])%(B[i]))%B[i];
		}
		System.out.println(ans);

	}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

public static long lcm(long a, long b) {
	long x, y;

	return ((a/gcd(a,b))*b);
}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 49504
(defn input []
  (vector
    (Integer/parseInt (read-line))
    (->> (clojure.string/split (read-line) #"\s")
      (mapv #(Integer/parseInt %)))))

(defn Thumbnail [[N As]]
  (let [avg (/ (apply + As) (count As))
        tmp (map #(Math/abs (double (- % avg))) As)
        result (.indexOf tmp (apply min tmp))]
    (when (= -1 result) (throw (Exception. "Error")))
    result))

(->> (input)
  Thumbnail
  println)

Measured memory_bytes: 66664
#include <iostream>
#include <cstring>
#define N 1000
using namespace std;

int C[N + 1][N + 1];
char X[N + 1];
char Y[N + 1];

int Longest(int n1, int n2)
{
    for (int i = 0; i <= n2; i++)
    {
        C[0][i] = 0;
    }
    for (int i = 0; i <= n1; i++)
    {
        C[i][0] = 0;
    }

    for (int i = 1; i <= n1; i++)
    {
        for (int j = 1; j <= n2; j++)
        {
            if (X[i - 1] == Y[j - 1])
            {
                C[i][j] = C[i - 1][j - 1] + 1;
            }
            else
            {
                C[i][j] = max(C[i][j - 1], C[i - 1][j]);
            }
        }
    }

    return C[n1][n2];
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> X;
        cin >> Y;

        int n1 = strlen(X);
        int n2 = strlen(Y);
        cout << Longest(n1, n2) << endl;
    }

    return 0;
}



Measured memory_bytes: 7000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 998244353
#define MAX 1000000000000
#define N 105
ll w[N],v[N];
ll dp[N][100005];
ll n;
ll solve(ll i,ll val)
{
    if(i==n) return MAX;
    if(dp[i][val]!=-1) return dp[i][val];
    ll ans1=MAX,ans2=MAX,ans3=MAX;
    if(val<=v[i])
    {
        ans1=w[i];
    }
    else{
        ans2=w[i]+solve(i+1,val-v[i]);
    }
    ans3=solve(i+1,val);
  //  cout<<ans1<<gap<<ans2<<gap<<ans3<<endl;
    return dp[i][val]=min(ans1,min(ans2,ans3));
}
int main()
{
    scanf("%d",&n);
    ll W;
    scanf("%lld",&W);
    for(ll i=0;i<n;i++)
    {
        scanf("%lld %lld",&w[i],&v[i]);
    }
    memset(dp,-1,sizeof dp);
    ll ans=0;
    for(ll i=1;i<=100000;i++)
    {
        ll t=solve(0,i);
        if(t<=W) ans=i;
    }
    printf("%lld\n",ans);

}



Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;
bool diff[101][2];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	#define endl '\n'
	int x, n; cin >> x >> n;
	
	bool equal = false;
	for(int i = 0; i < n; i++){
		int p; cin >> p;
		if(x > p)diff[x - p][0] = true;
		else if(x < p)diff[p - x][1] = true;
		else equal = true;
	}
	if(!equal)cout << x << endl;
	else{
		for(int i = 1; i < 100;i++ ){
			if(!diff[i][0]){
				cout << x - i << endl;
				break;
			}
			else if(!diff[i][1]){
				cout << x + i << endl;
				break;
			}
		}
	}
	

}


Measured memory_bytes: 3652
n = int(input())
bs = list(map(int, input().split()))
arr = []
for i in range(n):
    if i == 0 or i == 1:
        arr.append(bs[0])
    else:
        arr.append(bs[i-1])
        if bs[i-1] < arr[i-1]:
            arr[i-1] = bs[i-1]
print(sum(arr))


Measured memory_bytes: 3060
#include<cstdio>

int main(){
  int n,a,b,ans = 0;
  scanf("%d %d %d",&n,&a,&b);
  for(int i=0;i<n;i++){
    int t;
    scanf("%d",&t);
    if(t<a||t>=b) ans++;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
n = gets.to_i
as = gets.split.map(&:to_i)

cs = Hash.new(0)
as.each do |a|
  cs[a] += 1
end

sum = cs.inject(0) do |r, (_k, v)|
  r + v * (v - 1) / 2
end

as.each do |a|
  puts sum - (cs[a] - 1)
end


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

using namespace std;
using ll = long long;
using indx = size_t;
#define endl '\n'

int main() {
    int n, k;
    cin >> n >> k;
    vector<char> d(k);
    for (auto& e : d) cin >> e;

    int ans = n;
    while (true) {
        bool flag = true;
        string s = to_string(ans);
        for (auto& e : d) {
            if (s.find(e) != string::npos) {
                flag = false;
                break;
            }
        }
        if (flag) 
            break;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial, cos, pi, degrees
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

MOD = 10**9 + 7
INF = float('inf')

A, B, H, M = list(map(float, input().split()))

aB = M/60
aA = (H+aB)/12

aB = aB * 2 * pi
aA = aA * 2 * pi

rad = abs(aB - aA)
if rad > pi:
    rad = 2*pi - rad

print(sqrt(A**2+B**2-2*A*B*cos(rad)))


Measured memory_bytes: 9928
m,k = map(int,input().split())

if k>=2**m:
  print(-1)

elif m == 0:
  print(" ".join(["0","0"]))

elif m == 1 and k == 0:
  print("0 0 1 1")

elif m == 1 and k == 1:
  print(-1)

elif m >= 2:
  b = [i for i in range(2**m)]
  b.remove(k)
  c = sorted(b,reverse = True)
  ans = b + [k] + c + [k]
  ans = list(map(str,ans))
  print(" ".join(ans))

Measured memory_bytes: 30476
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    string s; cin >> s;
    int n = s.size();
    bool flag = false;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i]==s[j]){
                flag = true;
                break;
            }
        }
        if(flag){
            break;
        }
    }

    if(flag){
        cout << "no" << endl;
    }else{
        cout << "yes" << endl;
    }
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC085_C solver = new ABC085_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC085_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int y = in.nextInt();

            int ichi = 0;
            int gosen = 0;
            int sen = 0;

            boolean flag = false;

            for (int i = 0; i <= n; ++i) {
                for (int j = 0; j <= n; ++j) {
                    int sum = 10000 * i + 5000 * j + 1000 * (n - i - j);
                    if (sum == y && (n - i - j) >= 0) {
                        ichi = i;
                        gosen = j;
                        sen = n - i - j;
                        flag = true;
                        break;
                    } else flag = false;
                }
                if (flag) break;
                else continue;
            }

            if (flag) {
                out.printf("%d", ichi);
                out.printf(" ");
                out.printf("%d", gosen);
                out.printf(" ");
                out.printf("%d", sen);
            } else out.println("-1 -1 -1 ");
        }

    }
}



Measured memory_bytes: 23380
#include<iostream>
using namespace std;
#include<stdio.h>
int f_r(int d,int x){
x=x+d;
if(x>=600)return 0;
return d*x*x+f_r(d,x);
}
int main(){
int d;
int s;
while((scanf("%d",&d))!=EOF){
s=f_r(d,0);
printf("%d\n",s);
}
return 0;
}

Measured memory_bytes: 1188
import math
n,d = map(int,input().split())
x = [0] * n
for i in range(n):
     x[i] = list(map(int,input().split()))

ans = 0
for i in range(n-1):
     for j in range(i+1,n):
          f = 0
          for k in range(d):
               f += (x[i][k] - x[j][k])**2
          if math.sqrt(f).is_integer():
               ans += 1
               
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

bool valid(const std::vector<int>& x, const std::vector<int>& y,
           const std::vector<int>& h, int Cx, int Cy, int &H) {

  size_t N = x.size();
  {
    int dx = abs(Cx-x[0]);
    int dy = abs(Cy-y[0]);
    H = h[0]+dx+dy;
  }
  for (size_t i = 1; i < N; ++i) {
    int dx = abs(Cx-x[i]);
    int dy = abs(Cy-y[i]);
    if (h[i] == 0) {
      if (H-(dx+dy) > 0) return false;
      continue;
    }
    if (H != h[i]+dx+dy) return false;
  }
  return true;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> x(N), y(N), h(N);
  for (size_t i = 0; i < N; ++i)
    scanf("%d %d %d", &x[i], &y[i], &h[i]);

  for (size_t i = 0; i < N; ++i)
    if (h[i] > 0) {
      std::swap(x[i], x[0]);
      std::swap(y[i], y[0]);
      std::swap(h[i], h[0]);
      break;
    }

  int Cx, Cy, H;
  for (Cx = 0; Cx <= 100; ++Cx)
    for (Cy = 0; Cy <= 100; ++Cy)
      if (valid(x, y, h, Cx, Cy, H))
        return !printf("%d %d %d\n", Cx, Cy, H);

  return 1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<numeric>
#define int long long
#define all(x) x.begin(),x.end()
#define maxn 1000000
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);

void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
void solve() {
 int n,k;
 cin>>n>>k;
 cout<<max((int)0,n-k-k);

}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //cout<<"Hello World"<<"\n";
    //int t;cin>>t;while(t--)
    solve();

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2> *arr=(pair<T1, T2> *) mem;
  for(i=0;i<N;i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
char memarr[96000000];
int N;
int M;
int A[100000];
int B[100000];
int main(){
  int i, j;
  long long res=0;
  wmem = memarr;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  sortA_L(N,A,B);
  for(i=0;i<N;i++){
    j =min_L(B[i], M);
    M -= j;
    res += (long long)A[i] * j;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190227-1 [beta]

// --- original code ---
// int N, M, A[1d5], B[1d5];
// {
//   int i, j;
//   ll res = 0;
//   rd(N,M,(A,B)(N));
//   sortA(N,A,B);
//   rep(i,N){
//     j = min(B[i],M);
//     M -= j;
//     res += (ll)A[i] * j;
//   }
//   wt(res);
// }


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
 
int s_asorts(const void* a, const void* b);
 
//昇順
int s_asorts(const void* a, const void* b) {
    return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
    return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
    return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
    int i;
    rept(i, 0, n) {
        l_cin2(*(a + i), *(b + i));
    }
    return 0;
}
int i_cins(int n, int* a) {
    int i;
    for (i = 0; i < n; i++) {
        i_cin(*(a + i));
    }
 
    return 0;
}
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}
 
long _max(long a, long b) {
    return a > b ? a : b;
}
long _min(long a, long b) {
    return a < b ? a : b;
}
int _swp(int* a, int* b)
{
    int tmp;
    tmp = *b; *b = *a; *a = tmp;
    return 0;
}


int main(){
    ll k;
    ll i=0;
    ll sum=100;
    scanf("%lld",&k);
    while(1){
        sum*=1.01;
        i++;
        if(sum>=k){
            printf("%lld",i);
            return 0;
        }
    }
    
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> num(n);
  for(int i=0;i<n;i++)
    cin >> num.at(i);
  int distance=0;
  for(int i=0;i<n;i++){
    if( num.at(i) > k - num.at(i) )
      distance += (k - num.at(i)) * 2;
    else
      distance += 2 * num.at(i);
  }
  cout << distance << endl;
    
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n, m;
	cin >> n >> m;
	vector<P> bridge(m);
	Rep(i, m){
		int s, t; cin >> s >> t;
		bridge[i] = make_pair(s, t);
	}
	sort(bridge.begin(), bridge.end());
	int ans = 1, cut = bridge[0].second - 1;
	Rep(i, m){
		if(bridge[i].first <= cut){
			if(bridge[i].second < cut){
				cut = bridge[i].second - 1;
			}
			continue;
		}else{
			cut = bridge[i].second - 1;
			ans += 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
typedef long long ll;
#include "bits/stdc++.h"
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<ll> l(n);
	for (int i = 0; i < n; i++)
	{
		cin >> l[i];
	}
	sort(l.rbegin(), l.rend());
	int sum = 0;
	for (int i = 1; i < n; i++)
	{
		sum += l[i];
	}
	if (l[0] < sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next().replaceAll("1", "a").replaceAll("9", "1").replaceAll("a", "9");
        
		System.out.println(a);
	}
}

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

int main(){
  string s,t,u;
  cin >> s >> t;
  u=t.substr(0,t.size()-1);
  if(s==u){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){
  int n;
  cin >> n;
  bool c[8];
  int temp;
  int count = 0;
  for(int i = 0; i < 8; i++) c[i] = false;
  for(int i = 0; i < n; i++){
    cin >> temp;
    temp /= 400;
    if(temp < 8)
      c[temp] = true;
    else count++;
  }
  temp = 0;
  for(int i = 0; i < 8; i++) if(c[i]) temp++;
  int ansmin = max(temp, 1);
  int ansmax = temp + count;
  cout << ansmin << " " << ansmax << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>


long long int fizzbussSum(int n) {
	long long int sum = 0;

	for (int i = 1; i < n+1; i++) {
		if (i % 3 == 0 || i % 5 == 0) {

		} else {
			sum+=i;
		}
	}
	return sum;
}


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

	std::cout << fizzbussSum(N) << std::endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define endl "\n"
#define ioss ios::sync_with_stdio(false);cin.tie(NULL);
typedef  long long ll;
using namespace std;


int main()
{
	ioss	
	int arr[2]={0,0};
  	int a;
  for(int i=0;i<3;i++)
  {
    cin>>a;if(a==5)arr[0]++;
    else if(a==7)arr[1]++;
  }
  if(arr[0]==2&&arr[1]==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int X[100000+1] = {0};
    int N;
    cin >> N;
    int ans = 0;
    for ( int i = 0; i < N; i++ ) {
        long long a;
        cin >> a;
        if ( a > 100000 ) { ans++; }
        else { X[a]++; }
    }
    for ( int i = 1; i <= 100000; i++ ) {
        if ( X[i] < i ) { ans += X[i]; }
        else if ( X[i] > i ) { ans += X[i] - i; }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

string stra;
string strb;
	
int	hikaku (int eda){
	int i,j;
	if(eda+1<strb.length()){
		
//		cout<<eda<<" "<<strb.length()<<endl;
				return -1;
	}

	
	j=strb.length()-1;
	for(i=eda;i>-1;i--){
		if(stra[i]==strb[j]||stra[i]=='?'){
			j--;
//			cout<<j<<"  SSSS"<<endl;
			
			if(j==-1)
				return 1;
		}else{
			return 0;
		}
	}
	return 1;
}
void outputstr(int eda){
	int i;
	
	
//	eda-strb.length()+1;
//	eda
		
	for(i=0;i<eda-strb.length()+1;i++){
		if(stra[i]=='?'){
			cout<<'a';
		}else{
			cout<<stra[i];
		}
	}
	
	cout<<strb;
	
	for(i=eda+1;i<stra.length();i++){
		if(stra[i]=='?'){
			cout<<'a';
		}else{
			cout<<stra[i];
		}
	}	
	cout<<endl;
	
}
int main(){
	int i;

	while (cin>>stra>>strb){
		
		if(stra.length()<strb.length()){
			cout<<"UNRESTORABLE"<<endl;
			
			
		}else{
			
			for(i=stra.length()-1;i>-1;i--){
				if(-1==hikaku(i)){
					cout<<"UNRESTORABLE"<<endl;
					goto END;
				}else if(0==hikaku(i)){
					;
				}else if(1==hikaku(i)){
					outputstr(i);
					goto END;
				}
			}
		}
		
		END:
			;
	}

	return 0;
}

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

int main(){
	
	int N;
	string str;
	cin >> N;
	
	while(N--){
		cin >> str;
		for( int i=0 ; i<str.size() ; i++ ){
			for( int j=i+1 ; j<str.size() ; j++ ){
				if( str[i] < str[j] ) swap( str[i] , str[j] );
			}
		}
		
		int p = 1;
		int numA = 0 ,numB = 0;
		for( int i=0 ; i<str.size() ; i++ ){
			numA += (str[i]-'0')*p;
			numB += (str[str.size()-i-1]-'0')*p;
			p*=10;
		}
		
		cout << numB - numA << endl ;
	}
	
	return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		int n = (int)Math.sqrt(N);
		for (int i=n; i>=1; i--) {
			if ( N%i==0 ) {
				System.out.println(String.valueOf(N/i).length());
				break;
			}
		}
	}
}


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

int main(){
  int n;
  cin>>n;
  if(n>=100000)
    cout<<90909;
  else if(n>=10000)
    cout<<n-9090;
  else if(n>=1000)
    cout<<909<<endl;
  else if(n>=100)
    cout<<n-90<<endl;
  else if(n>=10)
    cout<<9<<endl;
  else
    cout<<n<<endl;
    
    
  
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long m,k;
  cin >> m >> k;
  if(m==0){
    if(k==0){
      cout << "0 0\n";
    }else{
      cout << "-1\n";
    }
  }else if(m==1){
    if(k==0){
      cout << "0 0 1 1\n";
    }else{
      cout << "-1\n";
    }
  }else{
    if(pow(2ll,m)<=k){
      cout << "-1\n";
    }else{
      for(int i=0;i<pow(2,m);i++){
        if(i!=k){
          cout << i << ' ';
        }
      }
      cout << k << ' ';
      for(int i=pow(2,m)-1;i>=0;i--){
        if(i!=k){
          cout << i << ' ';
        }
      }
      cout << k << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF MOD
typedef long long ll;
typedef pair<int,int> P;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
//#define int long long 

/*Prim部分*/

vector<pair<int,int>> G[214514];//firstがコスト、secondが行き先

int prim(void){
    priority_queue<P,vector<P>,greater<P>> que;
    bool used[114514]={};
    int res=0;
    que.push({0,0});
    while(!que.empty()){
        P e = que.top();
        que.pop();
        if(used[e.second]==false){
            used[e.second]=true;
            REP(i,G[e.second].size()){
                que.push({G[e.second][i].first,G[e.second][i].second});
            }
            res += e.first;
        }
    }
    return res;
}

/*Prim部分　おわり*/

/*Build?部分*/
struct machi{
  int x,y,num;  
};

bool compx(machi F,machi G){
    if(F.x!=G.x){
        return F.x<G.x;
    }else{
        return F.y<G.y;
    }
}
bool compy(machi F,machi G){
    if(F.y!=G.y){
        return F.y<G.y;
    }else{
        return F.x<G.x;
    }
}


machi city[114514];

/*Build?部分　おわり*/


signed main(){
    int N,x,y;
    cin >> N;
    REP(i,N){
        cin >> x >> y;
        city[i].x = x;
        city[i].y = y;
        city[i].num = i;
    }
    sort(city,city+N,compx);
    REP(i,N-1){
        G[city[i].num].push_back(make_pair(min(abs(city[i].x-city[i+1].x),abs(city[i].y-city[i+1].y)),city[i+1].num));
        G[city[i+1].num].push_back(make_pair(min(abs(city[i].x-city[i+1].x),abs(city[i].y-city[i+1].y)),city[i].num));
        
    }
    sort(city,city+N,compy);
    REP(i,N-1){
        G[city[i].num].push_back(make_pair(min(abs(city[i].x-city[i+1].x),abs(city[i].y-city[i+1].y)),city[i+1].num));
        G[city[i+1].num].push_back(make_pair(min(abs(city[i].x-city[i+1].x),abs(city[i].y-city[i+1].y)),city[i].num));
    }
    int Ans= prim();
    
    cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 14328
import sys
import math
input = sys.stdin.readline

_a, _b, _x = map(int, input().split())


def chker(a, b, x):
    th = (a ** 2 * b / 2)
    if x == th:
        print(math.degrees(math.acos(a / (a ** 2 + b ** 2) ** 0.5)))
    elif x < th:
        c = 2 * x / (a * b)
        print(math.degrees(math.acos(c / (c ** 2 + b ** 2) ** 0.5)))
    else:
        c = 2 * b - 2 * x / a ** 2
        print(math.degrees(math.atan(c / a)))


chker(_a, _b, _x)


Measured memory_bytes: 3064
//warito_kousoku

using System;

namespace ASDS1_4_wariate_
{
    class Program
    {
        class hikkoshi
        {
            public int P;
            public int k;
            public int[] A;
            public hikkoshi(int P,int k,int[] A)
            {
                this.P = P;
                this.k = k;
                this.A = A;
            }

        }

        static void Main(string[] args)
        {
            var input = getsplit();
            int n = getint(input[0]);
            int k = getint(input[1]);
            var A = new int[n];
            int sum = 0;
           

            for (int i = 0; i < n; i++)
            {
                A[i] = getint(Console.ReadLine());
                sum += A[i];
            }

            Console.WriteLine(BinarySearch(sum,k,A));


        }
        static bool check(hikkoshi a)
        {
            
            int stack= 0;
            int track = 1;

            foreach (var s in a.A)
            {
                if (stack+s <= a.P)
                {
                    stack += s;
                   
                }
                else
                {
                    if (s > a.P ||track == a.k)
                    {
                        return false;
                    }
                    else
                    {
                        track++;
                        stack = s;
                    }
                }
            }
            return true;
        }

        static int BinarySearch(int sum,int k,int[] A)
        {
            int left = 0;
            int right = sum;
            int mid;

            while (left < right)
            {
                mid = (left + right) / 2;
                hikkoshi Z = new hikkoshi(mid,k,A);
              

                if (check(Z))
                {
                    right = mid;
                }
                
                else
                {
                    left = mid + 1;
                }
            }
            return right;
        }




        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint(string a)
        {
            int x = int.Parse(a);
            return x;
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> p;


int main(void)
{
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll tmp = a - b;
  ll hoge = pow(10, 18);
  if (abs(tmp) > hoge) {
    cout << "Unfair" << endl;
  }else if (k % 2 == 0){
    cout << tmp << endl;
  }else{
    cout << tmp * -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


class UnionFind3:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2


n, k, l = map(int, input().split())
ufd, ufr = UnionFind3(n), UnionFind3(n)
for _ in range(k):
    p, q = map(int, input().split())
    ufd.union(p - 1, q - 1)
for _ in range(l):
    r, s = map(int, input().split())
    ufr.union(r - 1, s - 1)
d = defaultdict(int)
for i in range(n):
    d[ufd.root(i), ufr.root(i)] += 1
print(*(d[ufd.root(i), ufr.root(i)] for i in range(n)))


Measured memory_bytes: 41576
from collections import defaultdict

N, K = [int(x) for x in input().split()]
S = input()

ans = S
target_char = S[0]
replacing = False
for i in range(N):
    if S[i] != target_char:
        ans = ans[0:i] + target_char + ans[i + 1:]
        replacing = True
    else:
        if replacing:
            K -= 1
            replacing = False
    if K == 0:
        break

score = 0
for i in range(N):
    if i != 0 and ans[i] == 'L' and ans[i - 1] == 'L':
        score += 1
    if i != N - 1 and ans[i] == 'R' and ans[i + 1] == 'R':
        score += 1

print(score)




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

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;

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

    vector<int> a(n);

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

    sort(a.begin(),a.end(),greater<int>());

    int ans = 0;
    for(int i = 0;i < n;i++){
        if(i % 2 == 0){
            ans += a[i];
        } else {
            ans -= a[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    char input[20] = {}, *str;
    unsigned short int cnt = 0;
    scanf("%s", input);
    str = input;
    while ( *str != 0 ) { cnt++; str++; }
    str--;
    while ( cnt != 0 ) {
        printf("%c", *str);
        cnt--; str--;
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String S  = scan.next();
		int N = S.length();
		int f = 0;

		for (int i = 0; i < N/2; i++) {
			if (S.charAt(i) != S.charAt(N-1-i)) {
				f++;
				break;
			}
		}

		for (int i = 0; i < N/4; i++) {
			if (S.charAt(i) != S.charAt((N-3)/2 - i)) {
				f++;
				break;
			}
		}

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

	}

}

Measured memory_bytes: 35624
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define inf 200000000000
const int maxnodes=1005;
#define ll long long
#define N 101
#define EPS 0.01
#define ld long double

int32_t main()
{
    IOS;

    map<vector<int>,int> m;
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        string s;
        cin >> s;
        vector<int> v(26,0);
        for(int j = 0;j < s.length();j++)
        {
            v[s[j]-'a']++;
        }
        ans += m[v];
        m[v]++;
    }
    cout << ans;
}   

Measured memory_bytes: 29952
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> A;
bool f(int n) {
	if (n <= 0) return false;
	if (n > N) return true;
	int x = N-1 - n;
	long long s = A[x];
	for (int i = 0; i < N; ++ i) if (i != x) {
		if (A[i] > 2*s) return false;
		s += A[i];
	}
	return true;
}
int main() {
	cin >> N;
	A.resize(N);
	for (auto& x : A) cin >> x;
	sort(A.begin(), A.end());
	int l = 0, r = N+1;
	while (r - l >= 2) {
		int m = (l+r)/2;
		if (f(m)) l = m; else r = m;
	}
	cout << r << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
//const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

bool is_in(pii c, pii p, int r){
    
    
    return pow((p.first - c.first),2) + pow((p.second - c.second),2) <= r*r;
    
}


int main() {
    int n,m,d;cin>>n>>m>>d;
    
    double av = 0;
    
    //given dの数は (n, n-d),...(d+1,1), (1,d+1),...,(n-d,n)の 2(n-d)通り

    if(d==0){
        av = 1/(double)n;
    }else{
        av = 2*(double)(n-d)/((double)n * (double)n);
    }
    printf("%.10lf\n",av * (m-1));
    
    return 0;
}
















Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int h;
	while (h = readln.chomp.to!int, h) {
		auto field = new int[][](h, 5);
		foreach (i; 0..h) {
			field[i] = readln.chomp.split.map!(to!int).array;
		}
		int score;
		while (1) {
			bool f;

			foreach (i; 0..h) {
				foreach (j; 0..4) {
					auto num = field[i][j];
					if (!num) continue;
					auto cnt = 1;
					foreach (k; j+1..5) {
						if (field[i][k] == num) cnt++;
						else break;
					}
					if (cnt >= 3) {
						score += num * cnt;
						f = 1;
						foreach (k; j..j+cnt) {
							field[i][k] = 0;
						}
						break;
					}
				}
			}

			foreach (i; 0..5) {
				foreach (j; 1..h) {
					if (field[j][i]) continue;
					foreach_reverse (k; 1..j+1) {
						field[k][i] = field[k-1][i];
					}
					field[0][i] = 0;
				}
			}
			if (!f) break;
		}
		score.writeln;
	}
}

Measured memory_bytes: 2028
#include <stdio.h>
#include <string.h>

int main(void)
{
    char contest[4];

    fgets(contest, 4, stdin);
    contest[strcspn(contest, "\n")] = '\0';

    if (strcmp(contest, "ABC") == 0)
        puts("ARC");
    if (strcmp(contest, "ARC") == 0)
        puts("ABC");

    return 0;
}

Measured memory_bytes: 1492