akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class  Main{
    public static void main(String[] args) throws Exception{
        //MScanner sc = new MScanner("chess.in");
        MScanner sc = new MScanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        //int n=sc.nextInt();int[]in=new int[n];
        //for(int i=0;i<n;i++)in[i]=sc.nextInt();
        double w=sc.nextInt();
        double h=sc.nextInt();
        double x=sc.nextInt();
        double y=sc.nextInt();
        pw.print(h*w/2+" ");
        if(w/2==x && h/2==y) {
        	pw.print(1);
        }
        else {
        	pw.print(0);
        }
        pw.flush();
    }
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if (a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main (void){
	int a,b,c,cost=0;
	cin >> a >> b >> c;
	if((abs(a-b))%2==1&&(abs(b-c))%2==1){
		cost++;
		a++;
		c++;
	} else if((abs(a-b))%2==1&&(abs(a-c))%2==1){
		cost++;
		b++;
		c++;
	} else if((abs(a-c))%2==1&&(abs(b-c))%2==1){
		cost++;
		a++;
		b++;
	}
	if(a>b) std:swap(a,b);
	if(b>c) std::swap(b,c);
	if(a>b) std::swap(a,b);
	cost+=(2*c-a-b)/2;
	cout << cost << endl;
	return 0;
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "ARC\n";
  } else {
    cout << "ABC\n";
  }
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>
using namespace std;

//long long a[100000];
//long long b[100000];

using namespace std;
 
//const long long MAX_N = (long long) 1 << 41;
//double a_dat[MAX_N * 2 - 1];
//double b_dat[MAX_N * 2 - 1];
const int MAX_N = 1 << 17;
long long dat[MAX_N * 2 - 1];
long long dat_added[MAX_N * 2 - 1];
int n;
 
void init(int _n){
    n = 1;
    while(n < _n){
        n *= 2;
    }
    for(int i = 0; i < 2 * n - 1; i++){
        dat[i] = 0;
        dat_added[i] = 0;
    }
}
 
void radd(int a, int b, int k, int l, int r, int x){
    if(r <= a || b <= l){
        return;
    }
    if(a <= l && r <= b){
        dat_added[k] += x;
        return;
    }
    dat[k] += (min(b, r) - max(a, l)) * x;
    radd(a, b, 2 * k + 1, l, (l + r) / 2, x);
    radd(a, b, 2 * k + 2, (l + r) / 2, r, x);
}
 
long long rsum(int a, int b, int k, int l, int r){
    if(r <= a || b <= l){
        return 0;
    }
    if(a <= l && r <= b){
        return dat[k] + dat_added[k] * (r - l);
    }
    long long vl = rsum(a, b, 2 * k + 1, l, (l + r)/2);
    long long vr = rsum(a, b, 2 * k + 2, (l + r)/2, r);
    return vl + vr + dat_added[k] * (min(b, r) - max(a, l));
}

int main(){
    int N;
    int q;
    cin >> N >> q;
    init(N);
    for(int i = 0; i < q; i++){
        int p;
        int s;
        int t;
        int x;
        cin >> p;
        if(p == 0){
            cin >> s >> t >> x;
            radd(s - 1, t, 0, 0, N, x);
        } else {
            cin >> s >> t;
            cout << rsum(s - 1, t, 0, 0, N) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7160
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

void no() {
	puts("NO");
	exit(0);
}

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

	int H, W, N;
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	string S, T;
	cin >> S >> T;

	for (int i = 0; i < 4; i++) {
		int curr = sr;
		int curc = sc;
		for (int j = 0; j < N; j++) {
			if (i == 0) {
				if (S[j] == 'L')curc--;
				if (curc <= 0)no();
				if (T[j] == 'R' && curc < W)curc++;
			}
			if (i == 1) {
				if (S[j] == 'R')curc++;
				if (curc >= W + 1)no();
				if (T[j] == 'L' && curc > 1)curc--;
			}
			if (i == 2) {
				if (S[j] == 'U')curr--;
				if (curr <= 0)no();
				if (T[j] == 'D' && curr < H)curr++;
			}
			if (i == 3) {
				if (S[j] == 'D')curr++;
				if (curr >= H + 1)no();
				if (T[j] == 'U' && curr > 1)curr--;
			}
		}
	}
	puts("YES");
	return 0;
}



Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<pii> v(m);
  vector<pii> sorted(m);
  rep(i,m) {
    int p, y;
    cin >> p >> y;
    v[i].first = p;
    v[i].second = y;
    sorted[i].first = p;
    sorted[i].second = y;
  }
  sort(sorted.begin(), sorted.end());
  map<pii, int> mp;
  int tempP = 0;
  int tempY = 0;

  rep(i,m) {
    auto pr = sorted[i];
    if (tempP != pr.first) {
      tempY = 1;
    } else tempY++;
    tempP = pr.first;
    mp[pr] = tempY;
  }
  rep(i,m) {
    cout << setfill('0') <<  right << setw(6) << v[i].first << setfill('0') << right << setw(6) << mp[v[i]] << endl;
  }
  
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <vector>
using namespace std;
void show(const vector<int> &a,int n)
{
    int i;
    for(i=0;i<n-1;i++)
        cout<<a[i]<<' ';
    cout<<a[i]<<endl;
    return;
}
int main ()
{
    vector<int> a;
    int n,m,j,i,k;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>m;
        a.push_back(m);
    }
    show(a,n);
    for(i=1;i<n;i++)
    {
        m = a[i];
        j = i-1;
        while(j>=0&&a[j]>m)
        {
            a[j+1] = a[j];
            --j;
        }
        a[j+1] = m;
        show(a,n);
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int n;
  cin >> n;
  int ar[n + 5];
  for (int i = 1; i <= n; i++){
    cin >> ar[i];
  }
  ll sum[n + 5];
  sum[0] = 0;
  for (int i = 1; i <= n; i++){
    sum[i] = sum[i - 1] + ar[i];
  }
  vector<ll>tmp;
  ll x, y;
  auto get_sum = [&] (int l, int r){
    return sum[r] - sum[l - 1];
  };
  auto F = [&](int L, int R){
    int l = L;
    int r = R;
    ll mn = 1e15;
    while (l <= r){
      int mid = (l + r) >> 1;
      ll sum_right = get_sum(mid + 1, R);
      ll sum_left = get_sum(L, mid);
      if (sum_left < sum_right){
        l = mid + 1;
      } else {
        r = mid - 1;
      }
      if (abs(sum_left - sum_right) < mn){
        mn = abs(sum_left - sum_right);
        x = sum_left;
        y = sum_right;
      }
    }
    tmp.push_back(x);
    tmp.push_back(y);
  };
  ll ans = 1e18;
  for (int i = 2; i <= n - 2; i++){
    tmp.clear();
    F(1, i);
    F(i + 1, n);
    sort(tmp.begin(), tmp.end());
    ans = min(ans, tmp[3] - tmp[0]);     
  }
  cout << ans << "\n";
  return 0;
}

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

char a[110][110];
int dp[110][110];

int main () {
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", a[i]);
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i + 1 < n) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (a[i][j] != a[i + 1][j]));
			if (j + 1 < m) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (a[i][j] != a[i][j + 1]));
		}
	}
	printf("%d\n", dp[n - 1][m - 1] + 1 + (a[0][0] == '#') >> 1);
	return 0;
}


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

