akhauriyash/Code-Regression huggingface dataset:
def solve(s, t):
    n, m = len(s), len(t)
    dp = [[0] * (m+1) for _ in range(n+1)]
    s, t = ' ' + s, ' ' + t

    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if s[i] == t[j]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])

    cur = dp[n][m]
    ans = ''
    while n > 0 and m > 0:
        if s[n] == t[m]:
            ans += s[n]
            cur, n, m = cur-1, n-1, m-1
        elif dp[n-1][m] == cur:
            n -= 1
        else:
            m -=1

    return ans[::-1]


def main():
    s = input()
    t = input()
    print(solve(s, t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 111580
#include<bits/stdc++.h>
using namespace std;
long long fun(long long x, long long y)
{
	long long tmp = 0;
	while (y != 0)
	{
		tmp = y;
		y = x%y;
		x = tmp;
	}
	return x;
}
int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<b-a+1-(b/c-(a-1)/c+b/d-(a-1)/d-b/(c*d/(fun(c,d)))+(a-1)/(c*d/(fun(c,d))));
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int main() {

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

	if (A + B >= C) printf("Yes");
	else printf("No");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N){
    rep1(i,N*10){
        ll x = i*1.08;
        if(x == N) return i;
    }
    return 0;
}

int main(){
    ll N; cin >> N;
    if(solve(N) == 0) pr(":(");
    else pr(solve(N));
    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,q; cin >> k >> q;
    vector<ll> d(k),a(k);
    for (int i=0;i<k;++i) cin >> d[i];
    ll n,x,m,sum,cnt,cnt1,cnt2,ans;
    for (int i=0;i<q;++i){
        cin >> n >> x >> m;
        sum=cnt1=cnt2=0,cnt=x%m;
        for (int j=0;j<k;++j){
            a[j]=d[j]%m; sum+=a[j];
            if (!a[j]) ++cnt1;
            if (j<(n-1)%k){
                cnt+=a[j];
                if (!a[j]) ++cnt2;
            }
        }
        cnt+=(n-1)/k*sum;
        ans=n-1-cnt/m-(n-1)/k*cnt1-cnt2;
        cout << ans << endl;
    }
}

Measured memory_bytes: 384
<?php
  $num = (int)fgets(STDIN);
$res = 0;

for($i=1; $i<10; $i++){
  if($num % $i === 0){
  	$cul = $num / $i;
    for($j=1; $j<10; $j++){
      if($cul / $j === 1){
        echo 'Yes';
        $res = 1;
        break 2;
      }elseif($j === 9){
        continue;
      }
    }
  }else{
    continue;
  }
}

if($res === 0){
  echo 'No';
}

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

typedef unsigned long long ull;

int main(void) {
    int n;
    ull a, b, tmpa, tmpb;

    cin >> n;

    a = 1; b = 1;

    while (n--) {
        cin >> tmpa >> tmpb;
        ull p = max(a / tmpa, b / tmpb);

        while (true) {
            if (p * tmpa >= a && p * tmpb >= b) {
                break;
            }
            p++;
        }

        a = tmpa * p;
        b = tmpb * p;
    }

    cout << a + b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
const int INF = 1e9;
template<int V>
struct Dijkstra {
	typedef int T;
//	const int INF = 1e9;
	typedef pair<T, int> P;
	vector<P> g[V];

	void add(int from, int to, T dist) {
		g[from].push_back(P(dist, to));
	}

	T res[V];
	void exec(int s) {
		fill_n(res, V, INF);
		priority_queue<P, vector<P>, greater<P>> q;
		q.push(P(0, s));
		res[s] = 0;
		while (!q.empty()) {
			P p = q.top(); q.pop();
			if (res[p.second] < p.first) continue;
			for (P e: g[p.second]) {
				if (p.first+e.first < res[e.second]) {
					res[e.second] = p.first+e.first;
					q.push(P(e.first+p.first, e.second));
				}
			}
		}
	}
};
 
Dijkstra<1100> djk;
const int MN = 32;
int p2id(int x, int y) {
	return x*MN+y;
}

int ink[MN][MN];
bool block[MN][MN];
const int d4[4][2] = {
	{0, 1},
	{1, 0},
	{0, -1},
	{-1, 0},
};

int h, w;

bool isB(int x, int y) {
	return (0 <= x && x <= w && 0 <= y && y <= h);
}

int main() {
	cin >> h >> w;
	int sid, gid;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == 'S') {
				sid = p2id(j, i);
			} else if (s[j] == 'G') {
				gid = p2id(j, i);
			} else if (s[j] == '#') {
				block[i][j] = true;
			} else if (s[j] == 'o') {
				ink[i][j] = 1;
			} else if (s[j] == 'x') {
				ink[i][j] = 2;
			}
		}
	}

	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			int idi = p2id(x, y);
			for (int d = 0; d < 4; d++) {
				int yy = y + d4[d][1], xx = x + d4[d][0];
				int idj = p2id(xx, yy);
				if (!isB(xx, yy)) continue;
				if (block[yy][xx]) continue;


				if (ink[yy][xx] == 0) {
					djk.add(idi, idj, 2);
				} else if (ink[yy][xx] == 1) {
					djk.add(idi, idj, 1);
				}

				//ink
				djk.add(idi, idj, 3); //1

				yy += d4[d][1]; xx += d4[d][0];
				idj = p2id(xx, yy);
				if (!isB(xx, yy)) continue;
				if (block[yy][xx]) continue;
				djk.add(idi, idj, 4); //2

				yy += d4[d][1]; xx += d4[d][0];
				idj = p2id(xx, yy);
				if (!isB(xx, yy)) continue;
				if (block[yy][xx]) continue;
				djk.add(idi, idj, 5); //3
			}
		}
	}
	djk.exec(sid);
	printf("%d\n", djk.res[gid]);
    return 0;
}

