akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int n = sc.nextInt();
			int q = sc.nextInt();
			if(n == 0 && q == 0)break;
			else calc(n, q);
			
		}
	}
	public void calc(int n, int q){
		ArrayList<int[]> list = new ArrayList<int[]>();
;		String[] eras = new String[1001];
		
		int eranum = 1;
		for(int i = 0; i < n; i++){
			String eraname = sc.next();
			int erayear = sc.nextInt();
			int wesyear = sc.nextInt();
			eras[eranum] = eraname;
			
			list.add(new int[]{wesyear - erayear + 1, wesyear, eranum});
			eranum++;
		}
		
		list = mergeSort(list);
		
		for(int i = 0; i < q; i++){
			int wesyear = sc.nextInt();
			int ans = 0;
			for(int j = 0; j < list.size(); j++){
				int[] item = list.get(j);
				if(wesyear < item[0]){
					break;
				}
				else if(wesyear >= item[0] && wesyear <= item[1]){
					System.out.println(eras[item[2]] + " " + (wesyear - item[0] + 1));
					ans = 1;
					break;
				}
			}
			if(ans == 0) System.out.println("Unknown");
		}
	}
	public ArrayList<int[]> mergeSort(ArrayList<int[]> list){
		if(list.size() > 1){
			int m = list.size() / 2;
			int n = list.size() - m;
			ArrayList<int[]> a1 = new ArrayList<int[]>();
			ArrayList<int[]> a2 = new ArrayList<int[]>();
			for(int i = 0; i < m; i++) a1.add(list.get(i));
			for(int j = 0; j < n; j++) a2.add(list.get(j + m));
			a1 = mergeSort(a1);
			a2 = mergeSort(a2);
			return merge(a1, a2);
		}
		else return list;
	}

	public ArrayList<int[]> merge(ArrayList<int[]> a1, ArrayList<int[]> a2){
		int i = 0;
		int j = 0;
		ArrayList<int[]> a = new ArrayList<int[]>();
		while(i < a1.size() || j < a2.size()){
			if(i < a1.size() && (j >= a2.size() || a1.get(i)[0] < a2.get(j)[0])){
				a.add(a1.get(i));
				i++;
			}
			else{
				a.add(a2.get(j));
				j++;
			}
		}
		return a;
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 117068
// abc129d.cpp : Lamp
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int h,w; cin>>h>>w;

	vector<string> s(h);
	vector<vi> c(h,vi(w));

	int x, y;
	rp(t,h){ //LR
		cin>>s[t];
		x = y = 0;
		rp(l,w){
			int r = w - 1 - l;
			c[t][l] += s[t][l]=='.'? x++: x=0; //L
			c[t][r] += s[t][r]=='.'? y++: y=0; //R
		}
	}

	rp(l,w){ //TB
		x = y = 0;
		rp(t,h){
			int b = h - 1 - t;
			c[t][l] += s[t][l]=='.'? x++: x=0; //T
			c[b][l] += s[b][l]=='.'? y++: y=0; //B
		}
	}

	int ans = 1;
	rp(i,h) rp(j,w) if(ans < c[i][j]+1) ans = c[i][j] + 1;
	cout<< ans <<endl;
}

Measured memory_bytes: 20096
#define _USE_MATH_DEFINES
 
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <numeric>
#include <string>
#include <map>
#include <sstream>
using namespace std;
 
int main() {
	string S;
	int N, x = 0, maxValue = 0;
	cin >> N >> S;
	for(int i = 0;i < N; i++){
		if(S[i] == 'I'){
			x++;	
		}
		else x--;
		if(maxValue < x) maxValue = x;	
	}
	cout << maxValue << endl;	
}

Measured memory_bytes: 256
sx, sy, tx, ty = gets.split.map(&:to_i)

ans = "D"
(tx-sx+1).times do
	ans += "R"
end

(ty-sy+1).times do
	ans += "U"
end

(tx-sx+1).times do
	ans += "L"
end

(ty-sy).times do
	ans += "D"
end

(tx-sx).times do
	ans += "R"
end

(ty-sy+1).times do
	ans += "U"
end

(tx-sx+1).times do
	ans += "L"
end

(ty-sy+1).times do
	ans += "D"
end

ans += "R"

print ans, "\n"