int max(int x, int y)
{
  return x > y ? x : y;
}

int main(void)
{ 
  int q, slen, tlen;
  char s[1005];
  char t[1005];
  int lcs[1005][1005] = {}; // 1-origin
  
  scanf("%d", &q);
  
  while (q--) {
    scanf("%s%s", s, t);
    slen = strlen(s);
    tlen = strlen(t);
    for (int i = 0; i < slen; i++)
      for (int j = 0; j < tlen; j++)
        if (s[i] == t[j])
          lcs[i+1][j+1] = lcs[i][j] + 1;
    	else
          lcs[i+1][j+1] = max(lcs[i][j+1], lcs[i+1][j]);
    printf("%d\n", lcs[slen][tlen]);
  }
  
  return 0;
}



Measured memory_bytes: 5804
N = int(input())
ans = 10
for i in range(1,10**5+1):
    if N % i == 0:
        A = i
        B = N//i
        stA = str(A)
        stB = str(B)
        ans = min(ans,max(len(stA),len(stB)))
    else:
        pass
print(ans)

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

vector<ll> a, p;

// レベルnバーガーの下からx段までに含まれるパティの数
ll func(ll n, ll x) {
    if (n == 0) {
        return 1;
    }
    if (x == 1) {
        return 0;
    }
    else if (x < 2 + a[n - 1]) {
        return func(n - 1, x - 1);
    }
    else if (x == 2 + a[n - 1]) {
        return p[n - 1] + 1;
    }
    else if (x < 3 + 2 * a[n - 1]) {
        return p[n - 1] + 1 + func(n - 1, x - 2 - a[n - 1]);
    }
    else {
        return 1 + 2 * p[n - 1];
    }
}

