akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using Pdi = pair<double, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int H, M, h, m, K; cin >> H >> M >> h >> m >> K;
    int T = 60 * H + M, t = 60 * h + m;
    int ans = max(0LL, t - T - K);
    Out(ans);

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define l first
#define r second
#define int long long

using namespace std;

const int maxn = 1e6 + 1;

int a[maxn], x[maxn];
int fc[maxn];
bool ec[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 2; i <= n; i++) {
        fc[i] = fc[i - 1];
        for (int x = i; x % 2 == 0; x /= 2)
            ++fc[i];
    }
    for (int i = 0; i < n; i++) {
        char c; cin >> c;
        a[i] = c - '1';
    }
    bool ho = 0;
    for (int i = 0; i < n; i++)
        ho |= (a[i] == 1);
    for (int i = 0; i < n; i++)
        ec[i] = (fc[n - 1] - fc[i] - fc[n - i - 1] > 0);
    if (!ho) {
        int ans = 0;
        for (int i = 0; i < n; i++)
            if (!ec[i]) ans ^= a[i];
        cout << ans;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (!ec[i]) ans ^= (a[i] % 2);
    cout << ans;
    return 0;
}


Measured memory_bytes: 18560
from math import sqrt

def solve0(N, A):
    S = sorted(A)
    S0 = S[-1]
    S1 = S[-2]

    for a in A:
        if a == S0:
            print(S1)
        else:
            print(S0)

def solve(N, A):
    D = int(sqrt(N))
    M = []
    for i in range(0, N, D):
        M.append(max(A[i:i+D]))
    M.append(0)
    for i in range(0, N):
        d = i // D
        l = d*D
        m = 0
        for j in range(l, min(l+D, N)):
            if i != j and A[j] > m:
                m = A[j]
        m0 = m
        if d == 0:
            m = max(m, max(M[d+1:]))
        elif d >= len(M) - 1:
            m = max(m, max(M[:d]))
            pass
        else:
            #print(d, len(M))
            #print("M[:d]", M[:d])
            #print("M[d+1:]", M[d+1:])
            m = max(m, max(M[:d]), max(M[d+1:]))
        print(m)
        #print("d=%d,"%d, m, max(A[:i]+A[i+1:]))
        #assert m == max(A[:i]+A[i+1:])


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    solve0(N, A)

#l = list(range(1, 200))
#solve(len(l), l)
main()


Measured memory_bytes: 14132
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = a; i < b; i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

int main() {
    fast_io;
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    int pos = 0;
    vi l(k), r(k);
    int day = 0;
    while (pos < n && day < k) {
        if (s[pos] == 'o') {
            l[day++] = pos;
            pos += c;
        }
        pos++;
    }
    pos = n - 1;
    day = k - 1;
    while (pos >= 0 && day >= 0) {
        if (s[pos] == 'o') {
            r[day--] = pos;
            pos -= c;
        }
        pos--;
    }
    lp(i, 0, k) if (l[i] == r[i]) cout << l[i]+1 << "\n";
}

Measured memory_bytes: 3348
// eight possible abs handling patterns
let eightFn = 
    [| for i in [1L;-1L] do 
       for j in [1L;-1L] do 
       for k in [1L;-1L] do 
            yield (fun (ar: int64[]) -> i*ar.[0] + j*ar.[1] + k*ar.[2]) |]
// read N and M
let [|n;m|] = stdin.ReadLine().Split() |> Array.map int
// generate processed input, using int64.
let processedInput =
    [| for i in 1..n do
         let ar = stdin.ReadLine().Split() |> Array.map int64
         yield Array.map (fun fn -> fn ar) eightFn |]
// do the work
[ for i in 0..7 do
    let arr = Array.map (fun (ar: int64[]) -> ar.[i]) processedInput
    Array.sortInPlace arr // mutate!
    yield (Array.sum arr.[n-m..n-1]) ]
|> List.max
|> printfn "%d"

Measured memory_bytes: 15324
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W

