akhauriyash/Code-Regression huggingface dataset:
class DisjointSet:
    def __init__(self):
        self.rank = {}
        self.p = {}

    def makeSet(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if x == y:
            return
        if(self.rank[x] > self.rank[y]):
            self.p[y] = x
        else:
            self.p[x] = y
            if(self.rank[x] == self.rank[y]):
                self.rank[y] += 1

    def findSet(self, x):
        if(x != self.p[x]):
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]



N, M = map(int, input().split())

ds = DisjointSet()
for i in range(N):
    ds.makeSet(i+1)

for i in range(M):
    X, Y, Z = map(int, input().split())
    ds.unite(X, Y)

ans = set()

for i in range(1, N+1):
    a = ds.findSet(i)
    ans.add(a)

print(len(ans))

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    int answer = 0;
    for (int i = 0; i <= min(n, k); ++i) {
        for (int j = 0; j <= i; ++j) {
            vector<int> d;
            int sum = 0;
            for (int l = 0; l < i - j; ++l) {
                sum += v[l];
                d.push_back(v[l]);
            }
            for (int l = 0; l < j; ++l) {
                sum += v[n - 1 - l];
                d.push_back(v[n - 1 - l]);
            }
            sort(d.begin(), d.end());
            for (int l = 0; l < d.size() && l < k - i; ++l) {
                if (d[l] < 0) sum -= d[l];
            }
            answer = max(answer, sum);
        }
    }
    cout << answer << endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);

  int i,N; cin >> N;
  string s;
  int ans[4] = {0,0,0,0};
  rep(i,N){
      cin >> s;
      if(s=="AC"){ans[0]++;}
      if(s=="WA"){ans[1]++;}
      if(s=="TLE"){ans[2]++;}
      if(s=="RE"){ans[3]++;}
  }
  cout << "AC x " + to_string(ans[0]) << endl;
  cout << "WA x " + to_string(ans[1]) << endl;
  cout << "TLE x " + to_string(ans[2]) << endl;
  cout << "RE x " + to_string(ans[3]) << endl;

  return 0;
}


Measured memory_bytes: 3716
//
// Created by moono on 2018/10/27.
//

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


