akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return a;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int main() {
  string a,b; cin >>a >>b;
  string ansa = "", ansb = "";
  int aint = stoi(a), bint = stoi(b);
  rep(i, bint) ansa += a;
  rep(i, aint) ansb += b;
  if (a < b) cout <<ansa <<endl;
  else cout <<ansb <<endl;
}

Measured memory_bytes: 256
s = input()
s = s[::-1]
import re
a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

ans = "YES"
i = 0
while(i<len(s)):
  if s[i:i+5] == a:
    i = i+5
  elif s[i:i+7] == b:
    i = i+7
  elif s[i:i+5] == c:
    i = i+5
  elif s[i:i+6] == d:
    i = i+6
  else:
    ans = "NO"
    break
print(ans)

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

int n, u[6009], depth[6009], num[6009]; string S; pair<string, int> dp[6009]; bool used[6009];
vector<int>A, B;

int main() {
	cin >> n >> S;
	for (int i = 0; i < 2 * n; i++) {
		if (S[i] == 'b') { depth[i + 1] = depth[i] + 1; num[i] = B.size(); B.push_back(i); }
		else { depth[i + 1] = depth[i] - 1; num[i] = A.size(); A.push_back(i); }
		if (depth[i + 1] == 0) used[i] = true;
	}
	for (int i = 2 * n - 1; i >= 0; i--) { if (used[i] == true) u[i] = i; else u[i] = u[i + 1]; }

	for (int i = 2 * n - 1; i >= 0; i--) {
		dp[i] = dp[i + 1];
		if (depth[i + 1] > 0 && S[i] == 'b') {
			string V = "";
			for (int j = i; j < A[num[i]]; j++) { if (S[j] == 'b') V += S[j]; }
			for (int j = A[num[i]]; j <= u[i]; j++) V += S[j];
			dp[i] = max(dp[i], make_pair(V, -i));
		}
	}
	string ans = ""; int cx = 0;
	while (dp[cx].first != "") {
		ans += dp[cx].first;
		cx = u[dp[cx].second * -1] + 1;
	}
	for (int i = 0; i < A.size(); i++) {
		if (A[i] >= cx) { cx = B[i] + 1; ans += "ab"; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0 && m==0) break;
    vector<int> t(n);
    vector<int> h(m);
    rep(i,n) cin >> t[i];
    rep(i,m) cin >> h[i];
    int tsum=0, hsum=0;
    rep(i,n) tsum += t[i];
    rep(i,m) hsum += h[i];
    pair<int,int> ans;
    int sumans=10000000;
    ans.first = ans.second = -1;
    rep(i,n){
      rep(j,m){
        if(tsum-t[i]+h[j]==hsum-h[j]+t[i]){
          if(sumans>t[i]+h[j]){
            ans.first=t[i]; ans.second=h[j];
            sumans = t[i]+h[j];
          }
        }
      }
    }
    //cout << "ans:";
    if(ans.first == -1 && ans.second == -1) cout << "-1" << endl;
    else cout << ans.first << " " << ans.second << endl;
  }
  return 0;
}



Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    vector<int> a(3);
    int k;
    cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a.rbegin(), a.rend());
    a[0] *= pow(2, k);
    cout << accumulate(all(a), 0);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    cout << (((n + 2 - 1) / 2 >= k) ? "YES\n" : "NO\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010,maxm=200010;
int n,m,cnt;
struct edge{
    int from,to,next;
}edges[maxm];
int head[maxn];
int main(){
    scanf("%d%d",&n,&m);
    for(register int i=1;i<=m;i++){
        scanf("%d%d",&edges[i].from,&edges[i].to);
        edges[i].next=head[edges[i].from];
        head[edges[i].from]=i;
    }
    int p;
    for(register int i=head[1];i;i=edges[i].next){
        p=edges[i].to;
        for(register int j=head[p];j;j=edges[j].next) if(edges[j].to==n){
            printf("POSSIBLE\n");return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN=1005;
int a[5];
int num[5];
int flag;
void dfs(int cur, int sum, int f)
{
    sum+=a[cur]*f;
    if(flag)
        return;
    if(cur==4&&sum==7)
    {
        printf("%d%c%d%c%d%c%d=7\n", a[1], num[1]==1?'+':'-',a[2],num[2]==1?'+':'-',a[3],num[3]==1?'+':'-', a[4]);
        flag=1;
        return ;
    }
    if(cur==4)
        return ;
    num[cur]=1;
    dfs(cur+1,sum,1);
    num[cur]=0;
    dfs(cur+1,sum,-1);
}
int main()
{
    int n;
    scanf("%d", &n);
    flag=0;
    a[4]=n%10;
    a[3]=n/10%10;
    a[2]=n/100%10;
    a[1]=n/1000%10;
    dfs(1,0,1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
int main()
{
    SPEED
    string s, t;
    cin >> s >> t;

    string s2 = "";

    for (int i = 0; i < t.size()-1; ++i)
    {
        s2 += t[i];
    }

    if (s.size()!= s2.size())
    {
        cout << "No";
        return 0;
    }

    bool not_possible = false;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i]!=s2[i])
        {
            not_possible = true;
            break;
        }
    }

    if (not_possible)
    {
        cout << "No";
    }
    else 
    {
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>

int main()
{
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);
   
   int count=0;
   
   for(int i=a;i<=b;i++)
   {
       if(c%i==0)count++;
   }
   
   printf("%d\n",count);
     
}


Measured memory_bytes: 2756
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  string S; cin>>S;
  vector<int> st;
  int ans = 0;
  int len = S.length();
  int depth = 0;
  st.push_back(S[0] - '0');
  for(int i = 1; i < len; i++) {
    int	v = S[i] - '0';
    if(st.empty()) {
      st.push_back(v);
    } else {
      if(st.back() + v == 1) {
	ans += 2;
	st.pop_back();
      }	else st.push_back(v);
    }

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


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(l,r,i) for(int i=l;i>=r;i--)
using namespace std;

typedef long long LL;
const int INF =2147483647;
int qread(){
    int w=1,c,ret;
    while((c=getchar())> '9'||c< '0')
    w=(c=='-'?-1:1); ret=c-'0';
    while((c=getchar())>='0'&&c<='9')
    ret=ret*10+c-'0';
    return ret*w;
}
const int MAXN =100+3;
int n,m,v[MAXN],cnt,sum;
int main(){
    n=qread(),m=qread();
    up(1,n,i) v[i]=qread(),sum+=v[i];
    up(1,n,i){
        if(v[i]*4*m>=sum) ++cnt;
    }
    puts(cnt>=m?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 
const ll INF = 1e18;

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> v(N);
    for (int i = 0; i < N; ++i) cin >> v[i];
    sort(v.begin(), v.end());

    ll min_height = INF;
    for (int i = 0; i + K - 1 < N; ++i) {
        min_height = min(min_height, v[i + K - 1] - v[i]);
    }
    cout << min_height << endl;
}

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


void func() {
    int N;
    cin >> N;
    vector<int> arr;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        arr.push_back(a);
    }
    sort(arr.begin(),arr.end());
    cout << arr[N - 1] - arr[0] << endl;
}
int main() {
    func();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define alpha_size 26
const int maxn = 1e3 + 10;
const int INF = 1 << 29;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr); 
    int n, x, y;
    cin >> n  >> x >> y;
    int g[n + 1][n + 1];
    --x, --y;
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        if (i == j) g[i][j] = 0;
        else g[i][j] = INF;
      }
    }
    for (int i = 0; i < n; i++)
     for (int j = 0; j < n; j++)
        g[i][j] = abs(i - j);
    g[x][y] = 1;
    g[y][x] = 1;
    map<int, int> m;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
          g[i][j] = min(g[i][j], g[i][x] + 1 + g[y][j]);
          g[i][j] = min(g[i][j], g[i][y] + 1 + g[x][j]);
        }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        m[g[i][j]]++;
   for (int i = 1; i <= n - 1; i++)
    cout << m[i] / 2 << endl;
}


Measured memory_bytes: 31744
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main() {

	int x, a;

	cin >> x >> a;

	if (x < a) {
		cout << 0 << endl;
	}
	else{
		cout << 10 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
using Graph = vector<vector<P> >;

Graph G;
const int INF = 2e9;

template <typename T>
vector<vector<T>> warshall_floyd(int n, vector<vector<T>> d) {

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) 
      for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
  return d;
}
int main(){
  int n;
  cin >> n;
  G.resize(n);

  vector<vector<int> > a(n,vector<int>(n));
  ll res = 0;
  rep(i,n) rep(j,n) cin >> a[i][j];
  rep(i,n) rep(j,n) {
    if (a[i][j] == 0) continue;
    res += a[i][j];
    G[i].push_back({j,a[i][j]});
  }
  res /= 2;
  auto dist = warshall_floyd<int>(n,a);
  vector<vector<bool>> memo(n,vector<bool>(n,false));
  for (int k = 0; k < n ; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n; j++) {
        if (a[i][j] != dist[i][j]) {
          puts("-1");
          return 0;
        }
        if (i == j || j == k || k == i) continue;
        if (dist[i][j] == dist[i][k] + dist[k][j] && !memo[i][j]) {
          memo[i][j] = true;
          res -= dist[i][j];
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
#define mp make_pair
#define mod 1000000007
#define INF 1e9+5
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(i,a,b) for(int i=a;i<(int)b;i++)
#define ff first
#define ss second
#define int long long
ll min(ll a, ll b) {return a>b?b:a;}
ll max(ll a, ll b) {return a>b?a:b;}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int flag=0;
    while(n)
    {
        if(n%10==7)
            flag=1;
        n/=10;
    }
    if(flag==1)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pb push_back
#define ld long double
#define mk make_pair
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    fastIO;
    ll n;
    cin>>n;
    ll x;
    ld val,val1,flag=0;
    for(int i=1;i<=n;i++)
    {
        val=(ld)i*(ld)1.08;
        x=(ll)val;
        if(floor(val)==n && x==n)
        {
            val1=i;
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        cout<<(ll)val1<<'\n';
    }
    else
    {
        cout<<":(\n";
    }
    return 0;
}

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

int main(void) {
	char str[201];
	int i, len;
	scanf("%s", str);
	len = (int)strlen(str);
	len -= 2;
	while (len >= 2) {
		str[len] = '\0';
		for (i = 0; i < len / 2; i++) {
			if (str[i] != str[len/2+i]) break;
		}
		if (i == len / 2) break;
		len -= 2;
	}
	printf("%d\n", len);
	return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

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);
}

//実行部
void Main()
{
  ll n; cin >> n;
  str s; cin >> s;
  map <char, ll> ans;
  ans['('] = 0, ans[')'] = 0;
  str f, b;
  rep(i, n)
  {
    if(ans.count(s[i])) ans[s[i]]++;
    if(ans[')'] > ans['('])
    {
      s = '(' + s;
      ans['(']++;
      i++;
      n++;
    }
  }
  map <char, ll> a;
  rep(i, n)
  {
    if(a.count(s[i])) a[s[i]]++;
    else a[s[i]] = 1;
  }
  if(a['('] != a[')'])
  {
    rep(i, a['('] - a[')']) b += ')';
  }
  s += b;
  fin(s)
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> mark(n*m+1);
  for (ll i = 0; i <= n; ++i) {
    ll b = i*m;
    for (ll j = 0; j <= m; ++j) {
      ll bb = b - i*j + (n-i)*j;
      mark[bb] = 1;
    }
  }

  swap(n, m);

  for (ll i = 0; i <= n; ++i) {
    ll b = i*m;
    for (ll j = 0; j <= m; ++j) {
      ll bb = b - i*j + (n-i)*j;
      mark[bb] = 1;
    }
  }

  cout << (mark[k] ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 8064
import math

def CountOrder(n, a):
    used = []
    order = 0
    for i in range(len(a)):
        nn = a[i] - 1
        for u in used:
            if u < a[i]:
                nn -= 1
        used.append(a[i])

        order += nn * math.factorial(n - 1 - i)

    return order + 1
        
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

print(abs(CountOrder(n, a) - CountOrder(n, b)))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef map<int, int> MII;
typedef vector<MII> VMII;
typedef pair<int, int> PII;
typedef priority_queue<PII> PQPII;
typedef vector<PQPII> VPQPII;

#define MP make_pair

int main() {
  int N, M;
  cin >> N >> M;

  VMII xss(M);
  VPQPII pqs(M);

  for (int i = 0; i < N; i++) {
    int n;
    cin >> n;
    auto& m = xss[n%M];
    if (m.count(n)) {
      m[n]++;
    } else {
      m[n] = 1;
    }
  }

  for (int i = 0; i < M; i++) {
    auto& m = xss[i];
    for (auto it = m.begin(); it != m.end(); it++) {
      pqs[i].push(MP(it->second, it->first));
    }
  }

  VII yss(M);

  /*
  for (int i = 0; i < M; i++) {
    auto& m = pqs[i];
    cout << i;
    cout << ":";
    while (!m.empty()) {
      auto x = m.top(); m.pop();
      cout << x.first << "," << x.second;
      cout << "  ";
    }
    cout << endl;
  }
  */

  for (int i = 0; i < M; i++) {
    auto& m = pqs[i];
    VI a;
    VI b;
    while (!m.empty()) {
      auto x = m.top(); m.pop();
      auto num = x.first;
      auto v = x.second;
      for (int j = 0; j < num / 2 * 2; j++) {
        a.push_back(v);
      }
      if (num % 2) {
        b.push_back(v);
      }
    }
    yss[i].insert(yss[i].end(), a.begin(), a.end());
    yss[i].insert(yss[i].end(), b.begin(), b.end());
  }

  /*
  cout << endl;
  for (int i = 0; i < M; i++) {
    cout << i << ":";
    for (auto x: yss[i]) {
      cout << x << " ";
    }
    cout << endl;
  }
  */

  int res = 0;
  for (int i = 0; i <= M/2; i++) {
    int j = (M-i)%M;
    auto& ys_i = yss[i];
    auto& ys_j = yss[j];

    if (i != j) {
      while (!ys_i.empty() && !ys_j.empty()) {
        ys_i.pop_back();
        ys_j.pop_back();
        res++;
      }
    } else {
      while (ys_i.size() >= 2) {
        ys_i.pop_back();
        ys_j.pop_back();
        res++;
      }
    }
  }

  /*
  cout << endl;
  for (int i = 0; i < M; i++) {
    cout << i << ":";
    for (auto x: yss[i]) {
      cout << x << " ";
    }
    cout << endl;
  }
  */


  for (int i = 0; i < M; i++) {
    const auto& ys_i = yss[i];
    for (int j = 0; j < ((int)ys_i.size())-1; j++) {
      //cout << j << " " << ys_i.size() << endl;
      if (ys_i[j] == ys_i[j+1]) {
        res++;
        j++;
      }
    }
  }

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 19072
import static java.util.Arrays.deepToString;
import static java.util.Arrays.fill;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int n = sc.nextInt();
			if (n == 0) break;
			T[] ts = new T[n];
			for (int i = 0; i < n; i++) {
				T t = new T();
				t.id = sc.nextInt();
				for (int j = 0; j < 4; j++) {
					int m = sc.nextInt();
					int s = sc.nextInt();
					t.time += m * 60 + s;
				}
				ts[i] = t;
			}
			Arrays.sort(ts);
			System.out.println(ts[0].id);
			System.out.println(ts[1].id);
			System.out.println(ts[n-2].id);
			
		}
	}
	public class T implements Comparable<T> {
		int id;
		int time;
		@Override
		public int compareTo(T o) {
			if (time != o.time) return time - o.time;
			return id - o.id;
		}
	}
}

Measured memory_bytes: 70756
def dijkstra(si, sj):
  d=[[1000 for _ in range(W)] for _ in range(H)]
  d[si][sj]=0
  color=[]
  for i in range(H):
    tmp=[]
    for j in range(W):
      if S[i][j]=="#":
        tmp.append("BLACK")
      else:
        tmp.append("WHITE")
    color.append(tmp)
  pi, pj=0, 0
  while True:
    mincost=1000
    for i in range(H):
      for j in range(W):
        if color[i][j]!="BLACK" and d[i][j]<mincost:
          mincost=d[i][j]
          pi, pj=i, j
    if mincost==1000:
      break
    color[pi][pj]="BLACK"
    if pi>0 and S[pi-1][pj]=="." and color[pi-1][pj]!="BLACK" and d[pi][pj]+1<d[pi-1][pj]:
      d[pi-1][pj]=d[pi][pj]+1
      color[pi-1][pj]="GRAY"
    if pi<H-1 and S[pi+1][pj]=="." and color[pi+1][pj]!="BLACK" and d[pi][pj]+1<d[pi+1][pj]:
      d[pi+1][pj]=d[pi][pj]+1
      color[pi+1][pj]="GRAY"
    if pj>0 and S[pi][pj-1]=="." and color[pi][pj-1]!="BLACK" and d[pi][pj]+1<d[pi][pj-1]:
      d[pi][pj-1]=d[pi][pj]+1
      color[pi][pj-1]="GRAY"
    if pj<W-1 and S[pi][pj+1]=="." and color[pi][pj+1]!="BLACK" and d[pi][pj]+1<d[pi][pj+1]:
      d[pi][pj+1]=d[pi][pj]+1
      color[pi][pj+1]="GRAY"
  maxV=0
  for i in range(H):
    for j in range(W):
      if d[i][j]<1000:
        maxV=max(maxV, d[i][j])
  return maxV
  
H, W=map(int, input().split())
S=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    if S[i][j]==".":
      ans=max(ans, dijkstra(i, j))
print(ans)

Measured memory_bytes: 80604
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rrep(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
const ll N=5e2+1,mod=1000000007;
signed main()
{
    fast;
    ll pro=1,temp,t,n,i,m,k,j,l,r,mid,x,y,z,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,sum=0,flag=1,i1=-1,i2=-1;
    cin>>n;
    ll a[n+1],b[n];
    rep(i,0,n)
    {
        cin>>a[i];
    }
    rep(i,0,n-1)
    {
        cin>>b[i];
    }
    rep(i,0,n-1)
    {
        temp=min(a[i],b[i]);
        a[i]-=temp;
        b[i]-=temp;
        ans+=temp;
        temp=min(a[i+1],b[i]);
        ans+=temp;
        a[i+1]-=temp;
        b[i]-=temp;
    }
    cout<<ans;
    return 0;
} 

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

#define DEG2RAD(deg) ((deg)/180.0 * acos(-1))

const int PREC = 8;
int n;

void koch(int k, double px, double py, double qx, double qy)
{
  if (k == n) {
    cout << fixed << setprecision(PREC) << px << " " << py << endl;
  } else {
    double sx = px + (qx - px) / 3;
    double sy = py + (qy - py) / 3;

    double tx = px + (qx - px) * 2 / 3;
    double ty = py + (qy - py) * 2 / 3;

    double upx = sx - px;
    double upy = sy - py;
    double r = DEG2RAD(60);
    double ux = sx + (upx * cos(r) - upy * sin(r));
    double uy = sy + (upx * sin(r) + upy * cos(r));

    koch(k+1, px, py, sx, sy);
    koch(k+1, sx, sy, ux, uy);
    koch(k+1, ux, uy, tx, ty);
    koch(k+1, tx, ty, qx, qy);
  }
  if (k == 0) {
    cout << fixed << setprecision(PREC) << qx << " " << qy << endl;
  }
}

int main()
{
  cin >> n; koch(0, 0, 0, 100, 0);
  return EXIT_SUCCESS;
}



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

int main(){
  int N,T,c,t,min,cnt;
  min = 10000;
  cnt = 0;
  cin >> N >> T;
  for(int i;i<N;i++){
    cin >> c >> t;
    if(T >= t){
      if(min > c){
        min = c;
      }
    }else{
      cnt +=1;
    }
  }
  if(cnt == N){
    cout << "TLE";
  }else{
    cout << min;
  }
}

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

int main() {
  int N,M,C,AB=0,Ans=0;
  vector <vector<int>> A(20,vector<int>(20));
  vector <int> B(20);
  cin >> N>>M>>C;
  for(int j =0;j<M;j++){
    cin >>B.at(j);
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }
  for(int i=0;i<N;i++){
    AB=0;
    for(int j=0;j<M;j++){
      AB += A.at(i).at(j)*B.at(j);
    }
    if(AB+C>0){
      Ans +=1;
    }
  }
  cout << Ans <<endl;
} 

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,j,sum,count;
		boolean p[]=new boolean[110000];
		Arrays.fill(p, true);
		for(i=2;i<110000;i++){
			if(p[i]){
				for(j=2;i*j<110000;j++){
					p[i*j]=false;
				}
			}
		}//
		while(true){
			sum=0;count=0;i=2;
			n=sc.nextInt();
			if(n==0) break;
			while(count<n){
				if(p[i]){
					sum+=i;
					count++;
				}
				i++;
			}//
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 0
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let nab: Vec<u32> = read_vec();
  let ans = if nab[0] * nab[1] < nab[2] { nab[0] *  nab[1] } else { nab[2] };
  println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
    int num;
    int elvbefor;
}eleve;
static int compare (eleve const *a, eleve const *b)
{
   return a->elvbefor - b->elvbefor;
}
int main() {
  int N;
  eleve tab[100000];
  memset(tab,100001,sizeof(eleve));
  scanf("%d",&N);
  for (int i = 0; i < N; i++) {
    scanf("%d",&tab[i].elvbefor);
    tab[i].num=i+1;
  }
  qsort(tab,N, sizeof(eleve),compare);
  for (int i = 0; i < N; i++) {
    printf("%d ",tab[i].num);
  }
  return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
struct bol{
	bool v[8];
};
long double x[8],y[8];
int n;
long double ret = 0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x[i] >> y[i];
	}
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			ret += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
		}
	}
	cout << setprecision(10);
	cout << (ret*2)/n;
	return 0;
}


Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int sum;
    rep(i, 0, N){
        cin >> a.at(i);
        if(i == 0) sum = a.at(i);
        else sum = sum xor a.at(i);
    }
    rep(i, 0, N){
        int ans = sum xor a.at(i);
        cout << ans << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4044
/**
     *    author:  shashank_hire
    **/
#include <bits/stdc++.h>
using namespace std;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define ld long double
#define MOD 1000000007

int main()
{
    IOS;
    string s1, s2, ans;
    cin>>s1>>s2;
    ll n1 = s1.size(), n2 = s2.size(), i, j;
    vector<vector<ll>> dp(n1+1, vector<ll>(n2+1));
    for(i=1;i<=n1;i++)
        for(j=1;j<=n2;j++)
            if(s1[i-1]==s2[j-1])
                dp[i][j] = 1 + dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);

    // for(i=1;i<=n1;i++)
    //     for(j=1;j<=n2;j++)
    //         cout<<dp[i][j]<<" \n"[j==n2];
    i=n1;
    j=n2;
    while(i>0 and j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            ans.push_back(s1[i-1]);
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<"\n";
    // cout<<dp[n1][n2]<<"\n";
    // cout<<"\n";
}

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

int main() {
    int N;
    cin >> N;
    int W[N];
    for (int i = 0; i < N; i++) {
        cin >> W[i];
    }

    int w_sub;
    int w_sub_min = 100000;
    for (int T = 1; T < N; T++) {
        int w_first = 0;
        int w_second = 0;
        for (int i = 0; i < T; i++) {
            w_first += W[i];
        }
        for (int i = T; i < N; i++) {
            w_second += W[i];
        }
        if (w_first - w_second > 0) {
            w_sub = w_first - w_second;
        }
        else {
            w_sub = w_second - w_first;
        }
        if (w_sub < w_sub_min) {
            w_sub_min = w_sub;
        }
    }
    cout << w_sub_min << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
List = [int(input()) for _ in range(M)]

P = 10**9+7
dp = [1]*(N+1)

for i in List:
    dp[i]=0

for j in range(1, N):
    if dp[j+1]!=0:
        dp[j+1] = (dp[j]+dp[j-1])%P
        
print(dp[N])

Measured memory_bytes: 50136
N, K = map(int, input().split())
a, b = [], []

for i in range(N):
    a0, b0 = map(int, input().split())
    a.append(a0)
    b.append(b0)

a, b = zip(*sorted(zip(a, b)))
num = 0
for i in range(N):
    num += b[i]
    if num >= K:
        print(a[i])
        break


Measured memory_bytes: 31072
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		int ans = 0;
		for (int i = 0; i < n + 1; i++) {
			if ((int) Math.floor(i * 1.08) == n) {
				ans = i;
			}
		}
		if (ans != 0) {
			System.out.println(ans);
		} else {
			System.out.println(":(");
		}
	}

}


Measured memory_bytes: 21844
import math
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
n = sum([pc[i][0] for i in range(d)])
prob = []
comp = [0 for _ in range(len(pc))]
for i in range(len(pc)):
    prob += [100*(i+1)] * (pc[i][0])
for i in range(len(pc)):
    comp[i] = pc[i][0]
ans = float('inf')

for i in range(2 ** d):
    score = 0
    num = 0
    max_num = 0
    for j in range(d):
        #print("score:", score, "num:", num, "j:", j, "i:", i)
        if (i>>j) & 1:
            score += 100*(j+1)*pc[j][0] + pc[j][1]
            num += pc[j][0]
            
        else:
            max_num = max(max_num, j+1)
            #if max_num == j+1:
                #max_num -= 1 
    if score < g:
        add_n = math.ceil((g-score)/(100*(max_num)))
        #if i == 24:
            #print(num, add_n, score, max_num)
        #print("add_n:", add_n, max_num)
        if add_n < pc[max_num-1][0]:
            num += add_n
            score += add_n * (100*(max_num+1))

    #print(score, num)
    if score >= g:
        ans = min(ans, num)
        #print(num,i)

print(ans)

Measured memory_bytes: 3064
fn main() {
    let scan = std::io::stdin();
    
    let mut line = String::new();

    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();

    let a: i32 = vec[0].parse().unwrap();
    let b: i32 = vec[1].parse().unwrap();

    if (a+b)%2==0 {
        println!("{}", (a+b)/2);
    } else {
        println!("{}", (a+b)/2+1);
    };
}

Measured memory_bytes: 4352
from itertools import permutations

n = int(input())
*ps, = (tuple(map(int, input().split())) for _ in range(n))

ret = 0
for perm in permutations(ps):
    it = iter(perm)
    p = next(it)
    for q in it:
        ret += ((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) ** 0.5
        p = q


def fact(n):
    if n == 0: return 1
    return n * fact(n - 1)


ret /= fact(n)

print(ret)


Measured memory_bytes: 3188
n,k=map(int,input().split())

backet=[0]*(10**5+1)
for i in range(n):
    a,b=map(int,input().split())
    backet[a]+=b

for i in range(1,10**5+1):
    if backet[i] >= k:
        print(i)
        exit()
    k-=backet[i]


Measured memory_bytes: 5736
#include <stdio.h>

int main(){
  int count[4][3][10],i,j,k,n,b,f,r,v;

  for(i=0; i<4; i++){
    for(j=0; j<3; j++){
      for(k=0; k<10; k++){
	count[i][j][k] = 0;
      }
    }
  }

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    count[b-1][f-1][r-1] += v;
  }

  for(i=0; i<4; i++){
    for(j=0; j<3; j++){
      for(k=0; k<10; k++){
	printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    if(i>2) break;

    for(n=0; n<20; n++) printf("#");

    printf("\n");
  }

  return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound
#define p_b push_back

struct UF {
    static const int N = 100100;//書き換え!
    int par[N];
    int rank[N];
    vector<int> group[N];

    UF() {
        rep(i, N) {
            par[i] = -1;
            rank[i] = 0;
            group[i].push_back(i);
        }
    }

    void exist(int x) {
        par[x] = x;
    }

    void init() {
        rep(i, N) {
            par[i] = -1;
            rank[i] = 0;
            group[i].push_back(i);
        }
    }

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

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            rep(i, group[x].size()) {
                group[y].p_b(group[x][i]);
            }
            group[x].clear();
        } else {
            par[y] = x;
            if (rank[x] == rank[y])++rank[x];
            rep(i, group[y].size()) {
                group[x].p_b(group[y][i]);
            }
            group[y].clear();
        }
    }

    bool top(int x) {
        return x == par[x];
    }
};

map<int, vector<int>> mx, my;
int N;
int X[100100];
int Y[100100];
set<pii> points;
UF uf;

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> X[i] >> Y[i];
        mx[X[i]].p_b(Y[i]);
        my[Y[i]].p_b(X[i]);
        points.insert(pii(X[i], Y[i]));
        uf.exist(Y[i]);
    }
    for (auto mxkv:mx) {
        if (mxkv.second.size() >= 2) {
            int si = mxkv.second.size();
            for (int j = 1; j < si; ++j) {
                uf.unite(mxkv.second[0], mxkv.second[j]);
            }
        }
    }

    int ans = 0;
    for (int y = 1; y <= 100000; ++y) {
        if (!uf.top(y)) {
            continue;
        }
        vector<int> group = uf.group[y];
        set<int> xs;
        rep(i, group.size()) {
            int y1 = group[i];
            vector<int> y2 = my[y1];
            rep(j, y2.size()) {
                int x = y2[j];
                xs.insert(x);
            }
        }
        ans += xs.size() * group.size();
    }

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


Measured memory_bytes: 31864
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, a, b; cin >> n >> a >> b;
  ll ans = n / (a+b) * a;
  cerr << ans << nl;
  ans += min(a, n - (n / (a+b) * (a+b)));
  cout << ans << nl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;

const greater <ll> gt;

ll A[200000];
ll B[200000];
ll k;
int n;

bool f(ll mi) {
    ll nx = k;
    for(int i = 0; i < n; ++i)
        nx -= max(A[i] - mi / B[i], 0LL);
    
    return (nx >= 0);
}

int main() {
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> A[i];
    for(int i = 0; i < n; ++i)
        cin >> B[i];
    
    sort(A, A + n);
    sort(B, B + n, gt);
    
    ll lo = 0, hi = 1e17;
    while(lo < hi) {
        ll mi = (lo + hi) >> 1;
        if(f(mi)) hi = mi;
        else lo = mi + 1;
    }
    
    cout << lo;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int n,a,b;bool ans;
int main()
{
	scanf("%d %d %d",&n,&a,&b);
	for(int i=a;i<=b;++i) if(!(i%n)) ans=1;
	puts(ans?"OK":"NG");return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    string s;
    cin >> s;
    vector<ll> num(3,0);
    for(int i=0;i<s.size();i++){
        num[s[i]-'a']++;
    }
    bool jg=true;
    ll cnt=s.size()/3,am=(s.size()%3?1:0);
    for(int i=0;i<3;i++){
        if(num[i]>=cnt && num[i]<=cnt+am);
        else jg=false;
    }
    cout <<(jg?"YES":"NO") << endl;
    

    return 0;
}

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

  int n,tmp,r[100010]={};
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>tmp;
    for(int j=-1;j<=1;j++) if(tmp+j>=0) r[tmp+j]++;
  }
  int maxr=0;
  for(int i=0;i<100010;i++) maxr=max(r[i],maxr);
  cout<<maxr<<endl;

  return 0;

}







Measured memory_bytes: 640
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

constexpr int MAX_V = 100000;
constexpr int MAX_N = 50000;

typedef pair<int, int> D; // dist, change
typedef tuple<D, int, int> P; // D, rail, pos

vector<int> p[MAX_N];
vector<int> t[MAX_N];
vector<D> dist[MAX_N];

bool visited[MAX_V];
set<pair<int, int>> S[MAX_V];
unordered_map<string, int> converter;

inline int input_station() {
	string station_name;
	cin >> station_name;

	if(!converter.count(station_name)) {
		converter.insert({station_name, converter.size()});
	}

	return converter[station_name];
}

string dijkstra(int s, int g, int T) {
	memset(visited, false, sizeof(visited));
	priority_queue<P, vector<P>, greater<P>> que;

	for(const auto &e : S[s]) {
		dist[e.first][e.second] = D(0, 0);
		que.push(make_tuple(D(0, 0), e.first, e.second));
	}

	while(!que.empty()) {
		D d;
		int r, q;
		tie(d, r, q) = que.top();
		que.pop();

		if(dist[r][q] < d) continue;

		const int v = p[r][q];

		if(v == g) return to_string(d.first) + " " + to_string(d.second);

		if(!visited[v]) {
			for(const auto &e : S[v]) {
				const D next_dist(d.first + T, d.second + 1);

				if(dist[e.first][e.second] > next_dist) {
					dist[e.first][e.second] = next_dist;
					que.push(make_tuple(next_dist, e.first, e.second));
				}
			}
		}

		visited[v] = true;

		if(0 < q) {
			const D next_dist(d.first + t[r][q - 1], d.second);

			if(dist[r][q - 1] > next_dist) {
				dist[r][q - 1] = next_dist;
				que.push(make_tuple(next_dist, r, q - 1));
			}
		}

		if(q < static_cast<int>(p[r].size()) - 1) {
			const D next_dist(d.first + t[r][q], d.second);

			if(dist[r][q + 1] > next_dist) {
				dist[r][q + 1] = next_dist;
				que.push(make_tuple(next_dist, r, q + 1));
			}
		}
	}

	return "-1";
}

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

	int N, T;
	cin >> N >> T;

	const int A = input_station();
	const int B = input_station();

	for(int i = 0; i < N; ++i) {
		int a;
		cin >> a;

		p[i].resize(a);
		t[i].resize(a - 1);
		dist[i].resize(a, D(INT_MAX, INT_MAX));

		for(int j = 0; j < a; ++j) {
			p[i][j] = input_station();
			S[p[i][j]].insert({i, j});
		}

		for(auto &e : t[i]) cin >> e;
	}

	cout << dijkstra(A, B, T) << endl;
}

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