int main() {

    ll n, x; cin >> n >> x;
    a.resize(n + 1);
    p.resize(n + 1);
    a[0] = 1;
    p[0] = 1;
    for (ll i = 1; i < n + 1; i++) {
        a[i] = 2 * a[i - 1] + 3;
        p[i] = 2 * p[i - 1] + 1;
    }
    cout << func(n, x) << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int k; cin>>k;
  int num = 7%k;
  if (num==0){
    cout << 1 << endl;
    return 0;
  }
  rep(i,100000000){
    num = (num*10+7)%k;
    if (num==0){
      cout << i+2 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3588
def dfs(k,r,l,p,e,t)
    return 0 if r > t + e || l < t - e
    return 1 if t - e <= r && l <= t + e
    h = (r.to_f + l.to_f)/2
    if k == 0
        return 1 if h.between?(t - e, t + e)
        return 0
    end
    ret = 0
    if h >= t
        ret += (1 - p) * dfs(k-1,r,h,p,e,t)
        ret += p * dfs(k-1,h,l,p,e,t)
    else
        ret += (1 - p) * dfs(k-1,h,l,p,e,t)
        ret += p * dfs(k-1,r,h,p,e,t)
    end
    return ret
end

k, r, l = gets.split.map(&:to_i)
p = gets.to_f
e = gets.to_f
t = gets.to_f

puts sprintf("%.15f", dfs(k,r,l,p,e,t))

Measured memory_bytes: 6156
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

int main(void) {
  ll a,b,n;cin>>a>>b>>n;
  ll ans = floor((a * min((b-1),n)*1.0)/(1.0*b));
  pr(ans);
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define ub upper_bound
#define st first
#define nd second
#define ll long long
#define pii pair < ll , ll >


int a, b, t[100], ans;

bool p(int x){

	fill(t, t+10, 0);
	int i = 0;
	while(x){
		t[i] = x%10;
		x /= 10;
		i++;
	}

	for(int j = 0; j <= i/2; j++)
		if(t[j] != t[i-j-1])
			return 0;
	return 1;
}


int main(){

	cin >> a >> b;
	for(int i = a; i <= b; i++)
		if(p(i))
			ans++;
	cout << ans << endl;
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> pref(N + 1);
  vector<int> p(M);
  vector<int> y(M);
  for (int i = 0; i < M; ++i) {
    cin >> p[i] >> y[i];
    pref[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < N + 1; ++i) {
    sort(pref[i].begin(), pref[i].end());
  }
  for (int i = 0; i < M; ++i) {
    int l = p[i];
    int r = lower_bound(pref[p[i]].begin(), pref[p[i]].end(), y[i]) - pref[p[i]].begin() + 1;
    printf("%06d%06d\n", l, r);
  }
}

Measured memory_bytes: 7808
from itertools import permutations
from math import sqrt,factorial
n=int(input())
p=[tuple(map(int,input().split(' '))) for j in range(n)]
al = factorial(n)
ans = 0
l= [i for i in range(n)]
l=permutations(l)
for i in l:
    tmp = 0
    for j in range(n-1):
        tmp += sqrt((p[i[j]][0]-p[i[j+1]][0])**2+(p[i[j]][1]-p[i[j+1]][1])**2)
    ans += tmp/al
print(ans)

Measured memory_bytes: 41196
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		Map<Integer, List<Integer>> map = new HashMap<>();
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int u = Integer.parseInt(sa[0]) - 1;
			int v = Integer.parseInt(sa[1]) - 1;
			List<Integer> list = map.get(u);
			if (list == null) {
				list = new ArrayList<>();
				map.put(u, list);
			}
			list.add(v);
		}
		sa = br.readLine().split(" ");
		int s = Integer.parseInt(sa[0]) - 1;
		int t = Integer.parseInt(sa[1]) - 1;
		br.close();

		boolean[][] visit = new boolean[n][3];
		int[] cnt = new int[n];
		visit[s][0] = true;
		cnt[s] = 1;
		Queue<Ken> que = new ArrayDeque<Ken>();
		Ken ken = new Ken();
		ken.p = s;
		ken.cnt = 1;
		que.add(ken);
		while (!que.isEmpty()) {
			Ken cur = que.poll();
			List<Integer> list = map.get(cur.p);
			if (list == null) {
				continue;
			}
			for (int next : list) {
				if (cur.k == 2) {
					if (!visit[next][0]) {
						visit[next][0] = true;
						cnt[next] = cur.cnt + 1;
						if (next == t) {
							break;
						}
						ken = new Ken();
						ken.p = next;
						ken.cnt = cnt[next];
						que.add(ken);
					}
				} else {
					if (!visit[next][cur.k + 1]) {
						visit[next][cur.k + 1] = true;
						ken = new Ken();
						ken.p = next;
						ken.k = cur.k + 1;
						ken.cnt = cur.cnt;
						que.add(ken);
					}
				}
			}
		}
		System.out.println(cnt[t] - 1);
	}

	static class Ken {
		int p, k, cnt;
	}
}


Measured memory_bytes: 78468
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int f[5];
bool cmp(int x, int y)
{
	return x > y;
}
int main()
{
	int a, b;
	scanf("%d %d",&a,&b);
	f[1] = a+b;
	f[2] = a-b;
	f[3] = a*b;
	sort(f+1,f+1+3,cmp);
	printf("%d\n",f[1]);
	
	
	
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
struct T {int m, s;};
struct {T t[4]; int n, p;} d[1000000], x;
int main()
{
	int n, i, j;
	while (cin >> n, n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> d[i].n;
			for (j = d[i].p = 0; j < 4; j++)
			{
				cin >> d[i].t[j].m >> d[i].t[j].s;
				d[i].p += d[i].t[j].m * 60 + d[i].t[j].s;
			}
		}
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (d[j].p > d[j+1].p)
				{
					x = d[j];
					d[j] = d[j+1];
					d[j+1] = x;
				}
			}
		}
		cout << d[0].n << endl << d[1].n << endl << d[n-2].n << endl;
	}
}