Measured memory_bytes: 1336
import sys

def main():
  input = sys.stdin.readline
  a, b, q = map(int, input().split())
  s = [0]*a
  for i in range(a):
    s[i] = int(input())
  
  t = [0]*b
  for i in range(b):
    t[i] = int(input())

  s_near = [0]*a
  k = 0
  for i in range(a):
    if k == b-1:
      s_near[i] = abs(s[i]-t[b-1])
      continue
    while True:
      sub = min([abs(s[i]-t[k]), abs(s[i]-t[k+1])])
      if sub == abs(s[i]-t[k+1]):
        k += 1
        if k == b-1:
          s_near[i] = sub
          break
        continue
      else:
        s_near[i] = sub
        break
  
  t_near = [0]*b
  k = 0
  for i in range(b):
    if k == a-1:
      t_near[i] = abs(t[i]-s[a-1])
      continue
    while True:
      sub = min([abs(t[i]-s[k]), abs(t[i]-s[k+1])])
      if sub == abs(t[i]-s[k+1]):
        k += 1
        if k == a-1:
          t_near[i] = sub
          break
        continue
      else:
        t_near[i] = sub
        break
  
  
  for i in range(q):
    x = int(input())
    if x <= s[0]:
      sub1 = s[0]-x+s_near[0]
    elif x >= s[a-1]:
      sub1 = x-s[a-1]+s_near[a-1]
    else:
      l, r = 0, a
      while r-l > 1:
        k = (r+l)//2
        if x <= s[k]:
          r = k
        else:
          l = k
      sub1 = min([s[r]-x+s_near[r], x-s[l]+s_near[l]])
    
    
    if x <= t[0]:
      sub2 = t[0]-x+t_near[0]
    elif x >= t[b-1]:
      sub2 = x-t[b-1]+t_near[b-1]
    else:
      l, r = 0, b
      while r-l > 1:
        k = (r+l)//2
        if x <= t[k]:
          r = k
        else:
          l = k
      sub2 = min([t[r]-x+t_near[r], x-t[l]+t_near[l]])
    ans = min([sub1, sub2])
    print(ans)


if __name__ == "__main__":
  main()

Measured memory_bytes: 20140
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define mod 1000000007
using namespace std;


int main(void){
    ll n; cin>>n;
    vl a(n);
    ll maxi1 = 0;
    ll maxi2 = 0;
    for(int i=0;i<n;++i){
        cin>>a[i];
        if(maxi1 <= a[i]){
            maxi2 = maxi1;
            maxi1 = a[i];
        }else if(maxi2 <= a[i]) maxi2 = a[i];
    }
    for(int i=0;i<n;++i){
        if(a[i] == maxi1) cout<<maxi2<<endl;
        else cout<<maxi1<<endl;
    }
}


Measured memory_bytes: 3200
#include<stdio.h>
 
int main(void)
{
  int i;
  int b[5];
  
  for(i=0;i<5;i++)
  {
    scanf("%d",&b[i]);
  }
  
  for(i=0;i<5;i++)
  {
    if(b[i]!=i+1)
    {
      printf("%d",i+1);
      return 0;
    }
  }
}

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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

signed main()
{

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    int ans = 0;
    int s = 0;
    rep1(i, a.size())
    {
        s = s + a[i];
        s = s % MOD;
    }

    //cout << s << endl;

    rep(i, a.size() - 1)
    {
        int temp = a[i] * s % MOD;
        ans = (ans + temp) % MOD;
        s = (s + MOD - a[i + 1]) % MOD;
    }

    cout << ans << endl;

    return 0;
}


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

