akhauriyash/Code-Regression huggingface dataset:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17

def check(books, x, i, m, n):
    ab = [0 for i in range(m)]
    ret = 0
    for k in range(n):
        if i % 2 == 1:
            book = books[k]
            for tab, b in enumerate(book[1:]):
                ab[tab] += b
            ret += book[0]
        i //= 2
    # print(bin(i), ab)
    for cab in ab:
        if cab < x:
            return INF

    return ret

def main():
    n, m, x = getList()
    books = [getList() for _ in range(n)]
    ans = INF
    for i in range(2**n):
        # print(i)
        tmp = check(books, x, i, m, n)
        if ans > tmp:
            ans = tmp

    if ans == INF:
        print(-1)
    else:
        print(ans)
if __name__ == "__main__":
    main()



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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int n,m;
  int a,b;
  int city[60] = {0};

  scanf("%d %d",&n,&m);

  REP (i, m) {
    scanf("%d %d",&a,&b);
    city[a - 1] += 1;
    city[b - 1] += 1;
  }

  REP (i, n) printf("%d\n",city[i]);
}


Measured memory_bytes: 256
// Brijesh Panara (201601074)
// DAIICT (India)
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> > 
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"   "<<#y<<" : "<<y<<"  "<<#z<<" : "<<z<<endl;

#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define READ freopen("input.txt","r",stdin);
#define WRITE freopen("output.txt","w",stdout);
#define RANDOM srand(time(NULL));

#define MOD 1000000007
#define NAX 1000005
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN


ll solve()
{
    ll n;
    cin>>n;

    string str;
    cin>>str;

    vector<string> temp;
    FOR(i,'0','9'+1)
    FOR(j,'0','9'+1)
    FOR(k,'0','9'+1)
    {
        string z;
        z.pb(i);
        z.pb(j);
        z.pb(k);
        temp.pb(z);
    }

    ll sz = temp.size();

    ll pos[sz];
    FOR(i,0,sz)
    pos[i]=0;

    FOR(i,0,n)
    {
        FOR(j,0,sz)
        {
            if(pos[j]<3)
            {
                if(str[i]==temp[j][pos[j]])
                    pos[j]++;
            }
        }
    }

    ll cnt = 0;
    FOR(i,0,sz)
    if(pos[i]>=3)
    cnt++;

    cout<<cnt<<"\n";
    return 0;
}


int main()
{
    FAST;
    
    ll t=1;
    // cin>>t;
    
    while(t--!=0)
    {
        ll stat = solve();
    }
    return 0;
}



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

typedef long long ll;
int main()
{
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

long long n, k, a[110], dp[110][100010], pref[110][100010], mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp, 0, sizeof(dp));
    memset(pref, 0, sizeof(pref));
    cin >> n >> k;
    for(long long i = 1; i <= n; i++) {
    	cin >> a[i];
	}
	dp[0][0] = 1;
	for(long long i = 1; i <= k; i++) {
		dp[0][k] = 0;
	}
	for(long long i = 1; i <= n; i++) {
		pref[i - 1][0] = 1;
		for(long long j = 1; j <= k; j++) {
			pref[i - 1][j] = pref[i - 1][j - 1] + dp[i - 1][j];
			pref[i - 1][j] %= mod;
		}
		for(long long j = 0; j <= k; j++) {
			dp[i][j] += pref[i - 1][j] - pref[i - 1][j - min(j, a[i]) - 1];
			if(dp[i][j] < 0) {
				dp[i][j] = mod + dp[i][j];
			}
			dp[i][j] %= mod;
		}
	}
	cout << dp[n][k] % mod << endl;
}

Measured memory_bytes: 172160
n, m = map(int, input().split())
low = 0
high = 100001

for i in range(m):
  l,m = map(int, input().split())
  low = max(low, l)
  high = min(high, m)
if high-low+1<0:
  print(0)
else:
  print(min(high-low+1, n))

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