int main() {
    int a;
    string s;

    cin >> a >> s;
    if(a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
}


Measured memory_bytes: 504
// 1203
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf INT_MAX
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int a[105];
 
int32_t main()
{
    fast;
    int n, ans = inf, val; cin >> n;
    For(i, 0, n) cin >> a[i];

    sort(a, a+n);
    int l = a[0], h = a[n-1];

    Rep(j, l, h) {
        val = 0;
        For(i, 0, n) {
            val += ((a[i] - j) * (a[i] - j));
        }
        //cout << val << " ";
        ans = min(val, ans);
    }

    cout << ans;

    
    return 0;
}

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

int main(){
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;

    vector <int> x,y;
    double con, conmax;
    int imax,jmax;

    int ii=F/(100*A);
    int jj=F/(100*B);

    for(int i=0; i<=ii; i++){
        for(int j=0; j<=jj; j++){
            if( 100*A*i+100*B*j <= F ){
                x.push_back( 100*A*i+100*B*j );
            }
        }
    }

    ii=F/C;
    jj=F/D;

    for(int i=0; i<=ii; i++){
        for(int j=0; j<=jj; j++){
            if( C*i+D*j <= F ){
                y.push_back( C*i+D*j );
            }
        }
    }

    conmax=0.0;
    imax=100*A;
    jmax=0;
    for(auto xx : x){
        for(auto yy : y){
            if( (double) xx/100*E >= yy && (xx+yy)<=F && (xx+yy)>0 ){
                con = (double) 100*yy/(xx+yy);
                if( conmax<con ){
                    conmax=con;
                    imax=xx+yy;
                    jmax=yy;
                }
            }
        }
    }

    cout << imax << " " << jmax << endl;

    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    uint32_t D, N;

    cin >> D >> N;
    if(N!=100)
        cout << (uint32_t)(pow(100, D) * N) << endl;
    else
        cout << (uint32_t)(pow(100, D) * 101) << endl;

    return 0;
}

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

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

    vector< vector<int> > stu(N, vector<int>(2));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 2; j++){
            cin >> stu.at(i).at(j);
        }
    }

    vector< vector<int> > che(M, vector<int>(2));
    for(int i = 0; i < M; i++){
        for(int j = 0; j < 2; j++){
            cin >> che.at(i).at(j);
        }
    }

    vector<int> ans(N, 0);
    //int mindis = abs(stu.at(0).at(0) - che.at(0).at(0)) + abs(stu.at(0).at(1) - che.at(0).at(1));

    for(int i = 0; i < N; i++){
        int mindis = abs(stu.at(i).at(0) - che.at(0).at(0)) + abs(stu.at(i).at(1) - che.at(0).at(1));
        for(int j = 0; j < M; j++){
            int nowdis = abs(stu.at(i).at(0) - che.at(j).at(0)) + abs(stu.at(i).at(1) - che.at(j).at(1));
            //if(i == 1 && j == 3) cout << "ここ" << nowdis << " " << mindis << endl;

            if(nowdis < mindis) {
                ans.at(i) = j;
                mindis = nowdis;
            }
        }
        cout << ans.at(i) + 1 << endl;
    }

    return 0;
}

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

using namespace std;

class UnionFind {
private:
  std::vector<int> data;
public:
  UnionFind(const int size):data(size,-1){}
  void union_set(int x, int y){
    x = this->get_root(x);
    y = this->get_root(y);
    
    if (x != y) {
      if (this->data[y] < data[x]) {
        swap(x, y);
      }
      this->data[x] += this->data[y];
      this->data[y] = x;
    }  
  }
  bool is_same(const int x, const int y){
    return this->get_root(x) == this->get_root(y);
  }
  int get_root(const int x){
    return this->data[x] < 0 ? x : this->data[x] = this->get_root(this->data[x]);
  }
  int get_size(int x){
    return -this->data[this->get_root(x)];
  }
};

using Edge = struct edge{
  int from, to, cost;
  edge(const int s, const int t, const int c):from(s),to(t),cost(c){}
  bool operator<(const edge& e) const {return cost < e.cost;}
};

struct Graph{
  int v_size;
  vector<Edge> edge_set;
  
  Graph(const int v_size):v_size(v_size){}
  
  void add_edge(const int s, const int t, const int w){
    this->edge_set.emplace_back(Edge{s, t, w});
  }
};

int mst(Graph& g){
  UnionFind uf(g.v_size);
  int ans {0};

  sort(begin(g.edge_set), end(g.edge_set));

  for(auto&& e : g.edge_set){
    if(!uf.is_same(e.from, e.to)){
      ans += e.cost;
      uf.union_set(e.from, e.to);
    }
  }
  
  return ans;
}

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

  int x;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      cin >> x;
      if(x != -1){
        g.add_edge(i, j, x);
      }
    }
  }

  cout << mst(g) << endl;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define maxn 1010
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize(2)
#define ll long long
#define makefa(n) for(int i=1;i<=(n);i++)f[i]=i;
#define hh puts("");
#define db long double
int main(){
    db a,b,c;
cin>>a>>b>>c;
if(a+b+2*sqrt(a*b)<c)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++){
        cin >> d[i];
    }

    vector<int> num(110);
    for(int i = 0; i < n; i++){
        num[d[i]]++;
    }

    int ans = 0;
    for(int i = 1; i <= 100; i++){
        if(num[i] > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, W; cin >> N >> W;
	vector<pair<int, ll>>vec(N);
	rep(i, 0, N) {
		int a;cin >> a;
		ll b; cin >> b;
		vec[i] = make_pair(a, b);
	}
	vector<vector<ll>>dp(N + 1, vector<ll>(W + 1, 0));
	rep(i, 0, N) {
		int weight = vec[i].first;
		ll value = vec[i].second;
		rep(j, 0, W + 1) {
			if (weight > j) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - weight] + value);
			}
		}
	}
	cout << dp[N][W] << "\n";

	return 0;
}

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