using Graph=vector<vector<int>>;
int main(){
    int n; cin>>n;
    Graph g(n),rg(n);
    for(int i=0;i<n;i++){
        int p; cin>>p; p--;
        g[p].push_back(i);
        rg[i].push_back(p);
    }
    vector<int> a(n,-1);
    auto grundy=[&](int v){
        set<int> s;
        for(auto to:g[v]){
            if(a[to]!=-1) s.insert(a[to]);
        }
        for(int i=0;;i++){
            if(!s.count(i)){
                return i;
            }
        }
        assert(false);
    };
    auto greedy=[&](){
        vector<int> d(n);
        queue<int> que;
        for(int i=0;i<n;i++){
            d[i]=g[i].size();
            if(d[i]==0){
                que.push(i);
            }
        }
        while(!que.empty()){
            int v=que.front(); que.pop();
            a[v]=grundy(v);
            for(auto to:rg[v]){
                d[to]--;
                if(d[to]==0) que.push(to);
            }
        }
    };
    function<bool(int,int)> dfs=[&](int v,int val){
        assert(a[v]==-1);
        for(auto to:g[v]){
            if(a[to]==val) return false;
        }
        for(auto to:rg[v]){
            if(a[to]==val) return false;
        }
        a[v]=val;
        for(auto pre:rg[v]){
            if(a[pre]==-1){
                bool ret=dfs(pre,grundy(pre));
                a[v]=-1;
                return ret;
            }
        }
        return true;
    };
    auto solve=[&](int v){
        int val=grundy(v);
        if(dfs(v,val)) return true;
        for(auto to:g[v]){
            if(a[to]==-1){
                if(dfs(to,val)) return true;
                else return false;
            }
        }
        assert(false);
    };
    
    greedy();
    int id=find(a.begin(),a.end(),-1)-a.begin();
    cout<<(solve(id) ? "POSSIBLE" : "IMPOSSIBLE")<<endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;

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

int f(int x) {
  if (x == 0) return 0;
  int res = 1;
  rep(i, x) { res *= x - i; }

  return res;
}

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

  int a = 0, b = 0;
  int use[n];
  rep(i, n) use[i] = 0;
  rep(i, n) {
    int p;
    cin >> p;
    use[p] = 1;
    int u = 0;
    for (int j = 1; j < p; ++j) {
      u += use[j];
    }
    a += f(n - i - 1) * (p - 1 - u);
  }

  rep(i, n) use[i] = 0;
  rep(i, n) {
    int p;
    cin >> p;
    use[p] = 1;
    int u = 0;
    for (int j = 1; j < p; ++j) {
      u += use[j];
    }
    b += f(n - i - 1) * (p - 1 - u);
  }

  cout << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p 998244353

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

int inverse(int a){
	return power(a, p - 2);
}

int *fact, *fact_inv;

int comb(int N, int k){
	if(k < 0 || N < k){
		return 0;
	}
	else{
		return MOD(fact[N] * MOD(fact_inv[k] * fact_inv[N - k]));
	}
}

signed main(){
	int N, X, i, j, K, x;
	scanf("%lld%lld", &N, &X);
	int *pow2 = (int *)malloc(sizeof(int) * (N + 1));
	pow2[0] = 1;
	for(i = 1; i <= N; i++){
		pow2[i] = MOD(2 * pow2[i - 1]);
	}
	fact = (int *)malloc(sizeof(int) * (N + 1));
	fact[0] = 1;
	for(i = 1; i <= N; i++){
		fact[i] = MOD(fact[i - 1] * i);
	}
	fact_inv = (int *)malloc(sizeof(int) * (N + 1));
	for(i = 0; i <= N; i++){
		fact_inv[i] = inverse(fact[i]);
	}
	int ans = 0, now;
	for(K = 0; K <= N; K++){
//		printf("K = %lld\n", K);
		now = 0;
		for(x = K; x < X && x <= 2 * K; x++){
			now = MOD(now + comb(K, x - K));
		}
//		printf("now1 = %lld\n", now);
		if(X % 2 == 1 && K >= X - 1 && 2 * K > X){
			now++;
		}
		for(j = 1; 2 * j < K; j++){
			now = MOD(now + comb(K - 2 * j, X - 1 - K));
		}
//		printf("now = %lld\n", now);
		ans = MOD(ans + comb(N, K) * now);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

string s;
ll ans;
ll p, g;

void solve() {
	for (int i = 0; i < s.size(); i++) {
		p += 1;
		if (p <= g) {
			ans += s[i] == 'g' ? 1 : 0;
		} else {
			p -= 1;
			ans += s[i] == 'g' ? 0 : -1;
			g += 1;
		}
	}
	cout << ans << endl;
}

int main() {
	cin >> s;
	solve();
	return 0;
}




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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] cnt = new int[100];
            int ans = 0;
            for (int i = 1; i <= N; i++) {
                String s = String.valueOf(i);
                char c1 = s.charAt(0);
                char c2 = s.charAt(s.length() - 1);
                if (c1 == '0' || c2 == '0') {
                    continue;
                }
                int n = (c2 - '0') * 10 + (c1 - '0');
                cnt[n]++;
            }
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    ans += cnt[i * 10 + j] * cnt[j * 10 + i];
                }
            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



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

int main(){
  int x[100], y[100];
  double d1 = 0.0;
  double d2_1 = 0.0;
  double d3_1 = 0.0;
  double d3;
  double d4_1 = 0.0;

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i];
  for (int i = 1; i <= n; i++) cin >> y[i];

  for (int i = 1; i <= n; i++){
  d1 += fabs(x[i]-y[i]);
  }

  for (int i = 1; i <= n; i++){
  d2_1 += pow(fabs(x[i]-y[i]), 2);
  }
  double d2 = sqrt(d2_1);

  for (int i = 1; i <= n; i++){
  d3_1 += pow(fabs(x[i]-y[i]), 3);
  }
  d3 = pow(d3_1, 1/3.0);

  for (int i = 1; i <= n; i++){
  if (d4_1 <= fabs(x[i]-y[i])) d4_1 = fabs(x[i]-y[i]);
  }

  printf("%lf\n%lf\n%lf\n%lf\n", d1, d2, d3, d4_1);

return 0;
}

Measured memory_bytes: 3348
text = list(input())
check = 0
flag = False

def upper_count(string,c = 0):      # 文字列中の大文字の個数をカウント
      for i in range(len(string)):
            if string[i].isupper() == True:
                  c += 1
      return c