Measured memory_bytes: 31740
#include <iostream>
using namespace std;
int main(){
  int D, G, p[10], c[10] ;
  cin >> D >> G;
  for(int i=0; i<D; ++i){
    cin >> p[i] >> c[i];
  }
  int ans=1e3;
  for(int mask=0; mask<(1<<D); ++mask){
    int s=0, num=0, rest_max=0; 
    for(int i=0; i<D; ++i){
      if(mask >>i &1){
        s+= 100*p[i]*(i+1)+c[i];
        num+=p[i];
      }
      else{
        rest_max=i;
      }
    }
    int need=0; 
    if(s<G){
      int s1=100*(rest_max+1);
      need=(G-s+s1-1)/s1;
      if(need>= p[rest_max]) continue;
      num+= need;
    }
    ans= min(ans,num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy3

from math import sqrt
def count(k, t):
    if k*k - 4*t < 0: return 0
    if t == 0: return 0

    r = (-k + sqrt(k*k - 4*t)) / 2
    r = int(r)

    if r*r + k*r + t == 0 and 1 <= r: return 1
    return 0

def f(N):
    ret = 0
    for x in range(1, N+1):
        for y in range(1, N+1):
            k = x+y
            t = x*x + y*y + x*y - N
            # count solutions to z^2 + kz + t = 0
            ret += count(k, t)
    return ret


ans = dict()

for i in range(1, 10**4+1):
    ans[i] = 0

for x in range(1, 10**2+1):
    for y in range(1, 10**2+1):
        if (x**2 + y**2 > 10**4): continue
        for z in range(1, 10**2+1):
            n = x*x + y*y + z*z + x*y + x*z + y*z
            if n > 10**4: continue
            ans[n] += 1

N = int(input())
for i in range(1, N+1):
    print(ans[i])

Measured memory_bytes: 69652
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int one = min(a, k);
    k -= one;
    int zero = min(b, k);
    k -= zero;
    int minus_one = min(c, k);
    k -= minus_one;
    cout << one - minus_one;
    return 0;
}

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

struct data{
    int y,x,cost;
    data(int a,int b,int c):y(a),x(b),cost(c){}
    bool operator<(const data &d)const{
        return cost>d.cost;
    }
};
const int dx[]={-1,0,1,-1,1,-1,0,1};
const int dy[]={-1,-1,-1,0,0,1,1,1};

const int INF=1001001001;
int H,W,N,sx,sy;
int L[5];
int px[5][50],py[5][50];

int fld[20][20];
int dist[20][20][20][20];

void getDist(int ssy,int ssx){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            dist[ssy][ssx][i][j]=INF;
        }
    }

    if(fld[ssy][ssx])return;

    dist[ssy][ssx][ssy][ssx]=0;

    priority_queue<data>Q;
    Q.push(data(ssy,ssx,0));

    while(Q.size()){
        data d=Q.top();Q.pop();
        if(dist[ssy][ssx][d.y][d.x]<d.cost)continue;

        for(int i=0;i<8;i++){
            int ny=d.y+dy[i];
            int nx=d.x+dx[i];
            if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx])continue;
            if(dist[ssy][ssx][ny][nx]<=d.cost+1)continue;
            dist[ssy][ssx][ny][nx]=d.cost+1;
            Q.push(data(ny,nx,d.cost+1));
        }
    }

}

int calc(vector<int>p){
    bool dp[2][50]={{0}};
    dp[0][0]=true;

    //for(int i=0;i<p.size();i++)cout<<p[i]<<" ";cout<<endl;
    for(int i=0;i<N;i++){
        //for(int j=0;j<H+W;j++)cout<<dp[i&1][j]<<" ";cout<<endl;
        for(int j=0;j<(i?L[p[i-1]]-1:1);j++){
            int cy=(i?py[p[i-1]][j]:sy);
            int cx=(i?px[p[i-1]][j]:sx);
            if(dp[i&1][j]==false)continue;
            for(int k=0;k<L[p[i]]-1;k++){
                int ny=py[p[i]][k];
                int nx=px[p[i]][k];
                if(k>=dist[cy][cx][ny][nx]+j){
                    dp[(i+1)&1][k]=true;
                }
                //cout<<ny<<" "<<nx<<"<---"<<cy<<" "<<cx<<endl;
            }
            dp[i&1][j]=false;
        }
    }
    //for(int i=0;i<H+W;i++)cout<<dp[N&1][i]<<" ";cout<<endl;
    for(int i=0;i<50;i++)if(dp[N&1][i])return i;
    return INF;
}