Measured memory_bytes: 1064
#include<iostream>
using namespace std;
int main()
  {int n,m;
   cin>>n>>m;
   int a[m];
   for(int i=0;i<m;i++)
     cin>>a[i];
   int sum=0;
   for(int i=0;i<m;i++)
     sum+=a[i];
   int d=n-sum;
   if(d<0)
     cout<<-1;
   else
     cout<<d;
}

Measured memory_bytes: 3644
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

inversion = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            inversion += 1

A.sort()

inversion2 = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] < A[j]:
            inversion2 += 1

print((K * (K - 1) // 2 * inversion2 + K * inversion) % MOD)


Measured memory_bytes: 3188
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, M);
    AIN(ll, A, N);
    priority_queue<ll> q;
    FOR(a, A)
    {
        q.push(a);
    }
    REP(i, M)
    {
        ll a = q.top();
        q.pop();
        q.push(a / 2);
    }
    ll ans = 0;
    while (not q.empty())
    {
        ans += q.top();
        q.pop();
    }
    OUT(ans);
}

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

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    //freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	
	string S;
	cin >> S;
	
	if(S[S.size()-1]=='s'){
		cout << S << "es";
	}
	else{
		cout << S << "s"; 
	}
	
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define pi pair <int, int>
typedef long long ll;
int n;

map <pi, pi> parent;
map <pi, int> size;
map <pi, set<int>> xs, ys;

auto root (auto v)
{
	if (parent[v] == v) return v;
	return parent[v] = root(parent[v]);
}

void merge (pi a, pi b)
{
	a = root(a);
	b = root(b);
	if (a != b)
	{
		if (size[a] < size[b]) swap(a, b);
		parent[b] = a;
		size[a] += size[b];
	}
}

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

	int a, b;
	cin >> n;
	vector<int> x[100001], y[100001];
	pi coo[n];
	
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		coo[i] = {a, b};
		parent[coo[i]] = coo[i];
		size[coo[i]] = 1;
		
		x[a].push_back(b);
		y[b].push_back(a);
	}
	
	for (int i = 1; i <= 100000; i++)
		for (int j: x[i])
			merge({i, j}, {i, x[i][0]});
	
	for (int i = 1; i <= 100000; i++)
		for (int j: y[i])
			merge({j, i}, {y[i][0], i});
	
	for (pi q: coo)
	{
		xs[root(q)].insert(q.first);
		ys[root(q)].insert(q.second);
	}
	
	ll ans = 0;
	for (pi q: coo)
		if (q == root(q)) ans += (ll)(xs[q].size()) * (ll)(ys[q].size());
	
	cout << ans - n;
}

