akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define double long double
typedef complex<double> P;

struct NODE{
	long long x;
	double c;
};
bool operator < (const NODE &a,const NODE &b){
	return a.c > b.c;
}

void solve(long long x_s, long long y_s, long long x_t, long long y_t, long long N, vector<long long> x, vector<long long> y, vector<long long> r){
	P ps[1002];
	ps[N] = P(x_s,y_s);
	ps[N+1] = P(x_t,y_t);
	r.push_back(0);
	r.push_back(0);
	
	for(int i = 0 ; i < N ; i++){
		ps[i] = P(x[i],y[i]);
	}
	double best[1002];
	for(int i = 0 ; i < 1002 ; i++) best[i] = 1e18;
	
	best[N] = 0;
	priority_queue<NODE> Q;
	Q.push({N,0.0});
	bool done[1002] = {};
	while( Q.size() ){
		auto q = Q.top();  Q.pop();
		if( done[q.x] ) continue;
		done[q.x] = true;
		
		for(int i = 0 ; i < N+2 ; i++){
			double nc = q.c + max((double)0.0,abs(ps[i]-ps[q.x])-r[i]-r[q.x]);
			if( done[i] or best[i] < nc ) continue;
			best[i] = nc;
			Q.push({i,nc});
		}
	}
	printf("%.15Lf\n",best[N+1]);
	
	
		
}

int main(){	
	long long N;
	long long y_s;
	long long x_s;
	long long x_t;
	long long y_t;
	scanf("%lld",&x_s);
	scanf("%lld",&y_s);
	scanf("%lld",&x_t);
	scanf("%lld",&y_t);
	scanf("%lld",&N);
	vector<long long> r(N-1+1);
	vector<long long> y(N-1+1);
	vector<long long> x(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
		scanf("%lld",&r[i]);
	}
	solve(x_s, y_s, x_t, y_t, N, x, y, r);
	return 0;
}


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

int main(){
    int64_t n;
    cin>>n;
    int64_t j=1;
    int z=sqrt(n);
    for(int i=1;i<z+1;i++){
        if(n%i==0){
            j=i;
        }
    }
    cout<<j+(n/j)-2<<endl;
}

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

using namespace std;

int n;
int arr[200005];

int main()
{
	cin >> n;
	int x=0;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		x^=arr[i];
	}
	for(int i=0;i<n;i++)
	{
		cout << (x^arr[i]) << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int x,s=0;
	int i=5;
	while(i--)
	{
		cin >> x;
		s+=x;
	}

	cout << 15-s ;
	
	
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a <= b){
              if(c <= a){
              cout << c <<" "<< a <<" "<< b <<endl;
              }else if(c <= b){
              cout << a <<" "<< c <<" "<< b <<endl;
              }else{
              cout << a <<" "<< b <<" "<< c <<endl;
                }
     }else{
              if(c <= b){
              cout << c <<" "<< b <<" "<< a <<endl;
              }else if(c <= a){
              cout << b <<" "<< c <<" "<< a <<endl;
              }else{
              cout << b <<" "<< a <<" "<< c <<endl;
                }
     }
}


Measured memory_bytes: 3068
N,M=gets.chomp.split.map(&:to_i)
X=gets.chomp.split.map(&:to_i).sort

if N>=M
  puts 0
  exit
end

y=[]
0.upto(M-2) do |i|
  y << X[i+1] - X[i]
end
y.sort!
y.reverse!
ans=X[M-1]-X[0]

if N > 1
  0.upto(N-2) do |i|
    ans -= y[i]
  end
end

puts ans

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, w;
    string s;
    map<string, int> m;
    cin >> N;
    rep(i, N) {
        cin >> s;
        m[s] ++;
    }
    cin >> M;
    rep(i, M) {
        cin >> s;
        m[s] --;
    }
    w = 0;
    rep(i, m.size()) {
    }
    for(auto itr = m.begin(); itr != m.end(); ++itr) {
        if(itr->second > w)
            w = itr->second;
    }
    cout << w << endl;
}

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

#define ll long long
#define ar array