if text[0] == "A":
      if "C" in text[2:len(text)-1]:
            flag = True

#print(flag,upper_count(text))

if flag == True and upper_count(text) == 2:
      print("AC")
else:
      print("WA")
      

Measured memory_bytes: 9116
#include <stdio.h>
int main(){
	int H,W,i,j;
	while(1){
	scanf("%d %d",&H,&W);
	if(H!=0 && W!=0){
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i+j)%2==0){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
	}else{
		break;
	}
	printf("\n");
	}
}

Measured memory_bytes: 1000
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextLong();
		}
		
		long[]s = new long[n+1];
		for(int i = 0; i < n; i++) {
			s[i+1] = s[i] + a[i];
		}
      	//Map<Long,Integer> map = new HashMap<>();
		Map<Long,Long> map = new HashMap<>();
		
		for(int i = 0; i < n+1; i++) {
			if(!map.containsKey(s[i])) {
				map.put(s[i], (long)0);
			}
			map.put(s[i], map.get(s[i])+1);
		}
		long cnt = 0;
		
		/*for(int i = 0; i < map.size(); i++) {
			if(map.get(s[i]) < 2) {
				continue;
			}else {
				cnt += map.get(s[i])*(map.get(s[i])-1)/2;
			}
		}*/
		
		for(long ss: map.keySet()) {
			if(map.get(ss) < 1) {
				continue;
			}else {
              	long x=map.get(ss);
				cnt += x*(x-1)/2;
			}
		}
		
		System.out.println(cnt);
		
	}

}

Measured memory_bytes: 101700
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

class Road{
public:
  int distance;
  int speed_limit;
  Road(int _d,int _s) : distance(_d),speed_limit(_s) {}
  Road() : distance(INF),speed_limit(0) {}
};

class State{
public:
  int city;
  int speed;
  double time;
  int prev;
  State() : city(0),speed(1),time(0.0), prev(0){}
  State(int _c,int _s,double _t,int _p) : city(_c),speed(_s),time(_t),prev(_p){}
  
  bool operator<(const State& s) const{
    return time < s.time;
  }

  bool operator>(const State& s) const{
    return time > s.time;
  }
};

int main(){
  int total_cities;
  int total_roads;
  while(~scanf("%d %d",&total_cities,&total_roads)){
    if(total_cities == 0 && total_roads == 0) break;
    int start,goal;
    scanf("%d %d",&start,&goal);

    Road edges[100][100];
    for(int road_idx = 0; road_idx < total_roads; road_idx++){
      int from,to,distance,speed_limit;
      scanf("%d %d %d %d",&from,&to,&distance,&speed_limit);
      edges[from][to].distance = distance;
      edges[from][to].speed_limit = speed_limit;
      edges[to][from].distance = distance;
      edges[to][from].speed_limit = speed_limit;
    }

    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(start,1,0.0,0)); //pos,speed,time

    bool dp[50][50][50];

    memset(dp,false,sizeof(dp));
    double res = -0.1;
    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(dp[s.prev][s.city][s.speed]) continue;

      if(s.city == goal && s.speed == 1){
	res = s.time;
	break;
      }

      dp[s.prev][s.city][s.speed] = true;

      for(int to = 1; to <= total_cities; to++){
	if(edges[s.city][to].distance >= INF) continue;
	if(s.prev == to) continue;

	if(edges[s.city][to].speed_limit >= s.speed - 1
	   && s.speed-1 >= 1){
	  que.push(State(to,
			 s.speed -1,
			 s.time + (double)edges[s.city][to].distance/(double)(s.speed - 1),
			 s.city));
	}

	if(edges[s.city][to].speed_limit >= s.speed + 1
	   && s.time != 0.0){
	  que.push(State(to,
			 s.speed + 1,
			 s.time + (double)edges[s.city][to].distance/(double)(s.speed + 1),
			 s.city));
	}
	
	if(edges[s.city][to].speed_limit >= s.speed){
	  que.push(State(to,
			 s.speed,
			 s.time + (double)edges[s.city][to].distance/(double)(s.speed),
			 s.city));

	}
      }
    }

    if(res < 0){
      printf("unreachable\n");
    }
    else{
      printf("%.5f\n",res);
    }

  }
}

Measured memory_bytes: 21992
#S = list(map(str, input()))
S = input()