Measured memory_bytes: 26112
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <functional>
using namespace std;

long long N, K, A[200009], V;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; if (A[i] == 1) V = i;
	}
	long long E = K - 1;
	long long E1 = ((V - 1) + E - 1) / E;
	long long E2 = ((N - V) + E - 1) / E;
	long long E3 = (N - 1 + E - 1) / E;
	cout << min(E1 + E2, E3) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define inf (int)1e18
//#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1=998244353;
int const mod=1000000007;
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// ******** Using PBDS ********
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}


signed main()
{
    haha
    int a,b,n;
    cin>>a>>b>>n;
    int x=min(b-1,n);
    cout<<a*x/b<<endl;
   
     
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  int l[m], r[m];
  for(int i = 0; i < m; i++)cin >> l[i] >> r[i];

  int ll = 0, rr = 10e+5;
  for(int i = 0;  i < m; i++){
    if(ll < l[i])ll = l[i];
    if(r[i] < rr)rr = r[i];
  }
  int cnt = 0;
  for(int i = 1; i <= n; i++){
    if(ll <= i && i <= rr)
      cnt++;
  }

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


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

int main(){
    int N;
    cin >> N;
    int a[N];
    int i;
    for(i=0; i<N; i++){
        cin >> a[i];
    }
    int minj, j, cnt;
    cnt = 0;
    for(i=0; i<N-1 ;i++){
        minj = i;
        for(j=minj; j < N; j++){
            if(a[minj] > a[j]) minj =j;
        }
        if(minj != i){
            swap(a[minj] , a[i]);
            cnt++;
        }
    }
    for(i=0; i<N; i++){
        if(i-N+1)cout << a[i] << " ";
        else cout << a[i] << endl;
    }
    cout << cnt << endl;
    
    return 0;
}


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

int main() {
	long long int n,res=0;
	cin>>n;

	for(int i=1;i<=n;++i) {
        if(i%3 != 0 && i%5 != 0)
            res += i;
	}
	cout<<res;
}


Measured memory_bytes: 3632
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();
        if(A<10 && B<10)System.out.println(A*B);
        else System.out.println(-1);
    }
}


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

using namespace std;

int main()
{
    int a,b,c,x,y,i;long long  k=0;
    long long t=0;
    scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
    if(c*2>=(a+b))
        {long long r=0;
        r=x*a+y*b;
            printf("%lld\n",r);return 0;}
    else
    {
        if(x>=y)
            {k=c*x*2;}
        else
            {k=c*y*2;}
        /*if(x%2)
            {t=t+a;x=x-1;}
        if(y%2)
           {
               t=t+b;y-=1;
           }*/
        int p;
        if(x>=y)
            {p=y;}
        else
            {p=x;}
        t=t+p*2*c;
        if(x>y)
            t=t+(x-y)*a;
        else if(y>=x)
            t=t+(y-x)*b;
        if(k>=t)
             printf("%lld\n",t);
         else
            printf("%lld\n",k);
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int a = n*(n-1)/2;
    int b = m*(m-1)/2;
    System.out.println(a+b);
  }
}


Measured memory_bytes: 21844
n, t = map(int, input().split())
path_lst = []
for i in range(n):
    ci, ti = map(int, input().split())
    path_lst.append((ci, ti))
possible_lst = [path_lst[i][0] for i in range(n) if path_lst[i][1] <= t]
if possible_lst == []:
    print("TLE")
else:
    print(min(possible_lst))


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	vector<string>p;
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		string x;
		cin >> x;
		p.push_back(x);
	}

	while (1) {
		
		bool f = 0;
		for (int i = 0; i < p.size(); i++) {
			int t = 0;
			for (int j = 0; j < p[i].size(); j++) {
				if (p[i][j] == '#')continue;
				t++;
			}
			if (t == p[i].size()) {
				p.erase(p.begin() + i);
				f = 1;
				i--;
			}
		}

/*
		for (int i = 0; i < p.size(); i++) {
			cout << p[i] << endl;
		}
	*/	
		for (int i = 0; i < p[0].size(); i++) {
			int t = 0;
			for (int j = 0; j < p.size(); j++) {
				if (p[j][i] == '#')continue;
				t++;
			}
			if (t == p.size()) {
				for (int k = 0; k < p.size(); k++) {
					p[k].erase(p[k].begin() + i);
				}
				f = 1;
			}
		}

		

		if (!f)break;




	}
	for (int i = 0; i < p.size(); i++) {
		cout << p[i] << endl;
	}


	return 0;



}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (k, s) = readLine()!!.split(' ').map { it.toInt() }
    var ans = 0
    for (x  in 0 .. k) {
        for (y  in 0 .. Math.min(s-x,k)) {
            if (s-x-y <= k) ans ++
        }
    }
    println(ans)
}


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

