akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X = sc.nextInt();
		int c = 0;
		int A;
		for(int i=0;i<N;i++) {
			A=sc.nextInt();
			c += 1+(D-1)/A;
		}
		c += X;
		System.out.println(c);
	}

}


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

int main(){
    int n,x;
    cin>>n>>x;
    vector<int> a(n);
    
    for(int i=0;i<n;i++) cin>>a[i],x-=a[i];
    
    sort(a.begin(),a.end());
    
    cout<<n+(x/a[0])<<endl;
    
    return 0;
}


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 ld = long double;
using P = pair<int, int>;

int main() {
	int n, d;
	cin >> n >> d;
	cout << ceil((double)n / (2 * d + 1)) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#define P 100010
using namespace std;

int n,m;
long long int a[P];

int main()
{
	cin>>n>>m;
	priority_queue<int> q;
	int temp;
	for(int i=1;i<=n;++i)
	{
		cin>>temp;
		q.push(temp);
	}
	while(m--)
	{
		temp=q.top()/2;
		q.pop();
		q.push(temp);
	}
	long long int ans=0;
	while(!q.empty())
	{
		ans+=q.top();
		q.pop();
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<64)-1
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }


/*
   -------
         |
    **   |
   -------      
   |
   ------------------------------------------------------------------------------------------------------
*/

void solve(){
    
    int N;cin>>N;
    int m;cin>>m;
    vector<int> s(m);
    vector<int> c(m);
    REP(i,m){ cin>>s[i];cin>>c[i];}
    REP(i,1000){
        string S = to_string(i);
        if(S.length() != N)   continue;
        bool f = true;
        REP(j,m){
            if(S[s[j]-1] != '0' + c[j]) f=false;           //for all given positions and for all possible integers;;; O(10^N*m) 
        }
        if(f){
           cout<<i<<endl;
           return ;
        }
    }
    puts("-1");
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
#define umap unordered_map
#define all(x) x.begin(), x.end()
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M ;
    }
    return res%M;
}
lli solve(){
    lli a, b, c;
    cin>>a>>b>>c;
    lli count = 0;
    loop(i, a, b+1){
        if(i%c == 0)
            count++;
    }
    cout<<count<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
	// cin>>t;
    t = 1;
    while(t>0){ 
        t--;
        solve();
    }
}

Measured memory_bytes: 3648
def main():

    match_count = int(input())
    matches = [input().split() for i in range(match_count)]
    
    taro_result = [3 if match[0] > match[1] else 1 if match[0] == match[1] else 0 for match in matches]
    print('%d %d' % (sum(taro_result), sum(3 if item == 0 else 1 if item == 1 else 0 for item in taro_result)) )


main()

Measured memory_bytes: 7928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;

  ll p = 1;
  while(1){
    if(p * p > n){
      cout << (p - 1) * (p - 1) << endl;
      return 0;
    }
    p++;
  }
  return 0;
}


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

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>


int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll cnt = 0;
    while(A >= B)
    {
        B <<= 1;
        cnt++;
    }
    while(B >= C)
    {
        C <<= 1;
        cnt++;
    }
    cout << (cnt <= K ? "Yes" : "No") << endl;




    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm. fill_n(&an[0][0],n*m,0); typedef long long ll;*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
#define print(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}

void solve(){
	int k;
	cin >> k;
	int a,b;
	cin >> a >> b;
	bool pr = false;
	if(a%k == 0)pr = true;
	if(b%k == 0)pr = true;
	int t1 = a/k;
	int t2 = b/k;
	if(t1 != t2)pr = true;
	
	if(pr)cout << "OK" << endl;
	else cout << "NG" << endl;
}
/* When you have to multiply many things , do it in different (multiple) lines, not in a single line .*/
int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int nT = 1;
	//cin >> nT;
	FE(i,1,nT)
		solve();
	return 0;
}