S = S[0:len(S)-1]
if len(S) % 2 == 0:
    while True:
        if len(S) == 2:
            if S[0] == S[1]:
                print(2)
                exit()
            else:
                print(1)
                exit()
            
        left = S[0:len(S)//2]
        right = S[len(S)//2:len(S)]
        if left == right:
            print(len(S))
            exit()
        else:
            S = S[0:len(S)-2]
else:
    S = S[0:len(S)-1]
    while True:
        if len(S) == 2:
            if S[0] == S[1]:
                print(2)
                exit()
            else:
                print(1)
                exit()
            
        left = S[0:len(S)//2]
        right = S[len(S)//2:len(S)]
        if left == right:
            print(len(S))
            exit()
        else:
            S = S[0:len(S)-2]

Measured memory_bytes: 3064
import Control.Monad
import Data.Function
import Data.List

main ::IO()
main = do
  n <- readLn
  nss <- replicateM n $ map read . words <$> getLine
  let [ns, ms] = transpose $ sortBy (flip compare `on` sum) nss
  print $ solve ns ms
  where
    solve [] [] = 0
    solve (n:ns) (m:ms) = n - solve ms ns

Measured memory_bytes: 125180
#include <bits/stdc++.h>
using namespace std;
int dp[200005][3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int b[3];
        int j,k,l;
        for(j=0;j<3;j++)
        cin>>b[j];
        for(j=0;j<3;j++)
        {
            for(k=0;k<3;k++)
            {
                if(j!=k)
                dp[i+1][j]=max(dp[i+1][j],dp[i][k]+b[j]);
            }
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

#define lli long long int
#define DEBUG 1
#define REP(i,n) for(int i=0;i<n;i++)
lli minAns;

//22:14
int main(){

	lli n,m;
	vector<lli> x;
	vector<lli> y;
	cin>>n>>m;

	REP(i,m){
		lli tmp;
		cin>>tmp;
		x.push_back(tmp);
	}

	sort(x.begin(),x.end());

	for(lli i=1;i<m;i++){
		y.push_back(x[i]-x[i-1]);
	}
	sort(y.begin(),y.end());

	lli ans=0;
	for(lli i=0;i<m-n;i++){
		ans += y[i];
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define heap priority_queue
using namespace std;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 5065, INF = 1e18; 
int n, a, b, p[maxn], cnt[maxn][maxn]; 

int dp[maxn][maxn]; // first i elements are sorted, and the last element that remains in the same position is j. 

signed main()
{
	cin >> n >> a >> b; 
	for(int i = 1; i <= n; i++) 
	 	cin >> p[i]; 
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			cnt[i][j] = cnt[i-1][j] + (p[i] <= j); 
		}
	}	
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= n; j++) 
			dp[i][j] = INF; 
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			if(p[i] >= j) {
				dp[i][j] = dp[i-1][j]; 
				continue; 
			} 
			dp[i][j] = min(dp[i-1][j] + b, dp[i-1][p[i]] + a * (cnt[i][j] - cnt[i][p[i]])); 
		}
	}
	cout << dp[n][n] << '\n'; 
}


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

int n, m;
vector< vector<int> > vres;

int main() {
	ios::sync_with_stdio(false);
	n = 1407, m = 38;
	for (int i = 0; i < m; ++i) {
		vector<int> vadd;
		vadd.push_back(1);
		for (int j = 0; j < (m - 1); ++j) vadd.push_back(2 + j + (m - 1) * i);
		vres.push_back(vadd);
	}
	for (int i = 0; i < (m - 1); ++i) {
		for (int j = 0; j < (m - 1); ++j) {
			int cur = j;
			vector<int> vadd;
			vadd.push_back(i + 2);
			for (int k = 0; k < (m - 1); ++k) {
				vadd.push_back(vres[k + 1][cur + 1]);
				cur = (cur + i) % (m - 1);
			}
			vres.push_back(vadd);
		}
	}
	cout << n << ' ' << m << '\n';
	for (int i = 0; i < n; ++i) {
		for (auto j : vres[i]) cout << j << ' '; cout << '\n';
	}
}

Measured memory_bytes: 768
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int[][] field = new int[11][5];
		int base = (7 * 9 + 6 * 3) % 11;
		int[] sums = new int[11];
		for (int i = 0; i < 11; i++) {
			for (int j = 0; j < 5; j++) {
				if (i == 0) {
					if (j == 0) {
						field[i][j] = base;
					} else {
						field[i][j] = (field[i][j - 1] + 9) % 11;
					}
				} else {
					field[i][j] = (field[i - 1][j] + 63) % 11;
				}
				sums[field[i][j]]++;
			}
		}
		int n = sc.nextInt() - 2;
		int k = sc.nextInt();
		long total = sums[k] * (n / 11);
		n %= 11;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 5; j++) {
				if (field[i][j] == k) {
					total++;
				}
			}
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 23764
"use strict";
function main(input) {
  const x = parseInt(input[0]);
  const en500 = Math.floor(x / 500);
  const en5  = Math.floor((x - en500*500) / 5);

  console.log(en500*1000 + en5*5);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  cin >> a >> b;
  if (a == 1)
    a = 100;
  if (b == 1)
    b = 100;
  if (a > b)
    cout << "Alice" << endl;
  else if (a < b)
    cout << "Bob" << endl;
  else
    cout << "Draw" << endl;
}


Measured memory_bytes: 256
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long double ld;
typedef long long ll;
 
typedef vector<ll> vec; 
#define inf LLONG_MAX
 
#define PP pair<int,int>
#define pb push_back
 
#define ff first
#define ss second
 
#define P pair<ll,ll>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define N 1005
#define mod 1000000007

ll n,m;
ll dp[5000];
ll visit[5000];
vector<pair<ll,vec>> p(N);

ll solve(ll x,ll pre)
{
      
      if(x<=0)
            return 0;
            
      ll &ans=dp[x];
      
      if(ans!=1e14)
            return ans;
      
      if(visit[x])
            return 1e14;
            
      visit[x]=1;
            
      for(int i=1;i<=m;i++)
      {
            ll tt=(1<<n)-1;
            for(auto X:p[i].ss)
            {
                  ll zz=((1<<n)-1)-(1<<(X-1));
                  tt=tt&zz;
            }
            tt=tt&x;
            
            if(tt!=x)
                  ans=min(ans,p[i].ff+solve(tt,i));
      }
      
      return ans;
}


int32_t main()
{
      FAST;
      
      cin>>n>>m;
      
      for(int i=1;i<=m;i++)
      {
            ll x,y;
            cin>>x>>y;
            p[i].ff=x;
            while(y--)
            {
                  ll q;
                  cin>>q;
                  p[i].ss.pb(q);
            }
      }
      
      
      for(int i=0;i<5000;i++)
            dp[i]=1e14, visit[i]=0;
            
      ll ans=solve((ll)pow(2,n)-1,0);

      if(ans>=1e14)
            ans=-1;
            
      cout<<ans<<"\n";
      
      
}



Measured memory_bytes: 512
n,m = map(int, input().split())

accurate = [0] * n
correct = 0
wrong = [0] * n
penalty = 0

for i in range(m):
    p,s = input().split()
    num = int(p) - 1 
    if s == 'AC' and accurate[num] == 0:
        accurate[num] += 1
        correct += 1
        penalty += wrong[num]
    elif s == 'WA':
        wrong[num] += 1 

print('{} {}'.format(correct,penalty))

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

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

int main(void){
    int n;
    scanf("%d", &n);
    int a, b, c, d;
    a = n/1000;
    b = (n/100)%10;
    c = (n/10)%10;
    d = n%10;
    if(a+b+c+d==7)printf("%d+%d+%d+%d=7\n", a, b, c, d);
    else if(a+b+c-d==7)printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if(a+b-c+d==7)printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if(a+b-c-d==7)printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if(a-b+c+d==7)printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if(a-b+c-d==7)printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if(a-b-c+d==7)printf("%d-%d-%d+%d=7\n", a, b, c, d);
    else if(a-b-c-d==7)printf("%d-%d-%d-%d=7\n", a, b, c, d);
    return 0;
}

Measured memory_bytes: 128
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  _  <- readLn::IO Int
  ls <- map words . lines <$> getContents
  let otoshidama = listToTuple ls
  print $sum $map btcTojpy otoshidama

listToTuple [] = []
listToTuple ([x1,x2] : xs) = ((read::String->Double)x1,x2) : listToTuple xs

btcTojpy (x,s)
  |s=="BTC" = x*380000
  |otherwise = x

Measured memory_bytes: 4252
N,x = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
S = 0
count = 0

for i in range(N):
  S += A[i]
  
if S < x:
  print(N-1)
  exit()
else:
  for i in range(N):
    b = x - A[i]
    if b > 0:
      count += 1
      x -= A[i]
    elif b == 0:
      count += 1  
      break
    else:
      break
  print(count)

Measured memory_bytes: 3064
use std::io::{Read, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let mut buf = String::new();
    stdin.read_to_string(&mut buf).unwrap();
    let mut buf = buf.split_whitespace();

    let a: i32 = buf.next().unwrap().parse().unwrap();
    let b: i32 = buf.next().unwrap().parse().unwrap();

    println!("a {} b",
        if a < b {
            "<"
        } else if a > b {
            ">"
        } else {
            "=="
        }
    );
}


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

int n;
int col[205];
vector<int> G[205];
int dist[205];

bool dfs(int v,int c,int p){
	col[v]=c;
	for(int i=0;i<G[v].size();i++){
		if(col[G[v][i]]==0){
			if(!dfs(G[v][i],-c,v))return false;
		}else{
			if(col[G[v][i]]==col[v])return false;
		}
	}
	return true;
}

int calc(int v){
	memset(dist,-1,sizeof(dist));
	queue<int> que;
	que.push(v);
	dist[v]=0;
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			if(dist[G[v][i]]==-1){
				dist[G[v][i]]=dist[v]+1;
				que.push(G[v][i]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans=max(ans,dist[i]);
	}
	return ans+1;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		for(int j=0;j<n;j++){
			if(s[j]=='1'){
				G[i].push_back(j);
			}
		}
	}
	if(!dfs(0,1,-1)){
		printf("%d\n",-1);
		return 0;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans=max(ans,calc(i));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 436
from collections import defaultdict
N = int(input())
dic = defaultdict(list)
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x,y = map(int,input().split())
        dic[i].append((x-1,y))
# print(dic)
 
from itertools import product
P = product(range(2),repeat=N)
# print(list(p))
 
ans = 0
for p in P:
    flg = True
    for i in range(N):
        if p[i] == 1:
            for xi,yi in dic[i]:
                if p[xi] != yi:
                    flg = False
        if not flg:
            break
    if flg: ans = max(ans, sum(p))
print(ans)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int N,K;
	cin >> N >> K;
	int x[110];
	REP(i,N) cin >> x[i];
	int ans=0;
	REP(i,N){
		if(abs(K-x[i]) >= x[i]-0) ans+=2*x[i];
		else ans+=2*abs(K-x[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int answer = 0;
  for(int i=1;i<N+1;i++)
  {
    int count = 0;
    for(int j=1;j<N+1;j++)
    {
      if(i%2==0)
      {
        continue;
      }
      if(i%2==1)
      {
        if(i%j==0)
        {
          count ++;
        }
      }
      if(j==N&&count==8)
      {
        answer++;
      }
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
	Scanner cin = new Scanner(System.in);
	while(true){
		int n,c=0;
		n=cin.nextInt();
		if(n==0){
			break;
		}
		for(int i=1;i<n+1;i++){
			int q=i;
			while(true){
				if(q%5==0){
					c=c+1;
					q=q/5;
				}
				if(q%5!=0){
					break;
				}
		    }
		}
		System.out.println(c);
	}
	}
}

Measured memory_bytes: 18164
import java.util.Scanner;

class Main{
	static int n;
	static long ans = 1000000000;
	static int[] memo;
	static int[] dp;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int t = sc.nextInt()*1000;
		int a = sc.nextInt() * 1000;
		int[] h = new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt() ;
		}
		int ans = 1000000000;
		int key = 0;
		for(int i = 0;i < n;i++){
			int d = Math.abs(a - (t-h[i]*6));
			if(d < ans){
				key = i+1;
				ans = Math.min(ans, d);
			}
		}
		System.out.println(key);
	}
}







class Pair implements Comparable{
	int from;
	int end;
	int dis;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return dis - otherpair.dis;
	}
}


Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int main(){

	int n, l[1000], r[1000];

	cin >> n;

	for (int i = 0; i < n; ++i) {

		cin >> l[i] >> r[i];

	}
	int num = 0;
	for (int i = 0; i < n; ++i) {

		num =num + r[i] - l[i] + 1;

	}

	cout << num << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const int mod = 1000000007;
const double PI = acos(-1);
double a,b,x;
int main(){
  cin >> a >> b >> x;
  if(a*a*b >= 2*x){
    cout << syo(15) << (atan((a*b*b)/(2*x))) * (180/PI) << endl;
  }else{
    cout << syo(15) << atan((2*(a*a*b - x))/(a*a*a)) * (180/PI) << endl;
  }
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nm = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			int n = (int)nm[0];
			long m = nm[1];
			long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			long[] sums = new long[n + 1];
			for (int i = 0; i < n; i++) {
				sums[i + 1] = (sums[i] + a[i]) % m;
			}

			var counts = sums.GroupBy(
				x => x,
				(key, e) => new { Value = key, Count = (long)e.Count() })
				.Where(x => x.Count > 1)
				.ToArray();

			long ans = 0;
			foreach (var count in counts) {
				ans += (count.Count * (count.Count - 1) / 2);
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 36188
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

#define FOR(i,a,b) for(int i=(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

struct unionfind{

  unionfind(int n) : par(n) , size(n,1){
    REP(i,n) par[i] = i;
  }

  int root(int x){
    if(par[x] == x) return x;
    return (par[x] = root(par[x]));
  }

  bool find(int x,int y){
    return root(x) == root(y);
  }

  void set(int x,int y){
    x = root(x);
    y = root(y);

    if(x == y)return;

    if(size[x] > size[y]){
      par[y] = par[x];
      size[x] += size[y];
    }else{
      par[x] = par[y];
      size[y] += size[x];
    }

    return;
  }

private:
  vector<int> par;
  vector<int> size;

}typedef UF;

LL const MOD = 1000000007;

struct edge{
    LL s,t;
    LL cost;
    edge(LL v1,LL v2,LL y):s(v1),t(v2),cost(y){

    }

    bool operator <(const edge& right)const{
        return cost < right.cost;
    }
};

struct forX{
    LL id;
    LL x;
    LL y;

    forX(){

    }

    forX(LL ind,LL i,LL j):id(ind),x(i),y(j){

    }

    bool operator <(const forX& right)const{
        return x < right.x;
    }
};

struct forY{
    LL id;
    LL x;
    LL y;

    forY(){

    }

    forY(LL ind,LL i,LL j):id(ind),x(i),y(j){

    }

    bool operator <(const forY& right)const{
        return y < right.y;
    }
};

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

    LL n;
    cin >> n;

    vector<forX> vecx(n+1);
    vector<forY> vecy(n+1);

    for(int i = 1; i < n+1; i++){
        LL x,y;
        cin >> x >> y;
        vecx[i] = forX(i,x,y);
        vecy[i] = forY(i,x,y);
    }
    sort(vecx.begin()+1,vecx.end());
    sort(vecy.begin()+1,vecy.end());

    vector<edge> e;
    for(int i = 1; i < n; i++){
        e.push_back(edge(vecx[i].id,vecx[i+1].id,min(abs(vecx[i+1].x-vecx[i].x),abs(vecx[i+1].y - vecx[i].y))));
        e.push_back(edge(vecy[i].id,vecy[i+1].id,min(abs(vecy[i+1].y-vecy[i].y),abs(vecy[i+1].x - vecy[i].x))));
    }

    UF uf = unionfind(n+1);

    sort(e.begin(),e.end());

    LL ans = 0;

    for(int i = 0; i < e.size(); i++){
        if(uf.find(e[i].s,e[i].t)){

        }else{
            ans += e[i].cost;
            uf.set(e[i].s,e[i].t);
        }
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 13040
#include <stdio.h>

int main (void)
{   
    int K,A,B,i;
    
    scanf("%d",&K);
    scanf("%d",&A);
    scanf("%d",&B);

    for(i=A; i<=B; i++){
      if(i % K == 0){
        printf("OK\n");  
        return 0;
      }
    }
    printf("NG\n");  
    

    return 0;

}


Measured memory_bytes: 1660
N, K = map(int, input().split())

def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret

def nPr(n,r):
    tmp = 1
    for i in range(n,n-r,-1):
        tmp *= i
    return tmp

for i in range(1, K+1):
    sukima = nCr(N-K+1, i)
    p = nPr(K-1, i-1) // nPr(i-1, i-1)
    print(sukima*p%(10**9+7))

Measured memory_bytes: 3444
#include<iostream>
#include<string>
using namespace std;
string s;
int pd(int l)
{
	int mid=(l+1)/2;
	for(int i=0;i<mid;i++)
	if(s[i]!=s[i+mid]) return 0;
	return 1;
}
int main()
{
	cin>>s;
	int len=s.length();
	if(len&1)
	{
		for(int i=2;i<=len;i+=2)
		if(pd(len-i)) 
		{
			printf("%d\n",len-i+1);
			return 0;
		}
	}
	else 
	{
		for(int i=3;i<=len;i+=2)
		if(pd(len-i)) 
		{
			printf("%d\n",len-i+1);
			return 0;
		}
	}
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	int n;
	int w[];
	int k;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		k = scan.nextInt();
		w = new int[n];
		for (int i = 0; i < n; i++) {
			w[i] = scan.nextInt();
		}
	}

	void run() {
		int left = 1;
		int right = 100000 * 10000;
		int p = Integer.MAX_VALUE;
		while(left < right) {
			int mid = (left + right) / 2;
			int cnt = 1;
			int sumWeight = 0;
			for (int i = 0; i < w.length; i++) {
				if (w[i] > mid) {
					cnt = Integer.MAX_VALUE;
					break;
				}
				sumWeight += w[i];
				if (sumWeight > mid) {
					sumWeight = w[i];
					cnt++;
				}
				if (cnt > k) {
					break;
				}
			}
			if (cnt <= k) {
				p = Math.min(p, mid);
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		System.out.println(p);
	}
}



Measured memory_bytes: 71024
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

int n, t, ans;
vi v;

signed main() {
	cin >> n;
	FOR(i, n) {
		cin >> t;
		v.pb(t);
	}
	sort(all(v));
	FOR(i, n) for (int j = i + 1; j < n; j++) for (int k = j + 1; k < n; k++) {
		if (v[i] != v[j] && v[j] != v[k] && v[i] + v[j] > v[k]) {
			ans++;
		}
	}
	cout << ans;
}

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

struct LCA {
  int N, logN; // logN-1 == floor(lg(N-1))
  vector<vector<int>> G;
  vector<int> depth;
  // vから根の方向に2^k回登ったときのノード parent[k][v]
  vector<vector<int>> parent;

  LCA(int size) : N(size), G(size), depth(size) {
    logN = 0;
    for(int x = 1; x < N; x *= 2) logN++;
    parent.assign(logN+1, vector<int>(N));
  }

  // どちらが根であってもOK
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void dfs(int v, int par, int dep) {
    depth[v] = dep;
    parent[0][v] = par;
    for(int next : G[v]) {
      if(next != par) dfs(next, v, dep + 1);
    }
  }

  void init(int root) {
    dfs(root, -1, 0);
    for(int k = 1; k < logN; k++) {
      for(int v = 0; v < N; v++) {
        if(parent[k - 1][v] == -1) parent[k][v] = -1;
        else parent[k][v] = parent[k - 1][parent[k - 1][v]];
      }
    }
  }

  int lca(int u, int v) {
    if(depth[u] > depth[v]) swap(u, v); // vのほうが深くなる
    // uとvの深さが同じになるまでvを根の方向に移動する
    for(int k = 0; k < logN; k++) {
      if(((depth[v] - depth[u]) >> k) & 1) {
        v = parent[k][v];
      }
    }
    if(u == v) return u;
    for(int k = logN - 1; k >= 0; k--) {
      if(parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};

int main() {
  ios::sync_with_stdio(false);
  int N; cin >> N;
  LCA lca(N);
  for(int u = 0; u < N; u++) {
    int k; cin >> k;
    while(k--) {
      int v; cin >> v;
      lca.add_edge(u, v);
    }
  }
  lca.init(0);
  int Q; cin >> Q;
  while(Q--) {
    int u, v; cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
}

Measured memory_bytes: 16492
#include <stdio.h>
int main(void){
    int i=0,j,x;
    int a[10000];
    while(1){
        scanf("%d",&x);
        if(x==0) break;
        a[i]=x;
        i=i+1;
    }
    for(j=1;j<=i;j++){
        printf("Case %d: %d\n",j,a[j-1]);
    }
    return 0;
}


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

int main() {
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << fixed << setprecision(12) << (double)w * h / 2.0 << " "
       << (x * 2 == w && y * 2 == h) << endl;
  return 0;
}


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

int n, m;
pair<long long, long long> a[100004];
string s;
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i = 0;i<n;i++)
		cin>>a[i].first>>a[i].second;
	sort(a,a+n);
	long long ans = 0;
	int idx = 0;
	while(m){
		if(m<=a[idx].second){
			ans += a[idx].first*m;
			break;
		}
		else{
			ans += a[idx].first*a[idx].second;
			m -= a[idx].second;
			idx++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792