mod=10**9+7
N=input()
X=map(int, sys.stdin.readline().split())
L=map(lambda x: pow(x,mod-2,mod), range(1,N))

L_RUISEKI=[]

for i,x in enumerate(L):
    if i==0: L_RUISEKI.append(x)
    else: L_RUISEKI.append(L_RUISEKI[-1]+x)

ans=0
for i in range(N-1):
    value=X[i+1]-X[i]
    ans+=value*L_RUISEKI[i]


fact=[1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)

print ans*fact[N-1]%mod

Measured memory_bytes: 53212
# include <stdio.h>
int main (void)
{
	int ri,repeat;
	int a,b,c;
	scanf("%d",&repeat);
	for (ri=1;ri<=repeat;ri++){
		scanf("%d%d%d",&a,&b,&c);
		if (a>b&&a>c)
			if ((a*a)==(b*b+c*c))
				printf("YES\n");
			else printf("NO\n");
		else if (b>a&&b>c)
			if ((b*b)==(a*a+c*c))
				printf("YES\n");
			else printf("NO\n");
		else if (c>b&&c>a)
			if ((c*c)==(b*b+a*a))
				printf("YES\n");
			else printf("NO\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<int> X(N);
  vector<int> Y(N);
  vector<int> A(N);
  
  for (int i = 0; i < N; ++i) cin >> X.at(i) >> Y.at(i) >> A.at(i);
  
  int Xl = 0;
  int Xr = W;
  int Yu = H;
  int Yd = 0;
  
  for (int i = 0; i < N; ++i) {
    switch (A.at(i)) {
      case 1:
        if (Xl < X.at(i)) Xl = X.at(i);
        break;
      case 2:
        if (Xr > X.at(i)) Xr = X.at(i);
        break;
      case 3:
        if (Yd < Y.at(i)) Yd = Y.at(i);
        break;
      case 4:
        if (Yu > Y.at(i)) Yu = Y.at(i);
        break;
    }
  }
  if (Xl > Xr || Yd > Yu) {
    cout << 0 << endl;
  }
  else {
    cout << (Xr -Xl) * (Yu - Yd)  << endl;
  }
  
}

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

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

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  if(N<1200)
  {
    cout << "ABC" << endl;
  }
  else if(N>=1200&&N<2800)
  {
    cout << "ARC" << endl;
  }
  else
  {
    cout << "AGC" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 301;
const ll MOD = 1e9+7;
const double eps = 1e-9;

ll get(ll x) {
	ll y = 0;
	for(int i=0; i<=40; i+=2) {
		y |= (ll(x & 1))<<ll(i);
		x >>= 1;
	}
	return y;
}

int main() {
	ll n;
	scanf("%lld",&n);
	
	for(ll m=0; m<(1<<20); m++) {
		ll cur = get(m);
		ll neg = n - cur;
		if(neg>0) continue;
		neg *= -1;
		bool f = 1;
		for(ll i=0; i<=40; i++)
			if((neg & (1ll<<i)) && i%2==0) {
				f = 0;
				break;
			}
		if(f) {
			ll ans=0;
			int mx = 0;
			for(ll i=0; i<=40; i++)
				if((cur & (1ll<<i)) || (neg & (1ll<<i))) { 
					ans |= (1ll<<i);
					mx = i;
				}
			string res = "";
			for(int i=mx; i>=0; i--)
				res += (ans & (1ll<<i) ? "1" : "0");
			puts(res.c_str());
			return 0;
		}
	}
 	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;

vector<ll> d = vector<ll>(100010);
Graph g = Graph(100010);
void dfs(int n, ll dist, int p) {
  for(auto e : g.at(n)) {
    if(e.first == p) continue;
    d.at(e.first) = dist + e.second;
    dfs(e.first, d.at(e.first), n);
  }
}

int main() {
  int N, Q, K;
  cin >> N;

  int a, b, c;
  REP(i, N - 1) {
    cin >> a >> b >> c;
    a--;
    b--;
    g.at(a).push_back({b, c});
    g.at(b).push_back({a, c});
  }

  cin >> Q >> K;
  K--;
  dfs(K, 0, -1);

  int x, y;
  REP(i, Q) {
    cin >> x >> y;
    x--;
    y--;
    ll ans = d.at(x) + d.at(y);
    cout << ans << endl;
  }
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    ll N;
    cin >> N;

    string ans = "";
    while (N != 0) {
        int r = N % 2;
        if (r < 0) r += 2;

        N = (N - r) / (-2);
        ans += (r + '0');
    }

    reverse(ans.begin(), ans.end());
    if (ans == "") ans = "0";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible");
	}
}

Measured memory_bytes: 35716
#include <stdio.h>

int main(void){
	int s;
	
	scanf("%d",&s);
	
	int i=1;
	
	if(s==1||s==2){
		printf("4\n");
	}else{
		while(s!=4){
			if(s%2==0){
				s=s/2;
			}else{
				s=3*s+1;
		}
		
		i++;
		}
	
		printf("%d\n",i+3);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<deque>
#include<algorithm>
using namespace std;
int main (void)
{
 string S;
 int Q;
 cin >> S;
 cin >> Q;
 deque<char> Stmp (S.size ());
 for (int i = 0; i < S.size (); i++)
 	Stmp [i] = S.data () [i];
 int T, F;
 char C;
 int frontback = 0;
 for (int i = 0; i < Q; i++)
 {
	cin >> T;
	if (T == 1)
		frontback = 1 - frontback;
	else
	{
		cin >> F >> C;
		if (frontback == 0)
		{
			if (F == 1)
			  Stmp.emplace_front (C);
			else
		  	  Stmp.emplace_back (C);
		}
		else
		{
			if (F == 1)
			  Stmp.emplace_back (C);
			else
		  	  Stmp.emplace_front (C);
		}
	}
 }
 if (frontback == 1)
 	reverse(Stmp.begin(), Stmp.end ());
 for (auto &e: Stmp)
 	cout << e;
 return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

ll mp[5001][5001];
ll dp[5001][5001][4];

int main(){
    ll r,c, k;
    cin >> r >> c >> k;
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            mp[i][j] = 0;
        }
    }
    for(int i = 0; i < k; i++){
        ll x,y,v;
        cin >> x >> y >> v;
        mp[x-1][y-1] = v;
    }

    for(int j = 0; j <= r; j++){
        for(int i = 0; i <= c; i++){
            for(int l = 0; l < 4; l++){
                dp[j][i][l] = 0;
            }
        }
    }

    for(int j = 0; j < r; j++){
        for(int i = 0; i < c; i++){
            dp[j][i+1][0] = max(dp[j][i+1][0], dp[j][i][0]);
            dp[j][i+1][1] = max(dp[j][i+1][1], dp[j][i][1]);
            dp[j][i+1][1] = max(dp[j][i+1][1], dp[j][i][0]+mp[j][i]);
            dp[j][i+1][2] = max(dp[j][i+1][2], dp[j][i][2]);
            dp[j][i+1][2] = max(dp[j][i+1][2], dp[j][i][1]+mp[j][i]);
            dp[j][i+1][3] = max(dp[j][i+1][3], dp[j][i][3]);
            dp[j][i+1][3] = max(dp[j][i+1][3], dp[j][i][2]+mp[j][i]);

            dp[j+1][i][0] = max(dp[j][i][3], dp[j][i][2]+mp[j][i]);
            dp[j+1][i][1] = max(dp[j][i][3], dp[j][i][2]+mp[j][i]);
            dp[j+1][i][2] = max(dp[j][i][3], dp[j][i][2]+mp[j][i]);
            dp[j+1][i][3] = max(dp[j][i][3], dp[j][i][2]+mp[j][i]);
        }
    }

    ll ans = 0;
    ans = max(dp[r][c-1][3], dp[r-1][c][3]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 379164
from itertools import permutations
n, m = map(int, input().split())
edges = {tuple(map(int, input().split())) for _ in range(m)}

ans = 0
for i in permutations(range(2, n+1), n-1):
    load = [1]+list(i)
    ans += sum(1 for edge in zip(load, load[1:])
               if tuple(sorted(edge)) in edges) == n-1
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cstdio>
#include <bitset>
using namespace std;


int main() {

	int x, t;
	cin >> x >> t;
	if(x - t > 0) cout << x - t << endl;
	else cout << 0 << endl;

	return 0;
}

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

vector<pair<int,int>>pairs;
int main(){
  int N,M;cin>>N>>M;
  vector<int> Ken[120000];
  int P[120000],Y[120000];
  for(int i=0;i<M;i++){
    cin>>P[i]>>Y[i];
    Ken[P[i]].push_back(Y[i]);
  }
  for(int i=0;i<N;i++){
    sort(Ken[i+1].begin(),Ken[i+1].end());
  }
  for(int i=0;i<M;i++){
    printf("%06d",P[i]);
    printf("%06d\n",int(lower_bound(Ken[P[i]].begin(),Ken[P[i]].end(),Y[i])-Ken[P[i]].begin())+1);
  }


}

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

template<typename T> class Dijkstra {
public:
  struct edge {
    int to; T cost;
  };
  int V;
  vector<vector<edge>> G;
  vector<T> dist;
  using pti = pair<T,int>;
  Dijkstra(int n) : V(n), G(V), dist(V, numeric_limits<T>::max()) {}
  void add(int u, int v, T cost) {
    G.at(u).push_back((edge) {v, cost});
  }
  void solve(int s) {
    priority_queue<pti, vector<pti>, greater<pti>> Q;
    dist.at(s) = 0;
    Q.push(pti(0, s));
    while (!Q.empty()) {
      pti p = Q.top();
      Q.pop();
      int v = p.second;
      if (dist.at(v) < p.first) continue;
      for (auto &w : G.at(v)) {
        if (dist.at(w.to) > dist.at(v) + w.cost) {
          dist.at(w.to) = dist.at(v) + w.cost;
          Q.push(pti(dist.at(w.to), w.to));
        }
      }
    }
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  Dijkstra<long> D(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    D.add(--a, --b, c);
  }
  for (int i = 0; i + 1 < N; i++) {
    D.add(i + 1, i, 0);
  }
  D.solve(0);
  long ans = D.dist.at(N - 1);
  cout << ((ans == LONG_MAX) ? -1 : ans) << "\n";
}

Measured memory_bytes: 9340
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;

  int xmax = -100;
  int ymin = 100;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    xmax = max(xmax, x);
  }
  for (int i = 0; i < m; i++) {
    int y;
    cin >> y;
    ymin = min(ymin, y);
  }

  if (xmax < ymin && xmax < Y && X < ymin) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
  
  return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

ll N, X;
vector<ll> a, p;
ll calc(ll n, ll x) {
  if(n == 0) {
    if(x <= 0) return 0;
    else return 1;
  } else if(x <= 1 + a[n - 1]) {
    return calc(n - 1, x - 1);
  } else {
    return p[n - 1] + 1 + calc(n - 1, x - 2 - a[n - 1]);
  }
}

int main() {
  cin >> N >> X;
  a.push_back(1); p.push_back(1);
  REP(i, N) {
    a.push_back(a[i] * 2 + 3);
    p.push_back(p[i] * 2 + 1);
  }
  ll ans = calc(N, X);
  cout << ans << endl;
}

Measured memory_bytes: 3568
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int[] p = new int[3];
        p[0] = int.Parse(input[0]);
        p[1] = int.Parse(input[1]);
        p[2] = int.Parse(input[2]);
        Array.Sort(p);
        Console.WriteLine(p[0]+p[1]);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e3, maxH = 1e4 + 1, inf = 1e9; int h, n;
struct Magic
{
  int a, b;
  void read() { scanf("%d %d", &a, &b); }
};
Magic magics[maxN];

lli memo[maxH];

int main()
{
  while (scanf("%d %d", &h, &n) != EOF)
  {
    for (int i = 0; i < n; i ++)
      magics[i].read();

    for (int i = 0; i < h; i ++)
      memo[i] = inf;
    memo[h] = 0;
    for (int hh = h; hh >= 0; hh --)
      for (int i = 0; i < n; i ++)
      {
        int res = max(0, hh - magics[i].a);
        memo[res] = min(memo[res], memo[hh] + magics[i].b);
      }
    printf("%lld\n", memo[0]);
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    cout << n/3;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
use itertools::iproduct;
use proconio::{input, marker::Usize1};

fn main() {
    input!(r: usize, c: usize, goods: [(Usize1, Usize1, u64)]);

    let mut val = array![0; r, c];
    for &(r, c, v) in &goods {
        val[r][c] = v;
    }

    let mut dp = array![0; r + 1, c + 1, 4];
    for (i, j, k) in iproduct!(0..=r, 0..=c, (0..=3).rev()) {
        if i < r {
            max_assign!(dp[i + 1][j][0], dp[i][j][k]);
        }
        if j < c {
            max_assign!(dp[i][j + 1][k], dp[i][j][k]);
        }
        if i < r && j >= 1 && val[i][j - 1] > 0 {
            max_assign!(dp[i + 1][j][1], dp[i][j][k] + val[i][j - 1]);
        }
        if j < c && i >= 1 && k < 3 && val[i - 1][j] > 0 {
            max_assign!(dp[i][j + 1][k + 1], dp[i][j][k] + val[i - 1][j]);
        }
    }

    println!("{}", dp[r][c].iter().max().unwrap())
}

#[macro_export]
macro_rules! array {
    ($v:expr; $l:expr, $($r:expr),*) => { vec![array!($v; $($r),*); $l] };
    ($v:expr; $l:expr) => { vec![$v; $l] };
    () => { vec![] };
}

#[macro_export]
macro_rules! max_assign {
    ($x:expr, $y:expr) => {{
        let rhs = $y;
        if $x < rhs {
            $x = rhs;
            true
        } else {
            false
        }
    }};
}


Measured memory_bytes: 714060
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())
S = [list(map(int, list(input())[: -1])) for _ in range(N)]
e = [[0] * M for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M - 1): e[i][j + 1] = e[i][j] + ((S[i - 1][j] == 1) and (S[i - 1][j + 1] == 1))
for i in range(1, N):
  for j in range(M): e[i + 1][j] += e[i][j]

cs = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M): cs[i][j + 1] = cs[i][j] + (S[i - 1][j] == 1)
for i in range(1, N):
  for j in range(M + 1): cs[i + 1][j] += cs[i][j]

T = [[0] * N for _ in range(M)]
for i in range(N):
  for j in range(M): T[j][i] = S[i][j]

N, M = M, N
ee = [[0] * M for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M - 1): ee[i][j + 1] = ee[i][j] + ((T[i - 1][j] == 1) and (T[i - 1][j + 1] == 1))
for i in range(1, N):
  for j in range(M): ee[i + 1][j] += ee[i][j]


#print(cs)

for i in range(Q):
  u, l, d, r = map(lambda x: int(x) - 1, input().split())
  rese = e[d + 1][r] - e[d + 1][l] - e[u][r] + e[u][l]
  resee = ee[r + 1][d] - ee[r + 1][u] - ee[l][d] + ee[l][u]
  res = cs[d + 1][r + 1] - cs[d + 1][l] - cs[u][r + 1] + cs[u][l]
  print(res - rese - resee)


Measured memory_bytes: 241100
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    int count = 0;
    for (int i=1; i <= N; i++) {
        if (to_string(i).size() % 2 != 0) {
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = [int(x) for x in input().split()]

dp = [0]*n

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])

print(dp[-1])


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 1e+5;
const int Q = 50000;
int n, q;
int s[N], t[Q];

int binary_search(int x) {
  int l = -1;
  int r = n-1;
  int m;
  while (r-l > 1) {
    m = (l+r)/2;
    if (x <= s[m])
      r = m;
    else
      l = m;
  }

  if (s[r]==x)
    return r;
  else
    return -1;
}

int main() {
  int i;
  scanf("%d ", &n);
  for (i=0; i<n; i++)
    scanf("%d ", s+i);
  scanf("%d ", &q);
  for (i=0; i<q; i++)
    scanf("%d ", t+i);

  int res = 0;
  for (i=0; i<q; i++)
    if (binary_search(t[i]) != -1)
      res++;

  printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 1776
// F - Enclose All
#include <bits/stdc++.h>

using namespace std;

#define	EPS	1e-6

const double PI = 2.0 * acos(0.0);

struct point {
	double x, y;
	point(double x = 0, double y = 0) : x(x), y(y) {}
	point operator+(const point &p) const { return point(x + p.x, y + p.y); }
	point operator-(const point &p) const { return point(x - p.x, y - p.y); }
	double len() { return sqrt(x * x + y * y); }
	double cross(const point &p) const { return x * p.y - y * p.x; }
	double dist() const { return sqrt(x * x + y * y); }
};

double angle(const point &p1, const point &p2, const point &p3)
{
	point va = p2 - p1;
	double l = sqrt(va.x * va.x + va.y * va.y);
	if (l > EPS) va.x /= l, va.y /= l;
	point vb(-va.y, va.x);
	point v = p3 - p1;
	double x = v.x * va.x + v.y * va.y;
	double y = v.x * vb.x + v.y * vb.y;
	return atan2(y, x);
}

double cc_radius(const point &a, const point &b, const point &c)
{
	return (b - a).dist() * (c - b).dist() * (a - c).dist() / abs((b - a).cross(c - a)) / 2;
}

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<point> p(n);
	for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
	double ans = 0;
	if (n < 3) {
		ans = (p[0] - p[1]).dist() / 2;
	} else {
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++)
				for (int k = j + 1; k < n; k++) {
					double a1 = abs(angle(p[i], p[j], p[k]));
					double a2 = abs(angle(p[j], p[i], p[k]));
					double a3 = abs(angle(p[k], p[j], p[i]));
					double r = 0;
					if (a1 > PI / 2) {
						r = (p[j] - p[k]).dist() / 2;
					} else if (a2 > PI / 2) {
						r = (p[i] - p[k]).dist() / 2;
					} else if (a3 > PI / 2) {
						r = (p[i] - p[j]).dist() / 2;
					} else {
						r = cc_radius(p[i], p[j], p[k]);
					}
					ans = max(ans, r);
				}
	}

	cout << fixed << setprecision(16) << ans << endl;

	return 0;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

int n;
ll ans;

int main(){
	scanf("%d", &n);
	REP(i, 1, n - 1)
		ans += (n - 1) / i;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3780
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    H,W=map(int,input().split())
    A=[str(input()) for i in range(H)]

    for i in range(H+2):
        if i ==0 or i==H+1:
            print(''.join(['#']*(W+2)))
        else:
            print('#'+A[i-1]+'#')

resolve()

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s;
  cin >> s;
  ll n = SZ(s);
  map<char, ll> mp;
  rep(i, n) {
    if(mp.find(s[i]) == mp.end()) mp[s[i]]=0;
    ++mp[s[i]];
  }
  ll ans = n*(n-1)/2+1;
  for(auto x : mp) ans -= x.second*(x.second-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 640
# 文字列を取得
C1 = str(input())
C2 = str(input())

# 文字列の結合
ori_str = C1 + C2

# 末尾から１文字ずつ取得して逆さま文字を生成
rev_str = ori_str[-1::-1]

# 比較結果を出力
if ori_str == rev_str:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9000
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
dict_A = Counter(A)
sum_comb = 0
for v in dict_A.values():
    sum_comb += int((v * (v - 1)) / 2)

for a in A:
    print(sum_comb - dict_A[a] + 1)

Measured memory_bytes: 34112
package main

import "fmt"

func main(){
	var N, T int
	c := 0x7fffffff
	t := 0x7fffffff

	fmt.Scan(&N, &T)
	for N > 0 {
		var temp1 int
		fmt.Scan(&temp1, &t)
		if temp1 < c && t <= T {
			c = temp1
		}
		N--
	}
	if c == 0x7fffffff {
		fmt.Println("TLE")
	} else {
		fmt.Println(c)
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inp_vecN for(int i=0;i<n;i++)cin>>v[i]; 
vector<int> get_Factors(ll n)
{
      vector <int> v;
      for(ll i=1; i<=sqrt(n)+1; i++)
      {
            if(n%i==0)
            {
                  v.push_back(i);
                  v.push_back(n/i);
            }
      }

      return v;
}
string get_bin(ll n)
{
    string s = "";
    while(n > 0)
    {
        s += ('0' + n%2);
        n /= 2;
    }
    reverse(s.begin(), s.end());
    return s;
}

ll bin_to_dec(string s)
{
    ll ans = 0;
    for(auto ch: s)
    {
        ans *= 2;
        ans += (ch - '0');
    }
    return ans;
}
void PrintVector(vector<int> v,int n)
{

    for(int i=0;i<n;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
int no_of_primeFactors(int n)  
{ 
    int count=0;
    while (n % 2 == 0)  
    {  
        count++;
        n = n/2;  
    }  
   
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    { 
        while (n % i == 0)  
        {  
           count++;
            n = n/i;  
        }  
        
    }  
    if (n > 2)  
        count++;
    return count;
} 
 ll gcd(int a, int b)
{ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
} 
   
  ll lcm(int a, int b)  
{  
    return (a/gcd(a, b)*b);  
}  



ll pwr(ll base,ll expo,ll m)
{
    if(base==0) return 0LL;
    if(expo==0) return (1LL%m);
    if((expo&1)==0) {ll temp=pwr(base,expo>>1,m); return (temp*temp)%m;}
    return ((base%m)*pwr(base,expo-1,m))%m;
}

int main(int argc, char const *argv[])
{
    ios;
    ll k,a,b,c;
    cin>>k;
    ll age=0,bal=100;
    while(bal<k)
    {
      bal=floor(1.01 * bal);
      age++;
    }
   
      cout<<age;
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string number;
    cin>>number;
    int i;
    int sum=0;
    for(i=0;i<number.size();i++)
    {
        sum+=(number[i]-'0');
    }
    //cout<<"Sum = "<<sum<<endl;
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define int long long
typedef vector<int> vi;
typedef pair<int, int> pii;
const double PI = acos(-1.0);
const int mod = 1e9 + 7;
int pows(int a , int b){int res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
const int N = 1e5+5;
int dp[N] ;
vector<int> v[N] ;
void init() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
}
int dfs(int n) {
    if(dp[n]!=-1)
        return dp[n] ;
        int res = 0 ;
    for(auto it : v[n]) res = max(res , 1 + dfs(it)) ;
    return dp[n] = res ;
}
void solve(){
    memset(dp,-1,sizeof dp) ;
    int  n , m ;
    cin >> n >> m ;
    for(int i = 0 ; i < m ; i++){
        int a , b ;
        cin >> a >> b ;
        a-- ; b-- ;
        v[a].pb(b) ;
    }
    int res = 0 ;
    rep(i,0,n)  res = max(res , dfs(i)) ;
    cout << res << endl ;
}
int32_t main()
{
    init();
    int t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


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

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

    vector<long long>h(n);
    rep(i,0,n){
        cin>>h[i];
    }

    bool jdg=true;

    for (long long i=n-1;i>0;i--){
        if(h[i-1]-h[i]>1){
            jdg=false;
            break;
        }
        else if (h[i-1]-h[i]==1){
            h[i-1]--;
        }
    }

    if(jdg){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int INF = 5*1e8;

class UnionFind{
  vi p,r;
public:
  UnionFind(int n):p(n,-1),r(n,0){ }
  int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }
  bool same(int x,int y){return find(x)==find(y);}
  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }
};

inline int MSB(int x){ return x>0?31-__builtin_clz(x):-1; }

struct LCA{
  vector<vi> par,w;
  vi depth;
  int ln;
  
  LCA(void){}
  LCA(const vector<vi> &t, const vi weight, int root){
    int n = t.size(); ln = MSB(n)+1;
    depth.resize(n); par.resize(ln,vi(n));
    w.resize(ln,vi(n)); w[0] = weight;

    stack< pair<int,int> > s;
    s.push(make_pair(root,-1));
    while(s.size()){
      int v = s.top().first, p = s.top().second; s.pop();
      par[0][v] = p;
      depth[v] = ((p<0)?0:(depth[p]+1));

      for(int u : t[v]){
	if(u != p)s.push(make_pair(u,v));
      }
    }

    rep(k,ln-1)rep(v,n){
      if(par[k][v]<0){
	par[k+1][v] = -1;
	w[k+1][v] = INF;
      }else{
	par[k+1][v] = par[k][par[k][v]];
	w[k+1][v] = min(w[k][v], w[k][par[k][v]]);
      }
    }
  }

  inline int min_lca(int u, int v){
    int res = INF;
    if(depth[u] > depth[v])swap(u,v);
    rep(k,ln){
      if((depth[v]-depth[u])>>k & 1){
	res = min(res, w[k][v]);
	v = par[k][v];
      }
    }

    if(u==v)return min(res, w[0][u]);
    for(int k = ln-1;k>=0;k--){
      if(par[k][u] != par[k][v]){
	res = min(res, min(w[k][u], w[k][v]));
	u = par[k][u];
	v = par[k][v];
      }
    }
    return min(res, min(w[1][u], w[1][v]));
  }
  inline int dep(int v){ return depth[v]; }
};

int main(){
  int n,m,k,Q;
  cin >> n >> m >> k >> Q;
  vector< vector<pii> > g(n);
  rep(i,m){
    int a,b,l;
    cin >> a >> b >> l; a--; b--;
    g[a].push_back(pii(b,l));
    g[b].push_back(pii(a,l));
  }

  vi dis(n,INF);
  priority_queue<pii> q;
  rep(i,k){
    int f;
    cin >> f; f--;
    dis[f] = 0;
    q.push(pii(0,f));
  }

  while(q.size()){
    pii p = q.top(); q.pop();
    int d = -p.first, v = p.second;
    if(dis[v] < d)continue;
   
    for(pii nxt : g[v]){
      int u = nxt.first, cost = d+nxt.second;
      if(dis[u] > cost){
	dis[u] = cost;
	q.push(pii(-cost,u));
      }
    }
  }

  vector<pii> order(n);
  rep(i,n)order[i] = pii(dis[i],i);

  sort(all(order)); reverse(all(order));
  UnionFind uf(n);

  vector<vi> tree(n);
  rep(i,n){
    int v = order[i].second;
    vector<pii> nxt;
    for(pii p : g[v]){
      int u = p.first;
      nxt.push_back(pii(dis[u],u));
    }
    sort(all(nxt)); reverse(all(nxt));
    for(pii p : nxt){
      int u = p.second;
      if(dis[u] < dis[v])break;
      if(!uf.same(v,u)){
	tree[u].push_back(v);
	tree[v].push_back(u);
	uf.unite(v,u);
      }
    }
  }
 
  LCA query(tree, dis, 0);
  rep(i,Q){
    int u,v;
    cin >> u >> v; u--; v--;
    cout << query.min_lca(u,v) << endl;
  }
}

Measured memory_bytes: 31444
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int a, b; cin >> a >> b;
  if(a <= 5) cout << "0\n";
  else if(a <= 12) cout << b / 2 << "\n";
  else cout << b << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

//143 E
int main(void) {
	ll n, m, l;
	cin >> n >> m >> l;
	vector <vector<ll>>wf = vector<vector<ll>>(n,vector<ll>(n,1e10));
	rep(i, 0, n)wf[i][i] = 0;
	rep(i, 0, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		wf[a][b] = c;
		wf[b][a] = c;
	}
	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				wf[i][j] = min(wf[i][j],wf[i][k] + wf[k][j]);
			}
		}
	}

	ll INF = 1e10;
	vector<vector<ll>>wf2 = vector<vector<ll>>(n, vector<ll>(n, 1e10));
	
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (wf[i][j] <= l) wf2[i][j] = 1;
		}
	}

	rep(i, 0, n)wf2[i][i] = 0;

	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				wf2[i][j] = min(wf2[i][j],wf2[i][k] + wf2[k][j]);
			}
		}
	}

	ll q;
	cin >> q;

	rep(i, 0, q) {
		ll s, t;
		cin >> s >> t;
		s--;
		t--;
		cout << (wf2[s][t] == INF ? -1 : wf2[s][t] - 1) << endl;
	}
}

Measured memory_bytes: 1920