int main() {
    int N,K;
    cin >> N >> K;
    long long a;
    vector<long long> fire;
    for(int i=0;i<N;i++){
        cin >> a;
        fire.push_back(a);
    }
    sort(fire.begin(),fire.end());
    long long ans=1e15+7;
    long long jg=0;
    for(int j=0;j<=N-K;j++){
        if(fire[j]*fire[j+K-1]<0){
            jg=abs(fire[j+K-1]-fire[j])+min(abs(fire[j]),abs(fire[j+K-1]));
            
        }else{
            jg=max(abs(fire[j+K-1]),abs(fire[j]));
        }
        ans=min(ans,jg);
    }
 cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

int n;
vec<vec<pair<int, int>>> a;

int solve() {
  int res = 0;
  rep(i, 1 << n) {
    vec<int> p;
    rep(j, n) {
      p.pb((i >> j) & 1);
    }
    bool f = true;
    rep(j, n) {
      if (p[j]) {
        rep(k, a[j].size()) {
          int t = a[j][k].second;
          int r = p[a[j][k].first - 1];
          if (t != r) {
            f = false;
            break;
          }
        }
      }
      if (!f) break;
    }
    int sum = 0;
    if (f) {
      rep(j, n) {
        if (p[j]) {
          sum++;
        }
      }
    }
    res = max(res, sum);
  }
  return res;
}

int main() {
  cin >> n;
  rep(i, n) {
    int k; cin >> k;
    vec<pair<int, int>> t;
    rep(j, k) {
      int x, y; cin >> x >> y;
      t.emplace_back(x, y);
    }
    a.pb(t);
  }
  cout << solve() << endl;
  return 0;
}

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

int main(){
    string s,t;
    cin>>s>>t;
    vector<char> vs(s.size()),vt(t.size());
    for(int i=0;i<s.size();i++) vs[i]=s[i];
    for(int i=0;i<t.size();i++) vt[i]=t[i];
    sort(vs.begin(),vs.end());
    sort(vt.begin(),vt.end(),greater<char>());
    for(int i=0;;i++){
        if(vs[i]<vt[i]){
            cout<<"Yes"<<endl;
            break;
        }else if(vs[i]>vt[i]){
            cout<<"No"<<endl;
            break;
        }
        if(i==min(s.size(),t.size())-1){
            if(s.size()<t.size()) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys
n=int(input())
AC=0
WA=0
TLE=0
RE=0
for i in range(n):
    moji=input()
    if moji =='AC':
        AC+=1
    elif moji =='WA':
        WA+=1
    elif moji =='TLE':
        TLE+=1
    else:
        RE+=1
A=[AC,WA,TLE,RE]
B=['AC','WA','TLE','RE']
for i in range(4):
    q=A[i]
    print(B[i],end='')
    print(' x ',end='')
    print(q)
    


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

int main()
{
	int n, a[110];
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int ans = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] != a[i - 1]) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
xy.sort()
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    for j in range(i+1,N):
        tmp = (xy[j][0]-xy[i][0],xy[j][1]-xy[i][1])
        d[tmp] += 1
if N == 1:
    print(1)
else:
    print(N-max(d.values()))

Measured memory_bytes: 3572
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    System.out.println(a+b>=10?"error":a+b);
  }
}

Measured memory_bytes: 32468
#include<stdio.h>
int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=(S-h*3600)/60;
	s=(S-m*60)%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
int main()
{
    int a, b,i,j;
    char s[101][101];
    scanf("%d%d", &a, &b);
    for (i = 0; i < 50; i++)
    {
        for (j = 0; j < 100; j++)
            s[i][j] = '.';
    }
    for (i = 50; i < 100; i++)
    {
        for (j = 0; j < 100; j++)
            s[i][j] = '#';
    }
    a--;
    b--;
    i = 0;
    j = 1;
    while (b != 0)
    {
        s[i][j] = '#';
        b--;
        j += 2;
        if (j == 101)
        {
            j = 1;
            i+=2;
        }
    }
    i = 51;
    j = 1;
    while (a != 0)
    {
        s[i][j] = '.';
        a--;
        j += 2;
        if (j == 101)
        {
            j = 1;
            i+=2;
        }
    }
    printf("100 100\n");
    for (i = 0; i < 100; i++)
    {
        for (j = 0; j < 100; j++)
            printf("%c", s[i][j]);
        printf("\n");
    }
    return 0;
}

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

const int N = 1e5 + 10, M = 32;
int n, ans, x, ar[N], cnt[N], mark[M];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
		x ^= ar[i];
		
		int tmp = ar[i];
		while (tmp % 2 == 0) {
			cnt[i]++;
			tmp /= 2;
		}
		mark[++cnt[i]]++;
	}
	
	for (int i = M - 2; i >= 0; i--)
		if (x & (1LL << i)) {
			if (!mark[i + 1])
				return cout << -1, 0;
			x = ~x;
			ans++;
		}
	cout << ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'