int main(){
    cin>>W>>H>>N>>sx>>sy;sx--;sy--;
    for(int i=0;i<N;i++){
        cin>>L[i];
        for(int j=0;j<L[i];j++){
            cin>>px[i][j]>>py[i][j];
            px[i][j]--;py[i][j]--;
        }
        fld[py[i][L[i]-1]][px[i][L[i]-1]]=1;
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            getDist(i,j);
        }
    }
    int ans=INF;
    vector<int>p;
    for(int i=0;i<N;i++)p.push_back(i);
    do{
        ans=min(calc(p),ans);
    }while(next_permutation(p.begin(),p.end()));

    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1848
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if(k % 2 == 0){
        if(abs(a - b) > (ll)1e18){
            cout << "Unfair" << endl;
        } else {
            cout << a - b << endl;
        }
    } else {
        if(abs(b - a) > (ll)1e18){
            cout << "Unfair" << endl;
        } else {
            cout << b - a << endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
int main()
{
    Imposter
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll l,r,d;
        cin>>l>>r>>d;
        ll temp=l/d;
        ll temp1=r/d;
        if(l%d!=0 || r%d!=0)
        cout<<temp1-temp<<endl;
        else
        cout<<temp1-temp+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

int main(){
    char s[110000];
    int N, i;
    int cont0 = 0, cont1 = 0;

    for(i=0; i<110000; i++){
        scanf("%s", &s[i]);
        if(s[i] == '\0'){
            break;
        }
        if(s[i] == '0'){
            cont0 += 1;
        }else{
            cont1 += 1;
        }
    }

    if(cont0 > cont1){
        printf("%d", cont1*2);
    }else{
        printf("%d", cont0*2);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); n *= 2;
	std::string s; cin >> s;
	
	std::function<bool ()> check = [&]() {
		std::vector<int> vec(30, 0);
		for(int i = 0; i < n / 2; i++) vec[s[i] - 'a']++;
		for(int i = n / 2; i < n; i++) vec[s[i] - 'a']--;
		for(int i = 0; i < 30; i++) if(vec[i]) return false;
		return true;
	};
	if(!check()) {
		printf("0\n");
		return 0;
	}
	auto tmp = s.substr(n / 2, n / 2);
	reverse(begin(tmp), end(tmp));
	s = s.substr(0, n / 2) + tmp;
	
	using P = std::pair<std::string, std::string>;
	std::map<P, i64> mp;
	for(int i = 0; i < (1 << (n / 2)); i++) {
		std::string x, y;
		for(int j = 0; j < n / 2; j++) {
			if(i >> j & 1) x += s[j];
			else y += s[j];
		}
		mp[{x, y}]++;
	}
	
	i64 ans = 0;
	for(int i = 0; i < (1 << (n / 2)); i++) {
		std::string x, y;
		for(int j = 0; j < n / 2; j++) {
			if(i >> j & 1) x += s[j + n / 2];
			else y += s[j + n / 2];
		}
		ans += mp[{x, y}];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 91520
from itertools import product

def solve(NUM, LIST):
    lst = [i for i, li in enumerate(LIST) if li == NUM]
    if len(lst) == 0:
        return 10 ** 5
    ANS = (len(lst) - 1) * 10
    ANS += abs(sum(l[i] for i in lst) - target[NUM])
    return ANS

target = list(map(int, input().split()))
l = [int(input()) for _ in range(target[0])]

ans = 10 ** 5
for pat in product([0, 1, 2, 3], repeat=target[0]):
    tmp = sum(solve(i + 1, pat) for i in range(3))
    ans = min(ans, tmp)
print(ans)


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

using namespace std;

int main() {
	int n, t, a;
	cin >> n >> t >> a;
	int m = 1e9, j;
	for (int i = 0; i < n; i++) {
		int h;
		cin >> h;
		int d = (t - a) * 1000 - h * 6;
		if (abs(d) < m) m = abs(d), j = i;
	}
	cout << j + 1 << endl;
	return 0;
}


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

int dp[110][100100], n, k, l[110];

int main(){

	scanf("%d %d", &n, &k);
	
	for(int i = 0; i < n; i++) scanf(" %d", &l[i]);
	
	for(int i = n - 1; i >= 0; i--){
		
		for(int j = 0; j < k + 1; j++){
			if(i == n - 1) dp[i][j] = j <= l[i];
			else dp[i][j] = dp[i + 1][j] - ((j < l[i] + 1) ? 0 : dp[i + 1][j - l[i] - 1]);
			if(dp[i][j] < 0) dp[i][j] += 1000000007;
		}
		
		if(i != 0) {for(int j = 1; j < k + 1; j++) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % 1000000007;}
	}
	
	printf("%d", dp[0][k] % 1000000007);
			
	return 0;
}


Measured memory_bytes: 42968
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=100,OO=228;
struct edge{
    int from,to,flow,capacity;
    edge(int f,int t,int c):from(f),to(t),flow(0),capacity(c){}
};
vector<int> g[N*N*2];
vector<edge> es;
void ae(int a,int b,int c){
    es.pb(a,b,c);g[a].pb(es.size()-1);
    es.pb(b,a,0);g[b].pb(es.size()-1);
}
int source,sink;
int q[N*N*2],dist[N*N*2];
uint y[N*N*2];
bool bfs(){
    std::fill(dist,dist+N*N*2,N*N*2);
    dist[source]=0;
    int l=0,r=0;
    q[r++]=source;
    while(l<r){
        int v=q[l++];
        for(int x:g[v]){
            if(dist[v]+1<dist[es[x].to]&&es[x].flow+1<=es[x].capacity){
                dist[es[x].to]=dist[v]+1;
                q[r++]=es[x].to;
            }
        }
    }
    return dist[sink]<N*N*2;
}
int dfs(int v,int pu=OO){
    if(v==sink)return pu;
    for(;y[v]<g[v].size();++y[v]){
        int x=g[v][y[v]];
        int val=min(pu,es[x].capacity-es[x].flow);
        if(dist[es[x].to]==dist[v]+1&&es[x].flow+1<=es[x].capacity&&(val=dfs(es[x].to,val))){
            es[x].flow+=val;
            es[x^1].flow-=val;
            return val;
        }
    }
    return 0;
}
int dinic(){
    int ans=0,res;
    while(bfs()){
        memset(y,0,sizeof y);
        while(res=dfs(source))ans+=res;
    }
    return ans;
}
char f[N][N];

int32_t main(){
    int n,m;
    cin>>n>>m;
    forn(i,n)forn(j,m){
        cin>>f[i][j];
    }
    forn(i,n)forn(j,m){
        ae(i*m+j,n*m+i*m+j,1);
        forn(k,n)if(i!=k&&f[i][j]!='.'&&f[k][j]!='.')ae(n*m+i*m+j,k*m+j,1);
        forn(k,m)if(j!=k&&f[i][j]!='.'&&f[i][k]!='.')ae(n*m+i*m+j,i*m+k,1);
        if(f[i][j]=='S')source=n*m+i*m+j;
        if(f[i][j]=='T')sink=i*m+j;
    }
    int ans=0;
    if(source%m==sink%m||(source-n*m)/m==sink/m)ans=-1;
    else ans=dinic();
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 86812
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int a,b,c,d;

	cin>>a>>b>>c>>d;
	int ans = min(b, d) - max(a,c);
	ans = max(ans,0);

	cout<<ans<<endl;


	return 0;
}

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

int main() {
	int N,b;
	int   ans;
	ans = 0;
	vector<int>a;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> b;
		a.push_back(b);
	}

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


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n], s=0, c=0;
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    s+=a[i];
  }
  
  for(int i=0; i<n; i++){
    if(a[i]<(float)s/(4.0*m)) continue;
	else c++;
  }
  if(c>=m) printf("Yes");
  else printf("No");
  return 0;
} 
  

Measured memory_bytes: 128
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    char s[15]; scanf("%s", s);
    if (s[0] == 'R') puts("Sunny");
    if (s[0] == 'S') puts("Cloudy");
    if (s[0] == 'C') puts("Rainy");
    return 0;
}


Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const arr = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const res = _ => {
  const len = arr.filter((e, i)=>arr.indexOf(e)===i).length
  return len
}

console.log(res())

Measured memory_bytes: 7500
// main is solve AtCoder ABC110 - A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a := readInt()
	b := readInt()
	c := readInt()
	l := []int{a, b, c}
	var i int
	var m int
	i, m = max(l)
	l = remove(l, i)
	fmt.Println((m * 10) + l[0] + l[1])
}