using namespace std;
constexpr int CMAX = 200010;

char strng[CMAX];

int main() {
	int n; scanf("%d", &n);
	scanf("%s", strng);
	int ans = 0;
	int procRed = 0;
	for (int i = 0; strng[i]; ++i) if (strng[i] == 'R') ++procRed;
	for (int i = 0; i < procRed; ++i) if (strng[i] != 'R') ++ans;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4024
import java.util.*;

class Main{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> arr = new ArrayList<Integer>();
		
		int i;
		int x = sc.nextInt();
		while(x != 0){
			arr.add(x);
			x = sc.nextInt();
		}
		
		int size = arr.size();
		for(i = 0; i < size; i++){
			System.out.println("Case"+" "+(i+1)+":"+" "+arr.get(i));
		}
	}
}


Measured memory_bytes: 44104
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        int n = Integer.parseInt(nk[0]);
        int k = Integer.parseInt(nk[1]);
        int[] trees = new int[n];
        
        for (int i = 0; i < n; i++) {
            trees[i] = Integer.parseInt(br.readLine());
        }
        
        Arrays.sort(trees);
        /*for (int i = 0; i < n; i++) {
            System.out.println(trees[i]);
        }*/
        
        int min = 1000000000;
        int diff = 0;
        for (int i = 0; i+k-1 < n; i++) {
            diff = trees[i+k-1] - trees[i];
            if (diff < min) {
                min = diff;
                //System.out.println(i);
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 31028
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
	int[] a = new int[n];
	int min = 1000000;
	int max = -1000000;
	long sum = 0;
	
	for(int i = 0; i < n; i++){
	    a[i] = s.nextInt();

	    if(a[i] < min) min = a[i];
	    if(a[i] > max) max = a[i];
	    sum += a[i];
	}
	System.out.println(min+" "+max+" "+sum);
    }
}



Measured memory_bytes: 41508
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    int N, T, A;
    cin >> N >> T >> A;
    int ans = 0;
    int ans_difference = 2e9 + 10000;
    for(int i = 0; i < N; i++){
        int H;
        cin >> H;
        if(ans_difference > abs(A * 1000 - (T * 1000 - H * 6))){
            ans = i;
            ans_difference = abs(A * 1000 - (T * 1000 - H * 6));
        }
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>

using namespace std;

void print(int n,int *X){

  for(int i=0;i<n;i++){ 
   cout<<X[i];
   if(i!=n-1) cout<<" ";
  }
  cout<<endl;

}

void insertion_sort(int n,int *X){

  print(n,X);
  
  for(int i=1;i<n;i++){
    int v = X[i];
    int j=i-1;
    while(j>=0 && v<X[j]){
      X[j+1]=X[j];
      j--;
    }
    X[j+1] = v;
    print(n,X);
  }
    

}


int main(){

  int A[101];
  int N;
  
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>A[i];

  insertion_sort(N,A);
 

  
 
  return 0;
}

Measured memory_bytes: 3088
var i,j,h,w,x,y,z:longint;
	a:array[-5..50]of longint;
	s:string;
begin
	readln(h,w);
	for i:=1 to h do begin
		readln(s);
		for j:=1 to w do inc(a[ord(s[j])-96]);
	end;
	if(h mod 2=0)and(w mod 2=0)then
		begin z:=h*w div 4;end;
	if(h mod 2=0)and(w mod 2=1)then
		begin y:=h div 2;z:=(h*w-2*y)div 4;end;
	if(h mod 2=1)and(w mod 2=0)then
		begin y:=w div 2;z:=(h*w-2*y)div 4;end;
	if(h mod 2=1)and(w mod 2=1)then
		begin x:=1;y:=h div 2+w div 2;z:=(h*w-2*y-x)div 4;end;
	for i:=1 to 26 do 
		while(a[i]>3)and(z>0)do
			begin dec(z);dec(a[i],4);end;
	if z>0 then begin write('No');exit;end;
	for i:=1 to 26 do 
		while(a[i]>1)and(y>0)do
			begin dec(y);dec(a[i],2);end;
	if y>0 then begin write('No');exit;end;
	write('Yes');
end.


Measured memory_bytes: 128
n=int(raw_input())
for i in range(n):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split())
    a=((x1-x2)**2+(y1-y2)**2)**0.5
    b=((x1-x3)**2+(y1-y3)**2)**0.5
    c=((x2-x3)**2+(y2-y3)**2)**0.5
    s=(a+b+c)/2
    ss=(s*(s-a)*(s-b)*(s-c))**0.5
    sina=2*ss/b/c
    r=a/sina/2
    a*=a
    b*=b
    c*=c
    px=(a*(b+c-a)*x3+b*(a+c-b)*x2+c*(a+b-c)*x1)/16/ss**2
    py=(a*(b+c-a)*y3+b*(a+c-b)*y2+c*(a+b-c)*y1)/16/ss**2

    print '%.3f %.3f %.3f'%(px,py,r)