int check(int p){
  int ans = 0;
  while(p % 2 == 0){
    ++ans;
    p /= 2;
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i){
    cin >> a.at(i);
  }
  int res = 100000;
  for(int i = 0; i < n; ++i){
    res = min({res,check(a.at(i))});
  }
  cout << res;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end());
#define REVERSE(v)  reverse(v.begin(), v.end());
typedef long long ll;
using namespace std;

int main() {
  int N,K; cin>>N>>K;
  if(N%K==0) cout<<0<<endl;
  else cout<<1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) { cin >> a[i]; }
    sort(a.begin(), a.end());

    if (n % 2 == 0) {
        ll even_n = 1;
        for (int i = 0; i < n / 2; i++) {
            if (a[2 * i] != even_n || a[2 * i + 1] != even_n) {
                cout << 0 << endl;
                return 0;
            }
            even_n += 2;
        }
    } else {
        if (a[0] != 0) {
            cout << 0 << endl;
            return 0;
        }
        ll odd_n = 2;
        for (int i = 1; i <= n / 2; i ++) {
            if (a[2 * i - 1] != odd_n || a[2 * i] != odd_n) {
                cout << 0 << endl;
                return 0;
            }
            odd_n += 2;
        }
    }
    ll ans = 1;
    for (int i = 0; i < n / 2; i++) {
        ans *= 2;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int k, n;
	cin>>k>>n;
	vector<int> a(n);
	for(auto &x : a){
		cin>>x;
	}
	int mx = k - a[n - 1] + a[0];
	for(int i = 1; i < n; i++){
		mx = max(mx, a[i] - a[i - 1]);
	}
	cout<<k - mx<<endl;

	return 0;
}