Measured memory_bytes: 3608
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  long long N, mod, ans;
  mod = 1000000007;

  cin >> N;

  if(N == 1){
    cout << 1 << endl;
    return 0;
  }

  vector<int> prime;
  prime.push_back(2);

  for(int i=3;i<=1000;i++){
    bool flag = true;
    for(int j=2;j<i;j++){
      if(i%j == 0) flag = false;
    }
    if(flag) prime.push_back(i);
  }

  long long m[prime.size()];
  for(int i=0;i<prime.size();i++){
    m[i] = 0;
  }

  for(int n=1;n<=N;n++){
    int ns = n;
    for(int i=0;i<prime.size();i++){
      int j = 0, p = prime[i];
      while(ns%p == 0){
        j++;
        ns = ns/p;
      }
      m[i] += j;
    }
  }



  ans = 1;
  for(int i=0;i<prime.size();i++){
    ans = (ans*(m[i]+1))%mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N, M ,K;
ll Main() {
    // しゃくとり法パターン
    cin >> N >> M >> K;
    vl A(N+1, 0);
    vl B(M+1, 0);
    
    rep(i,N) {
        ll tmp;
        cin >> tmp;
        A[i+1] = A[i] + tmp;
    }

    rep(i,M) {
        ll tmp;
        cin >> tmp;
        B[i+1] = B[i] + tmp;
    }
    
    ll ans = 0;
    ll j = M;
    rep(i, N+1) {
        if(A[i] > K) {
            break;
        }
        
        while(A[i]+B[j] > K) {
            j--;
        }
        
        ans = max(ans, i+j);
    }
    cout << ans << endl;
    return 0;
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
    fastio;

    int n;
    cin >> n;
    int A[n];
    int working = 0;
    int evens = 0;
    FOR(i, 0, n) {
        cin >> A[i];
        if (A[i] % 4 == 0) {
            working++;
        }
        if (!odd(A[i])) {evens++;}
    }
    evens -= working;
    if (working + (evens/2)>= n/2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(void) {

	char s[20], t[20];
	int i;

	scanf("%s", s);
	scanf("%s", t);

	if (strlen(t) - strlen(s) == 1 && strncmp(s, t, strlen(s))==0) {
		printf("Yes");
	}

	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1776
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef vector<vector<int>> Graph;
void add_edge(Graph& g, int from, int to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

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

	ll x; cin >> x;
	ll i = 1;
	ll sum = 1;
	while(sum < x) { ++i; sum += i; }

	cout << i << endl;
}



Measured memory_bytes: 3628
#include <iostream>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    Int c[3][3];
    Int d[3][3];
    for (Int i = 0; i < 3; ++i) {
        for (Int j = 0; j < 3; ++j) {
            cin >> c[i][j];
            d[j][i] = c[i][j];
        }
    }
    if ((c[0][0] - c[1][0] == c[0][1] - c[1][1]) && (c[0][0] - c[1][0] == c[0][2] - c[1][2])) {
        if ((c[0][0] - c[2][0] == c[0][1] - c[2][1]) && (c[0][0] - c[2][0] == c[0][2] - c[2][2])) {
            if ((d[0][0] - d[1][0] == d[0][1] - d[1][1]) && (d[0][0] - d[1][0] == d[0][2] - d[1][2])) {
                if ((d[0][0] - d[2][0] == d[0][1] - d[2][1]) && (d[0][0] - d[2][0] == d[0][2] - d[2][2])) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

long long gcd(long long a, long long b) {
    for(;;) {
        if(a == 0)
            return b;
        b %= a;
        if(b == 0)
            return a;
        a %= b;
    }
}

long long lcm(long long a, long long b) {
    long long temp = gcd(a, b);
    return temp ? (a / temp * b) : 0;
}

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(K % 2 == 0) {
        if(abs(A - B) > 100000000000000000) {
            cout << "Unfair" << endl;
            return 0;
        }
        cout << A - B << endl;
    } else {
        ll A_t = B + C;
        ll B_t = A + C;
        ll C_t = A + B;
        if(abs(A_t - B_t) > 100000000000000000) {
            cout << "Unfair" << endl;
            return 0;
        }
        cout << A_t - B_t << endl;
    }
    return 0;
}

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

using namespace std;

long long mod = 1e9 + 7;

long long powm(long long a, long long n) {
    long long res = 1;
    for (int i = 0; i < n; ++i) {
        res *= a;
        res %= mod;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long n;
    cin >> n;
    cout << ((((powm(10, n) - 2 * powm(9, n)) + mod) % mod + powm(8, n)) + mod) % mod;
    return 0;
}

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

#define X first
#define Y second
#define MP make_pair

using namespace std;

typedef long long ll;

const int N = 1e7 + 12;
const ll mod = 1e9 + 7;

int n, m;
bool gd[N], was[N];

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

	cin >> n >> m;
	for(int i = 1, x;i <= m;i++)
		cin >> x, gd[x] = 1;
	queue<int> q;
	q.push(0);
	was[0] = 1;
	while(q.size()){
		int v = q.front();
		if(v >= n){
			cout << v;
			exit(0);
		}
		q.pop();
		for(int i = 0;i <= 9;i++){
			if(gd[i])
				continue;
			if(!was[v * 10 + i]){
				was[v * 10 + i] = 1;
				q.push(v * 10 + i);	
			}
		}
	}
}


Measured memory_bytes: 3920
from heapq import heappush as pu, heappop as po

n,m,s,t = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
    u,v,a,b = map(int,input().split())
    e[u].append((v,a,b))
    e[v].append((u,a,b))

def dik(s,v):
    S = [float("INF")]*(n+1)
    S[s] = 0
    h = []
    pu(h,[0,s])
    while h:
        d,now = po(h)
        for nex in e[now]:
            a,b = nex[0],nex[v]
            if d+b < S[a]:
                S[a] = d+b
                pu(h,[d+b,a])
    return S[::-1]
ans = []
cost = 10**15
now = 0
for i,j in zip(dik(s,1),dik(t,2)):
    now = max(now,cost-i-j)
    ans.append(now)
print(*ans[:-1][::-1],sep="\n")

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

int main(){
    int n;
    cin >> n;
    int tmp = 0;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        if (i != x) tmp++;
    }
    if (tmp == 0 || tmp == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
a=int(input())
if (a//100)%9==0:
  b=100
else:
  b=900
if ((a-(a//100)*100)//10)%9==0:
  c=10
else:
  c=90
if (a-(a//10)*10)%9==0:
  d=1
else:
  d=9
print(b+c+d)

Measured memory_bytes: 8952
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
  ll n,m,l;cin >>  n >>m >>l;
  vvpl g(n);
  rep(i,m){
    ll a,b,c;cin >> a >>b >>c;a--;b--;
    g[a].pb({b,c});
    g[b].pb({a,c});
  }
  vvl gg(n,vl(n,INF/10));
  rep(z,n){
    vl d(n,inf);
    pqueue(pl) que;
    que.push({0,z});
    d[z]=0;
    while(!que.empty()){
        pl p=que.top();
        que.pop();
        ll v=p.se;
        if(d[v]<p.fi)continue;
        rep(i,g[v].size()){
            pl ed=g[v][i];
            if(d[ed.fi]>d[v]+ed.se){
                //prev[ed.fi]=v;
                d[ed.fi]=d[v]+ed.se;
                que.push({d[ed.fi],ed.fi});
            }
        }
    }
    rep(j,n){
      if(d[j]<=l)gg[z][j]=1;
    }
  }
  /*rep(i,n){
    cout << i <<endl;
    for(auto p:gg[i])cout << p <<" ";
    cout << endl;
  }*/
  rep(i,n)gg[i][i]=0;
  rep(k,n)rep(i,n)rep(j,n)chmin(gg[i][j],gg[i][k]+gg[k][j]);
  /*rep(i,n){
    rep(j,n){
      cout << gg[i][j] <<" ";
    }
    cout <<endl;
  }*/
  ll q;cin >> q;
  rep(i,q){
    ll x,y;cin >> x >>y;x--;y--;
    if(gg[x][y]!=INF/10)cout << gg[x][y]-1 <<endl;
    else cout << -1 <<endl;
  }
}

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

A = sorted(A)
A = A + [-1]

ans = 0
total = 0
for i in range(N):
    total += A[i]

    if total >= A[i+1]/2:
        ans += 1
    else:
        ans = 0

print(ans)

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll ans;
    for (ll i = 0; i < 5; i++) {
        ll a;
        cin >> a;
        if (a == 0) {
            ans = i + 1;
            break;
        }
    }
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3528
import sys
import math
import bisect

def main():
    A = []
    for i in range(5):
        A.append(int(input()))
    m = int(input())
    ans = 'Yay!'
    for i in range(len(A)):
        for j in range(len(A)):
            if abs(A[i] - A[j]) > m:
                ans = ':('
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

set<int> se[200][201];
string s;

set<int> rec(int l, int r) {
  if (se[l][r].size()) return se[l][r];
  
  int nest = 0;

  set<int> res;
  bool flag = 0;
  for (int i=l; i<r; ++i) {
    if (s[i]=='(') nest++;
    else if (s[i]==')') nest--;
    if (nest == 0 && (s[i]=='/'||s[i]=='+'||s[i]=='*'||s[i]=='-')) {
      flag = 1;
      set<int> leftset = rec(l, i);
      set<int> rightset = rec(i+1, r);
      FOR(it, leftset) {
        FOR(jt, rightset) {
          if (s[i]=='/') {
            if (*jt!=0)
              res.insert(*it / *jt);
          }
          else if (s[i]=='+')
            res.insert(*it + *jt);
          else if (s[i]=='-')
            res.insert(*it - *jt);
          else if (s[i]=='*')
            res.insert(*it * *jt);
        }
      }
    }
  }
  if (!flag) {                    // ツ可可算ツ子ツ鳴ウツつオ
    if (s[l]=='('&& s[r-1]==')') return rec(l+1,r-1);
    res.insert(atoi(s.substr(l,r-l).c_str()));
  }
  // cout << s.substr(l,r-l) << endl;
  // cout << "res : ";
  // FOR(it, res)
  //   cout << *it << " ";
  // cout << endl;
  return se[l][r] = res;
}

int main() {
  while(cin>>s, s!="#"){
    int n = s.size();
    REP(i,n) REP(j,n+1)
      se[i][j].clear();
    cout << rec(0,s.size()).size() << endl;
  }
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;


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

    for (int i = 1; i <= n / 2 + 1; i++) {
        if ((n * 2) % i == 0 && (n * 2) / i == i + 1) {
            cout << "Yes" << endl;
            cout << i + 1 << endl;
            vector<vector<int>> s(i + 1, vector<int>(i));
            int c = 1;
            for (int j = 0; j < i; j++) {
                for (int k = j; k < i; k++) {
                    s[j][k] = c;
                    c++;
                }
            }
            c = 1;
            for (int j = 0; j < i; j++) {
                for (int k = j + 1; k <= i; k++) {
                    s[k][j] = c;
                    c++;
                }
            }

            for (int j = 0; j < i + 1; j++) {
                cout << i << " ";
                for (int k = 0; k < i; k++) {
                    cout << s[j][k];
                    if (k == i - 1) {
                        cout << endl;
                    } else {
                        cout << " ";
                    }
                }
            }
            return 0;
        }
    }

    cout << "No" << endl;
}


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

#define long long long int
static const long MOD = 998244353;
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<vector<vector<int>>> g(3, vector<vector<int>>(n));
    for (int t = 0; t < 3; t++) {
        int m;
        cin >> m;
        for (int i = 0; i < m; i++) {
            int x, y;
            cin >> x >> y;
            x--;
            y--;
            if (x > y) swap(x, y);
            g[t][x].push_back(y);
        }
    }
    vector<vector<int>> gr(3, vector<int>(n));
    int mx = 0;
    for (int t = 0; t < 3; t++) {
        vector<int> z(n + 1);
        int zz = 0;
        for (int i = n - 1; i >= 0; i--) {
            zz++;
            for (int j : g[t][i]) {
                z[gr[t][j]] = zz;
            }
            while (z[gr[t][i]] == zz) gr[t][i]++;
            mx = max(mx, gr[t][i]);
        }
    }
    vector<vector<long>> ss(3, vector<long>(mx + 1));
    vector<long> pw(n + 1);
    pw[0] = 1;
    for (int i = 0; i < n; i++) {
        pw[i + 1] = pw[i] * 716070898 % MOD;
    }
    for (int t = 0; t < 3; t++) {
        for (int i = 0; i < n; i++) {
            ss[t][gr[t][i]] += pw[i + 1];
            ss[t][gr[t][i]] %= MOD;
        }
    }
    long res = 0;
    for (int i = 0; i <= mx; i++) {
        for (int j = 0; j <= mx; j++) {
            if ((i ^ j) > mx) continue;
            long s = ss[0][i];
            s *= ss[1][j];
            s %= MOD;
            s *= ss[2][i ^ j];
            s %= MOD;
            res += s;
            res %= MOD;
        }
    }
    cout << res << "\n";
    return 0;
}

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

int main() {
	int n;cin>>n;
	vector<int> l(n);
	map<int,int> m;
	m[-1]=0;
	for(int i=0;i<n;i++){
		cin>>l[i];
		m[i]=m[i-1]+l[i];
	}
	sort(l.begin(),l.end());
	int ans=0;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			int idx=lower_bound(l.begin(),l.end(),l[i]+l[j])-l.begin();
			ans+=idx-j-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  long long a,b;
  int n;
  while(cin>>a>>b>>n) {
    a = a%b*10 ;
    int ans = 0;
    REP(i,n) {
      ans += a/b;
      a = a%b*10;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
from bisect import bisect_right as br
from itertools import combinations_with_replacement as cwr

MAX = 110000
ROOT = 340
tf = [True] * MAX
tf[0] = tf[1] = False
for i in range(2, ROOT + 1):
  if tf[i]:
    for j in range(i * i, MAX, i):
      tf[j] = False
primes = [i for i in range(MAX) if tf[i]]

while True:
  n, p = map(int ,input().split())
  if n == -1:break
  init = br(primes, n)
  choice = primes[init:init+100]
  lst = []
  for i, j in cwr(choice, 2):
    lst.append(i + j)
  lst.sort()
  print(lst[p - 1])


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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define MT make_tuple

using PII = pair<int, int>;
using TI3 = tuple<int, int, int>;
using LL = long long;
using ULL =  unsigned long long;
using MAT = array<array<LL, 2>, 2>;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d", &head);
    RI(tail...);
}
void RLL() {}
template<typename... T>
void RLL( LL& head, T&... tail ) {
    scanf("%lld", &head);
    RLL(tail...);
}
void print() {putchar('\n');}
template<typename T, typename... U>
void print(T head, U... tail) {
    cout << head << " ";
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 2005

int a[MAX_N];
bitset<4000005> dp;

int main()
{
    int n;
    RI(n);
    REP(i, n) {
        RI(a[i]);
    }

    dp.set(0, true);
    REP(i, n) {
        dp = dp | (dp << a[i]);
    }
    int M = 0;
    REP(i, n) {
        M += a[i];
    }
    REP(i, (M+1)/2, 4000005) {
        if(dp.test(i)) {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll n;
  cin>>n;
  ll arr[n];
  for(ll &i:arr)
    cin>>i;
  ll sum=0;
  for(ll i=1;i<n;i++)
  {
    if(arr[i-1]>arr[i])
    {
      sum+=(arr[i-1]-arr[i]);
      arr[i]+=(arr[i-1]-arr[i]);
    }
  }
  cout<<sum;
  return 0;
}

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

int H, W;

int main() {
    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            return 0;
        } else if (W % 2 == 0) {
            if (H % 2 == 0) {
                for (int i = 0; i < H / 2; i++) {
                    for (int i = 0; i < W / 2; i++) {
                        cout << "#.";
                    }
                    cout << endl;
                    for (int i = 0; i < W / 2; i++) {
                        cout << ".#";
                    }
                    cout << endl;
                }
            } else {
                for (int i = 0; i < H / 2; i++) {
                    for (int i = 0; i < W / 2; i++) {
                        cout << "#.";
                    }
                    cout << endl;
                    for (int i = 0; i < W / 2; i++) {
                        cout << ".#";
                    }
                    cout << endl;
                }
                for (int i = 0; i < W / 2; i++) {
                    cout << "#.";
                }
                cout << endl;
            }
            
            
        } else {
            if (H % 2 == 0) {
                for (int i = 0; i < H / 2; i++) {
                    for (int i = 0; i < W / 2; i++) {
                        cout << "#.";
                    }
                    cout << "#";
                    cout << endl;
                    for (int i = 0; i < W / 2; i++) {
                        cout << ".#";
                    }
                    cout << ".";
                    cout << endl;
                }
            } else {
                for (int i = 0; i < H / 2; i++) {
                    for (int i = 0; i < W / 2; i++) {
                        cout << "#.";
                    }
                    cout << "#";
                    cout << endl;
                    for (int i = 0; i < W / 2; i++) {
                        cout << ".#";
                    }
                    cout << ".";
                    cout << endl;
                }
                for (int i = 0; i < W / 2; i++) {
                    cout << "#.";
                }
                cout << "#";
                cout << endl;
                
            }
        }
        
        cout << endl;
        
    }
}


Measured memory_bytes: 3080
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    int64_t first = 0, second = 0;
    cin >> n;
    std::vector<int64_t> s;
    for (int i = 0; i < n; i++) {
        int m1;
        cin >> m1;
        s.push_back(m1);
    }
    std::sort(s.begin(), s.end(), std::greater<int64_t>());
    int64_t len = 0;
    for (auto x : s) {
        if (x == len) {

            len = 0;
            if (first == 0)
                first = x;
            else {
                second = x;
                cout << first * second << endl;
                exit(0);
            }

        } else {
            len = x;
        }
    }
    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define MAX 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef long long ll;

int main()
{
    FASTIO
   /* 
   double start_time = clock();
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  #endif
    */
    int n,k;
    cin >> n >> k;
    vector<int> H(n, 0);
    for(int i = 0; i < n; i++) cin >> H[i];

      vector<int> ans(n+5, INF);
    ans[0] = 0;
    for(int i = 0; i < n; i++){
      for(int j = 1; j <= k && (i+j) < n; j++){
      ans[i+j] = min(ans[i+j], ans[i] + abs(H[i+j] - H[i]));
    }
  }
    cout << ans[n-1]<<endl;

     //double end_time = clock();
  //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
   
    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys

#n= int(input())
#tmp= float(input())
while(1):
    tmp = input().split()
    m,f,r = list(map(lambda a: int(a), tmp))

    if((m==-1)and(f==-1)and(r==-1)):
        sys.exit()

    sum=m+f
    if((m==-1)or(f==-1)):
        print("F")
    elif(sum>=80):
        print("A")
    elif(sum>=65):
        print("B")
    elif(sum>=50):
        print("C")
    elif(sum>=30):
        if(r>=50):
            print("C")
        else:
            print("D")
    else:
        print("F")




Measured memory_bytes: 5604
H,W,N = map(int, input().split())

field = {}
for i in range(N):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    for j in range(a-1, a+2):
        for k in range(b-1, b+2):
            if not j in field:
                field[j] = {}
            if not k in field[j]:
                field[j][k] = 0
            field[j][k] += 1

ans = [0] * 10
for kh in field.keys():
    for kw in field[kh].keys():
        if 1 <= kh <= H-2 and 1 <= kw <= W-2:
            ans[field[kh][kw]] += 1

tmp = (H-2)*(W-2)
for i in range(1,10):
    tmp -= ans[i]

ans[0] = tmp
for i in range(10):
    print(ans[i])



Measured memory_bytes: 142796
#include <stdio.h>
int main(void){
    int a,b,i=0,j,k,d,sum[200];
    while(scanf("%d %d",&a,&b)!=-1){
        sum[i] = a+b;
        i++;
    }
    for(j=0;j<i;j++){
        d=10;
        for(k=1;;k++){
            if(sum[j]<d){
                printf("%d\n",k);
                break;
            } else {
                d*=10;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 600
N = int(input())
ST = []
for _ in range(N):
    x, l = map(int, input().split())
    ST.append((x - l, x + l))

ST.sort(key=lambda x: x[1])

cnt = 1
last = ST[0][1]
for i in range(1, N):
    if ST[i][0] < last:
        continue
    else:
        cnt += 1
        last = ST[i][1]

print(cnt)


Measured memory_bytes: 18260
import math
n=int(input())
#n = math.floor(x*1.08)
ans = n/1.08
if math.floor(math.floor(ans)*1.08) == n:
    print(math.floor(n/1.08))
elif math.floor(math.ceil(ans)*1.08) ==n:
    print(math.ceil(n/1.08))
else:
    print(":(")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll h,w;
    cin >> h >> w;
    if(h%3 == 0 || w%3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = min(h,w);
    if(w%2 == 0) {
        rep2(i,1,h) {
            chmin(ans,abs(i*(w/2)-(h-i)*w));
        }
    } else {
        rep2(i,1,h) {
            chmin(ans,max(i*(w/2+1),(h-i)*w)-min(i*(w/2),(h-i)*w));
        }
    }
    if(h%2 == 0) {
        rep2(i,1,w) {
            chmin(ans,abs(i*(h/2)-(w-i)*h));
        }
    } else {
        rep2(i,1,w) {
            chmin(ans,max(i*(h/2+1),(w-i)*h)-min(i*(h/2),(w-i)*h));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

void solve(int r, int D, int x);

void solve(int r, int D, int x) {
  int cur = x;
  for (int i = 0; i < 10; i++) {
    int nex = r * cur - D;
    printf("%d\n", nex);
    cur = nex;
  }
}

int main() {
  int r, D, x;
  cin >> r >> D >> x;
  solve(r, D, x);
  return 0;
}


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

using namespace std;

int main(){

	string s;
	while(cin>>s){
		string ns;
		for(int i = 0; i < s.size(); i++){
			if(s[i]=='@'){
				string ss=s.substr(i+1,2);
				for(int i = 0; i < ss[0]-'0'; i++){
					ns+=ss[1];
				}
				i+=2;
			}
			else{
				ns+=s[i];
			}
		}
		cout<<ns<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
bool h[2005];
vector<int>edge[2005];
int dist[2005][2005];
int sum[2005][2005];
int cnt[2005][2005];
P dfs(int v,int u,int g,int d){
	dist[g][v] = d;
	if(h[v]){
		sum[g][v] = d;
		cnt[g][v] = 1;
	}
	rep(i,edge[v].size()){
		if(edge[v][i] == u) continue;
		P p = dfs(edge[v][i],v,g,d+1);;
		sum[g][v] += p.fi;
		cnt[g][v] += p.sc;
	}
	return P(sum[g][v],cnt[g][v]);
}
int gen(int v,int u,int g){
	int S = 0, mx = 0;
	rep(i,edge[v].size()){
		if(edge[v][i] == u) continue;
		S += sum[v][edge[v][i]];
		mx = max(mx,sum[v][edge[v][i]]);
	}
	if(mx <= S/2) return cnt[g][v]+S%2;
	else{
		int id;
		rep(i,edge[v].size()){
			if(edge[v][i] == u) continue;
			if(mx == sum[v][edge[v][i]]) id = edge[v][i];
		}
		int reduction = gen(id,v,g);
		if(reduction <= S-mx) return cnt[g][v]+S%2;
		else return (reduction-S+mx)+cnt[g][v];
	}
}
int check(int v,int u,int g){
	int S = 0, mx = 0;
	rep(i,edge[v].size()){
		if(edge[v][i] == u) continue;
		S += sum[g][edge[v][i]];
		mx = max(mx,sum[g][edge[v][i]]);
	}
	if(u == -1){
		if(mx <= S/2) return S;
		int id = -1;
		rep(i,edge[v].size()){
			if(edge[v][i] == u) continue;
			if(sum[g][edge[v][i]] == mx) id = edge[v][i];
		}
		int reduction = gen(id,v,g);
		//cout << id << " " << v << " " << g << " " << reduction << endl;
		if(reduction > S-mx) return INF;
		else return S;
	}
}
int main(){
	cin >> n;
	string s; cin >> s;
	rep(i,n) if(s[i] == '1') h[i+1] = 1;
	rep(i,n-1){
		int a,b; cin >> a >> b;
		edge[a].pb(b);edge[b].pb(a);
	}
	repn(i,n) dfs(i,-1,i,0);
	int ans = INF;
	repn(i,n){
		if(sum[i][i]%2 == 1) continue;
		ans = min(ans,check(i,-1,i));
		assert(ans%2 == 0);
		//cout << i << " " << check(i,-1,i) << endl;
	}
	cout << (ans>INF/2?-1:ans/2) << endl;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a), end(a)

int main(void) {
    int N;
    cin >> N;
    vector<int> P(N), Q(N), A(N);
    REP(i, N) cin >> P[i];
    REP(i, N) cin >> Q[i];
    REP(i, N) A[i] = i + 1;
    int a, b;
    int dic = 0;
    do {
        bool isa = true;
        bool isb = true;
        REP(i, N) {
            if (A[i] != P[i]) isa = false;
            if (A[i] != Q[i]) isb = false;
        }
        if (isa) a = dic;
        if (isb) b = dic;
        dic++;
    } while (next_permutation(ALL(A)));
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int i = 1;
		do {

			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				while (true) {
					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
					if (x != 0) {
						continue;
					} else
						break;
				}
			}
		} while (++i <= n);
		System.out.println();

	}
}

Measured memory_bytes: 28900
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N, M;

    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        M = cin.nextInt();

    }
    static void solve()
    {
        input();
        if (Abs(N - M) > 1)
        {
            WriteLine(0);
            return;
        }
        long ans = 1;
        if (N == M)
            ans *= 2;
        
        for(int i = Max(N, M); i > 1; i--)
        {
            ans = (ans * i) % 1000000007;
        }

        for(int i = Min(N, M); i > 1; i--)
        {
            ans = (ans * i) % 1000000007;
        }
        WriteLine(ans);
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13140
def comb(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

MOD=10**9+7
MAXN=400000+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1):
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

N, K=map(int, input().split())
if K>=N-1:
    print(comb(N*2-1, N))
else:
    ans=1
    for i in range(1, K+1):
        ans=(ans+(comb(N-1, i)*comb(N, i))%MOD)%MOD
    print(ans)


Measured memory_bytes: 50848
<?php

fscanf(STDIN, "%d %d", $N, $T);

$mincost = 9999;
for($i == 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $c, $t);
    if ($t <= $T && $c < $mincost) {
        $mincost = $c;
    }
}

if ($mincost == 9999) {
    echo "TLE\n";
} else {
    echo $mincost . "\n";
}


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

int main()
{
	ios::sync_with_stdio(false);
	
	int a,b;
	cin>>a>>b;
	int maxv=0;
	
	cout<<max(max(a+b,a-b),a*b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
 
const int INF = 1000000007;
const int MAX_V = 1000007;
 
typedef long long ll;
typedef pair<int, int> P; //first: ???????????¢???second: ??????????????? 

struct edge{
    int to;
    int cost;
};

int V=0;
vector<edge > G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > qu;
  fill(d, d + V, INF);
  d[s] = 0;
  qu.push(P(0,s));
  while(!qu.empty()){
    P p = qu.top(); qu.pop();
    int v = p.second;    
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
	d[e.to] = d[v] + e.cost;
	qu.push(P( d[e.to], e.to ));
      }
    }
  }
}


int main(){

  int E,r;
  cin >> V >> E >> r;
  for(int i = 0 ; i < E; i++){
    int s , t , d;
    cin >> s >> t >> d;
    edge e;// = {t,d};
    e.to = t; e.cost = d;
    G[s].push_back(e);
  }
  dijkstra(r);
  for(int i = 0; i < V ; i++){
    if (d[i] == INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 34260