#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

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

    #ifndef ONLINE_JUDGE
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    while(t--){
    	int x;cin>>x;
    	if(x>=30)cout<<"Yes";
    	else cout<<"No";
    }
}


Measured memory_bytes: 3596
#126_B
s=input()
y=int(s[:2])
m=int(s[2:])
if 1<=y<=12:
    if 1<=m<=12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1<=m<=12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define REP(i,a,b) for (int i = a; i <b; i++)
#define ll long long
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n][3];
    REP(i,0,n)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    REP(i,1,n){
        a[i][0]+=max(a[i-1][1],a[i-1][2]);
        a[i][1]+=max(a[i-1][0],a[i-1][2]);
        a[i][2]+=max(a[i-1][0],a[i-1][1]);
    }
    cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]))<<"\n";
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

const int k = 38;

int main(void) {
	const int n = k * (k - 1) + 1;
	cout << n << " " << k << endl;

	
	rep(i, k) {
		cout << n;
		rep(j, k - 1) cout << " " << (k - 1)*i + j + 1;
		cout << endl;
	}



	rep(step, k - 1) {
		rep(start, k - 1) {
			cout << (k - 1)*(k - 1) + step + 1;
			rep(i, k - 1) {
				cout << " " << i * (k - 1) + (start + i * step) % (k - 1) + 1;
			}
			cout << endl;
		}
	}
	

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
int main()
{
	double mountain[100];
	int i;
	double max=0,min=7000,result;
	for(i=0; i<10; i++){
		scanf("%lf",&mountain[i]);
		if(mountain[i]>max){
			max=mountain[i];
		}
		else if(mountain[i]<min){
			min=mountain[i];
		}
	}
	result=max-min;
	printf("%f",result);
	return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >>s;
  bool hantei_a=false;
  bool hantei_b=false;
  bool hantei_c=false;
  for(int i=0;i<3;i++){
    if(s[i]=='a')hantei_a=true;
    if(s[i]=='b')hantei_b=true;
    if(s[i]=='c')hantei_c=true;
  }
  if(hantei_a==true&&hantei_b==true&&hantei_c==true){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    int n;
    while( cin >> n, n ) {
        string s;
        cin >> s;
        int fl = 0;
        int cnt[SIZE] = {};
        int player = 0;
        for( int i = 0; i < s.size(); ++i ) {
            if( s[i] == 'M' ) {
                ++cnt[player];

            }
            if( s[i] == 'S' ) {
                ++cnt[player];
                fl += cnt[player];
                cnt[player] = 0;

            }
            if( s[i] == 'L' ) {
                cnt[player] += fl;
                ++cnt[player];
                fl = 0;

            }

            ++player;
            if( player == n ) player = 0;
        }
        sort( cnt, cnt + n );
        for( int i = 0; i < n; ++i ) cout << cnt[i] << " ";
        cout << fl << endl;

    }
    return 0;
}




Measured memory_bytes: 3580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

ll get(ll n, vector<ll> buy, vector<ll> sell) {
  ll ret = n;
  vector<int> good;
  for(int i = 0; i < buy.size(); i++) {
    if(buy[i] < sell[i]) good.push_back(i);
  }
  if(good.size() == 3) {
    for(int i = 0; i * buy[0] <= n; i++) {
      if(i > 0 && buy[0] >= sell[0]) continue;
      for(int j = 0; i * buy[0] + j * buy[1] <= n; j++) {
        if(j > 0 && buy[1] >= sell[1]) continue;
        ret = max(ret, n + i * (sell[0] - buy[0]) + j * (sell[1] - buy[1]));
        int k = (n - i*buy[0] - j*buy[1]) / buy[2];
        ret = max(ret, n + i * (sell[0] - buy[0]) + j * (sell[1] - buy[1]) + k * (sell[2] - buy[2]));
      }
    }
  }
  if(good.size() == 1) {
    ll amt = ret / buy[good[0]];
    ret = max(ret, n + amt * (sell[good[0]] - buy[good[0]]));
  }
  if(good.size() == 2) {
    for(int i = 0; i * buy[good[0]] <= n; i++) {
      int j = n - i*(buy[good[0]]);
      j /= buy[good[1]];
      ret = max(ret, n + i * (sell[good[0]] - buy[good[0]]) + j * (sell[good[1]] - buy[good[1]]));
    }
  }
  return ret;
}

void solve() {
  ll n;
  vector<ll> a, b;
  a.resize(3);
  b.resize(3);
  cin >> n;
  for(int i = 0; i < 3; i++) cin >> a[i];
  for(int i = 0; i < 3; i++) cin >> b[i];
  n = get(n, a, b);
  n = get(n, b, a);
  cout << n << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  ll t;
  cin >> t;
  for(ll i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MX 30001
int main()
{
  bool p[MX];
  int T,ans;
  int i,j,k;

  for(i=2;i*i<MX;i++)if(!p[i])for(j=i+i;j<MX;j+=i)p[j]=1;
  while(cin>>T,T){
    ans=0;
    for(i=2;i<T;i++){
      if(p[i])continue;
      for(j=i;j<=T-i-j;j++){
	k=T-i-j;
	if(p[j]||p[k])continue;
	if(i+j<=k)continue;
	ans++;
      }
    }
    cout<<ans<<endl;
  }
}

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

using namespace std;

const int N = 234567, mod = 1e9 + 7;

void add(int& x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}

int mul(int x, int y) {
  return (long long) x * y % mod;
}

int qpow(int x, int y) {
  int result = 1;
  for (; y; y >>= 1, x = mul(x, x)) {
    if (y & 1) {
      result = mul(result, x);
    }
  }
  return result;
}

int n, a, b, c, fac[N], ifac[N], inv[N];

int binom(int n, int m) {
  return n < 0 || m < 0 || n < m ? 0 : mul(fac[n], mul(ifac[m], ifac[n - m]));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b >> c;
  int e = mul(c, qpow(100 - c, mod - 2)), s = a + b;
  a = mul(a, qpow(s, mod - 2));
  b = mul(b, qpow(s, mod - 2));
  fac[0] = ifac[0] = inv[1] = 1;
  for (int i = 1; i <= (n << 1); ++i) {
    if (i > 1) {
      inv[i] = mul(mod - mod / i, inv[mod % i]);
    }
    fac[i] = mul(fac[i - 1], i);
    ifac[i] = mul(ifac[i - 1], inv[i]);
  }
  int answer = 0;
  for (int i = n; i < (n << 1); ++i) {
    int result = 0;
    add(result, mul(mul(qpow(a, n), qpow(b, i - n)), i + mul(i, e)));
    add(result, mul(mul(qpow(a, i - n), qpow(b, n)), i + mul(i, e)));
    add(answer, mul(result, binom(i - 1, n - 1)));
  }
  cout << answer << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <limits>

#define sqr(a) (a)*(a)

using namespace std;

int main () {
    int n, A[100];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    int result = numeric_limits<int>::max();
    for (int i = 1; i <= 100; ++i) {
        int tempResult = 0;
        for (int j = 0; j < n; ++j) {
            tempResult += sqr(A[j] - i);
        }
        result = min(result, tempResult);
    }
    cout << result;
}


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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(is,1<<h)rep(js,1<<w) {
    int cnt = 0;
    rep(i,h)rep(j,w) {
      if (is>>i&1) continue;
      if (js>>j&1) continue;
      if (s[i][j] == '#') cnt++;
    }
    if (cnt == k) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] height = new int[n];

		for (int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}

		int[] ma = new int[n];
		for (int i = 0; i < m; i++) {
			int a, b;
			a = sc.nextInt();
			b = sc.nextInt();
			ma[a - 1] = Math.max(ma[a - 1], height[b - 1]);
			ma[b - 1] = Math.max(ma[b - 1], height[a - 1]);
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (height[i] > ma[i]) {
				ans++;
			}
		}
		System.out.println(ans);
		sc.close();

	}

}


Measured memory_bytes: 59612
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int  n = sc.nextInt();
     int m = sc.nextInt();
     int ans=0;
     if(n <= m){
       for(int i=0;i<m;i++){
         ans+=Math.pow(10,i)*n;
       }
     }else{
       for(int i=0;i<n;i++){
         ans+=Math.pow(10,i)*m;
       }
     }
     System.out.println(ans);
   }
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm> 

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

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) 
        std::cin >> a[i];
    int ans = a[0];
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, a[i]);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<int,int>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 














