akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

mine = []
score = 0
for n in range(1, N + 1):
    if n <= K:
        if T[n - 1] == "r":
            score += P
            mine.append("p")

        elif T[n - 1] == "s":
            score += R
            mine.append("r")

        else:
            score += S
            mine.append("s")

    else:
        if T[n - 1] == "r":
            if mine[n - 1 - K] == "p":
                mine.append("any")
                continue
            else:
                score += P
                mine.append("p")

        elif T[n - 1] == "s":
            if mine[n - 1 - K] == "r":
                mine.append("any")
                continue
            else:
                score += R
                mine.append("r")

        else:
            if mine[n - 1 - K] == "s":
               mine.append("any")
               continue
            else:
               score += S
               mine.append("s")


print(score)




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

int main() {
	int N;
	cin >> N ;
	if(N<=111){
		cout << 111 << endl;
	}
	else if(N<=222){
		cout << 222 << endl;
	}
	else if(N<=333){
		cout << 333 << endl;
	}
	else if(N<=444){
		cout << 444 << endl;
	}
	else if(N<=555){
		cout << 555 << endl;
	}
	else if(N<=666){
		cout << 666 << endl;
	}
	else if(N<=777){
		cout << 777 << endl;
	}
	else if(N<=888){
		cout << 888 << endl;
	}
	else {
	cout << 999 << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<fstream>
using namespace std;
    
#define NUM 10000
priority_queue<int> pqueue[NUM];

int main(){

    int n, q, order, t;
    cin >> n >> q;
    for(int i=0;i<q;i++){
        cin >> order >> t;
        switch (order)
        {
        case 0:
            int num;
            cin >> num;
            pqueue[t].push(num);
            break;
        case 1:
            if(!(pqueue[t].empty())) cout << pqueue[t].top() << endl;
            break;
        case 2:
            if(!(pqueue[t].empty()))pqueue[t].pop();
            break;
        default:
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4332
import numpy as np
K=int(input())

N=50
num=K//N
r=K%N
L=[N-1]*N
L=np.array(L)
L+=num
for i in range(N):
    if i<r:
        L[i]+=N-(r-1)
    else:
        L[i]-=r

print(N)
print(*L)



Measured memory_bytes: 17684
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
D = {}
E = {}
nn = 0
for i in C.keys():
    n = C[i]
    if n == 1:
        D[i] = 0
        E[i] = 0
    else:
        D[i] = int(n * (n - 1) / 2)
        nn += D[i]
        E[i] = int((n - 1) * (n - 2) / 2)
for k in range(N):
    n = A[k]
    print(nn - D[n] + E[n])

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

int main(){

  while(1){
    int a, b;
    string op;
    cin>>a>>op>>b; 
    if(op == "?") break;     

    int ans;
    if(op == "+") ans = a + b;
    if(op == "-") ans = a - b;
    if(op == "*") ans = a * b;
    if(op == "/") ans = a / b;

    cout<<ans<<endl;
  } 
  return 0;
 }



Measured memory_bytes: 3124
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}


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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, Q; cin >> N >> M >> Q;
  bool e[N];
  list< pair<bool, int> > ex;

  for(int i = 0; i < N; i++){
    ex.push_back(make_pair(true, i));
    e[i] = true;
  }
  list< pair<bool, int> >::iterator it = ex.begin();
  for(int i = 0; i < M; i++){
    int a; cin >> a;
    if(a % 2 == 0){
      //c = (c + a) % N;
      for(int i = 0; i < a; i++){
	it++;
	if(it == ex.end()) it = ex.begin();
      }
    }else{
      //c = ((c + N) - a) % N;
      for(int i = 0; i < a; i++){
	if(it == ex.begin()) it = ex.end();
	it--;
      }
    }
    e[(*it).second] = false;
    /*
    cout << '(';
    cout << it->second << ", ";
    */
    it = ex.erase(it);
    if(it == ex.end()) it = ex.begin();
    //cout << it->second << ")" << endl;
  }
  //cout << "--" << endl;
  //for(it = ex.begin(); it != ex.end(); it++) cout << it->second << endl;
  for(int i = 0; i < Q; i++){
    int q; cin >> q;
    cout << e[q] << endl;
  }
  return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back

#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    int a,b; cin>>a>>b;
    int ans = a*(a-1)+b*(b-1);
    if(ans != 0){
        printf("%d\n",ans/2);
    }else{
        printf("0");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define maxn 10005
#define ll long long
using namespace std;

typedef pair<int, int> P;

int n;
char s[maxn][15];
int ans;
int oa, bo, ba;

int main()
{
	cin >> n;
	ans = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%s", s[i]);
		int len = strlen(s[i]);
		for (int j = 0; j < len - 1; j++)
		{
			if (s[i][j] == 'A' && s[i][j + 1] == 'B')
				ans++;
		}
		if (s[i][0] == 'B' && s[i][len - 1] == 'A')
			ba++;
		else if (s[i][len - 1] == 'A')
			oa++;
		else if (s[i][0] == 'B')
			bo++;
	}
	//cout << ans << endl;
	//cout << oa << bo << ba;
	if (ba > 0)
	{
		ans += (ba - 1);
		ba = 1;
	}
	if (oa > 0 && ba > 0)
	{
		ans++;
		oa--;
	}
	if (bo > 0 && ba > 0)
	{
		ans++;
		bo--;
	}
	ans += min(oa, bo);
	cout << ans;

	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>


int main(void){
    int N;
    int a[100000];
    int ans[100000] = {};
    int howmany = 0;
    int index;
    int minus;
    int i;

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

    for (i = 0; i < N; i++){
        if (a[i] > 0){
            index = a[i];
            ans[index + 1] += 1;
            ans[index] += 1;
            ans[index - 1] += 1;
        }else if(a[i] == 0){
            ans[0] += 1;
            minus += 1;
        }
    }

    for (i = 0; i < 100000; i++){
        if (howmany < ans[i]){
            howmany = ans[i];
        }
    }

    if (minus > howmany){
        howmany = minus;
    }
    printf("%d\n", howmany);

    return 0;

}


Measured memory_bytes: 896
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
    double x1,y1,x2,y2,x,y;
    scanf("%lf %lf %lf %lf", &x1,&y1,&x2,&y2);
    x = x1-x2;
    y = y1-y2;
    printf("%f\n", sqrt(x*x+y*y));
}


Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
int p(int a){
  for(int i=2;i<=sqrt(a);i++){
    if(a%i==0)return 1;
  }
  return 0;
}
int main(){
  int n, m;
  cin >> n >> m;
  int ans;
  if(p(m)){
    for(int i=n;i<=m;i++){
      if(m%i==0){
        cout << m/i << endl;
        return 0;
      }
    }
  }
  puts("1");
  return 0;
}

Measured memory_bytes: 256
// 154 B

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

int main(){
    long long int n, m, tmp;
    string str;
    vector<pair<long long int, string>> p; 
    cin >> n >> m;
    for(long long int i=0; i<m; i++){
        cin >> tmp >> str;
        p.push_back(pair<long long int, string> (tmp, str));
    }
    
    long long int ac=0, wa=0;

    vector<pair<long long int, bool>> v (n, pair<long long int, bool>(0, false));
    for(long long int i=0; i<m; i++){
        if(v.at(p.at(i).first-1).second){
            continue;
        }else{
            if(p.at(i).second == "WA"){
                v.at(p.at(i).first-1).first++;
            }else{
                wa += v.at(p.at(i).first-1).first;
                v.at(p.at(i).first-1).second = true;
            }
        }
    }

    for(long long int i=0; i<n; i++){
        // cout << v.at(i).first << " " << v.at(i).second << endl;
        if(v.at(i).second) ac++;
    }
    
    cout << ac << " " << wa << endl;
    return 0;
}


Measured memory_bytes: 8048
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;

#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 FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))



int main(){

    vector<string> koho={"dream","dreamer","erase","eraser"};
    string s; cin>>s;
    reverse(s.begin(),s.end());
    REP(i,4){
        reverse(koho[i].begin(),koho[i].end());
    }
    
    while(s.size()!=0){
        bool flag=false;
        REP(i,4){
            if(s.find(koho[i])==0){
                flag=true;
                if(i==3){
                    REP(j,6)s.erase(s.begin());
                }else if(i==1){
                    REP(j,7)s.erase(s.begin());
                }else{
                    REP(j,5)s.erase(s.begin());
                }
            }
        }
        if(!flag){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    
    cout<<"YES"<<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

#ifdef _MSC_VER

#include <conio.h>

#else

#define getch()

#endif



int main(){

	int A=0;

	int B=0;

	scanf(" %d %d",&A,&B);

	int C=A+B;

	if(C>=24){

		C-=24;

	}

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

	getch();

}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
  int N,T,E;
  cin >> N >> T >> E;
  bool bfind = false;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if(bfind) continue;
    for(int j=-E; j<=E; j++){
      if((T+j) % x == 0){
        bfind = true;
        cout << i+1 << endl;
        break;
      }
    }
  }
  if(!bfind){
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ld x[70], y[70], c[70];
ld r[70], d[70][70], ang[70][70];
ld pi=abs(acos(-1.0));

ld dist(ld x1, ld y1, ld x2, ld y2){
	return pow((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2), 0.5);
}

ld yogen(ld a, ld b, ld c){
	return acos((a*a+b*b-c*c)/(a*b*2.0));
}

int main() {
	int N, K;
	cin >> N >> K;
	for(int i=0; i<N; ++i){
		cin >> x[i] >> y[i] >> c[i];
	}
	for(int i=0; i<N; ++i){
		for(int j=0; j<N; ++j){
			d[i][j]=dist(x[i], y[i], x[j], y[j]);
			ang[i][j]=atan2(y[j]-y[i], x[j]-x[i]);
		}
	}
	ld ng=0.0, ok=1e9, er=1e-10;
	while(ng+er<ok){
		ld mid=(ng+ok)/2.0;
		for(int i=0; i<N; ++i) r[i]=mid/c[i];
		int mx=0;
		for(int i=0; i<N; ++i){
			vector<pair<ld, int>> v;
			int stt=1;
			for(int j=0; j<N; ++j){
				if(i!=j){
					if(d[i][j]+r[i]<=r[j]+er) ++stt;
					else if(d[i][j]+er<r[i]+r[j]){
						ld p=yogen(r[i], d[i][j], r[j]);
						if(ang[i][j]-p<(-pi)){
							++stt;
							v.emplace_back(make_pair(ang[i][j]-p+pi*2.0, 1));
						}else{
							v.emplace_back(make_pair(ang[i][j]-p, 1));
						}
						if(ang[i][j]+p>pi){
							++stt;
							v.emplace_back(make_pair(ang[i][j]+p-pi*2.0, -1));
						}else{
							v.emplace_back(make_pair(ang[i][j]+p, -1));
						}
					}
				}
			}
			sort(v.begin(), v.end());
			mx=max(mx, stt);
			for(int i=0; i<v.size(); ++i){
				stt += v[i].second;
				mx=max(mx, stt);
			}
		}
		if(mx>=K) ok=mid;
		else ng=mid;
	}
	cout << setprecision(15) << ok << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d)
    {
        cout << "Left" << endl;
    }
    else if (a + b == c + d)
    {
        cout << "Balanced" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "Ofast"
#endif
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

const int MAXN = 200228;
pair<ll, ll> a[MAXN];
pair<ll, int> as[MAXN];
pair<ll, int> bs[MAXN];


int cnt[MAXN];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
        as[i] = { a[i].first, i };
        bs[i] = { a[i].second, i };
        cnt[i] = 1;
    }

    sort(as, as + n);
    sort(bs, bs + n);


    ll cur = 0;
    for (int i = 0; i < n; ++i) {
        cur += as[i].first;
    }

    int zeros = 0;

    ll ans = (1ll << 60);

    for (int i = n; i >= 0; --i) {
        ll cans = cur;
        if (zeros == 0 && i != 0 && i != n) {
            cans += min(as[i].first - as[i - 1].first, bs[n - i].first - bs[n - i - 1].first);
        }

        ans = min(ans, cans);

        if (i != 0) {
            cur -= as[i - 1].first;
            cur += bs[n - i].first;
            zeros += (--cnt[as[i - 1].second] == 0);
            zeros -= (++cnt[bs[n - i].second] == 1);
        }
    }

    cout << ans << "\n";
}
 

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

using namespace std;
using lint = long long;

const int INF = 1e9;

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

    string S;
    cin >> S;
    S = 'A' + S;
    int N = S.size();

    vector<int> num(26), split(1, INF - 10);
    vector<vector<int>> appear(26, vector<int>(1, INF));
    for (int i = N - 1; i > 0; i--) {
        num[S[i] - 'a']++;
        appear[S[i] - 'a'].push_back(i);
        if (*min_element(num.begin(), num.end()) == 1) {
            split.push_back(i - 1);
            for (int j = 0; j < 26; j++) {
                num[j] = 0;
            }
        }
    }

    reverse(split.begin(), split.end());
    for (int i = 0; i < 26; i++) {
        reverse(appear[i].begin(), appear[i].end());
    }

    string ans;
    int pos = 0, k = 0, K = split.size();
    while (k < K) {
        for (int i = 0; i < 26; i++) {
            int npos = *lower_bound(appear[i].begin(), appear[i].end(), pos + 1);
            if (npos > split[k]) {
                pos = npos;
                ans += char('a' + i);
                k++;
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1488
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int d = x / 500;
            int ans = 1000 * d;
            x -= d * 500;
            d = x / 5;
            ans += 5 * d;
            out.println(ans);
        }

    }

    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: 21332
#include <cstdio>
#include <algorithm>


int N, map[10][10], dx[3] = {0, 1, 0}, dy[3] = {1, 1, 2};
int x[12], y[12], bl[12];


bool check(int x, int y, int t){
    int u = 1;
    if(t > 0) u = 2;
    for(int i = -u; i <= u; i++){
        for(int j = -u; j <= u; j++){
            if(std::abs(i) + std::abs(j) > u) continue;
            if(t == 1 && (i == 0 && std::abs(j) == 2 || j == 0 && std::abs(i) == 2)) continue;
            if(x + j >= 10 || y + i >= 10 || x + j < 0 || y + i < 0) return false;
            if(!map[y + i][x + j]) return false;
        }
    }
    return true;
}

void ss(int x, int y, int t, int v){
    //v???-????????????????????????+?????????????????????
    int u = 1;
    if(t > 0) u = 2;
    for(int i = -u; i <= u; i++){
        for(int j = -u; j <= u; j++){
            if(std::abs(i) + std::abs(j) > u) continue;
            if(t == 1 && (i == 0 && std::abs(j) == 2 || j == 0 && std::abs(i) == 2)) continue;
            if(x + j >= 10 || y + i >= 10 || x + j < 0 || y + i < 0) continue;
            map[y + i][x + j] += v;
        }
    }
}

bool solve(int n){
    if(n == N){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                if(map[i][j]) return false;
            }
        }

        for(int i = 0; i < N; i++){
            printf("%d %d %d\n", x[i], y[i], bl[i]);
        }
        return true;
    }

    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            if(!map[i][j]) continue;

            for(int k = 0; k < 3; k++){
                if(!check(j + dx[k], i + dy[k], k)) continue;
                ss(j + dx[k], i + dy[k], k, -1); //???????????????

                x[n] = j + dx[k]; y[n] = i + dy[k]; bl[n] = k + 1;
                if(solve(n + 1)) return true;
                ss(j + dx[k], i + dy[k], k, 1); //???????????????
            }
            return false;
        }
    }

    return false;
}

int main(){
    scanf("%d", &N);
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            scanf("%d", &map[i][j]);
        }
    }

    solve(0);


    return 0;
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) { 
        a = b;
        return true; 
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) { 
        a = b; 
        return true; 
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int N;
    cin >> N;

    for (int i = -500; i < 500; i++) {
        for (int j = -500; j < 500; j++) {
            if (pow(i, 5) - pow(j, 5) == N) {
                cou(i << " " << j);
                goto end;
            }
        }
    }
end: {} { {; }}

}

Measured memory_bytes: 4048
// Aizu Vol-6 0621: Russian Flag
// 2017.9.5 bal4u@uu

#include <stdio.h>

#define W 0
#define B 1
#define R 2

char map[53];
int f[53][3], s[53][3];
int tr['Z'];

int main()
{
	int n, m, mn, x, y, w, b, r, sw, sb, sr, min;

	tr['W'] = W, tr['B'] = B, tr['R'] = R;
	scanf("%d%d", &n, &m); mn = n * m;
	for (y = 1; y <= n; y++) {
		scanf("%s", map+1);
		for (x = 1; x <= m; x++) f[y][tr[map[x]]]++;
	}
	for (y = 1; y <= n; y++) for (x = 0; x < 3; x++) s[y][x] = s[y-1][x] + f[y][x];

	min = mn+1;
	for (w = 1; w <= n-2; w++) { sw = s[w][W];
		for (b = w+1; b <= n-1; b++) { sb = s[b][B] - s[w][B];
			for (r = b+1; r <= n; r++) { sr = s[n][R] - s[b][R];
				if (mn - (sw + sb + sr) < min) min = mn - (sw + sb + sr);
			}
		}
	}
	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 1800
import scala.io.StdIn.readLine

object Main extends App {
  val h = readLine().toLong
  val log2 = (x: Double) => Math.log10(x) / Math.log10(2.0)
  val sqrt = log2(h).toLong + 1
  println(Math.pow(2, sqrt).toLong - 1)
}

Measured memory_bytes: 25536
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n = inp[0]
a = []
n.times do
  a.push(inp[0])
end
kom = 0
ckom = 0
clis = 0
lismax = 0
ans = 0
h = {}
(a.size).times do |i|
  h[a[i]] = i
end
lis = h[1] - 1
clis = 0
(1..n).each do |d|
  if (h[d] > lis)
    clis += 1
    lismax = [lismax,clis].max
  else
    clis = 1
  end
  lis = h[d]
end
lismax
ans = (n-lismax)
p ans

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

using namespace std;

typedef long long ll;

#define p(x) cout << x << endl
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define range(i, begin, end) for(int i = begin; i < (int)(end + 1); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int a, b;
    cin >> a >> b;

    if((a + b) % 2 == 0) {
        p((a + b) / 2);
    } else {
        p("IMPOSSIBLE");
    }

    return 0;
}


Measured memory_bytes: 256
#n=int(input())
a,b,c=map(str,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(m)]

if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO")




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

int main(){
  string str;
  cin >> str;
  int res = 700;
  for(int i = 0 ; i < str.size() ; i++){
    if(str[i] == 'o')res += 100;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = input()

right_EW = Counter(S)
left_EW = {"E":0,"W":0}

ans = len(S)
for s in S:
    right_EW[s] -= 1
    #print(left_EW,right_EW)
    temp = left_EW["W"] + right_EW["E"]
    if temp < ans: ans = temp
    left_EW[s] += 1
    
print(ans)

Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

vector<int> sum(100008);
vector<int> prime(100009,1);
int ans[100009];
int main(){
    prime[0]=0;
    prime[1]=0;
    for (int i=2;i <100009;i++){
        if (prime[i]==1){
            for (int j=i+i; j < 100009;j=j+i) prime[j]=0;
        }
    }
    sum[0]=0;
    for (int i=1;i < 100008;i++){
        if (i%2==0) sum[i]=sum[i-1];
        else{
            if (prime[i]==1 && prime[(i+1)/2]==1) sum[i]=sum[i-1]+1;
            else sum[i]= sum[i-1]; 
        }
    }
    int q;
    cin >> q;
    for (int y=0; y < q;y++){
        int l,r;
        cin >> l >> r;
        ans[y]=sum[r]-sum[l-1];
    }
    for (int j=0;j < q;j++){
        cout << ans[j] << endl; 
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

vector<int> G[101];
bool passed[101];
int maxPath=0;
int maxNode;

void dfs(int s,int depth){
	maxPath=max(maxPath,depth);
	if(maxPath==maxNode)
		return;
	for(int i = 0; i<G[s].size(); i++){
		int to=G[s][i];
		if(!passed[to]){
			passed[to]=true;
			dfs(to,depth+1);
			passed[to]=false;
			if(maxPath==maxNode)
				return;
		}
	}
}

int main(){
	int n;
	while(scanf("%d",&n)&&n!=0){
		maxPath=0;
		memset(passed,0,sizeof(passed));
		for(int i = 0; i < 101; i++)
			G[i].clear();
		set<int> s;
		for(int i = 0; i < n; i++){
			int a,b;
			//cin>>a>>b;
			scanf("%d %d",&a,&b);
			a--;
			b--;
			s.insert(a);
			s.insert(b);
			G[a].push_back(b);
			G[b].push_back(a);
		}
		maxNode=s.size();
		for(set<int>::iterator it = s.begin(); it!=s.end(); it++){
			passed[*it]=true;
			dfs(*it,1);
			passed[*it]=false;
			if(maxPath==maxNode)
				break;
		}
		printf("%d\n",maxPath);
	}
	return 0;
}

Measured memory_bytes: 0
H, W = map(int, input().split())
if H == 1 or W == 1:
    ans = 1
elif H % 2 == 0:
    if W % 2 == 0:
        ans = H*(W//2)
    else:
        ans = H*((W-1)//2)+(H//2)
elif H % 2 == 1:
    if W % 2 == 0:
        ans = H*(W//2)
    else:  # W%2==1
        ans = H*((W-1)//2)+((H+1)//2)
print(ans)


Measured memory_bytes: 3060
from math import factorial

n, m = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

ans = 0
diff = abs(n - m)
if diff == 0:
    ans = (factorial(n) ** 2) * 2 % mod
elif diff == 1:
    ans = factorial(n) * factorial(m) % mod
print(ans)


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

using namespace std;

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

  int n, y;
  cin >> n >> y;
  y /= 1000;

  for (int c = 0; c <= 20001; ++c) {
    int a = (y+4*c-5*n);
    if (a%5 == 0 && a >= 0 && n-c-a/5 >= 0) {
      cout << a/5 << " " << n-c-a/5 << " " << c << endl;
      return 0;
    }
  }
  cout << "-1 -1 -1" << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 100005;

ll n,s;

ll eval(ll n,ll b){
	ll sum = 0;
	while(n){
		sum += n % b;
		n/=b;
	}
	return sum;
}

int main(){
	cin >> n >> s;
	fu(i,2,sqrt(10e11)+1){
		if(eval(n,i) == s){
			cout << i << '\n';
			return 0;
		}
	}
	ll ans = LLONG_MAX;
	fd(i,sqrt(10e11)+1,0){
		ll l = (n + 1 + i + 1 - 1)/(i + 1);
		ll r = (i==0 ? LLONG_MAX : n / i );
		if(i >= r || i >= l)continue;
		if(eval(n,l) >= s && eval(n,r) <= s){
			ll m;
			while(l <= r){
				m = l + (r-l)/2;	
				ll res = eval(n,m);
				if(res < s){
					r = m - 1;	
				}
				else if(res > s){
					l = m + 1;
				}
				else{
					ans = min(ans, m);
					r = m - 1;
				}
			}
		}
	}
	if(ans == LLONG_MAX)ans = -1;
	cout << ans << '\n';
}


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

bool prime(int n){
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    for(int i = 3; i * i <= n; i += 2){
        if(n % i == 0) return false;
    }
    return true;
}

int main(void){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int num = 0;
        cin >> num;
        if(prime(num)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vi w(n + 1, 0), e(n + 1, 0);
  rep(i, n) {
    w[i + 1] = w[i];
    e[i + 1] = e[i];
    if(s[i] == 'W')
      w[i + 1]++;
    else
      e[i + 1]++;
  }
  int res = 3 * 100000;
  rep(i, n) {
    int sum = w[i] + e[n] - e[i + 1];
    res = min(res, sum);
  }
  cout << res << endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  cin >> n;

  vector<int> a(n);

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

    if (a[i] <= 0) countNeg++;
  }

  ll ans = 0;
  int minn = 1000000001;
  for (int i = 0; i < n; i++) {
    ans += abs(a[i]);
    minn = min(minn, abs(a[i]));
  }

  // - が偶数なら全部+にできる
  // 奇数なら一個だけ-になるのでabsが最小のものを-にする

  if (countNeg % 2 != 0) {
    ans -= minn * 2;  // すでに最小のものもansに計上されているので*2して引く
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e;
  cin >> a ;
  b=a/1000;
  c=a/100-b*10;
  d=a/10-b*100-c*10;
  e=a-b*1000-c*100-d*10;
  if (b==c && c==d){
    cout << "Yes" << endl;}
  else if (d==c && e==d) {
    cout << "Yes" << endl;}
  else {
    cout << "No" << endl;}
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.on('SIGINT', function(){
    input_stdin_array = input_stdin.split("\n");
    main();
    process.exit();
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
	/*reading input*/
	var s = readLine().split(" ");	
	var N = parseInt(s[0]);
	var X = parseInt(s[1]);
	s = readLine().split(" ");
	var a = [0];
	for (var i=0; i < N; i++) a.push(parseInt(s[i]));
	
	/*building dp matrix*/
	var dp = [];
	for (var i=0; i <= N; i++) {
		dp.push([]);
		for (var j=0; j <= 50*50; j++){
			dp[i].push(0);
		}
	}
	
	/* calculating dp */
	dp[0][0]=1;
	for (var e=1; e <= N; e++){
		for (var i=N; i >= 1; i--){
			for (var j=0; j <= 50*50; j++){
				if (j - a[e] >= 0){
					dp[i][j] += dp[i-1][j-a[e]];
				}
			}
		}
	}
	
	/* calculating the answer */
	var ans=0;
	for (var i=1; i <= N; i++){
		ans += dp[i][X*i];
	}
	
	console.log(ans.toString());
}


Measured memory_bytes: 14796
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    string a,b;
    IN  a >> b;
    a += b;
    int n = stoi(a),h;
    h = sqrt(n);
    if(h*h == n)Yes;
    else No;
    
    
    
	return  0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){

    int N, K, x, output;
    cin >> N;
    cin >> K;
    float center = K / 2;
    
    output = 0;
    
    for( int i = 0; i < N; ++i ){
        scanf("%d", &x);
        if( x <= center ){
            output += x * 2;
        }else{
            output += ( K - x ) * 2;
        }
    }
    
    cout << output << endl;
    
    return 0;

}


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

int main()
{
  int A, B, C;
  int res=0;
  cin >> A >> B >>C;

  if(A+B+C >21) cout << "bust" << endl;
  else cout << "win" << endl;
}




Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,x = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	s = 10^18
	g = zeros(Int,n,n)
	for i in 1:n
		g[i,1] = a[i]
		for j in 2:n
			g[i,j] = min(g[i,j-1],a[(i-j+n)%n+1])
		end
	end
	for time in 0:n-1
		t = 0
		for i in 1:n
			t += g[i,time+1]
		end
		t += x*time
		s = min(s,t)
	end
	println(s)
end

main()

Measured memory_bytes: 143488
N, M = map(int, input().split())
I = [[i, 1] for i in range(N)]
B = [0] * M
for i in range(M):
  B[M - 1 - i] = [int(x) - 1 for x in input().split()]
NC = [0] * M
def n2(n):
  return n * (n - 1) // 2
NC[-1] = n2(N)
def root(a):
  #print(a, I[a][0])
  if I[a][0] == a:
    return a
  else:
    I[a][0] = root(I[a][0])
    return I[a][0]
def union(a, b):
  ra = root(a)
  rb = root(b)
  na = I[ra][1]
  nb = I[rb][1]
  if ra == rb:
    return 0
  if ra < rb:
    I[rb][0] = ra
    I[ra][1] += I[rb][1]
  else:
    I[ra][0] = rb
    I[rb][1] += I[ra][1]
  return n2(na + nb) - n2(na) - n2(nb)
for i in range(M - 1):
  a, b = B[i]
  NC[M - 2 - i] = NC[M - 1 - i] - union(a, b)
for nc in NC:
  print(nc)

Measured memory_bytes: 36624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define vi vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

int cnt[1<<20];
int32_t main(){ fast;
               int n; cin>>n;
               ll answer = 0;
               rep(i, n){
                   int x; cin>>x;
                   cnt[x]++;
                   answer += x;
               }
               int q; cin>>q;
               while(q--){
                   int x, y; cin>>x>>y;
                   answer -= (long long) cnt[x] * x;
                   answer += (long long) cnt[x] * y;
                   cnt[y] += cnt[x];
                   cnt[x] = 0;
                   cout<<answer<<endl;
               }
}


Measured memory_bytes: 4044
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
rs = []
a = sum(As)
for i in range(a):
    i += 1
    if a % i == 0:
        rs.append(i)
        rs.append(a//i)
    if a < i**2:
        break
rs = sorted(rs)[::-1]
for r in rs:
    Bs = sorted([A%r for A in As])
    sum1 = 0
    sum2 = r*N - sum(Bs)
    R = None
    for b in Bs:
        sum1 += b
        sum2 -= r - b
        if abs(sum1 - sum2) % r == 0:
            if max(sum1, sum2) > K:
                continue
            R = r
            break
    if R:
        break
print(R)


Measured memory_bytes: 42476
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

int a[arr];

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int n;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=1e9;
    for (int i=-100;i<=100;i++){
        int cur=0;
        for (int j=0;j<n;j++){
            cur+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,cur);
    }
    cout<<ans<<"\n";
}


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

#define int long long
typedef pair <int, int> pii;

const int N = 1e5 + 10;
int n, ans[N];
vector <pii> adj[N];

void dfs(int v, int p, int d) {
	ans[v] = (d & 1);
	for (pii i : adj[v])
		if (i.first != p)
			dfs(i.first, v, d + i.second);
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u, w;
		cin >> v >> u >> w;
		v--; u--;
		adj[v].push_back({u, w});
		adj[u].push_back({v, w});
	}
	dfs(0, 0, 0);
	
	for (int i = 0; i < n; i++)
		cout << ans[i] << '\n';
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
  if (c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
    cout << "vowel" << endl;
  }
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	for(int i=n-1;i>=1;i--){
		string t=s.substr(0,i);
		if(t.size()%2) continue;
		if(t.substr(0,t.size()/2)==t.substr(t.size()/2)){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(int i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
ll f(ll a){
       if(a%4==1){return 0;}
       if(a%4==2){return a;}
       if(a%4==3){return 1;}
       return a+1;
}
int main()
{
       ll a,b;
       cin>>a>>b;
       int xorr = 1;
       if(a==0){
              a=1;
       }
       cout<<(f(b)^f(a-1))<<endl;
}


Measured memory_bytes: 256
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
dp=[0]*(2**n)
dp[0]=1
for i in range(1,2**n):
    e=bin(i)[2:]
    y=e.count('1')
    for j in range(len(e)):
        if e[-j-1]=='1':
            if g[y-1][j]:
                    dp[i]+=dp[i-(2**j)]
                    dp[i]%=mod


print(dp[-1]%mod)
            
    
    

Measured memory_bytes: 90388
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

bool kaibun(int p){
	string str = to_string(p);
	string rev = str;
	reverse(rev.begin(), rev.end());
	if(str==rev){
		return true;
	}else{
		return false;
	}
}

int main(void){
	int a, b;
	cin >> a >> b;
	
	int counter = 0;
	
	for(int i=a;i<=b;i++){
		if(kaibun(i) == true){
			counter++;
		}
	}
	cout << counter << endl;
	
	return 0;
}


Measured memory_bytes: 256
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(j>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)





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

int n;

int main(){
	scanf("%d", &n);
  	for(int i = 1; i <= n; i++){
    	if(i * (i + 1) / 2 >= n){
          	int t = i * (i + 1) / 2 - n;
        	for(int j = 1; j <= i; j++)
              	if(j != t) printf("%d\n", j);
          	return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a;
    cin >> a;
    int aa = a*a;
    int aaa = aa * a;
    cout << a+aa+aaa << endl;
    return 0;
}

Measured memory_bytes: 3664