Measured memory_bytes: 1024
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
   // FI(); /// skip this line for compile
    ll n,arr[101],ans=999999999;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> arr[i];

    for(int i=1; i<101; i++)
    {
        ll sum  = 0;
        for(int j=0; j<n; j++)
        {
            sum+= (i-arr[j])*(i-arr[j]);
        }
        ans = min(sum,ans);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3632
N = int(input())
a = list(map(int,input().split()))
W,Q = 0,0 
for i in a:
    if i%4 == 0:
        Q += 1
    elif i%2 == 0:
        W += 1
if Q >= N//2 or Q >= (N-W)/2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
N, M = map(int, input().split())
p = list(map(lambda x: int(x) - 1, input().split()))


class DisjointSet():
    def __init__(self, n):
        self.parent = list(range(n))
        self.rank = [0] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


d = DisjointSet(N)
for i in range(M):
    xi, yi = map(int, input().split())
    d.unite(p[xi - 1], p[yi - 1])

ans = 0
for i in range(N):
    if d.find(p[i]) == d.find(i):
        ans += 1
print(ans)


Measured memory_bytes: 13812
mark = ['S', 'H', 'C', 'D']
n = STDIN.gets.to_i
cards = {}
for i in 0 .. 3 do
  for j in 1 .. 13 do
    cards.store(mark[i] + " " + j.to_s, true)
  end
end

for i in 1 .. n do
  input = STDIN.gets
  input.chomp!
  if cards.has_key?(input)
    cards[input] = false
  end
end

cards.each{|key, value|
  if value
    print key + "\n"
  end
}

Measured memory_bytes: 8628
#include<stdio.h>

int main(){
int n[4][13] ={0};
int j,i,cards,number,k;
char mark;

scanf("%d",&cards);
for(j = 0 ; j < cards; j++){

scanf(" %c %d",&mark,&number);
  if(mark == 'S'){
  n[0][number-1] = 1;
  }else if(mark == 'H'){
  n[1][number-1] = 1;
  }else if(mark == 'C'){
  n[2][number-1] = 1;
  }else if(mark == 'D'){
  n[3][number-1] = 1;
  }
}

for(i = 0; i < 4; i++){
  for(k = 0; k < 13; k++){
    if(n[i][k] == 0){
    if(i == 0){
    printf("S %d\n",k+1);
    }else if(i == 1){
    printf("H %d\n",k+1);
    }else if(i == 2){
    printf("C %d\n",k+1);
    }else if(i == 3){
    printf("D %d\n",k+1);
    }
    }
  }
}


return 0;
}


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


using namespace std;

void solve() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<>());

    if (s < t) {
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    solve();
    return 0;
}


Measured memory_bytes: 256
import math
import numpy as np
N = int(input())
m_list = []
max_p = math.floor(-1+math.sqrt(1+N))
for p in range(1, max_p+1):
   if N % p == 0:
       m = N//p -1
       m_list.append(m)
print(int(np.sum(m_list)))

Measured memory_bytes: 20512
K=int(input())
from math import gcd
ans=0
g=[[0]*(K+1) for _ in range(K+1)]
for i in range(1,K+1):
    for j in range(1,K+1):
        g[i][j] = gcd(i,j)

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=g[i][g[j][k]]
print(ans)

Measured memory_bytes: 68244