string n;
int k, m;

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

	cin >> n >> k;
	int m=n.size(), ans=0;
	for(int i=0; i<m; ++i) {
		for(int d1=1; d1<=9; ++d1) {
			if(i==0&&d1>n[0]-'0')
				continue;
			bool less1=i||d1<n[0]-'0';
			if(k==1) {
				++ans;
			} else {
				for(int j=i+1; j<m; ++j) {
					for(int d2=1; d2<=9; ++d2) {
						if(!less1&&d2>n[j]-'0')
							continue;
						bool less2=less1||d2<n[j]-'0';
						if(k==2) {
							++ans;
						} else {
							for(int k=j+1; k<m; ++k) {
								for(int d3=1; d3<=9; ++d3) {
									if(!less2&&d3>n[k]-'0')
										continue;
									++ans;
								}
								if(n[k]>'0')
									less2=1;
							}
						}
					}
					if(n[j]>'0')
						less1=1;
				}
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  int l, r, t[n+1][n+1], ans[q];
  for (int i=0; i<n+1; i++) for (int j=0; j<n+1; j++) t[i][j] = 0;
  for (int i=0; i<q; i++) ans[i] = 0;
  for (int i=0; i<m; i++) {
    scanf("%d%d", &l, &r);
    t[l][r]++;
  }
  for (int i=0; i<n+1; i++) for (int j=1; j<n+1; j++) t[i][j] += t[i][j-1];
  for (int i=0; i<q; i++) {
    scanf("%d%d", &l, &r);
    for (int j=l; j<r+1; j++) ans[i] += t[j][r] - t[j][l-1];
  }
  for (int i=0; i<q; i++) printf("%d\n", ans[i]);
  return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
int main(){
	int in;
	int h=0,m=0,s=0;
	scanf("%d",&in);

	while(in>=3600){
	in -= 3600;
	h++;
	}

	while(in>=60){
	in -= 60;
	m++;
	}

	s = in;

	printf("%d:%d:%d\n",h,m,s);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    ll r, D, x;
    cin >> r >> D >> x;

    rep(i, 2000, 2010) {
        x = r*x - D;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int compare(const void *a,const void *b){
  return *(int*)b-*(int*)a;
}


int main(){
	
	int N,a[110],i,alice=0,bob=0;
	
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	
	qsort(a,N,sizeof(int),compare);
	
	for(i=0;i<N;i++){
		if(i%2==0){
		alice+=a[i];
		} else {
			bob+=a[i];
		}
	}
	
	printf("\n\n%d\n\n",alice-bob);
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> T3; // -dist, node, -prev_cost

struct Edge { int to, d, c; };
int d[10000];

int calc(vector<vector<Edge>> &G) {
    for (int i=0; i<10000; ++i) d[i] = 1e8;
    int cost = 0;
    priority_queue<T3> q;
    q.push(T3(0, 0, 0));
    while ( ! q.empty()) {
        int dist = -get<0>(q.top());
        int v = get<1>(q.top());
        int pcost = -get<2>(q.top());
        q.pop();
        if (d[v] <= dist) continue;
        d[v] = dist;
        cost += pcost;
        for (Edge &e: G[v]) {
            if (d[v] + e.d <= d[e.to]) {
                q.push(T3(-(d[v] + e.d), e.to, -e.c));
            }
        }
    }
    return cost;
}

int main() {
    int n, m, u, v, d, c;
    while (cin >> n >> m, n) {
        vector<vector<Edge>> G(n);
        for (int i=0; i<m; ++i) {
            cin >> u >> v >> d >> c;
            u --; v --;
            G[u].push_back((Edge){v, d, c});
            G[v].push_back((Edge){u, d, c});
        }
        cout << calc(G) << endl;
    }
    return 0;
}


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

int main()
{
	int x, y;
	cin >> x >> y;

	int first_try;
	if (x > y)
	{
		first_try = x - y + 2;
	}
	else
		first_try = y - x;
	x = -x;
	int second_try;
	if (x > y)
	{
		second_try = x - y + 1;
	}
	else
		second_try = 1 + y - x;

	cout << min(first_try, second_try) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// nCr(n,r)
int nCr(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (nCr(n - 1, r - 1) + nCr(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	if(a == 0) return b;
	else if(b == 0) return a;
	else return gcd(b,a % b);
}

// lcm(a,b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// swap(&a, &b);
void swap(int *a,int *b){
	int tmp;
	tmp = *a;	*a = *b;	*b = tmp;
	return;
}

// qsort(array, size, sizeof(int),comp);
int ASC(const int *a,const int *b){
	return (*a - *b);
}

int DESC(const int *a,const int *b){
	return (*b - *a);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	nongetpop(array,&(*size));
	return temp;
}

int nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	int n,k;
	char s[57];
	scanf("%d%d",&n,&k);
	scanf(" %s",s);
	s[k - 1] += 0x20;
	puts(s);
	return 0;
}


Measured memory_bytes: 128
from sys import stdin


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    print(sum(1
              for i in range(1 << N)
              if sum(1
                     for s, p in zip(
                         (sum(1 << int(j) - 1
                              for j in i.split()[1:])
                          for i in lines[1:-1]),
                         (int(i)
                          for i in lines[-1].split()))
                     if bin(i & s).count("1") % 2 == p) == M))
    return


main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int maxn = 205;

struct Floyd {

    int n;
    int d[maxn][maxn];

    void Init(int n) {
        this->n = n;
        memset(d,0x3f,sizeof(d));
        rep(i,1,n+1) d[i][i] = 0;
    }

    void AddEdge(int from, int to, int dist) {
        d[from][to] = dist;
    }

    void floyd() {
        rep(k,1,n+1) rep(i,1,n+1) rep(j,1,n+1)
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    int length(int S, int T) {
        return d[S][T];
    }

};


int main ()
{
    int n,m,R;
    scanf("%d%d%d",&n,&m,&R);
    int r[10];
    rep(i,0,R) scanf("%d",&r[i]);
    Floyd ans;
    ans.Init(n);
    rep(i,0,m) {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        ans.AddEdge(u,v,w);
        ans.AddEdge(v,u,w);
    }
    ans.floyd();
    sort(r,r+R);
    int Min = INF;
    do {
        int temp = 0;
        rep(i,1,R)
            temp += ans.length(r[i-1],r[i]);
        Min = min(Min,temp);
    } while (next_permutation(r,r + R));
    printf("%d\n",Min);

    return 0;
}


Measured memory_bytes: 384
import itertools
import copy
def count_hash(arr):
    b_count = 0
    for v in arr:
        for r in v:
            if r == "#":
                b_count += 1
    return b_count
def h_and_v(arr, k):
    rows = len(arr)
    cols = len(arr[0])
    mix_arr = []
    for i in range(rows):
        mix_arr.append(str(i) + "r")
    for j in range(cols):
        mix_arr.append(str(j) + "c")
    combo_arr = []
    for i in range(0, len(mix_arr)):
        temp_arr = list(itertools.combinations(mix_arr, i))
        combo_arr.append(temp_arr)
    del temp_arr
    del mix_arr
    all_combo = []
    for v in combo_arr:
        for r in v:
            all_combo.append(r)
    count = 0
    for a in all_combo:
        temp = copy.deepcopy(arr)
        for i, r in enumerate(a):
            if r[-1] == "r":
                temp[int(r[0])][:] = ["r"]*(len(temp[0]))
            else:
                for i in range(len(temp)):
                    temp[i][int(r[0])] = "r"
        if count_hash(temp) == k:
            count += 1
    print(count, end="")




def start():
    h,w,k = [int(v) for v in input().split(" ")]
    arr = []
    for i in range(h):
        arr.append([char for char in input()])
    h_and_v(arr, k)

start()

Measured memory_bytes: 9560
from collections import deque
n,qt = map(int,input().strip().split())
q = deque()
for i in range(n):
    name,time = input().strip().split()
    q.append((name,int(time)))
t = 0
while q:
    name,time = q.popleft()
    if time <= qt:
        t += time
        print(name,t)
    else:
        t += qt
        time -= qt
        q.append((name,time))

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	ld p[n+1], dp[n+1][n+1];
	for(int i=0; i<=n; i++)for(int j=0; j<=n; j++)dp[i][j]=(ld)0;
	for(int i=1; i<=n; i++){
		cin >> p[i];
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=i; j++){
			if(i==1&&j==1){
				dp[i][j] += p[i];
				dp[i][j-1] += 1.0-p[i];
			}else{
				dp[i][j] += dp[i-1][j-1]*p[i];
				dp[i][j-1] += dp[i-1][j-1]*(1.0-p[i]);
			}
		}
	}
	ld ans = 0;
	for(int j=0; j<=n; j++){
		if(j>n-j)ans += dp[n][j];
	}
	cout << fixed <<  setprecision(12) << ans << endl;
	
}	


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

int main() {
    auto ceildiv = [](auto a, auto b) { return ((a + b - 1) / b); };
    int N, X, T;
    std::cin >> N >> X >> T;
    std::cout << (T*ceildiv(N, X)) << '\n';
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;

int main(){
    int n, m; cin >> n >> m;
    vector<int> height(n);
    rep(i, n) cin >> height[i];
    Graph G(n+1);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int count=0;
    rep(i, n){
        ll v_height = height[i];
        bool flag =true;
        for (int nv : G[i+1]){
            if(v_height<=height[nv-1]) flag = false;
        }
        if(flag==true)count++;
        flag=true;
    }
    out(count); 
}


Measured memory_bytes: 8724
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>
#include <sstream>
#include <map>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9+7;

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

	vi p(n, 0);
	p[0] = 1;
	ll ans = 1;

	if (n % 2 == 0) {
		REP(i, n) {
			int a;
			cin >> a;
			if (a % 2 == 0 || p[a] == 2) {
				ans = 0;
				break;
			}
			else {
				p[a]++;
			}
		}
	}
	else {
		REP(i, n) {
			int a;
			cin >> a;
			if (a % 2 == 1 || p[a] == 2) {
				ans = 0;
				break;
			}
			else {
				p[a]++;
			}
		}
	}

	if(ans != 0) {
		REP(i, n / 2) {
			ans = ans * 2 % mod;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 640
num = int(input())
list = list(map(int,input().split()))
list_str = []
for i in list:
    list_str.append(str(i))

print(" ".join(list_str))
for i in range(1,num):
    v = list[i]
    j = i - 1
    while j>= 0 and list[j]>v:
        list[j+1] = list[j]
        j -= 1
    list[j+1] = v
    list_str = []
    for i in list:
        list_str.append(str(i))
    print(" ".join(list_str))



Measured memory_bytes: 5600
def solution():
    k, n = map(int, input().split())
    house = list(map(int, input().split()))
    next_dist = []

    for i in range(1, len(house)):
        next_dist.append(house[i]-house[i-1])
    next_dist.append(k-house[len(house)-1]+house[0])
    max_dis_index = next_dist.index(max(next_dist))
    del next_dist[max_dis_index]
    print(sum(next_dist))

solution()


Measured memory_bytes: 86436
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<ll, ll>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = LINF*5, n, K;
vector<P> v;

int main(void) {
    cin >> n >> K;
    rep(i, 0, n) {
        ll x, y;
        cin >> x >> y;
        v.pb(mp(x, y));
    }

    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) rep(l, 0, n) {
        if (i==j && i==k && i==l) continue;
        ll sx = v[i].first, tx = v[j].first, sy = v[k].second, ty = v[l].second;
        ll c = 0;
        rep(m, 0, n) if (v[m].first>=sx && v[m].first<=tx && v[m].second>=sy && v[m].second<=ty) c++;
        if (c>=K) ans = min(ans, abs(sx-tx)*abs(sy-ty));
    }
    

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   String n=kbd.next();
 
 if(n.compareTo("ABC")==0){
   System.out.println("ARC");
 }else{
    System.out.println("ABC");
 }
}
}


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

using i64 = int64_t;

void solve(int n, const vector<int> v){
    if(n == 0){
        for(int i=0;i<v.size();++i){
            if(i)cout << " ";
            cout << v[i];
        }
        cout << endl;
        return;
    }
    auto vv = v;
    for(int i=n;i>0;--i){
        if(v.size() > 0 && i>v.back())continue;
        vv.push_back(i);
        solve(n-i, vv);
        vv.pop_back();
    }
}

int main(){
    int n;
    while(cin >> n, n > 0){
        vector<int> v;
        solve(n, v);
    }

    return 0;
}



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

int main() {
  int n;
  cin >> n;
  long long m = 1000000000;
  long long lbmax = 0, lbmin = 2*m, ltmax = 0, ltmin = 2*m;
  for (int i=0; i<n; i++) {
    long long x, y, lt, lb;
    cin >> x >> y;
    lb = x + y;
    lt = x + (m - y);
    lbmax = max(lbmax, lb);
    lbmin = min(lbmin, lb);
    ltmax = max(ltmax, lt);
    ltmin = min(ltmin, lt);
  }
  long long ans = max(ltmax-ltmin, lbmax-lbmin);
  cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		String S = scan.next();
		int[] n = new int[1000000];
		
		int index = 0;
		int count = 1;
		char cur = S.charAt(0);
		char cur_c = cur;
		for (int i = 0; i < N; i++) {
			if (i == N - 1 || cur != S.charAt(i + 1)) {
				n[index++] = count;
				count = 0;
				if (i != N - 1)
					cur = S.charAt(i + 1);
			}
			count++;
		}
//		System.out.println(Arrays.toString(n));
		int sum = 0;
		for (int j = 0; j < K + (K + (cur_c == '1' ? 1 : 0)); j++)
			sum += n[j];
//		System.out.println(sum);
		int max = sum;
		if (cur_c == '0') {
			max = sum;
			sum = 0;
			for (int j = 1; j < K + (K + 2); j++)
				sum += n[j];
//			System.out.println(sum);
			max = Math.max(max, sum);
		}
		for (int i = (cur_c == '1' ? 0 : 1); i < index; i+= 2) {
//			System.out.println("m: " + n[i] + ", " + n[i + 1] + ", p: " + n[i + (K * 2 + 1)] + ", " + n [i + (K * 2 + 2)]);
			sum = sum - (n[i] + n[i + 1]) + (n[i + (K * 2 + 1)] + n [i + (K * 2 + 2)]);
//			System.out.println(sum);
			max = Math.max(max, sum);
		}
		System.out.println(max);
	}
    public static void main(String[] args) {
    	new Main().run();
    }
}


Measured memory_bytes: 30344
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri(), m = ri();
	if (n == m) {
		std::cout << 0 << std::endl;
		return 0;
	}
	int a[n + 1];
	for (int i = 1; i <= n; i++) a[i] = ri();
	a[0] = 0;
	n++;
	
	int64_t dp[n + 1][m + 1][n];
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
			for (int k = 0; k < n; k++) 
				dp[i][j][k] = 1000000000000000000;
	dp[1][m][0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= m; j++) {
			for (int k = 0; k < n; k++) {
				if (dp[i][j][k] == 1000000000000000000) continue;
				// use
				if (j) dp[i + 1][j - 1][k] = std::min(dp[i + 1][j - 1][k], dp[i][j][k]);
				// no use
				dp[i + 1][j][i] = std::min(dp[i + 1][j][i], dp[i][j][k] + std::max(0, a[i] - a[k]));
			}
		}
	}
	int64_t res = 1000000000000000000;
	for (int i = 0; i <= m; i++)
		for (int j = 0; j < n; j++) res = std::min(res, dp[n][i][j]);
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 179200
#include <stdio.h>
#define DIV 1000000007
int main(){
  char S[200000];
  int N=0;
  int a[200000];
  int b[200000];
  int c[200000];
  int n;

  scanf("%s",S);
  while(S[++N]!='\0') ;
  
  n=1;
  for(int i=0;i<N-2;i++)
    if(S[i]=='A')
      a[i]=n;
    else if(S[i]=='?'){
      a[i]=n;
      n=(long long int)n*3%DIV;
    }else
      a[i]=0;

  n=a[0];
  for(int i=1;i<N-1;i++)
    if(S[i]=='B')
      b[i]=n;
    else if(S[i]=='?'){
      b[i]=n;
      n=((long long int)n*3+a[i])%DIV;
    } else if(S[i]=='A'){
      b[i]=0;
      n=((long long int)n+a[i])%DIV;
    }else
      b[i]=0;

  n=b[1];
  for(int i=2;i<N;i++)
    if(S[i]=='C')
      c[i]=n;
    else if(S[i]=='?'){
      c[i]=n;
      n=((long long int)n*3+b[i])%DIV;
    }else if(S[i]=='B'){
      c[i]=0;
      n=((long long int)n+b[i])%DIV;
    }else
      c[i]=0;

  n=c[2];
  for(int i=3;i<N;i++)
    if(S[i]=='?')
      n=((long long int)n*3+c[i])%DIV;
    else if(S[i]=='C')
      n=((long long int)n+c[i])%DIV;

  //  for(int i=0;i<N;i++)
  //    printf("%c %d %d %d\n",S[i],a[i],b[i],c[i]);
  
  printf("%d\n",n);

  return 0;
}
      


Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;
const int maxn = 400005;

int ehead[maxn],ecnt;
struct edge {
	int u,v,next;
}edg[maxn];
void add(int u,int v) {
	edg[++ecnt]=(edge){u,v,ehead[u]};
	ehead[u]=ecnt;
	edg[++ecnt]=(edge){v,u,ehead[v]};
	ehead[v]=ecnt;
}

int n,m,col[maxn],com,bir,siz,sing;LL ans;bool tag;
void dfs(int u) {
	siz++;
	for (int v,j=ehead[u];j;j=edg[j].next)
	if (col[v=edg[j].v]<0) col[v]=col[u]^1,dfs(v);
	else if (col[v]!=col[u]^1) tag=false;
}
int main()
{
	#ifdef Amberframe
		freopen("agc011c.in","r",stdin);
		freopen("agc011c.out","w",stdout);
	#endif
	memset(col,-1,sizeof col);
	scanf("%d %d",&n,&m);
	for (int u,v,i=1;i<=m;i++)
		scanf("%d %d",&u,&v),add(u,v);
	for (int i=1;i<=n;i++)
	if (col[i]<0) {
		col[i]=0;tag=true;siz=0;dfs(i);
		siz>1?(bir+=tag,com++):(sing++);
	}
	ans+=(LL)com*com+(LL)bir*bir+(LL)sing*sing+(LL)sing*(n-sing)*2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8704
# Aizu - 0005
def De(a):
    res = []
    tmp = 2
    while a != 1:
        while not (a % tmp):
            a = round(a / tmp)
            res.append(tmp)
        tmp += 1
    return res

while True:
    try:
        tmp = input()
        a = [int(i) for i in tmp.split(' ')]
    except:
        break
    b = De(a[1])
    a = De(a[0])
    pa, pb = 0, 0
    GCD, LCM = 1, 1
    while True:
        if pa == len(a):
            for i in range(pb, len(b)):
                LCM *= b[i]
            break;
        if pb == len(b):
            for i in range(pa, len(a)):
                LCM *= a[i]
            break;
        if a[pa] == b[pb]:
            GCD *= a[pa]
            LCM *= a[pa]
            pa += 1
            pb += 1
            continue
        if a[pa] < b[pb]:
            LCM *= a[pa]
            pa += 1
            continue
        if a[pa] > b[pb]:
            LCM *= b[pb]
            pb += 1
            continue
    print('%d %d'%(GCD, LCM))

Measured memory_bytes: 7660
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;
#define MAX_N 100000
int parent[MAX_N],r[MAX_N];

void Makeset(int n){
    REP(i,n){
        parent[i] = i;
        r[i] = 0;
    }
}

int Find(int x){
    if(parent[x] == x) return x;
    else{
        return parent[x] = Find(parent[x]);
    }
}

void Union(int x,int y){
    int xroot = Find(x);
    int yroot = Find(y);
    if(xroot == yroot) return;
    if(r[x] < r[y]){
        parent[xroot] = yroot;
    }else{
        parent[yroot] = xroot;
        if(r[xroot] == r[yroot]) r[xroot]++;
    }
}

bool isUnion(int x,int y){
    if(Find(x) == Find(y)) return true;
    else return false;
}
vector<int> v[MAX_N];
int main(){
  int N,M;
  cin >> N >> M;
  Makeset(N);
  REP(i,N){
    int K;
    cin >> K;
    REP(j,K){
      int L;
      cin >> L;
      v[L-1].pb(i);
    }
  }
  REP(j,M){
    REPS(i,(int)v[j].size()-1){
      Union(v[j][i-1],v[j][i]);
    }
  }
  bool ans = true;
  REPS(i,N-1){
    if(! isUnion(0,i)){
      ans = false;
      break;
    }
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <cmath>
#include <cstdio>

constexpr auto PI = 3.14159265358979323846264338;

auto main () -> int
{
    int d , t;
    double x = 0 , y = 0;
    int angle = 0;
    while (std::scanf ("%d,%d" , & d , & t) == 2 && (d || t))
    {
        x += d * std::sin (angle * PI / 180.0);
        y += d * std::cos (angle * PI / 180.0);
        angle += t;
    }
    std::cout << static_cast <int> (x) << std::endl;
    std::cout << static_cast <int> (y) << std::endl;
}

Measured memory_bytes: 3392
using System;
 
namespace Circle
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            double area = Math.PI * Math.Pow(input, 2);
            area = Convert.ToInt32(area);
            
            var countArea = area / Math.PI * Math.Pow(1, 2);
            int output = Convert.ToInt32(countArea);
 
            Console.WriteLine(output);
        }
    }
}

Measured memory_bytes: 13268
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
map<int,int> mp;
vector<int> v;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int tmp;
		scanf("%d",&tmp);
		mp[tmp]++;
		if(mp[tmp]==1)
			v.push_back(tmp);
	}
	sort(v.begin(),v.end());
	if(v.size()==1&&v[0]==0)
	{
		printf("Yes");
		return 0;
	}
	if(v.size()==2&&v[0]==0&&mp[v[1]]==2*mp[v[0]])
	{
		printf("Yes");
		return 0;
	}
	if(v.size()!=3) 
	{
		printf("No");
		return 0;
	}
	
	if(mp[v[0]]!=mp[v[1]]||mp[v[2]]!=mp[v[1]])
	{
		printf("No");
		return 0;
	}
	
	if((v[0]^v[2])!=v[1]||(v[0]^v[1])!=v[2]||(v[1]^v[2])!=v[0])
	{
		printf("No");
		return 0;
	}
	else
	{
		printf("Yes");
		return 0;
	}
	return 0;
}
/*
12
17 16 1
17 16 1
17 16 1
17 1 1
*/

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

using namespace std;

#define INF 1e9
typedef pair<int,int> pii;

struct Point{
  int x,y;
};

int cnt[5];
int dp[5][1002];
Point cr[5][1002];

int getMD(const Point &p1,const Point &p2){
  return abs(p1.x-p2.x)+abs(p1.y-p2.y);
}

int main(){
  int H,W;
  while(cin >> W >> H, W){
    char in;    
    int sx,sy,gx,gy;
    memset(cnt,0,sizeof(cnt));
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> in;
        if(in == 'S'){
          sx = j; sy = i;
        }else if(in == 'G'){
          gx = j; gy = i;
        }else if(isdigit(in)){
          int n = in-'1';
          cr[n][cnt[n]++] = (Point){j,i};
        }
      }
    }
    for(int i = 0 ; i < 5 ; i++){
      cr[i][cnt[i]++] = (Point){sx,sy};
    }
    int res = INF, num = -1;
    for(int i = 0 ; i < 5 ; i++){
      for(int j = 0 ; j < 5 ; j++){
        for(int k = 0 ; k < cnt[j] ; k++){
          dp[j][k] = INF;
        }
      }
      dp[i][cnt[i]-1] = 0;
      int nj = i, j = (i+1)%5, ej = (i > 0 ? i-1 : 4);
      while(true){
        int m = nj == i ? 0 : 1;
        for(int k = 0 ; k < cnt[nj]-m ; k++){
          if(dp[nj][k] == INF) continue;
          for(int l = 0 ; l < cnt[j]-m ; l++){
            dp[j][l] = min(dp[j][l],dp[nj][k]+getMD(cr[nj][k],cr[j][l]));
          }
        }
        if(j == ej){
          for(int k = 0 ; k < cnt[j] ; k++){
            int d = dp[j][k] + getMD(cr[j][k],(Point){gx,gy});
            if(d < res){
              res = d;
              num = i+1;
            }
          }
          break;
        }
        nj++; nj %= 5;
        j++; j %= 5;
      }
    }
    if(res == INF){
      cout << "NA" << endl;
    }else{
      cout << num << " " << res << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<map>
#include<queue>
using namespace std;
map<int,int> m1;
priority_queue<int> q1;
int t[200005];
int check(int a){
	for(int i=0;;i++){
		if((1<<i)>a)return ((1<<i)-a);
	}
}
int main(){
	int n;
	int i,j,k;
	int a,b,c;
	int s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
		m1[t[i]]++;
		q1.push(t[i]);
	}
	while(!q1.empty()){
		a=q1.top(),q1.pop();
		if(m1[a]==0)continue;
		m1[a]--;
		b=check(a);
		if(m1[b]>0)m1[b]--,s++;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 20596
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      String s = scan.next();

      int count = 0;
      if(s.charAt(1) == 'S'){
        if(s.charAt(0) == 'R' || s.charAt(2) == 'R')
            count = 1;
        else
            count = 0;
      }else{
          if(s.charAt(0) == 'R'){
            if(s.charAt(2) == 'R'){
                count = 3;
            }else{
                count = 2;
            }
          }else if(s.charAt(2) == 'R'){
            if(s.charAt(0) == 'R'){
                count = 3;
            }else{
                count = 2;
            }
          }else
            count = 1;
        }
        System.out.println(count);
    }
}

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

void search(int a[], int c[]) {
  for (int i = 0; i < 5; i++) {
    if (a[i] == 1) {
      c[0]++;
    } else if (a[i] == 2) {
      c[1]++;
    } else {
      c[2]++;
    }
  }
}

int main() {
  int h[5];
  
  while (true) {
    cin >> h[0];
    if (h[0] == 0) break;
    for (int i = 1; i < 5; i++)
      cin >> h[i];

    int count[3] = {0};
    search(h, count);
    int count0 = 0;
    for (int i = 0; i < 3; i++)
      if (count[i] == 0) count0++;
    if (count0 != 1) {
      for (int i = 0; i < 5; i++)
	cout << 3 << endl;
    } else {
      for (int j = 0; j < 5; j++) {
	if (count[0] && count[1]) {
	  if (h[j] == 1) cout << 1 << endl;
	  else cout << 2 << endl;
	} else if (count[1] && count[2]) {
	  if (h[j] == 2) cout << 1 << endl;
	  else cout << 2 << endl;
	} else {
	  if (h[j] == 3) cout << 1 << endl;
	  else cout << 2 << endl;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3076
N=int(input())
a_list=list(map(int,input().split()))

money = 1000
for i in range(len(a_list) - 1):
  if a_list[i] < a_list[i+1]:
    money += (a_list[i+1] - a_list[i]) * (money // a_list[i])
print(money)

Measured memory_bytes: 61776
N,K = map(int, input().split())
Als = list(map(int, input().split()))
Als = [0] + Als

used = [False]*(N+1)
ls = []
key = []
k = 1
while True:
    ls.append(k)
    used[k] = True
    k = Als[k]
    if used[k]== True:
        key.append(k)
        break
#k回移動した先が入る

kind= ls.index(key[0]) 
if K <= kind:
    print(ls[K])
else:
    K = K - kind
    ls = ls[kind:]
    mn = K % len(ls)
    print(ls[mn])



Measured memory_bytes: 32300
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math

# x 個の玉を y グループに分ける場合の数 (1個以上の玉のグループ)
def f2(x, y):
    n = x + y - 1
    r = y - 1
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


# x 個の玉を y グループに分ける場合の数 (0個以上の玉のグループ)
def f(x, y):
    if x < y:
        return 0
    if x == 0 and y == 0:
        return 1
    if x == 0:
        return 0
    if y == 0:
        return 0
    return f2(x - y, y)


# Example: N = 5, K = 3
N, K = list(map(int, input().split()))

for i in range(1, K + 1):
    result = f(K, i) * (
        f(N - K, i - 1) +
        f(N - K, i) +
        f(N - K, i) +
        f(N - K, i + 1)
    )
    print(result % 1000000007)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int sw,i;
  
cin >> s;
  for(i=0;i<s.size();++i)
  {
  if(i%2==0) 
  {if(s.at(i)=='R' || s.at(i)=='U' || s.at(i)=='D') sw++;}
  else 
  {if(s.at(i)=='L' || s.at(i)=='U' || s.at(i)=='D') sw++;}
  }
  if(sw==s.size()) cout << "Yes";
  else cout << "No";
}

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

// definitions
#define __Imperial_Lord__ ONLINE_JUDGE
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<endl
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;

// cin and cout overloaded for vectors and sets
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>             
ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}

// code beigns in main
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
    	ll a;
    	cin >> a;
    	ll ans=a+a*a+a*a*a;
    	cout << ans << endl;
    }
    exec;
}

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

using namespace std;

#define REP(i, x, y) for (int i = x;i < y; i++)

const int8_t  INFC = 0x3f;
const int16_t INFS = 0x3f3f;
const int32_t INF  = 0x3f3f3f3f;
const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
    ios::sync_with_stdio(0);
    int n,k;
    cin >> n >> k;
    if (k==1)
    {
        cout << 0 << endl;
        return 0;
    }else
    {
        cout << n-k << endl;
        return 0;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val d = (1..n).map { sc.nextInt() }.sorted()
    val m = sc.nextInt()
    val t = (1..m).map { sc.nextInt() }.sorted()

    var di = 0
    var ti = 0
    while (ti < m && di < n) {
        when {
            d[di] == t[ti] -> {
                di++
                ti++
            }
            d[di] < t[ti] -> {
                di++
            }
            else -> {
                println("NO")
                return
            }
        }
    }

    println(if (ti == m) "YES" else "NO")
}

Measured memory_bytes: 127496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N, M;
    cin >> N >> M;
    vl A(M), B(M);

    rep(i, M){
        ll b, c;
        cin >> A[i] >> b;
        rep(_, b){
            cin >> c, c--;
            B[i] |= 1 << c;
        }
    }

    vl dp(1 << N, INF);
    dp[0] = 0;

    rep(bit, 1 << N){
        rep(i, M) chmin(dp[bit | B[i]], dp[bit] + A[i]);
    }

    ll ans = dp[(1 << N) - 1];

    cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 3680
#include<stdio.h>
#include<ctype.h>

#define STACK 100

 int main()
{
  
  int stack[STACK]; 
  int stack_n; 
  int sum; 
  int digit_f;
  int k; 
  char ch; 
  
  stack_n = 0;
  digit_f = 0;
 
  while( (ch = getchar()) != '\n' ) { 
    if( isdigit(ch) ) { 
      if( digit_f ) {
	stack[stack_n] = stack[stack_n] * 10 + (ch - '0'); 
      } else {
	stack[stack_n] = (ch - '0');
	digit_f++;
      }
    }
    if( isspace(ch) ) {
      if( digit_f ) {
	stack_n++;
	digit_f = 0;
      }
    }
    if( ch == '+' ) {
      if( stack_n > 1 ) {
	stack_n--;
      }
      stack[stack_n-1] += stack[stack_n];
      stack[stack_n] = 0;
    }
    if( ch == '-' ) {
      if( stack_n > 1 ) {
	stack_n--;
      }
      stack[stack_n-1] -= stack[stack_n];
      stack[stack_n] = 0;
    }

    if( ch == '*' ) {
      if( stack_n > 1 ) {
	stack_n--;
      }
      stack[stack_n-1] *= stack[stack_n];
      stack[stack_n] = 0;
    }
  }

  printf("%d\n",stack[0]);
  
  return 0;
}



Measured memory_bytes: 2144
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,V = LI()
B,W = LI()
T = I()
if V<=W:
    print('NO')
else:
    if (max(A,B)-min(A,B))/(V-W)<=T:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9196
#include <iostream>
#include <set>
#define MOD 1000000007
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int N;
set<int> S;

int main(){
    cin >> N;
    int a = 0;
    rep(i,N){
        cin >> a;
        S.insert(a);
    }
    if(S.size()!= N){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll sum,h;
int main()
{
	scanf("%lld",&h);
	for (ll i=1;h>0;i*=2)
	{
		sum+=i;
		h/=2;
	}
	printf("%lld\n",sum);
}

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

int main(){
  int n;
  string s;
  cin>> n >> s;
  
  int r=0,w=0;
  for(int i=0; i<n; i++){
    if(s[i]=='R') r++;
    else w++;
  }
  int left=0,right=0;
  for(int i=0; i<n; i++){
    if(i<r && s[i]=='W') left++;
    else if(r<=i && s[i]=='R') right++;
  }
  cout<< max(left,right) <<endl;
}

Measured memory_bytes: 3752
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){
    return ((n + d -1) / d);
}
/*
inline double Sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
*/
// }}}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,s;
    cin >> k >> s;
    int cnt = 0;
    for(int i = 0;i <= k;++i){
        for(int j = 0;j <= k;++j){
            cnt += (s - (i + j) <= k && i + j <= s);
        }
    }

    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    int N, K; cin >> N >> K;
    ll ans = K;
    for(int i = 0; i < N-1; i++){
        ans *= (K-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, raw_input().split())

stu = []
che = []
ans = []

for i in xrange(n):
    a, b = map(int, raw_input().split())
    stu.append((a, b))
    
for i in xrange(m):
    a, b = map(int, raw_input().split())
    che.append((a, b))
    
for i in xrange(n):
    dis = float('inf')
    for j in xrange(m):
        if abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1]) < dis:
            index = j
            dis = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1])
    ans.append(index)
    
for i in ans:
    print i+1
    

Measured memory_bytes: 2696
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, V, U = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]

V -= 1
U -= 1
graph = [[] for _ in range(N)]
for a, b in AB:
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

# 深い方に逃げるべき
# 子どものうち一番深い場所の深さ
children_depths = [-1 for _ in range(N)]
parents = [None for _ in range(N)]


def dfs(v, parent):
    ret = 0
    for u in graph[v]:
        if u == parent:
            continue
        ret = max(ret, dfs(u, v) + 1)
    children_depths[v] = ret
    parents[v] = parent
    return ret


dfs(U, None)

v = V
dist = 1
while parents[v] != U:
    v = parents[v]
    dist += 1

# 何回親側に上がるか
p_cnt = 0
v = V
ans = 0
while dist > 0:
    ans = max(ans, dist - 1 + children_depths[v] + p_cnt)
    v = parents[v]
    p_cnt += 1
    dist -= 2
print(ans)


Measured memory_bytes: 115364
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

struct R {
  int id, point;
  std::string city;
  R(int in_id, std::string const& in_city, int in_point):
   id(in_id), point(in_point), city(in_city) {}
  bool operator<(R const& r) const {
    if(city != r.city) return city < r.city;
    return point > r.point;
  }
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<R> rs;
  for(int i = 0; i < N; ++i) {
    std::string S; int P; std::cin >> S >> P;
    rs.emplace_back(i+1, S, P);
  }
  std::sort(rs.begin(), rs.end());
  for(auto const& r: rs) std::cout << r.id << "\n";

  return 0;
}


Measured memory_bytes: 256