//int ct[100005][2];
const int N=105;
int n;
ll w[N],v[N];
int main()
{
     ll W;
     cin>>n>>W;
     for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
     ll dp[n+1][W+1];memset(dp,0LL,sizeof(dp));
     for(int i=1;i<=n;i++)
     {
          for(int j=1;j<=W;j++)
          {
               dp[i][j]=dp[i-1][j];
               if(j>=w[i]){
                    dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
               }
          }
     }
     cout<<dp[n][W];

     
}
























 

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef pair<string, string> SS;

const int maxn = 500550;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const ll linf = 2e18;
#define debug(x) cout << #x << " " << x << "\n";
ll a[10000005];
int main()
{
    ios::sync_with_stdio(0);
    int i, j, k, n, m;
    cin >> n;
    for (i = 2; i <= n; i++)
    {
        for (j = i; j <= n; j += i)
            a[j]++;
    }
    ll ans = 0;
    for (i = 1; i <= n; i++)
        ans += (1 + a[i]) * i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81760
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e4+7;
int rak[maxn],sa[maxn],tax[maxn],tp[maxn],Height[maxn];
char a[maxn];           //这里其实每个数组元素就相当于一个字符，连起来就相当于一个字符串，不要死板的以为只能输char数组,有很多转换变形 
int M,len;	
void Qsort()
{
    for(int i=0;i<=M;++i)   tax[i]=0;
    for(int i=1;i<=len;++i)    tax[rak[i]]++;
    for(int i=1;i<=M;++i)   tax[i]+=tax[i-1];
    for(int i=len;i>=1;--i)     sa[tax[rak[tp[i]]]--] = tp[i];
}
void suffixsort()
{
    M=5050;
    for(int i=1;i<=len;++i)
    {
        rak[i]=a[i];
        tp[i]=i;
    }
    Qsort();
    for(int w=1;w<=len;w<<=1)
    {
        int p=0;
        for(int i=len-w+1;i<=len;++i)
            tp[++p]=i;
        for(int i=1;i<=len;++i)
            if(sa[i]>w)
                tp[++p]=sa[i]-w;
        Qsort();
        swap(rak,tp);
        rak[sa[1]]=p=1;
        for(int i=2;i<=len;++i){
            rak[sa[i]]=((tp[sa[i-1]]==tp[sa[i]])&&(tp[sa[i-1]+w]==tp[sa[i]+w]))?p:++p;
            if(p==len)  break;
            M=p;
        }
    }
}
void getHeight()
{
    int j,k=0;
    for(int i=1;i<=len;++i){
    	if(rak[i]==1) continue;
        if(k)   k--;
        int j=sa[rak[i]-1];
        while (i+k<=len && j+k<=len &&a[i + k] == a[j + k]) k++;
        Height[rak[i]] = k;
    }
}
int check(int x)
{
    int mx=sa[1],mi=sa[1];
    for(int i=2;i<=len;++i){
        if(Height[i]<x) mx=mi=sa[i];
        else{
            if(sa[i]<mi)    mi=sa[i];
            if(sa[i]>mx)    mx=sa[i];
            if(mx-mi>=x)     return 1;
        }
    }
    return 0;
}
int main()
{
		cin>>len;cin>>(a+1);
		map<char,int> mp;int ok=0;
		for(int i=1;i<=len;i++)
		{
			if(mp.count(a[i]))
			{
				ok=1;break;
			}
			else mp[a[i]]=1;
		}                                  
        suffixsort();
        getHeight();
        int res=0;
        int l=1,r=len/2+1,mid;
        while(l<r)
        {
            mid=(l+r)>>1;
            if(check(mid)){
                res=mid;
                l=mid+1;
            }
            else{
                r=mid;
            }
        }
        cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>

bool sort_pair( std::pair< int, int > origin, std::pair< int, int > another )
{
    return origin.first < another.first;
}

int main()
{
    std::string a,b;
    std::cin>> a;
    std::cin>> b;

    int count = 0;

for( int i = 0; i < a.size(); i++ )
    {
        if( a[i] == b[i] )
        {
            count +=1;
        }
    }

 std::cout<< count;
}


Measured memory_bytes: 256
#include<stdio.h>
void dicemove(char com,int *A);
void serch0 (int *A,int *B);
void serch1(int *A,int *B);
int check(int *A,int *B);
int main(void)
{
  int A[100][6];
  int i,j,k,a,b,m,n=1;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    for(j=0;j<6;j++){scanf("%d",&A[i][j]);}
  }

  for(a=0;a<m;a++){
    for(b=a+1;b<m;b++){
      serch0(A[a],A[b]);
  for(j=0;j<7;j++)
    {
  for(i=0;i<4;i++)
    {if(A[a][0]!=A[b][0]){break;}
      dicemove('M',A[a]);
 n= check(A[a],A[b]);
 if(!n){printf("No\n"); break;}
    }
  if(!n){break;}
  if(n && j<4){dicemove('N',A[a]);}
  else if(n && j>3){dicemove('E',A[a]);}
    }
   if(!n){break;}
    }
     if(!n){break;}
  }
  if(j == 7){printf("Yes\n");}
  return 0;
}
void dicemove(char com,int *A){	
  int temp;
  switch(com){
	case 'E':
	  temp=A[0]; A[0]=A[3]; A[3]=A[5];A[5]=A[2]; A[2]=temp;
	  break;
	case 'N':
	  temp=A[0]; A[0]=A[1]; A[1]=A[5]; A[5]=A[4]; A[4]=temp;
	  break;
	case 'S':
	  temp=A[0]; A[0]=A[4]; A[4]=A[5]; A[5]=A[1]; A[1]=temp;
	  break;
	case 'W':
	  temp=A[0]; A[0]=A[2]; A[2]=A[5]; A[5]=A[3]; A[3]=temp;
	  break;
        case 'M':
          temp=A[1]; A[1]=A[3]; A[3]=A[4]; A[4]=A[2]; A[2]=temp;
	  break;
	}
}
void serch0(int *A,int *B){
  int i;
  for(i=0;i<4;i++)
    {if(A[0] == B[0]){break;}
      dicemove('E',A);
    }
 if(A[0]!=B[0]){
   for(i=0;i<4;i++)
     {
dicemove('N',A);
   if(A[0] == B[0]){break;}
     }
 }
}
void serch1(int *A,int *B){
  int i;
  for(i=0;i<4;i++)
    {if(A[1] == B[1]){break;}
      dicemove('M',A);
    }
}
int check(int *A,int *B){
  int i;
  for(i=0;i<6;i++)
    {
      if(A[i] != B[i]){break;}
    }
  if(i == 6){return 0;}
  else {return 1;}
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, m;
    cin >> n >> m;
    vl a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0;
    rep(i, n) sum += a[i];
    sort(rall(a));
    rep(i, m) {
        if(a[i]*4*m < sum) {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, os
range = xrange

def main():
    inp = [int(x) for x in os.read(0, os.fstat(0).st_size).split()]
    n, m = inp[0],inp[1]

    wi, vi = inp[2], inp[3]


    dp = [0] * (m + 1)
    for j in range(wi, m + 1):
        dp[j] = vi

    for i in range(n - 1):
        wi = inp[2*i + 4]
        vi = inp[2*i + 5]
        for j in reversed(range(wi, m + 1)):
            dp[j] = max(vi + dp[j - wi], dp[j])

    print(dp[-1])
main()

Measured memory_bytes: 5764
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============prime_factor============================
vector<pll> prime_factor(ll N)
{
  vector<pll> res;
  for (ll i = 2; i * i <= N; ++i) {
    if (N % i == 0) {
      ll cnt = 0;
      while (N % i == 0) {
        N /= i;
        cnt += 1;
      }
      res.push_back({i, cnt});
    }
  }
  if (N != 1) {
    res.push_back({N, 1});
  }
  return res;
}
//=================================================

ll com(ll r, ll c) {
  vector<ll> factor(51, 0);
  c = min(r - c, c);
  for (ll i = 0; i < c; ++i) {
    vector<pll> temp = prime_factor(r - i);
    for (ll j = 0; j < temp.size(); ++j) {
      pll now = temp.at(j);
      factor.at(now.first) += now.second;
    }
  }
  for (ll i = 2; i <= c; ++i) {
    vector<pll> temp = prime_factor(i);
    for (ll j = 0; j < temp.size(); ++j) {
      pll now = temp.at(j);
      factor.at(now.first) -= now.second;
    }
  }
  ll res = 1;
  for (ll i = 1; i < factor.size(); ++i) {
    res *= pow(i, factor.at(i));
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  for (ll i = 0; i < N; ++i) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  vector<pll> num_v;
  ll connect = 0;
  ll before = v.at(0);
  for (ll i = 0; i < N; ++i) {
    if (v.at(i) != before) {
      num_v.push_back({before, connect});
      connect = 1;
      before = v.at(i);
    }
    else {
      connect += 1;
    }
  }
  num_v.push_back({before, connect});
  ll cnt = 0;
  ll ans = 0;
  double sum = 0;
  for (ll i = 0; i < num_v.size(); ++i) {
    ll next = cnt + num_v.at(i).second;
    ll M = min(num_v.at(i).second, B - cnt);
    ll m = A - cnt;
    if (next >= A && (i == 0)) {
      for (ll j = m; j <= M; ++j) {
        ans += com(num_v.at(i).second, j);
      }
      cout << num_v.at(0).first << "\n";
      break;
    }
    else if (next >= A) {
      ans = com(num_v.at(i).second, m);
      sum += num_v.at(i).first * m;
      cout << std::fixed << std::setprecision(15) << (sum / A) << "\n";
      break;
    }
    cnt = next;
    sum += num_v.at(i).first * num_v.at(i).second;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 4196
import java.util.*;

public class Main {


    public static void main(String[] args){
        long mod = 1000000007;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long nn = n;
        int[] a = new int[n];
        int k = sc.nextInt();
        long res = 0;
        for(int i=k; i<=n+1; i++) {
            long max = (nn*2+1-i) * i / 2;
            max %= mod;
            long min = (long)i * (i-1) / 2;
            min %= mod;
            res += mod + (max-min+1);
            res %= mod;
        }
        System.out.println(res);


    }



}

Measured memory_bytes: 36504
//package AtCoder;
import java.io.*;
import java.util.*;

public class Main {
	static int dp(int i)
	{
		if(dp[i]!=-1)
			return dp[i];
		
		int ans=0;
		for(int x:adjLists[i])
			ans=Math.max(dp(x)+1, ans);
		
		return dp[i]=ans;
	}
	static int n,m,dp[];
	static ArrayList<Integer>[]adjLists;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();m=sc.nextInt();
		adjLists=new ArrayList[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
		{
			adjLists[i]=new ArrayList<>();
			dp[i]=-1;
		}
		while(m-->0)
			adjLists[sc.nextInt()-1].add(sc.nextInt()-1);
		int ans=0;
		for(int i=0;i<n;i++)
			ans=Math.max(ans, dp(i));
		System.out.println(ans);
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

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

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] ans = new double[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextDouble();
			return ans;
		}

	}
}


Measured memory_bytes: 55104
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion

struct edge{int to,cost;};
vector<vector<edge>> G(100100);
int dist[100100];
void dijkstra(int s) {
    fill(dist,dist+100100,INF);
    priority_queue<P,vector<P>,greater<P>> pri;
    dist[s]=0;
    pri.push({0,s});
    while(!pri.empty()) {
        P p = pri.top();pri.pop();
        int v = p.second;
        if(dist[v]<p.first) continue;
        for(auto e:G[v]) if(chmin(dist[e.to],dist[v]+e.cost)) pri.push({dist[e.to],e.to});
    }
}
signed main() {
    int n;cin >> n;
    rep(i, n-1) {
        int a,b,c;cin >> a >> b >> c;
        a--;b--;
        G[a].pb({b,c});
        G[b].pb({a,c});
    }
    int q,k;cin >> q >> k;
    dijkstra(--k);
    rep(i, q) {
        int a,b;cin >> a >> b;
        cout << dist[--a]+dist[--b] << char(10);
    }
    return 0;
}

Measured memory_bytes: 14032
#include <stdio.h>
#include <string.h>
#define N 100000


typedef struct{
  int time;
  char name[10];
}Pro;

int head,tail,n;
int  min(int,int);
void enqueue(Pro);
Pro dequeue(void);

Pro Q[N];

int main(){
  int q,i,c,e=0;
  Pro z;

  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s%d" ,Q[i].name,&Q[i].time);
  }
  head = 1;
  tail = n+1;
  while(head!=tail){
    z = dequeue();
    c = min(q,z.time);
    z.time -= c;
    e += c;
    if(z.time > 0){
      enqueue(z);
    }
    else printf("%s %d\n",z.name,e);
  }
  return 0;
}

void enqueue(Pro x){
  Q[tail] = x;
    tail = (tail + 1)% N;
   

}
Pro dequeue(){
  Pro x;  
  x = Q[head];
  head = (head + 1) % N;
   
  return x;  
}

int min(int v, int w){
  return v < w ? v:w;
}

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

using int64 = long long;
using uint64 = unsigned long long;

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

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

    int N, X;
    cin >> N >> X;

    int ans = -1;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;

        if (ans < 0) ans = abs(x - X);
        else ans = gcd(ans, abs(x - X));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<queue> 
#include<map>
#include<set>
#include<stack>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll; 
int n, x, m = 1000000, ans;
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &x);
		if (x < m)
		{
			m = x;
			ans++;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 888
def f(s):
    n =len(s)
    t = list(s)
    lower = t[:(n-1) // 2]
    upper = t[(n+1) // 2:]
    print('Yes' if t == t[::-1] and lower == lower[::-1] and upper == upper[::-1] else "No")

s = input()
f(s)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{ 
    static void Main(string[] args)
    {
        var num = Input.num;
        var ar = Input.ar;
        for (var i = 0; i < num; i++)
            if (i + 1 < ar[i])
            {
                WriteLine(-1);
                return;
            }
        var res = new int[num];
        for(var i=0;i<num;i++)
        {
            var ind = i - ar[i] + 1;
            for (var j = i; j > ind; j--)
                res[j] = res[j-1];
            res[ind] = ar[i];
        }
        WriteLine(string.Join("\n", res.Reverse()));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const double eps = 1e-11;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13268
import java.io.*;
import java.util.*;
public class Main {
    static String oper;
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        char[] chs = s.toCharArray();

        String oper = dfs(chs, 1, chs[0] - '0', "");
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < chs.length; i++) {
            sb.append(chs[i]);
            if(i < chs.length - 1)
                sb.append(oper.charAt(i));
        }  
        System.out.println(sb.toString() + "=7");
    }
    /*
     1 2 2 2
      ^ 
     cur = 1+2=3+2=7 oper = "+++"
    */
    private static String dfs(char[] chs, int idx, int cur, String opers) {
        if(idx == chs.length) {
            if(cur == 7)
                return opers;
            else return null;
        }
        
        String plus = dfs(chs, idx + 1, cur + (chs[idx] - '0'), opers + "+");
        if(plus != null)
            return plus;
        
        String nega = dfs(chs, idx + 1, cur - (chs[idx] - '0'), opers + "-");
        if(nega != null)
            return nega;
            
        return null;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

// i個投げてj個表の確率
double dp[3000][3000];
int main(){
    int n; cin>>n;
    double p[n]; rep(i,n) cin>>p[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j-1>=0) dp[i][j]+=dp[i-1][j-1]*p[i-1];
            dp[i][j]+=dp[i-1][j]*(1.0-p[i-1]);
        }
    }
    double ans=0;
    for(int i=(n+1)/2;i<=n;i++){
        ans+=dp[n][i];
    }
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 68864
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)
using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    REP (i, n) cin >> a[i];
    b = a;

    // a[0] > 0
    ll ans1 = 0;
    if (a[0] <= 0) {
        ans1 += 1 - a[0];
        a[0] = 1;
    }
    ll ac1 = a[0];
    REP (i, n-1) {
        ac1 += a[i+1];
        if ((ac1 >= 0) && (i%2 == 0)) {
            ans1 += ac1 - -1;
            a[i+1] -= ac1 - -1;
            ac1 = -1;
        }
        if ((ac1 <= 0) && (i%2 == 1)) {
            ans1 += 1 - ac1;
            a[i+1] += 1 - ac1;
            ac1 = 1;
        }
        // for (auto e : a) cout << e << " ";
        // cout << endl;
    }

    // a[0] < 0
    a = b;
    ll ans2 = 0;
    if (a[0] >= 0) {
        ans2 += a[0] - -1;
        a[0] = -1;
    }
    ll ac2 = a[0];
    REP (i, n-1) {
        ac2 += a[i+1];
        if ((ac2 <= 0) && (i%2 == 0)) {
            ans2 += 1 - ac2;
            a[i+1] += 1 - ac2;
            ac2 = 1;
        }
        if ((ac2 >= 0) && (i%2 == 1)) {
            ans2 += ac2 - -1;
            a[i+1] -= ac2 - -1;
            ac2 = -1;
        }
    }

    // for (auto e : a) cout << e << " ";
    // cout << "\n";

    cout << min(ans1, ans2) << "\n";
}

Measured memory_bytes: 1024
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

const int MOD = 1e9+7;

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<std::vector<int> > from(n,std::vector<int>());
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		from[a].emplace_back(b);
		from[b].emplace_back(a);
	}
	int ans = k;
	std::vector<int> que;
	que.reserve(n);
	que.emplace_back(0);
	int current = k-1;
	std::vector<int> went(n,0);
	for(int i=0;i<que.size();i++) {
		int x = que[i];
		went[x] = 1;
		int cnt = 0;
		for(int j:from[x]) {
			if(went[j]) continue;
			que.emplace_back(j);
			ans = (ans*(current-cnt))%MOD;
			cnt++;
		}
		if(current==k-1)current--;
	}
	print(ans);
	return 0;
}


Measured memory_bytes: 8052