Measured memory_bytes: 6568
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    int m = n/2;
    cout << d[m] - d[m-1] << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var hw = Console.ReadLine().Split(' ');
        var h = int.Parse(hw[0]);
        var w = int.Parse(hw[1]);

        var hlist = new List<List<char>>();
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine();
            var wlist = new List<char>();
            for (int j = 0; j < w; j++)
            {
                wlist.Add(s[j]);
            }
            hlist.Add(wlist);
        }

        hlist = m1(m1(hlist));

        for (int i = 0; i < hlist.Count; i++)
        {
            for (int j = 0; j < hlist[i].Count; j++)
            {
                Console.Write(hlist[i][j]);
            }
            Console.WriteLine();
        }
    }

    static List<List<char>> m1(List<List<char>> source)
    {
        var hlist = new List<List<char>>();
        for (int i = 0; i < source[0].Count; i++)
        {
            var f = false;
            var wlist = new List<char>();
            for (int j = 0; j < source.Count; j++)
            {
                f |= source[j][i] == '#';
                wlist.Add(source[j][i]);
            }
            if (f)
            {
                hlist.Add(wlist);
            }
        }
        return hlist;
    }
}

Measured memory_bytes: 13268
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 入力
        int n = sc.nextInt();
        //String s = sc.next();

        // 処理
        HashSet<String> s = new HashSet<>();
        for (int i = 0; i < n; i++){
            String a = sc.next();
            s.add(a);
        }
        int out = s.size();

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 77256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int i = 1;
    for (;;) {
        x *= 2;
        if (x > y) break;
        i++;
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int a;
	double b;
	while(~scanf("%d",&a))
	{
		b = sqrt(a);
		for(; b != (int)b;)
		{	
			a = a - 1;
			b = sqrt(a);
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

bool check(vector<int> a, vector<int> b)
{
  for(int i =0; i< (int)a.size(); ++i)
  {
    if(a[i]!=b[i])
      return false;
  }
  return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n), b(n), small(n), big(n);
    for(int i =0; i< n; ++i)
    {
      cin >> a[i];
    }
    for(int i =0; i< n; ++i)
    {
      cin >> b[i];
    }
    
    for(int i =0; i< n; ++i)
    {
      if(a[i] == b[i])
        continue;
      else if(a[i] < b[i])
      {
        small = a;
        big = b;
        break;
      }
      else
      {
        small = b;
        big = a;
        break;

      }
    }
    int ct =0;
    do
    {
      if(check(small,big))
        break;
      ct++;
    } while (next_permutation(small.begin(), small.end()));
    
    cout << ct;

    return 0;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

int n;
vector<string> s;

pair<int,int> calc(int l, int d){

    if('0' <= s[l][d] && s[l][d] <= '9')
        return make_pair(s[l][d] - '0', l + 1);
    bool mul = s[l][d] == '*';
    assert(s[l][d] != '.');
    ++l;
    vector<int> res;
    while(l != n && s[l].size() > d && s[l][d] == '.'){
        auto p = calc(l, d + 1);
        res.push_back(p.first);
        l = p.second;
    }
    auto f = [&](auto x, auto y){return mul ? x * y : x + y;};
    return make_pair(accumulate(res.begin(), res.end(), int(mul), f), l);
}

bool solve(){
    cin >> n;
    if(!n)
        return false;
    s.resize(n);
    for(int i = 0; i < n; ++i)
        cin >> s[i];

    cout << calc(0, 0).first << endl;
    return true;
}

signed main(){
    while(solve());
}



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

int main()
{
  int n, k;
  cin >> n >> k;
  
  string s;
  cin >> s;
  
  s.at(k - 1) = tolower(s.at(k - 1));
  
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i,b,e) for(int i=b;i<e;i++)

int main(){

    int n;
    cin >> n;
    int a = n / 100;
    int b = (n - (a * 100)) / 10;
    int c = n - (a * 100) - (b * 10);
    if(a == c) {
        cout << "Yes" << endl;
    }   else {
                cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define wsize 50
#define hsize 50

int c[hsize+2][wsize+2]={};//テヲツオツキ(テ」ツ?セテ」ツ?淌」ツ?ッテヲツ篠「テァツエツ「テヲツクツ暗」ツ?ソ)0,テゥツ卍ク1

void search(int y, int x){
    int needlY[8]={-1,-1,0,1,1,1,0,-1};
    int needlX[8]={0,1,1,1,0,-1,-1,-1};
    int i;
    c[y][x] = 0;
    
    for(i=0;i<8;i++){
        if(c[y + needlY[i]][x + needlX[i]])
            search((y + needlY[i]), (x + needlX[i]));
    }
    return;
}

int main (void){
    while(1){
        int w,h;
        int i,j;
        int count=0;
        scanf("%d %d",&w,&h);
        if(!w && !h)
            break;
        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                scanf("%d",&c[i][j]);
            }
        }

/*
    for(i=0;i<=h+1;i++){
        for(j=0;j<=w+1;j++){
            printf("%d ",c[i][j]);
        }
        printf("\n");
    }
*/

        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                if(c[i][j]){
                    //printf("%d %d\n",i,j);
                    count++;
                    search(i,j);
                }
            }
        }
        //printf("4-1  %d\n",c[4][1]);
        printf("%d\n",count);
    }
    
    return 0;
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  vector<int> arr(3);
  rep(i, 2) cin >> arr[i];
  arr[2] = arr[0] + arr[1];
  cout << (  any_of(arr.begin(), arr.end(), [](auto value){return value % 3 == 0;})
  ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
main(){
  int h,m,s,h1,m1,s1,h3,m3,s3,sum1,sum3;
  while(1){
  scanf("%d%d%d",&h,&m,&s);
  if(h==-1&&m==-1&&s==-1) break;
  sum1=h*3600+m*60+s;
  sum3=h*3600*3+m*60*3+s*3;
  sum1=7200-sum1;
  sum3=7200*3-sum3;

  h1=sum1/3600;
  sum1=sum1-h1*3600;
  m1=sum1/60;
  s1=sum1-m1*60;

  h3=sum3/3600;
  sum3=sum3-h3*3600;
  m3=sum3/60;
  s3=sum3-m3*60;

  /*  if(s%3==2){
    if(s3==0){
      if(m3==0){
	h3-=1;
	m3=59;
	s3=59;
      }
      else{
	m3-=1;
	s3=59;
      }
    }
    else s3-=1;
  }
  */

  printf("%02d:%02d:%02d\n%02d:%02d:%02d\n",h1,m1,s1,h3,m3,s3);
  }
  return 0; 
}

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

int N,M,Q;
vector<int> a,b,c,d;
int A[11];
int ans=0;

void dfs(int n){
    if(n==N+1){
        int score=0;
        for(int i=0;i<Q;i++){
            if(A[b[i]]-A[a[i]]==c[i]) score+=d[i];
        }
        ans=max(ans,score);
        return;
    }
    for(int i=min(A[n],M);i<=M;i++){
        A[n+1]=i;
        dfs(n+1);
    }
}

int main(void){
    cin>>N>>M>>Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for(int i=0;i<Q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    A[0]=1;
    dfs(0);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

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

	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		i % 2 == 0 ? suma += a[i] : sumb += a[i];
	}

	cout << suma - sumb << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b;
    cin >> a >> b;
    vector<int> v = {a, b, a+b};
    string ans = "Impossible";
    rep(i, 3) if (v[i]%3==0) ans = "Possible";
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3564