int main() {
    int N, X, n, min_n=1001;
    cin >> N >> X;

    //
    for (int i = 0; i < N; ++i) {
        cin >> n;
        X -=n;
        if(n < min_n) min_n = n;
    }

    //
    N+= X / min_n;

    //
    cout << N << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
	while(1){
		int H,W;
		cin>>H;
		cin>>W;
		if(H==0&&W==0){
			break;
		}else{
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					int u;
					u=i+j;
					if(u%2==0){
						printf("#");
					}else{
						printf(".");
					}
				}
			cout<<endl;
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#pragma warning(disable:4996)

#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  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 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 _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}

#pragma endregion


#include <stdio.h>

#include<stdio.h>
int main()
{
	int x, a, b, c, i, j, k, cnt = 0;

	i_cin4(a, b, c, x);

	for (i = 0; i <= a; i++)
		for (j = 0; j <= b; j++)
			for (k = 0;k <= c; k++)
				if (500 * i + 100 * j + 50*k == x)
					cnt++;
	i_cout(cnt);
	return 0;
}



Measured memory_bytes: 128
#include <cstdio>
int ans = 0;
char s[5];
int main()
{
	scanf("%s", s);
	for (int i = 0; i <= 3; i++)
	{
		if (s[i] == '+') ans++;
		else ans--;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 3e5 + 7, MOD = 998244353;
string s;
vector <int> a[3];
int type(char c) {
    if (c == 'R') return 0;
    else if (c == 'G') return 1;
    else return 2;
}   
int n, lmao_rofl[N], curva[4];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> s;
    for (int i = 0; i < n * 3; ++i) a[type(s[i])].app(i);
    for (int i = 0; i < 3; ++i) sort(all(a[i]));
    for (int i = 0; i < n; ++i) {
        vector <int> t;
        for (int j = 0; j < 3; ++j) t.app(a[j][i]);
        sort(all(t));
        for (int j = 0; j < 3; ++j) lmao_rofl[t[j]] = j;
    }   
    int ans = 1;
    curva[0] = n;
    for (int i = 0; i < 3 * n; ++i) {
        ans = (ans * curva[lmao_rofl[i]]) % MOD;
        --curva[lmao_rofl[i]]; ++curva[lmao_rofl[i] + 1];
    }   
    cout << ans << '\n';
}

Measured memory_bytes: 5764
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pil pair<int,along long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define pb push_back
#define mk make_pair
#define maxn 2009
#define eps 1e-12
using namespace std;
vector<int> g[maxn];
int depth[maxn],k;
ll ans=0;
inline void dfs(int pos,int prev)
{
	depth[pos]=depth[prev]+1;
	if(depth[pos]>(k/2))
	{
		ans++;
	}
	for(int i=0;i<g[pos].size();i++)
	{
		if(g[pos][i]!=prev)
		{
			dfs(g[pos][i],pos);
		}
	}
}
ll ans1=0;
inline void dfs1(int pos,int prev)
{
	depth[pos]=depth[prev]+1;
	if(depth[pos]>(k/2))
	{
		ans++;
	}
	if(depth[pos]>(k/2)+1)
	{
		ans1++;
	}
	for(int i=0;i<g[pos].size();i++)
	{
		if(g[pos][i]!=prev)
		{
			dfs1(g[pos][i],pos);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n>>k;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	if(k==1)
	{
		cout<<n-2<<"\n";
		return 0;
	}
	ll fans=n;
	if(k%2==0)
	{
		for(int i=1;i<=n;i++)
		{
			depth[0]=-1;
			dfs(i,0);
			fans=min(fans,ans);
			//cout<<ans<<"\n";
			ans=0;
			memset(depth,0,sizeof(depth));
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			ll tans=0;
			ll tans2=0;
			for(int j=0;j<g[i].size();j++)
			{
				dfs1(g[i][j],i);
				tans+=ans;
				tans2=max(tans2,ans-ans1);
				ans=0;
				ans1=0;
			}
			//cout<<tans<<" "<<tans2<<"\n";
			fans=min(fans,tans-tans2);
			memset(depth,0,sizeof(depth));
		}
	}
	cout<<fans<<"\n";
}

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

int main() {
  int n;
  cin >> n;
  vector<int> fib(n + 1);
  fib[0] = 1;
  fib[1] = 1;
  rep(i, n - 1) fib[i + 2] = fib[i + 1] + fib[i];
  cout << fib[n] << endl;
  return 0;
}


Measured memory_bytes: 3080
import numpy as np

N = np.array(list(map(int, list(input()))))

m = len(N)

A = np.array([i%2 for i in range(m)])
B = np.array([1 if i == 0 else 0 for i in A])

AA = np.count_nonzero((A-N) == 0)
BB = np.count_nonzero((B-N) == 0)

if AA > BB:
  print(m - AA)
else:
  print(m - BB)


Measured memory_bytes: 15684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;

class person {
  public:
    string cards;
    int head=0;

    bool isEmpty() {return head == cards.size();}

    char dequeue() {
      head++;
      return cards.at(head-1);
    }

    void input(string input) {cards=input;}
};

int main() {
  person a, b, c, *pp=0;
  char turn;
  string inputA, inputB, inputC;

  cin >> inputA >> inputB >> inputC;

  a.input(inputA);
  b.input(inputB);
  c.input(inputC);

  turn = 'a';

  while (true) {
    switch (turn) {
      case 'a':
        pp = &a;
        break;
      case 'b':
        pp = &b;
        break;
      case 'c':
        pp = &c;
        break;
    }

    if(pp->isEmpty()) break;
    turn = pp->dequeue();
  }

  switch (turn) {
  case 'a':
    cout << 'A' << endl;
    break;
  case 'b':
    cout << 'B' << endl;
    break;
  case 'c':
    cout << 'C' << endl;
    break;
  }
}

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

int main()
{
    int n,m;
    std::cin >> n >> m;
    std::vector<long long> a(m),b(m),c(m);
    for(int i = 0; i < m; i++){
        std::cin >> a[i] >> b[i];
        for(int j = 0; j < b[i]; j++){
            int t; std::cin >> t; t--;
            c[i] |= (1 << t);
        }
    }

    std::vector<std::vector<long long>> dp(m+10,std::vector<long long>(1 << n, 1000000000000000)); // dp[i][j] : i個目まで使った時のjで表される集合の最小コスト
    dp[0][0] = 0;

    for(int i = 0; i < m; i++){
        for(int j = 0; j < (1 << n); j++){
            dp[i + 1][j]= std::min(dp[i][j], dp[i + 1][j]);
            dp[i + 1][j | c[i]] = std::min(dp[i + 1][j | c[i]], dp[i][j]+ a[i]);
        }
    }
    std::cout << (dp[m][(1 << n) - 1] < 1000000000000000 ? dp[m][(1 << n) - 1] : -1) << std::endl;
}

Measured memory_bytes: 32640
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   map<string,int> mymap;
   int max=0;
   int fre=-100000000;
   string str;
   string str_max;
   string str_fre;
   while(cin>>str)
   {
     if(str.length()>max) 
     {
       max=str.length();
       str_max=str;                     
     }             
     mymap[str]++;      
   }             
   map<string,int>::iterator  iter;  
   for(iter = mymap.begin();iter!= mymap.end(); iter++)  
   {  
     if(iter->second>fre) 
     {
       str_fre=iter->first;
       fre=iter->second;                     
     }  
   }  
   cout<<str_fre<<" "<<str_max<<endl;
   //while(1);     
   return 0;  
 }
 

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define pb push_back
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}

int a[maxn];

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
    int n; cin >> n;
    for (int i = 0; i <n; i++) {
        int l, r; cin >> l >>r;
        a[l]++;
        a[r + 1]--;
    }
    int now = 0;
    int cnt = 0;
    for (int i = 0; i < maxn; i++) {
        now += a[i];
        if (now > 0)cnt++;
    }
    cout <<cnt <<endl;
    return 0;
}


Measured memory_bytes: 640
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static PrintWriter out = new PrintWriter(System.out);
    static String file = "../in";
    static int test = 10; // 0 for local testing, 1 for std input
    static int inf = 1_000_000, mod = 1_000_000_007;

    void swap(int[]ary, int i, int j)
    {
        int t = ary[i];
        ary[i] = ary[j];
        ary[j] = t;
    }
    
    String[] split() throws Exception
    {
        return in.readLine().split(" ");
    }

    int readInt() throws Exception
    {
        return Integer.valueOf(in.readLine());
    }

    long[] toLongArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        long[] ary = new long[n];
        for(int i = 0; i < n; i++) ary[i] = Long.valueOf(sp[i]);
        return ary;
    }

    int[] toIntArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        return ary;
    }

    String reverse(String str)
    {
        return new StringBuilder(str).reverse().toString();
    }


    long pow(long a, int pow)
    {
        long res = 1;
        while(pow > 0)
        {
            if(pow % 2 != 0) {
                res *= a;
                res %= mod;
            }
            a = a * a;
            a %= mod;
            pow /= 2;
        }

        return res;
    }

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
        // System.out.println((-100 + 0) / 2);

        
        new Main().a();

        
        out.flush();
    }

    void a() throws Exception
    {
        int[] ary = toIntArray();
        int a = ary[0], b = ary[1];

        int re = a * (a - 1) / 2 + b * (b - 1) / 2;

        // int[] nums = new int[210];
        // for(int i = 0; i < a; i++) nums[i] = 2;
        // for(int i = a; i < a + b; i++) nums[i] = 1;

        // for(int i = 0; i < a + b; i++)
        // {
        //     for(int j = i + 1; j < a + b; j++)
        //     {
        //         int sum = nums[i] + nums[j];
        //         if(sum % 2 == 0) re++;
        //     }
        // }

        out.println(re);
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define full(a) a.begin(),a.end()
#define stoink stack<ll>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define vgw vector<vector<pair<ll,ll> >
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
int main() {
 ll n,a,b;
 cin >> n >> a >> b;
 if ( (abs(b - a)) % 2 == 0)
    cout<< (abs(b - a))/2;
 else
 {
    cout<<min(a-1,n-b) + (b - a)/2 +1;
 }
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(void){
	int n,i;
	ll a[100100],t,itr[100100],tmp=-1,cnt=0,dft=-1,ans;
	cin >> n >> t;
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	for(i=(n-1); i>=0; i--){
		if(tmp<a[i]){
			itr[i] = a[i];
			tmp = a[i];
		}else{
			itr[i] = tmp;
		}
		itr[i] -= a[i];
	}
	for(i=0; i<n; i++){
		dft = max(dft,itr[i]);
	}
	for(i=0; i<n; i++){
		if(dft==itr[i]){
			cnt++;
		}
	}
	// ans = min(t,cnt);
	ans = cnt;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = 0;
		int[] coin = new int[3];
		for(int i = 0; i < 3; i++) {
			coin[i] = sc.nextInt();
		}
		int x = sc.nextInt();
		for(int t = 0; t <= coin[0]; t++) {
			for(int j = 0; j <= coin[1]; j++) {
				for(int k = 0; k <= coin[2]; k++) {
					int sum = 500 * t + 100 * j + 50 * k;
					if(sum == x) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23252
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 200005
using namespace std;
int n,ll,rr;
long long a[MN],ans=1e18;
long long solve(int mid){
	long long lst=1e18;
    int l=mid-1,r=n-1;
    for (int i=ll;i<mid;i++){
        long long tmp=abs(a[mid]-a[i]-a[i]);
        if (tmp>=lst){l=i-1;break;}lst=tmp;
    }lst=1e18;
    for (int i=rr;i<n;i++){
        long long tmp=abs(a[n]-a[i]-(a[i]-a[mid]));
        if(tmp>=lst){r=i-1;break;}lst=tmp;
    }rr=r,ll=l;return max(max(max(a[n]-a[r],a[r]-a[mid]),a[mid]-a[l]),a[l])-min(min(min(a[n]-a[r],a[r]-a[mid]),a[mid]-a[l]),a[l]);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),a[i]+=a[i-1];
	for(int i=2;i<n-1;i++)ans=min(ans,solve(i));
	printf("%lld\n",ans);
}


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

int main(){
  char C[3];
  int AC=0;
  int WA=0;
  int TLE=0;
  int RE=0;
  int k=0;
  int N=0;
  k = scanf("%d", &N);
  for (int i=0; i<N; i++){
    k = scanf("%s", C);
    if (strcmp(C, "AC")==0){
      ++AC;
    }else if (strcmp(C, "WA")==0){
      ++WA;
    }else if (strcmp(C, "TLE")==0){
      ++TLE;
    }else{
      ++RE;
    }

  }

  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", AC, WA, TLE, RE);

  return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, K, L = 0;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {cin >> H.at(i);}
  sort(H.begin(), H.end());
  if (N <= K) {cout << 0 << endl;}
  else {
    for (int i = 0; i < N - K; i++) {L += H.at(i);}
    cout << L << endl;
  }
}

Measured memory_bytes: 4048
#include<iostream>
#include<algorithm>
#define ll long long int
using namespace std;
ll N,K;
int main()
{
	ll res=0,maxy;
	cin>>N>>K;
	if (K==0)cout<<N*N<<endl;
	else
	{
		for (ll i=K;i<N;i++)
		{
			res+=N-i;
			res+=(N/(i+1)-1)*(i-K+1);
			//cout<<N-i<<" "<<(N/(i+1)-1)*(i-K+1)<<" "<<max(N%(i+1)-K+1,(ll)0)<<endl;
			if (N%(i+1)!=0)res+=max(N%(i+1)-K+1,(ll)0);
		}
		cout<<res<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int vtx = 0;
    int mx = -1000001;
    int idx = -1;
    rep(i, N)
    {
        if (S.at(i) == 'E')
        {
            vtx++;
        }
        else
        {
            vtx--;
        }
        if (mx < vtx)
        {
            mx = vtx;
            idx = i;
        }
    }
    int ans = 0;
    rep(i, idx)
    {
        if (S.at(i) == 'W')
        {
            ans++;
        }
    }
    rep2(i, idx + 1, N)
    {
        if (S.at(i) == 'E')
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 900
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  uint32_t a, b, c;
  cin >> a >> b >> c;

  uint32_t m = a + b;

  m = min(m, b + c);
  m = min(m, a + c);
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

vector<ll> vll;
ll num[ten52];

int main(void)
{
    ll m,n,i,j,k=1,k1=-1,d=0,d1=0,sum=0,sum2=0;
    string s,s1;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        d+=m;
        d1+=m;
        if((i%2) && d>-1)
        {
            sum+=abs(d+1);
            d=-1;
        }
        else if(!(i%2) && d<1)
        {
            sum+=abs(1-d);
            d=1;
        }
        if(!(i%2) && d1>-1)
        {
            sum2+=abs(d1+1);
            d1=-1;
        }
        else if((i%2) && d1<1)
        {
            sum2+=abs(1-d1);
            d1=1;
        }
    }
    cout<<min(sum,sum2);
    return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <sstream>
#include <vector>

struct Node{
    int id;
    int left;
    int right;

    int parent;
    int sibling;
    int degree;
    int depth;
    int height;
};

std::string get_type(Node& node){
    if(node.parent == -1) return "root";
    if(node.right >= 0 || node.left >= 0) return "internal node";
    return "leaf";
}

void to_str(std::stringstream& ss, Node& n){
    ss << "node " << n.id << ": ";
    ss << "parent = " << n.parent << ", ";
    ss << "sibling = " << n.sibling << ", ";
    ss << "degree = " << n.degree << ", ";
    ss << "depth = " << n.depth << ", ";
    ss << "height = " << n.height << ", ";
    //ss << "left = " << n.left << ", ";
    //ss << "right = " << n.right << ", ";
    ss << get_type(n) << std::endl;
}

int trace_depth(std::vector<Node>& nodes, Node& node){
    if(node.depth >= 0){
        ; // pass
    }else if(node.parent == -1){
        node.depth = 0;
        return 0;
    }else{
        int p = trace_depth(nodes, nodes[node.parent]);
        node.depth = p + 1;
    }
    return node.depth;
}

int trace_height(std::vector<Node>& nodes, Node& node){
    if(node.height >= 0){
        ; // pass
    }else if(node.left == -1 && node.right == -1){
        node.height = 0;
    }else{
        int ld = -1, rd = -1;
        ld = node.left >= 0 ? trace_height(nodes, nodes[node.left]) : -1;
        rd = node.right >= 0 ? trace_height(nodes, nodes[node.right]) : -1;
        node.height = ld > rd ? ld + 1 : rd + 1;
    }
    return node.height;
}

int main(int argc, char **argv){
    int N;
    std::cin >> N;

    std::vector<Node> nodes(N);
    
    for(int i = 0; i < N; i++){
        int id, l, r;
        std::cin >> id >> l >> r;
        nodes[id].id = id;
        nodes[id].left = l;
        nodes[id].right = r;
        nodes[id].parent = -1;
        nodes[id].sibling = -1;
        nodes[id].degree = -1;
        nodes[id].depth = -1;
        nodes[id].height = -1;
    }

    for(int i = 0; i < N; i++){
        int d = 0;
        if(nodes[i].left >= 0){
            nodes[nodes[i].left].parent = nodes[i].id;
            d++;
        }
        if(nodes[i].right >= 0){
            nodes[nodes[i].right].parent = nodes[i].id;
            d++;
        }
        nodes[i].degree = d;      
    }
    
    int max_depth = -1;
    for(int i = 0; i < N; i++){
        if(nodes[i].parent >= 0){
            if(nodes[nodes[i].parent].left != i){
                nodes[i].sibling = nodes[nodes[i].parent].left;
            }else{
                nodes[i].sibling = nodes[nodes[i].parent].right;
            }
        }
        trace_depth(nodes, nodes[i]);
        trace_height(nodes, nodes[i]);
    }

    std::stringstream ss;
    for(auto& n: nodes){
        to_str(ss, n);
    }

    std::cout << ss.str();
    
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
void dfs(vector<int>& result,int curr,vector<vector<int>>& mp,vector<int>& arr,int& rank){
  if(result[curr]!=-1 || rank<0){
    return ;
  } else {
    result[curr] = arr[rank];
    rank--;
    for(auto i:mp[curr]){
      dfs(result,i,mp,arr,rank);
    }
  }
}
int main(){
  int n;
  cin>>n;
  vector< vector<int> > mp(n+1);
  int a,b;
  for(int i=0;i<n-1;++i){
    cin>>a>>b;
    mp[a].push_back(b);
    mp[b].push_back(a);
  }
  
  vector<int> arr(n);
  for(int i=0;i<n;++i){
    cin>>arr[i];
  }
  
  int resultSum = 0;
  sort(arr.begin(),arr.end());
  for(int i=0;i<n-1;++i){
    resultSum += arr[i];
  }
  
  vector<int> result(n+1,-1);
  int rank = n-1;
  dfs(result,1,mp,arr,rank);
  
  cout<<resultSum<<endl;
  for(int i=1;i<=n;++i){
    cout<<result[i]<<" ";
  }
  cout<<endl;
  
  return 0;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int dp[100005];
int n;
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
  cin>>n;

  for(int i=0;i<n;i++)dp[i]=-1;
  vector<int> v;
  v.push_back(1);
  for(int i=1;i<=6;i++){v.push_back(pow(6, i));v.push_back(pow(9, i));};
  queue<int> q;
  q.push(n);
  q.push(0);
  dp[n]=0;
  while(q.size()) {
    int amount = q.front();q.pop();
    int cnt = q.front();q.pop();
    for(int i=0;i<v.size();i++){
      int rest = amount - v[i];
      if(rest < 0)continue;
      if(dp[rest]==-1||dp[rest] + 1 <= dp[rest]){
        dp[rest] = dp[amount] + 1;
        q.push(rest);q.push(cnt+1);
      }
    }
  }

  cout<<dp[0]<<endl;

  return 0;
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;
const int LEN = 2e3 + 10;
int ans[LEN];

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            int distance = min(j - i, abs(X - i) + abs(Y - j) + 1);
            ans[distance] += 1;
        }
    }
    for (int i = 1; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            String pref = in.next();
            String suf = in.next();

            for (int len = N; len > 0; len--) {
                String f = pref.substring(N - len);
                String s = suf.substring(0, len);
                if (f.equals(s)) {
                    out.println(2 * N - len);
                    return;
                }
            }
            out.println(2 * N);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


Measured memory_bytes: 8528
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL d[201][201];
int N,M;
int R;
int r[10];

LL dfs(int v,LL x,LL cost){
   if(x==((1<<R)-1)){
      return cost;
   }
   LL now=1e12;
   REP(i,R){
       if((x>>i)&1){
       }else{
          now=min(now,dfs(i,x|(1<<i),cost+d[r[v]][r[i]]));
       }
   }
   return now;
}

int main(){
    REP(i,201){
        REP(j,201){
            d[i][j]=1e12;
        }
        d[i][i]=0;
    }
    cin>>N>>M>>R;
    REP(i,R){
        cin>>r[i];
        r[i]--;
    }
    REP(i,M){
        LL a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    
    REP(k,N){
        REP(i,N){
            REP(j,N){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    /*REP(i,N){
        REP(j,N){
            cout<<d[i][j]<<" ";
        }
        cout<<endl;
    }*/
    //return 0;
    //ここから全探索
    LL ans=1e12;
    REP(i,R){
        ans=min(dfs(i,1<<i,0),ans);
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<int> S(N); for (auto &s : S) cin >> s;
    Int ans = 0;
    for (int i = 1; i < N; i++) {
        int s = 0, e = N - 1;
        Int tmp = 0;
        while (e > i && (e % i != 0 || s < e)) {
            tmp += S[s] + S[e];
            s += i, e -= i;
            ans = max(ans, tmp);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 640
N=int(input())
kekka=list(input().split())
#print(kekka)
base=kekka[0]
#result=0
for i in range(1,N):
    if base=="F":
        base="T"
        #print(1)
    elif base=="T":
        if kekka[i]=="T":
            base="T"
            #print(2)
        else:
            base="F"
            #print(3)
            
print(base)
        


Measured memory_bytes: 7016
import java.util.Scanner;

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


Measured memory_bytes: 46308
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	vector<int> a, b;
	while (1) {
		int aa, bb;
		cin >> aa >> bb;
		if (aa == 0 && bb == 0)break;
		a.push_back(aa);
		b.push_back(bb);
	}
	rep(j, (int)a.size()) {

		int ans = 0;

		Rep(i, a[j], b[j] + 1) {
			if (i % 4 == 0) {
				if (i % 100 != 0) {
					ans++;
					cout << i << endl;
				}
				else if (i % 400 == 0) {
					ans++;
					cout << i << endl;
				}
			}
		}

		if (ans == 0) {
			cout << "NA" << endl;
		}
		if(j != (int)a.size() - 1)
			cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3180
n, m = list(map(int, input().split(' ')))
an = list(map(int, input().split(' ')))

limit = sum(an) / (4 * m)

count = 0
for i in range(n):
    if an[i] >= limit:
        count += 1


if count >= m:
    print('Yes')
else:
    print('No')





Measured memory_bytes: 38460
long s,f,n,c['~~'];i;main(j){for(scanf(f="%ld\n",&n);i++<n;)for(j=0;j++<n;s+=fmin(c[i<<7|j]=*c,c[j<<7|i])*(j<i))scanf(f,c);n=!printf(f,s);}

Measured memory_bytes: 712
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next

  val ans = 700 + s.count(_ == 'o') * 100

  println(ans)

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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int L = a+b, R = c+d;
    if (L > R) {
        cout << "Left" << endl;
    } else if (L < R) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 3652
def main
  n = gets.to_i
  ans = 0
  (1..n).each do |i|
    next if i.even?
    cnt = 0
    (1..i).each do |j|
      cnt += 1 if i % j == 0
    end
    ans += 1 if cnt == 8
  end
  puts ans
end

main



Measured memory_bytes: 14264
a,b,c,x,y=map(int,input().split())
cost1=a*x+b*y
cost2=c*max([x,y])*2

if x>y:
    cost3=c*y*2+a*(x-y)
else:
    cost3=c*x*2+b*(y-x)

print(min([cost1,cost2,cost3]))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	int n;
	cin >> n;
	int next = n / 100 * 111;
	if (next < n) {
		next += 111;
	}
	cout << next << endl;
}


Measured memory_bytes: 3576
import sys

sys.setrecursionlimit(10**7)
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    kaizyo_append = kaizyo.append
    keta = [0 for i in range(60)]
    ans = 0
    for i in range(60):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for j in range(60):
            v, i = i % 2, i // 2
            keta[j] += v
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i] % MOD
        ans = ans % MOD

    print(ans)
if __name__ == '__main__':
    main()


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

int dp[5], vet[100005];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; i++) scanf("%d", &vet[i]);
	memset(dp, 0x3f3f3f3f, sizeof dp);
	dp[(n-1)%3] = 0;
	for (int i=n-2; i>=0; i--){
		dp[i%3] = 0x3f3f3f3f;
		if(i+2 < n) dp[i%3] = min(dp[i%3], dp[(i+2)%3] + abs(vet[i]-vet[i+2]));
		dp[i%3] = min(dp[i%3], dp[(i+1)%3] + abs(vet[i]-vet[i+1]));
	}
	printf("%d\n", dp[0]);
}

Measured memory_bytes: 640
import numpy as np
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a
def yaku(n):
    fct = factorize(n)
    y = divisorize(fct)
    ys = []
    for yy in y:
        ys.append(num(yy))
    ys.sort()
    return ys

n,m = list(map(int,input().split()))
if n == 1 and m == 1:
    print(1)
else:
    y = yaku(m)
    print(np.max(np.array(y)[np.array(y) <= m/n]))

Measured memory_bytes: 12456
P = 123456789012419
x = 31
ix = pow(x, P-2, P)
N = int(input())
A = [ord(s)-95 for s in input()]

def chk(k):
    D = {}
    s = 0
    for i in range(k):
        s = (s * x) % P
        s += A[i]
    X = [s]
    D[s] = k-1
    for i in range(k, N):
        s = ((s - pow(x, k-1, P) * A[i-k]) * x + A[i]) % P
        X.append(s)
        if s in D:
            if i - D[s] >= k:
                return 1
        else:
            D[s] = i
    return 0

l = 0
r = N//2 + 1
while r - l > 1:
    m = (l+r) // 2
    if chk(m):
        l = m
    else:
        r = m
print(l)

Measured memory_bytes: 3800
S = input()
 
def solve(S):
    buf = [1] * len(S)
 
    for i in range(len(buf) - 2):
        if S[i] == "R" and S[i+1] == "R":
            buf[i+2] += buf[i]
            buf[i] = 0
 
    for i in range(len(buf) - 1, 1, -1):
        if S[i] == "L" and S[i-1] == "L":
            buf[i-2] += buf[i]
            buf[i] = 0
 
    return " ".join(map(str, buf))
 
print(solve(S))

Measured memory_bytes: 17116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
int main() {
	int n,m,p;
	cin>>n>>m>>p;
	vector<int> d(m);
	for(int i=0;i<m;i++){
		cin>>d[i];
		d[i]-=p;
		if(d[i]<0)d[i]+=n;
	}
	sort(d.begin(),d.end());
	int ans=min(n-d[0],d[d.size()-1]);
	for(int i=0;i<m-1;i++){
		int r=d[i],l=n-d[i+1];
		ans=min(ans,r+l+min(r,l));
	}
	cout<<ans*100<<endl;
}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

string ReplaceString(string subject, const string& search,
                     const string& replace) {
    size_t pos = 0;
    while ((pos = subject.find(search, pos)) != string::npos) {
        subject.replace(pos, search.length(), replace);
        pos += replace.length();
    }
    return subject;
}

int main() {
    int n;
    while (cin >> n, n) {
        set<string> w;
        vector<pair<string, string>> ss(n);
        REP(i, n) {
            string a, b;
            cin >> a >> b;
            ss[i] = {a, b};
        }
        string in, out;
        cin >> in >> out;

        queue<string> que;
        que.push(in);
        w.insert(in);
        que.push("");
        int cnt = 0;
        while (!que.empty()) {
            string s = que.front(); que.pop();
            if (s == "") {
                cnt++;
                if (que.empty()) break;
                que.push("");
                continue;
            }
            if (s == out) {
                cout << cnt << endl;
                goto END;
            }

            REP(i, n) {
                string replaced = ReplaceString(s, ss[i].first, ss[i].second);
                if (s.length() < 110 && !EXIST(w, replaced)) {
                    que.push(replaced);
                    w.insert(replaced);
                }
            }
        }
        cout << -1 << endl;
    END: {}
    }
}

Measured memory_bytes: 6120
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int f(int n){
  int ret = 0;
  int keta = 0;
  int tmp = n;
  while(tmp > 0){
    tmp /= 2;
    keta++;
  }

  tmp = n%4;
  if(tmp == 1 || tmp == 2) ret++;
  FOR(i, 1, keta){
    int now = pow(2, i);
    if(n-n/(now*2)*(now*2)+1-now >= 0){
      int amari = (n-n/(now*2)*(now*2)+1-now)%2;
      if(amari) ret += now;
    }
  }
  return ret;
}

signed main() {
  int A, B; 
  cin >> A >> B;

  cout << (f(A-1)^f(B)) << "\n";

  return 0;
}

Measured memory_bytes: 384
def f(point):
    cnt = 0
    for i in range(N):
        a, f = A[i], F[i]
        cnt += max(0, a - point//f)
    return cnt <= K

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10**12
while (r-l) > 1:
    mid = (r+l)//2
    if f(mid):
        r = mid
    else:
        l = mid
print(r)


Measured memory_bytes: 119756
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl read
  unless (n == 0) $ do
    solve n <$> replicateM n (getl read) >>= print
    main

solve :: Int -> [Int] -> Int
solve n xs =  (sum . init . tail . sort) xs `div` (n-2)

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4200
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nmq = readln.split.to!(int[]);
    auto N = nmq[0];
    auto M = nmq[1];
    auto Q = nmq[2];

    auto cs = new int[][](N, N);
    foreach (_; 0..M) {
        auto lr = readln.split.to!(int[]);
        auto L = lr[0]-1;
        auto R = lr[1]-1;
        cs[L][R] += 1;
    }
    foreach (k; 1..N) {
        foreach (i; 0..N) {
            auto j = i+k;
            if (j >= N) break;
            cs[i][j] += cs[i+1][j] + cs[i][j-1];
            if (i+1 < j) cs[i][j] -= cs[i+1][j-1];
        }
    }
    foreach (_; 0..Q) {
        auto pq = readln.split.to!(int[]);
        writeln(cs[pq[0]-1][pq[1]-1]);
    }
}

Measured memory_bytes: 9468
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

const int MAX_P = 200000; //max
bool prime[MAX_P+1];

void Eratosthenes(void){
  for(int i=2;i<=MAX_P;i++)
    prime[i]=true;
  
  for(int i=2;i*i<=MAX_P;i++)
    if(prime[i])  
      for(int j=i;i*j<=MAX_P;j++)
	prime[i*j]=false;
}


bool calc(){
  int n;
  set<int> ss;
  
  scanf("%d",&n);

  for(int i=0;;i++){
    if(ss.find(n)!=ss.end()){
      puts("-1");
      break;
    }
    ss.insert(n);    

    if(n<10){
      printf("%d\n",i);
      break;
    }

    int max_n = 0;
    for(int i=10;i<n;i*=10){
      max_n = max(max_n,(n%i)*(n/i));
    }

    n = max_n;
  }
  
  return true;
}
  
int main(){
  int t;
  
  scanf("%d",&t);
  for(int i=0;i<t;i++){
    calc();
  }
  
  //while(calc());
  
  return 0;
}

Measured memory_bytes: 3236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	}
}

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

using namespace std;

int main(){

    int n, m;

    cin >> n >> m;

    int a;
    
    int sum  = 0;

    for(int i=0; i<m; i++){
        cin >> a;
        sum += a;
    }

    if(sum > n){
        cout << "-1\n";
    }else{
        cout << n - sum << endl;
    }
}

Measured memory_bytes: 3624