// スライス内の最大値を取得する
func max(nums []int) (index, max int) {
	max = math.MinInt64
	for i, n := range nums {
		if n > max {
			index = i
			max = n
		}
	}
	return
}

// ある要素を削除したスライスを返す
func remove(nums []int, i int) []int {
	return append(nums[:i], nums[i+1:]...)
}


func read() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, e := strconv.Atoi(read())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 998244353
//#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,m;
ll a[310][310];
ll b[310][310];
int main(){
	scanf("%lld%lld",&n,&m);
	if(n<m){
		rep(i,0,n)rep(j,0,m)scanf("%lld",&a[j][i]);
		ll t=n;n=m;m=t;
	}else{
		rep(i,0,n)rep(j,0,m)scanf("%lld",&a[i][j]);
	}

	ll r=0;
	rep(j,0,m){
		ll t=-1;
		rep(i,r,n)if(a[i][j]){
			t=i;
			break;
		}
		
		if(t!=-1){
//			printf("%lld %lld\n",j,t);
			rep(i,0,n)if(i!=t)if(a[i][j])rep(k,0,m)a[i][k]^=a[t][k];
			rep(k,0,m){ll temp=a[r][k];a[r][k]=a[t][k];a[t][k]=temp;}
			r++;
		}
	}
//	rep(i,0,n){rep(j,0,m)printf("%lld",a[i][j]);puts("");}
	ll ans=pom(2,r-1,MOD)*(pom(2,r,MOD)-1+MOD)%MOD*pom(2,n-r,MOD)%MOD*pom(2,m-r,MOD)%MOD;
//	printf("%lld ",r);
	printf("%lld",ans);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	string S;
	cin >> S;

	ll ans = 1;
	string prevS = S.substr(0, 1);
	ll s = S.length();
	ll stid = 1;
	while (stid < s) {
		if (prevS.length() > 1) {
			prevS = S.substr(stid, 1);
			stid++;
			ans++;
			// cout << stid << endl;
		} else if (prevS == S.substr(stid, 1)) {
			prevS = S.substr(stid, 2);
			stid += 2;
			ans++;
			if (stid > s) ans--;
			// cout << stid << " "<<2 << endl;
		} else {
			prevS = S.substr(stid, 1);
			stid++;
			ans++;
			// cout << stid <<" "<< 3 << endl;
		}

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

Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int n,i,j,minj,put,con = 0;
  int a[100];
  
  scanf("%d",&n);
  for(i = 0; i < n;i++){
    scanf("%d",&a[i]);
  }
  
  for(i = 0;i < n-1;i++){
    minj = i;
    for(j = i;j < n;j++){
      if(a[j] < a[minj]){
	minj = j;
      }
    }
     put = a[i];
    a[i] = a[minj];
    a[minj] = put;
    if(i != minj) con++;
  }

  for(i = 0;i < n;i++){
    if(i != 0) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",con);

  return 0;
}



Measured memory_bytes: 2104
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Vikash Kumar @ Codechef/codeforces 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/   
#include<bits/stdc++.h>
 
#define ll                    long long int
#define ll_MAX                LLONG_MAX
#define ll_MIN                LLONG_MIN
#define pi                    3.14159265358979323846
#define count_1(n)            __builtin_popcountll(n)
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define mid(s,e)              (s+(e-s)/2)
const int MX=10010896;
const int lmt=3164;
const int N=10000001;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
#define print_upto(a,n)        for(int i=0;i<n;i++)    cout<<a[i]<<" "; cout<<endl
#define print(a)        for (auto x : a) cout << x << " "; cout << endl

inline void solve(){
  ll x,k,d;cin>>x>>k>>d;
  x=abs(x);
  ll t=x/d;
  ll ans=0;
  if(k<=t){
    ans=x-k*d;
  }
  else{
    if (t % 2 == k % 2) ans = x - t * d;
		else ans = min(x - (t - 1) * d, abs(x - (t + 1) * d));
  }
  cout<<ans<<endl;
  
}

int main()
{
	cout<<fixed<<setprecision(12);
	fastio;ll  t=1,tc=1;
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
	#endif
	//cin>>t;
	while(t--){solve();}return 0;
}

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

const int N=100;

int main(){
	int n;
	long m[N+1][N+1], p[N+1];
	
	scanf(" %d", &n);
	for(int i=1; i<=n; ++i)
		scanf(" %ld %ld", &p[i-1], &p[i]);
		
	//for(int i=0; i<=n; ++i) printf("p[%d]=%ld\n", i, p[i]);
		
	for(int i=1; i<=n; ++i) m[i][i]=0;
	
	for(int s=2; s<=n; ++s){ //s??????????????????
		for(int i=1; i+s-1<=n; ++i){ //?§????i
			int j=i+s-1; //??????j
			m[i][j]=100000000; //????????§???????????§?????????
			for(int k=i; k<=j-1; ++k){ //?????????k
				m[i][j]=min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
				//printf("go %d %d %d\n",i, j, k);
			}
		}
	}
	
	printf("%ld\n", m[1][n]);
}

Measured memory_bytes: 1268
#include <bits/stdtr1c++.h>

using namespace std;
#define INP "solve"
#define OUT "solve"
const int QQ = 3e5 + 10;
const int maxN = 2e5 + 10;
const int maxM = 1e3 + 10;
const int oo = 1e9;
const int module = 1e9 + 7;

void doc() {
    freopen(INP ".inp","r",stdin);
    freopen(OUT ".out","w",stdout);
}

void solve() {
    int n;
    cin >> n;
    int x = 0;
    while (n--){
        int y;
        cin >> y;
        x ^= y;
    }
    cout << (x == 0 ? "Yes" : "No");
}
int main(int argc,char *argv[]) {
    //srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;

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

  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    int x = i - a[i];
    if (x <= 0)
      continue;
    cnt += m[x];
  }

  cout << cnt << endl;
  return 0;
}


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

int main(){
    int h,w,d;
    int z;
    cin >> h >> w >> d;
    vector <int> xx(h*w+1,0),yy(h*w+1,0);
    rep(i,h){
        rep(j,w){
            cin >> z;
            xx[z]=i+1;
            yy[z]=j+1;
        }
    }

    ll q;
    cin >> q;
    int l,r;
    vector <ll> ans(q,0);

    vector <ll> gg(h*w+1);

    rep(i,h*w+1){
        if(i<d){
            gg[i]=0;
        }
        else{
            gg[i]=gg[i-d]+abs(xx[i]-xx[i-d])+abs(yy[i]-yy[i-d]);
        }
        //cout << gg[i] << endl;
    }
    
    rep(i,q){
        //cout << i << endl;
        cin >> l >> r;
        ans[i]=gg[r]-gg[l];
        
    }

    rep(i,q){
        cout << ans[i] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 5276
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        
        String result = "Balanced";
        if (a+b > c+d) {
            result = "Left";
        } else if (a+b < c+d) {
            result = "Right";
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35564
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    if ((a+b)%2 == 0) {
        cout << (b-a)/2 << endl;
    }
    else {
        cout << min(a-1, n-b) + 1 + (b-a-1)/2 << endl;
    }
    return 0;
}




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

int main() {
  int N;
  cin >> N;
  int n;
  n = N % 10;
  //2,4,5,7,9
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
    cout << "hon" << endl;
  }else if(n == 3){
    cout << "bon" << endl;
  }else{
    cout << "pon" << endl;
  }
}

Measured memory_bytes: 3636
while True:
    try:
        n, x = map(int, input().split())
    
        if n==0 and x==0:
            break
    
    except:
        break
    
    S = []
    for i in range(1,n+1,1):
        for j in range(1,n+1,1):
            for k in range(1,n+1,1):
                
                if i<j<k:
                    s = i+j+k
                    if s==x:
                        S.append(s)
    
    Slen = len(S)
    print(Slen)
    
    continue


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define INF (1LL<<60)

ll dp[200010];
ll dp2[200010];

int main(){
	int n,m;
	cin >> n >> m;
	vector<int>a(n);
	rep(i,n)cin >> a[i],a[i]--;
	ll sm = 0;
	rep(i,n-1){
		if(a[i]<a[i+1]){
			sm += a[i+1]-a[i];
			dp[a[i]+2]++;
			dp[a[i+1]+1]--;
			dp2[a[i+1]+1] -= a[i+1]-a[i]-1;  
		}else{
			sm += m+a[i+1]-a[i];
			dp[a[i]+2]++;
			dp[m+a[i+1]+1]--;
			dp2[m+a[i+1]+1] -= m+a[i+1]-a[i]-1; 
		}
	}
	rep(i,2*m+2){
		dp[i+1] += dp[i];
		dp2[i] += dp[i];
		dp2[i+1] += dp2[i];
	}
	ll mx = 0;
	// rep(i,2*m){
	// 	cerr << dp[i] << " ";
	// }
	// cerr << endl;
	// rep(i,2*m){
	// 	cerr << dp2[i] << " ";
	// }
	// cerr << endl;
	rep(i,m){
		mx = max(mx,dp2[i]+dp2[i+m]);
		//cerr << sm-dp2[i]-dp2[i+m] << "  " << dp2[i] << " " << dp2[i+m] << endl;
	}
	cout << sm-mx << endl;
	return 0;
}

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

int main() {
  int N,A,B,C,D,Z=0;
  cin>>N>>A>>B>>C>>D;
  string S;
  cin>>S;
  for(int i=A;i<max(C,D);i++){
    if(S.at(i)=='#'&&S.at(i-1)=='#'){
      Z++;
      break;
    }
  }
  if(D<C){
    Z++;
    for(int i=B;i<=D;i++){
      if(S.at(i)=='.'&&S.at(i-1)=='.'&&S.at(i-2)=='.'){
        Z--;
        break;
      }
    }
  }
  if(Z==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 640
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

for i, pat in enumerate(itertools.permutations(range(1, N + 1)), N):
    if pat == P:
        a = i
    if pat == Q:
        b = i

ans = abs(a - b)

print(ans)


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

using namespace std;

int main(void){

  string N;
  int ans = 0;
  cin >> N;

  for(char s :N){
    ans += s - '0';
  }

  if(ans%9 == 0){
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;

}


Measured memory_bytes: 3720
#include"cstdio"
#include"cstring"
#include"iostream"
#include"algorithm"
using namespace std;

const int MAX=2e5+1;

struct p{int x,L;}c[MAX],d[MAX];
int n;
int a[MAX],b[MAX];

bool look(int mid)
{
    int num1=0,num2=0,A1=0,A0=0,L0=0,L1=0,T1,T0;
    for(int i=1;i<2*n;++i) if(a[i]>=mid) b[i]=1,++A1;else b[i]=0,++A0;
    for(int i=1;i<n<<1;++i){
        if(!b[i]){
          	L1=0,++L0;
          	if(L0==1) T0=i;
          	if(L0==2) d[++num2].x=T0;
          	if(L0>1) d[num2].L=L0;
        }else{
          	L0=0,++L1;
          	if(L1==1) T1=i;
          	if(L1==2) c[++num1].x=T1;
          	if(L1>1) c[num1].L=L1;
        }
    }if(!num1&&!num2) return A1>A0;int minn=1e9;
    for(int i=1;i<=num1;++i) if(minn>min(abs(c[i].x-n),abs(c[i].x+c[i].L-n-1))) minn=min(abs(c[i].x-n),abs(c[i].x+c[i].L-n-1));
    for(int i=1;i<=num2;++i) if(minn>min(abs(d[i].x-n),abs(d[i].x+d[i].L-n-1))) return 0;
    return 1;
}

int main()
{
    scanf("%d",&n);for(int i=1;i<2*n;++i) scanf("%d",&a[i]);
    int l=1,r=n*2-1,ans;
    while(l<=r){
        int mid(l+r>>1);
        if(look(mid)) l=mid+1,ans=mid;
        else r=mid-1;
    }printf("%d\n",ans);
    return 0;
}

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

#define int 		long long
#define vi 			vector <int>
#define si 			set <int>
#define pii 		pair<int,int>
#define fr(n) 		for(__typeof(n) i=0;i<n;i++)
#define rep(i,a,b) 	for(__typeof(b) i=a;i<b;i++)
#define repi(i,b,a) for(__typeof(a) i=b;i>=a;i--)
#define tr(a) 		for(auto it=a.begin();it!=a.end();it++)
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define FAST 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

void solve()
{
	int n,m;
	cin>>n;
	m=n;
	int a[n];
	fr(n)
	{
		cin>>a[i];
	}
	sort(a,a+n,greater<int>());
	int ans=a[0];
	m=m-2;
	rep(i,1,n)
	{
		if(m==0)
			break;
		else if(m==1)
		{
			ans=ans+a[i];
			break;
		}
		else
		{
			ans=ans+2*a[i];
			m=m-2;
		}
	}
	cout<<ans;
}

signed main()
{
	FAST
	int test=1;
	//cin>>test;
	while(test--)
	{
		solve();
	}
	cerr<<endl<<"Time elapsed : "<<time_passed<<endl;
	return 0;
}

Measured memory_bytes: 5356
#!/usr/bin/env python3
import sys


def solve(N: int):
    sum = 0
    for i in range(1, N+ 1):
        if i % 5 != 0 and i % 3 != 0:
            sum += i
    print(sum)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67380
i,p[1000],P;main(n,m){for(;scanf("%d%d",&n,&m)*n;P=!printf("%d\n",P)){for(i=n;i--;P+=p[i])scanf("%d",p+i);qsort(p,n,4,"YZXRPQ\213\0+\2\303");for(i=m-1;i<n;i+=m)P-=p[i];}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,AB,BC,CA;
    cin >> A >> B >> C;
    AB = 10*A+B+C;
    BC = 10*B+C+A;
    CA = 10*C+A+B;
    cout << max(max(AB,BC),max(BC,CA)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int A, B, C, D;
    scanf("%d %d %d %d",&A, &B, &C, &D);

    if(A + B > C + D) printf("Left\n");
    if(A + B < C + D) printf("Right\n");
    if(A + B == C + D) printf("Balanced\n");


    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int i, n, q, left, right;
  long cnt, sum, x;
  scanf("%d %d", &n, &q);
  long a[n];
  for (i=0; i<n; i++) scanf("%ld", &a[i]);
  for (i=0; i<q; i++) {
    scanf("%ld", &x);
    cnt = sum = 0;
    for (left=0, right=0; left<n; cnt+=right-left++) {
      for (; right<n && sum+a[right]<=x; sum += a[right++]);  
      sum -= a[left];
    }
    printf("%ld\n", cnt);
  }
  return 0;
}



Measured memory_bytes: 2632
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a/b; a -= t*b; swap(a,b); u -= t*v; swap(u,v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};
using mint = ModInt<MOD>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    vector<vector<int>> B(N+1, vector<int>(3, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) B[i+1][j] = B[i][j];
        for (int j = 0; j < 3; j++) {
            if (A[i] == B[i][j]) { B[i+1][j]++; break; }
        }
    }
    
    mint ans = 1;
    for (int i = 0; i < N; i++) {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
            if (A[i] == B[i][j]) cnt++;
        }
        ans *= cnt;
    }
    cout << ans << endl;
    return 0;
}
        

Measured memory_bytes: 6144
#include <cstdio>
#include <vector>
#include <functional>
#include <cassert>
#include <iostream>
using namespace std;

string s;

int win(int i, int j) {
    if (i == j) return i;
    if (i > j) swap(i, j);
    return s[j - i - 1] == '0' ? i : j;
}

int n;
vector<int> W[19];
int p[1<<19];

int solve(int i, int j, int k) {
    assert(i >= j);
    assert(i < 1<<n);
    assert(j >= 0);
    if (j == i + (1<<k)) return W[k][i];
    if (j == 0 && i + (1<<k) == 1<<n) return W[k][i];
    if (k == 0) return W[0][i];
    int w1, w2;
    const int h = 1 << (k-1);
    if (i + h <= 1 << n) w1 = W[k-1][i];
    else w1 = solve(i, j - h, k-1);
    if (j - h >= 0) w2 = W[k-1][j - h];
    else w2 = solve(i + h, j, k-1);
    return win(w1, w2);
}

int main() {
    cin >> n >> s;
    for (int i = 0; i < 1<<n; i++) scanf(" %d", &p[i]);
    for (int i = 0; i < 1<<n; i++) p[i+(1<<n)] = p[i];
    for (int k = 0; k <= n; k++) W[k].resize(1<<(n+1));
    for (int i = 0; i < 1<<(n+1); i++) W[0][i] = p[i];
    for (int k = 1; k <= n; k++)
        for (int i = 0; i + (1<<k) < 1<<(n+1); i++)
            W[k][i] = win(W[k-1][i], W[k-1][i + (1<<(k-1))]);

    for (int j = 0; j < 1<<n; j++) printf("%d\n", solve(j, j, n));
}



Measured memory_bytes: 44408
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  string s,ts;
  int st,en,cnt=0;
  cin >>s;
  bool can=true;
  for(int i=0;i<s.size();i++){
    if(s[i]!='x') ts+=s[i];
  }
  for(int i=0;i<ts.size();i++){
    if(ts[i]!=ts[ts.size()-1-i]){
      can = false;
      break;
    }
  }
  if(can==false){
    cout << "-1\n";
    return 0;
  }
  st=0;
  en=s.size()-1;
  while(st<en){
    if(s[st]==s[en]){
      st++;
      en--;
    }else if(s[st]=='x'){
      st++;
      cnt++;
    }else if(s[en]=='x'){
      en--;
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
from collections import deque
import sys
input=sys.stdin.readline


def BFS():
    color=["white" for _ in range(n)]
    D=[0]*n
    M=[[] for _ in range(n)]

    for u,v,w in UVW:
        M[u-1].append((v-1,w))
        M[v-1].append((u-1,w))

    D[0]=1
    color[0]="gray"
    queue=deque([0])

    while len(queue)>0:
        u=queue.popleft()
        for i,j in M[u]:
            if color[i]=="white":
                if j%2==0:D[i]=D[u]
                elif j%2==1:D[i]=-D[u]
                color[i]="gray"
                queue.append(i)
        color[u]="black"

    return D


n=int(input())
UVW=[list(map(int,input().split())) for _ in range(n-1)]
for i in BFS():
    if i==-1:print(0)
    else:print(i)

Measured memory_bytes: 87132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

#define INF 		2000000007
#define MOD			1000003

#define MAX 		100005

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

int main(){
	string str;cin>>str;
	int K;cin>>K;
	int N=str.size();
	
	set<string> sub;

	for(int i=0;i<N;++i)
		for(int j=1;j<=K&&(i+j)<=N;++j)
			sub.insert(str.substr(i,j));

	auto itr = sub.begin();
	for(int i=0;i<K;++i,++itr)	;
	cout << *(--itr) << endl;

	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;;
using ll = long long;

int main() {
	int N, K;
	cin >> N >> K;
	int i = N-K, cnt = 1;
	while (i >= 0) {
		
		cnt++;
		i = N - (pow(K,cnt));
	}
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 384
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
int main()
{
	int n, m, x;
	cin >> n >> m >> x;

	vector<int> costs(n);
	vector<vector<int>> addon(n, vector<int>(m));
	for (int i = 0; i < n; i++)
	{
		cin >> costs[i];
		for (int j = 0; j < m; j++)
		{
			cin >> addon[i][j];
		}
	}

	int res = IINF;
	for (int k = 0; k < (1 << n); k++)
	{
		int this_cost = 0;
		vector<int> level(m);
		for (int i = 0; i < n; i++)
		{
			if (k & (1 << i))
			{
				this_cost += costs[i];
				for (int j = 0; j < m; j++)
				{
					level[j] += addon[i][j];
				}
			}
		}

		bool is_good = true;
		for (int j = 0; j < m; j++)
		{
			if (level[j] < x)
				is_good = false;
		}
		if (is_good)
			res = min(res, this_cost);
	}
	if (res == IINF)
		cout << -1 << "\n";
	else
		cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 3596
S = input()
T = input()

d = {}
for a,b in zip(S,T):
    if a in d:
        if d[a] == b:
            continue
        else:
            print('No')
            exit()
    else:
        d[a] = b
l = len(set(d.values()))

print('Yes' if len(d) == l else 'No')

Measured memory_bytes: 3632
#include <bits/stdc++.h>
constexpr int INF = 1001001001;
using ll = long long;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++)
        cin >> x[i];
    
    sort(x.begin(), x.end());
    
    int ans = INF;
    for (int p = x[0] - 100; p <= x[n-1] + 100; p++) {
        int h = 0;
        for (int i = 0; i < n; i++)
            h += (x[i] - p) * (x[i] - p);
        ans = min(ans, h);
    }
    
    cout << ans << endl;
    
    return 0;
}


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

typedef long long ll;

int main(){
    int N;
    cin>>N;
    vector<vector<ll>> inp(3,vector<ll>(N));

    for(int i=0; i<3; i++){
        for(int j=0; j<N; j++){
            cin>>inp[i][j];
        }
    }

    for(int i=0; i<3; i++){
        sort(inp[i].begin(),inp[i].end());
    }

    ll ans = 0;

    for(int i=0; i<N; i++){
        auto itr1 = lower_bound(inp[0].begin(),inp[0].end(),inp[1][i]);
        auto itr2 = upper_bound(inp[2].begin(),inp[2].end(),inp[1][i]);
        ll tmp1 = itr1 - inp[0].begin();
        ll tmp2 = inp[2].end() - itr2;
        ans += tmp1*tmp2;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6400