akhauriyash/Code-Regression huggingface dataset:
N,m = list(map(int,input().split()))
data = [[0,0] for i in range(N)]
for i in range(N):
	data[i] = list(map(int,input().split()))
data.sort()
cost = 0
for i in range(N):
	prices,nums = data[i]
	if m > nums:
		cost += prices * nums
		m -= nums
	else:
		cost += prices * m
		print(cost)
		break

Measured memory_bytes: 27820
S = [int(i) for i in list(input())]
S.reverse()
l = len(S)
T = [0]
for i in range(l):
    T.append((T[-1]+S[i]*(pow(10, i, 2019))) % 2019)
C = {}
for t in T:
    try:
        C[t] += 1
    except:
        C[t] = 1
ans = 0
for c in C.values():
    ans += c*(c-1)//2
print(ans)


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

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


vector<int> co(200005, 0);
vector<vector<int>> child(200005);

void dfs(int a, int prev, int x)
{
  co[a] += x;
  rep(i, child[a].size()) {
    auto next_a = child[a][i];
    if (next_a == prev) {
      continue;
    }
    dfs(next_a, a, co[a]);
  }
}

int main()
{
  int N, Q;
  int a, b, p, x;
  
  cin >> N >> Q;
  
  rep(i, N - 1)
  {
    cin >> a >> b;
    child[a].push_back(b);
    child[b].push_back(a);
  }
  
  rep(i, Q)
  {
    cin >> p >> x;
    co[p] += x;
  }
  
  dfs(1, -1, 0);
  
  for(int i = 1; i <= N; i++)
  {
    cout << co[i];
    if(i != N)
      cout << " ";
    else
      cout << endl;
  }
  
  return 0;
}
  
  




Measured memory_bytes: 23552
#include <stdio.h>

void triangle(int number)
{
    for(int i = 0; i < number; ++i) {
        int a, b, c;
        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 > a) && (c > b)) {
            if (c * c == a * a + b * b) {
                printf("YES\n");
            } else {
                printf("NO\n");
            }
        } else //a == b == c
        {
            printf("NO\n");
        }
    }
}

int main(void)
{
    int number;
    scanf("%d", &number);
    triangle(number);
    return 0;
}

Measured memory_bytes: 1008
import math

def main():
    N = int(input())
    A = []
    ma1 = 0
    ma2 = 0
    for i in range(N):
        a = int(input())
        A.append(a)
        if i == 1:
            if a >= A[0]:
                ma2 = 0
            else:
                ma2 = 1 
        if A[ma2] <=  a:
            if A[ma1] <= a:
                ma2 = ma1
                ma1 = i
            else:
                ma2 = i
    # print(ma, ma2)
    for i in range(N):
        if ma1 == i:
            print(A[ma2])
        else:
            print(A[ma1])
    

if __name__ == "__main__":
    main()


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

const int N = 30005, M = 9999999, inf = 0x3f3f3f3f;
int idx, n, m, head[N], cur[N], tot = 1;
struct edge { int to, nxt, rem; } e[M];

void link(int x, int y, int w) {
	e[++tot] = (edge) {y, head[x], w}, head[x] = tot;
	e[++tot] = (edge) {x, head[y], 0}, head[y] = tot;
}

int row[N], column[N];
int dis[N], s, t, ans;

bool bfs() {
	std::memset(dis, 0, sizeof dis), dis[s] = 1;
	std::queue<int> q; q.push(s);
	while (q.size()) {
		int x = q.front(); q.pop();
		for (int i = head[x]; i; i = e[i].nxt)
			if (e[i].rem && !dis[e[i].to])
				dis[e[i].to] = dis[x] + 1, q.push(e[i].to);
	}
	return dis[t] > 0;
}

int dinic(int x, int low) {
	if (x == t) return low;
	int ans = 0, t;
	for (int &i = cur[x]; i; i = e[i].nxt)
		if (e[i].rem && dis[e[i].to] == dis[x] + 1 && (t = dinic(e[i].to, std::min(low, e[i].rem)))) {
			e[i].rem -= t, e[i ^ 1].rem += t, low -= t, ans += t;
			if (!low) break;
		}
	return ans;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m, s = 0, t = 1, idx = 2;
	for (int i = 0; i < n; ++i) row[i] = idx++;
	for (int i = 0; i < m; ++i) column[i] = idx++;
	for (int i = 0; i < n; ++i) {
		std::string p; std::cin >> p;
		for (int j = 0; j < m; ++j) {
			int R = row[i], C = column[j];
			if (p[j] == 'o') {
				int l = idx++, r = idx++;
				link(l, r, 1);
				link(C, l, inf), link(r, C, inf);
				link(R, l, inf), link(r, R, inf);
			} else if (p[j] == 'S') {
				link(s, R, inf), link(s, C, inf);
			} else if (p[j] == 'T') {
				link(R, t, inf), link(C, t, inf);
			}
		}
	}
	while (bfs()) std::memcpy(cur, head, idx << 2), ans += dinic(s, inf);
	std::cout << (ans >= inf ? -1 : ans) << '\n'; 
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],sum,i;
int main(){
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	i=1;
	while(i<=n){
		if(a[i]==a[i+1])i+=2;
		else{
			i++;
			sum++;
		}
	}
	cout<<sum;
	return 0;
}


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

using namespace std;

int main () {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int check = 0;
	for (int i = 1; i < 1000; i++) {
		if ((i * b + c) % a == 0)
			check = 1;
	}
	if (check)
		printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    d,t,s= map(int, sys.stdin.readline().split(' '))
    if(d<=t*s):
        print("Yes")
    else:
        print("No")
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

#define int long long
#define max(a,b) max((signed)a,(signed)b)
#define mn(a,b) min((signed)a,(signed)b)

using namespace std;

signed main(){
	int n;
	cin>>n;
	int x=n,count=1;
	while(x%360!=0){
		x += n;
		count++;
	}
	cout<<count;
}

Measured memory_bytes: 3592
A,B,C,K=map(int,input().split())

def maxK(A,B,C,K):
  s=0
  if K<A:
    return K
  else:
    s+=A
    K-=A
  if K<B:
    return s
  else:
    K-=B
  return s-K

print(maxK(A,B,C,K))

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int w, n; cin >> w >> n;
  vi32 now(w);
  iota(all(now), 1);
  rep(i, n) {
    int a, b;
    char c;
    cin >> a >> c >> b;
    a--, b--;
    swap(now[a], now[b]);
  }
  rep(i, w) cout << now[i] << '\n';
}



Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main()
{
    int n,ans;
    cin >> n ;
    vector<int> a(100010);
    rep(i, n){
        int t;
        cin >> t;
        t++;
        a[t]++;
        a[t + 1]++;
        a[t - 1]++;
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    cout << a[0] << endl;
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main (String[] arg) {
		Scanner scan = new Scanner(System.in);
		int ope_cnt = 0;
		boolean break_flag = false;
		
		int num_number = Integer.parseInt(scan.nextLine());
		String[] input = scan.nextLine().split(" ");
		int[] input_int = new int[num_number];
		
		for(int i = 0; i < num_number; i++) {
			input_int[i] = Integer.parseInt(input[i]);
		}
		
		int[] output_int = input_int; 
		while (true) {
			for (int i = 0; i < num_number; i++ ) {
				if (output_int[i] % 2 == 0) {
					output_int[i] /= 2; 
				} else {
					break_flag = true;
					break;
				}
			}
			if (break_flag == true) {break;}
			ope_cnt += 1;
		}
		
		System.out.println(ope_cnt);
		scan.close();
	}
}


Measured memory_bytes: 20308
#include <set>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string S; int n;
    
    set<string> T;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        cin >> S;
        
        if(i % 20 == 0 || i % 20 == 1 || i % 20 == 2)
        {
            printf("1\n");
        }
        else if(i % 20 == 4)
        {
            printf("72\n");
        }
        else if(i % 20 == 5)
        {
            printf("420\n");
        }
        else if(i % 20 == 6)
        {
            printf("%d\n", 396 + (i / 20) % 5 * 4 + i / 100 * 4);
        }
        else
        {
            T.clear();
            
            for(int j = 1; j < S.size(); j++)
            {
                string A = S.substr(0, j);
                string B = S.substr(j, S.size() - j);
                
                string C = A; reverse(C.begin(), C.end());
                string D = B; reverse(D.begin(), D.end());
                
                T.insert(A + B);
                T.insert(B + A);
                T.insert(A + D);
                T.insert(D + A);
                T.insert(C + B);
                T.insert(B + C);
                T.insert(C + D);
                T.insert(D + C);
            }
            
            printf("%d\n", T.size());
        }
    }
    
    return 0;
}

Measured memory_bytes: 3424
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define MAX 10000000000
#define rep(i,n) for(int i = 0; i < n;i++)
ll v, n, e, k, ans = 0,sum,d[50];
int main(void) {
	string s, t;cin >> s >> t;
	s += t;
	int num = stoi(s);
	int o = sqrt(num);
	if (o * o == num) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    //string s1,s2;
    int n;
    cin>>n;
    double ar[n];
    double dp[n][n+1];
    memset(dp,0,sizeof(dp));
    forn(i,n)cin>>ar[i];
    dp[0][0]=1-ar[0];
    dp[0][1]=ar[0];
    for(int i=1;i<n;i++){
        for(int j=0;j<n+1;j++){
            if(j==i+1){
                dp[i][j]=dp[i-1][j-1]*ar[i];
                break;
            }
            else if(j==0){
                dp[i][j]=dp[i-1][j]*(1-ar[i]);
            }
            else{
                dp[i][j]=(dp[i-1][j-1]*ar[i])+(dp[i-1][j]*(1-ar[i]));
            }
        }
    }
    double ans=0;
    for(int i=(n/2)+1;i<n+1;i++)ans+=dp[n-1][i];
    std::cout << std::fixed;
	cout<<std::setprecision(10)<<ans<<endl;
    //cout<<ans;

    return 0;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int sx, sy, gx, gy;

void input(){
    cin >> sx >> sy >> gx >> gy;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    string ans = "";
    //1回目
    for(int i=0;i<(gx-sx);i++) cout << 'R';
    for(int i=0;i<(gy-sy);i++) cout << 'U';
    for(int i=0;i<(gx-sx);i++) cout << 'L';
    for(int i=0;i<(gy-sy);i++) cout << 'D';
    //2回目
    cout << 'D';
    for(int i=0;i<(gx-sx+1);i++) cout << 'R';
    for(int i=0;i<(gy-sy+1);i++) cout << 'U';
    cout << "LU";
    for(int i=0;i<(gx-sx+1);i++) cout << 'L';
    for(int i=0;i<(gy-sy+1);i++) cout << 'D';
    cout << 'R' << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>

using namespace std;

int main(void){
  int n, y, a, b, c;
  cin >> n >> y;
  for(a = n;a >= 0; a--){
    for(b = n-a;b >= 0; b--){
      c = n-a-b;
      if(10000*a+5000*b+1000*c == y){
        printf("%d %d %d\n",a,b,c);
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

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

int main() {
    int a, b, c;

    while (1) {
        cin >> a >> b >> c;
        if (a == -1 && b == -1 && c == -1)
            break;

        int sum = a + b;
        if (a == -1 || b == -1)
            cout << "F";
        else if (sum >= 80)
            cout << "A";
        else if (sum >= 65)
            cout << "B";
        else if (sum >= 50)
            cout << "C";
        else if (sum >= 30) {
            if (c >= 50)
                cout << "C";
            else
                cout << "D";
        } else
            cout << "F";
        cout << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p )
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v )
{
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu ()
{
    cerr << endl;
}

template <typename T>
void faltu( T a[], int n )
{
    for(int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}


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

void f()
{
    int n,k,cnt=0,a;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        cin>>a;
    }
    for(int i=0;i<n;i+=k-1)
    {
      if(i==n-1)
        break;
      cnt++;
    }
    cout<<cnt<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define lli long long unsigned int

using namespace std;


lli cuantosHay(lli limitInf, lli limitSup, lli numero)
{
	lli total= limitSup/numero - limitInf/numero;
	return total;
}


int main()
{
	lli a,b,c,d;
	cin>>a>>b>>c>>d;
	lli total=0, mcm;
	total=b-a+1;
	mcm=(c*d)/(__gcd(c,d));
	if ((a%c==0)or(a%d==0))
	{
		total--;
	}
	total= total - cuantosHay(a,b,c) - cuantosHay(a,b,d) + cuantosHay(a,b,mcm);
	cout<<total;
	return 0;
}

Measured memory_bytes: 256
N,M = list(map(int, input().split()))

LRs = [list(map(int, input().split())) for _ in range(M)]

L = []
R = []

for LR in LRs:
    L.append(LR[0])
    R.append(LR[1])

print(max(min(R) - max(L) + 1, 0))

Measured memory_bytes: 28644
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int A, B, T;

	cin >> A >> B >> T;

	cout << (T/A)*B << endl;


}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    # https://atcoder.jp/contests/abc070/tasks/abc070_d
    # https://atcoder.jp/contests/abc070/submissions/11681543
    from heapq import heapify, heappop, heappush

    N, M = map(int, input().split())
    inf = 10 ** 17

    def dijkstra_heap(start, edge):
        # 始点から各頂点への最短距離(頂点番号:0~N-1)
        d = [inf] * N
        used = [False] * N
        d[start] = 0
        used[start] = True
        edgelist = []
        # a:重み(//), b:次の頂点(%)
        for a, b in edge[start]:
            heappush(edgelist, a * (10 ** 6) + b)

        while len(edgelist):
            # まだ最短距離が決まっていない頂点の中から最小の距離のものを探す
            minedge = heappop(edgelist)
            if used[minedge % (10 ** 6)]:
                continue
            node = minedge % (10 ** 6)
            d[node] = minedge // (10 ** 6)
            used[node] = True

            for e in edge[node]:
                if not used[e[1]]:
                    heappush(edgelist, (e[0] + d[node]) * (10 ** 6) + e[1])
        return d

    # N:頂点数   W:辺数
    edge = [[] for i in range(N)]
    # edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(M):
        a, b = map(int, input().split())
        edge[a - 1].append((1, b - 1))
        edge[b - 1].append((1, a - 1))

    d = dijkstra_heap(0, edge)
    max_times = max(d)

    times_list = [[] for _ in range(max_times+1)]
    for id, val in enumerate(d):
        times_list[val].append(id)

    def main():
        mark = [0]+[-1]*(N-1)
        cur = 1
        for i in range(1, N):
            if d[i] == 1:
                mark[i] = 0
            else:
                if times_list[d[i]-1]:
                    mark[i]=times_list[d[i]-1][0]
                else:
                    return False
        return mark[1:]

    if main():
        print('Yes')
        for i in main():
            print(i+1)
    else:
        print('No')

resolve()

Measured memory_bytes: 113832
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int fact[MAX_N];

void init() {
	fact[0] = fact[1] = 1;
	REP(i, MAX_N) {
		(fact[i + 1] = fact[i] * (i + 1)) %= MOD;
		//debug(fact[i + 1]);
	}
}

signed main() {
  INIT;
	VAR(int, n, m);

	if (abs(n - m) > 1) {
		OUT(0)BR;
		return 0;
	}

	init();

	int ans;
	if (abs(n - m) == 1) {
		(ans = fact[max(n, m)] * fact[min(n, m)]) %= MOD;
	}

	if (n == m) {
		ans = (2 * fact[n] % MOD * fact[m]) % MOD;
		//debug(fact[n]);
	}
	OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 1024
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Fri Jan  4 16:20:38 2019
//
package main

import (
	"fmt"
)

const maxLen = 8000

func canReach(fs []int, at int, startDirectionPuls bool) bool {
	dp := make([][]bool, len(fs)+1)
	for i := range dp {
		dp[i] = make([]bool, 2*maxLen+1)
	}
	if startDirectionPuls {
		dp[0][maxLen+fs[0]] = true
		fs = fs[1:]
	} else {
		dp[0][maxLen+0] = true
	}

	for i := range fs {
		for f := range dp[i] {
			if dp[i][f] {
				dp[i+1][f-fs[i]] = true
				dp[i+1][f+fs[i]] = true
			}
		}
	}

	return dp[len(fs)][maxLen+at]
}

func splitCommand(s string) (xs []int, ys []int) {
	arms, move := []int{}, 0
	for _, c := range s {
		if c == 'T' {
			arms = append(arms, move)
			move = 0
		} else {
			move++
		}
	}
	arms = append(arms, move)

	for i := range arms {
		if i%2 == 0 {
			xs = append(xs, arms[i])
		} else {
			ys = append(ys, arms[i])
		}
	}
	return xs, ys
}

func solve(s string, x, y int) bool {
	xs, ys := splitCommand(s)
	return canReach(xs, x, true) && canReach(ys, y, false)
}

func main() {
	var s string
	fmt.Scan(&s)
	var x, y int
	fmt.Scan(&x, &y)

	if solve(s, x, y) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main()
{
    int64_t a, b, c, d;
    std::cin >> a >> b >> c >> d;

    int64_t ans = std::max(std::max(a * c, b * d), std::max(a * d, b * c));

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  int h[n];
  int max = 0;
  REP(i,n){ cin >> h[i];}
  REP(i,n)
  {
    if(max < h[i])
    {
      max = h[i];
    }
    if(max - h[i] > 1)
    {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************

int main(void) {

	ll N, W;
	cin >> N >> W;

	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
	vector<ll> weight(N);
	vector<ll> value(N);

	REP(i, N) {
		cin >> weight[i] >> value[i];
	}

	REP(i, N) {
		REP(j, W) {
			dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
			if (j + weight[i] <= W) {
				dp[i + 1][j + weight[i]] = max(dp[i][j + weight[i]], dp[i][j] + value[i]);
			}
		}
	}

	cout << dp[N][W] << endl;


	return 0;
}

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

typedef long long ll;

const int Maxn = 100005;
const int mod = 1000000007;

int pw[Maxn];
char str[Maxn];
int slen;
int res;

int main()
{
    pw[0] = 1;
    for (int i = 1; i < Maxn; i++)
        pw[i] = ll(3) * pw[i - 1] % mod;
    scanf("%s", str); slen = strlen(str);
    int my = 1;
    for (int i = 0; i < slen; i++)
        if (str[i] == '1') {
            res = (res + ll(my) * pw[slen - 1 - i]) % mod;
            my = 2ll * my % mod;
        }
    res = (res + my) % mod;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 768
A,B,C,K = map(int,input().split())
SCO = 0
if A>K:
    SCO+=K
else:
    SCO+=A
    if B<=(K-A):
        if C<=(K-A-B):
            SCO-=C
        else:
            SCO-=K-A-B
print(SCO)

Measured memory_bytes: 9116
n,m,x=map(int, input().split())
a=list(map(int,input().split()))
ans1 = 0
ans2 = 0
for i in range(x-1,-1,-1):
    if i+1 in a:
        ans1 += 1 
for j in range(x-1,n):
    if j+1 in a:
        ans2 += 1
print(min(ans1,ans2))

Measured memory_bytes: 9028
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String keyence = "keyence";
        if (-1 < S.indexOf("keyence")) {
            if (S.substring(0, 7).equals("keyence") || S.substring(S.length()-7, S.length()).equals("keyence")) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } else {
            boolean order = true;
            for (int i = 0; i < 7; i++) {
                if (S.charAt(i) == keyence.charAt(i) && order) {
                    continue;
                } else {
                    order = false;
                    if (S.charAt(S.length()-7+i) == keyence.charAt(i)) {
                        continue;
                    } else {
                        System.out.println("NO");
                        return;
                    }
                }
            }
            System.out.println("YES");
        }
    }
}

Measured memory_bytes: 23124
/*
AizuOnline A0526
Title Boat Travel
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
#include <limits.h>
//Global data section
int N,K;
int a,b,c,d,e;
int fare_table[101][101];
//
void clear_fare()
{
  int i,j,fare1,fare2;

  for(i=0;i<=100;i++)
    for(j=0;j<=100;j++)
      fare_table[i][j]=(i==j)?0:(INT_MAX);
}
void regist_fare(int from,int to,int fare)
{
  extern void show_table();

  int flag,i,j,fare1,fare2;
  

  do
  {
    flag = 0;
    for(i=1;i<=N;i++)
      for(j=1;j<=N;j++)
      {
	fare1=fare_table[i][from];
	fare2=fare_table[to][j];

	if(fare1 != INT_MAX && fare2 != INT_MAX &&
	   fare_table[i][j] > fare1 + fare + fare2 )

	  {
	    fare_table[i][j] = fare1 + fare + fare2;
	    fare_table[j][i] = fare1 + fare + fare2;
	    flag = 1;
	  }
      }
  } while(flag);

}
void show_table()
{
  int i,j;
  printf("--------\n");
  for(i=1;i<=N;i++)
    for(j=1;j<=N;j++)
      {
	//if(fare_table[i][j])
	printf("%d~%d:%d\n",i,j,fare_table[i][j]);
      }
}
main()
{
  int i,shu,fare;

  while(EOF!=scanf("%d %d",&N,&K) && N && K)
    {
      clear_fare();
      for(i=0;i<K;i++)
	{
	  scanf("%d",&shu);
	  if(shu == 0)
	    {
	      scanf("%d %d",&a,&b);
	      fare=fare_table[a][b];
	      if(fare != INT_MAX)
		printf("%d\n",fare);
	      else
		printf("%d\n",-1);
	    }
	  else
	    {
	      scanf("%d %d %d",&c,&d,&e);
	      regist_fare(c,d,e);
	      //show_table();
	    }
	}
    }
return(0);
}

Measured memory_bytes: 640
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
  int n, m, Q;
  cin >> n >> m >> Q;
  int l, r;
  int ans[510][510] = {
    {0}
  };

  for (int i = 0; i < m; i++)
  {
    cin >> l >> r;
    ans[l][r]++;
  }
  for (int i = 0; i < 509; i++)
  {
    for (int j = 0; j < 509; j++)
    {
      ans[i + 1][j] += ans[i][j];
    }
  }
  for (int i = 0; i < 509; i++)
  {
    for (int j = 0; j < 509; j++)
    {
      ans[i][j + 1] += ans[i][j];
    }
  }

  int p, q;
  for (int i = 0; i < Q; i++)
  {
    cin >> p >> q;
    cout << ans[q][q] - ans[p - 1][q] - ans[q][p - 1] + ans[p - 1][p - 1] << "\n";
  }
}

Measured memory_bytes: 1920
n=int(input())
happy=[[] for i in range(n)]
for i in range(n):
  happy[i]=list(map(int,input().split()))
dp=[[0,0,0] for i in range(n)]
dp[0]=[happy[0][0],happy[0][1],happy[0][2]]
for i in range(1,n):
  #print('i is ',i)
  for j in range(3):#i日目に幸福jを選んだ場合の幸福最大をdp[i][j]とする。
    x=[]
    for k in range(3):
      if k!=j:
        x.append(dp[i-1][k])
    dp[i][j]=max(x)+happy[i][j]
    #print(j,x)
print(max(dp[n-1]))

Measured memory_bytes: 47320
using System;
using System.Linq;

namespace _0593
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = new int[x[0]];
            int[] b = new int[x[0]];
            for (int i = 0; i < x[0]; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 0; i < x[1]; i++)
            {
                int now = int.Parse(Console.ReadLine());
                int j = 0;
                while (now < a[j])
                {
                    j++;
                }
                b[j]++;
            }
            int max = 0;
            bool q = true;
            for (int i = x[1]; q; i--)
            {
                for (int j = 0; j < x[0]; j++)
                {
                    if (b[j] == i)
                    {
                        max = j;
                        q = false;
                    }
                }
            }
            Console.WriteLine(max + 1);
        }
    }
}

Measured memory_bytes: 9528
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

long long n;

long long modpow(long long a, long long b){
	if(b == 0) return 1;
	long long ret = pow(a, b / 2);
	ret = ret * ret;
	if(b % 2) ret = ret * a;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	int i = 0;
	long long sum = 0;
	while(sum < n){
		i++;
		sum += modpow(26, i);
	}
	sum -= modpow(26, i);
	n -= sum;
	for(int j = 0; j < i; j++){
		int of = 0;
		while(of * modpow(26, i - j - 1) < n) of++;
		of--;
		n -= modpow(26, i - j - 1) * of;
		cout << (char)('a' + of);
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 4096
//include
//------------------------------------------
#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>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
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();}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#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())

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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	FOR(i,1,10)FOR(j,1,10){
		cout<<i<<"x"<<j<<"="<<i*j<<endl;
	}
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

vector<ll> a;
vector<ll> a_sum;
ll memo[500][500];

ll cost(ll front,ll back){
    return a_sum[back] - (front ? a_sum[front-1] : 0);
}

ll dfs(ll front,ll back){
    if(front == back)return 0;
    if(back - front == 1)return cost(front,back);
    if(memo[front][back])return memo[front][back];
    ll ans = LINF;
    FOR(i,front,back){
        ans = min(ans,dfs(front,i)+dfs(i+1,back)+cost(front,back));
    }
    return memo[front][back] = ans;
}

signed main(){
    ll N;
    cin >> N;
    a.resize(N);
    FOR(i,0,N)cin >> a[i];
    a_sum = a;
    FOR(i,1,N)a_sum[i] += a_sum[i-1];
    cout << dfs(0,N-1) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),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())
#define fi first
#define sc second

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(10);
    int a,b,c;
    cin >> a >> b >> c;


    cout << c << " " << a << " " << b << endl;;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int l[n], r[n];
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &l[i], &r[i]);
  }
  int sum = n;
  for (int i = 0; i < n; i++) {
    sum += r[i]-l[i];
  }
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,ii,jj;
ll n,m,sum,num=INF;
ll ans;
ll a,b,c,d,e;
ll x[100005],y[100005],z[100005];
ll xa[100005],ya[100005],za[100005];
string s,t;
bool dame;

int main(){
	cin>>s;
	n=s.size();
	t = "YAKI";
	if(n<=3)dame=true;
	for(i=0;i<4;i++){
		if(s[i]!=t[i])dame=true;
	}
	if(dame){
		p("No");
	}else{
		p("Yes");
	}
	return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,flag;
  flag=0;
  cin>>a;
  for(int i=1;i<10;i++){
    if(1<=(a/i)&&(a/i)<=9&&a%i==0){
      flag=1;
    }else{
      
    }
  }
  if(flag==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=400000+10;
int head[maxn];
bool vis[maxn];
int num[maxn];
int node[maxn];
int que[maxn];
int nod[maxn];
struct Edge {
	int u,v;
	int next;
} edge[maxn];
int n,m;
int tol;
int cnt;
int ans;
int S,T;
bool flag;
void init() {
	memset(head,-1,sizeof(head));
	memset(node,0,sizeof(node));
	memset(num,0,sizeof(num));
	tol=0;
	cnt=0;
	ans=1;
	flag=true;
}
void add(int u,int v) {
	edge[tol].u=u;
	edge[tol].v=v;
	edge[tol].next=head[u];
	head[u]=tol++;
}
int bfs(int s) {
	int l=0,r=0;
	memset(vis,0,sizeof(vis));
	memset(que,0,sizeof(que));
	que[r++]=s;
	vis[s]=1;
	while(l<=r) {
		s=que[l++];
		for(int i=head[s]; i!=-1; i=edge[i].next) {
			int v=edge[i].v;
			if(vis[v]==0) {
				vis[v]=1;
				que[r++]=v;
			}
		}
	}
	return que[r-1];
}
void dfs(int u) {
	if(!flag)
		return;
	int top=0;
	vis[u]=1;
	for(int i=head[u]; i!=-1; i=edge[i].next) {
		int v=edge[i].v;
		if(vis[v]==0) {
			dfs(v);
			node[u]=max(node[u],node[v]);
			if(node[v]>1) top++;
			if(v!=T&&node[v]==1)
				num[u]++;
		}
	}
	node[u]++;
	if(top>=2) {
		flag=false;
		return;
	}
	if(u!=S&&u!=T&&node[u]>=2)
		nod[cnt++]=num[u];
}
void printf_(int u) {
	int t=ans;
	vis[u]=1;
	if(num[u]>0) {
		for(int i=1; i<=num[u]; i++) {
			printf("%d ",++ans);
		}
	}
	printf("%d%c",t,u==T?'\n':' ');
	ans++;
	for(int i=head[u]; i!=-1; i=edge[i].next) {
		int v=edge[i].v;
		if(v==T||v==S||node[v]>1) {
			if(!vis[v])
				printf_(v);
		}
	}
}
int main() {
	while(~scanf("%d",&n)) {
		init();
		m=n-1;
		int u,v;
		for(int i=0; i<m; i++) {
			scanf("%d %d",&u,&v);
			add(u,v);
			add(v,u);
		}
		T=bfs(1);
		S=bfs(T);
		memset(vis,0,sizeof(vis));
		dfs(S);
		/*cout<<S<<" "<<T<<endl;
		cout<<cnt<<endl;
		for(int i=1; i<=n; i++)
			printf("%d%c",node[i],i==n?'\n':' ');
		for(int i=1; i<=n; i++)
			printf("%d%c",num[i],i==n?'\n':' ');
		for(int i=0; i<cnt; i++)
			printf("%d%c",nod[i],i==cnt-1?'\n':' ');
		*/
		reverse(nod,nod+cnt);
		for(int i=0; i<cnt; i++) {
			if(nod[i]<nod[cnt-i-1])
				break;
			else if(nod[i]>nod[cnt-i-1]) {
				swap(S,T);
				break;
			}
		}
		memset(vis,0,sizeof(vis));
		if(!flag)
			printf("-1\n");
		else
			printf_(S);
	}
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	string s;
	cin >> s;
	cout << (((s[0] == s[s.size() - 1]) xor (s.size() % 2 != 0)) ? "First" : "Second") << "\n";
	return 0;
}


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

using namespace std;

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

    if(n%10==3){
        cout<<"bon"<<endl;
    }else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    
    int ans=1;
    
    for(int i=k;i<=n;i*=k){
        ans++;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N, K;
	
	cin >> N >> K;
	
	ll x[N], ans = mod;
	
	for(int i=0; i<N; i++)
		cin >> x[i];
	
	for(int i=0; i<N-K+1; i++){
		ll left = x[i];
		ll right = x[i + K - 1];
		ans = min(ans, min(abs(left), abs(right)) + right - left);
	}
	
	cout << ans;
	
	return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll, ll> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll k;
	cin >>n >>k;
	VL a(n);
	rep(i, n) cin >>a[i];
	sort(all(a));
	
	auto fnc=[&](ll m){
		ll rtn = 0;
		rep(i, n){
			if(a[i] < 0){
				auto z = partition_point(all(a), [&](auto p){return p * a[i] > m;});
				rtn += n - (z - a.begin());
			}else{
				auto z = partition_point(all(a), [&](auto p){return p * a[i] <= m;});
				rtn += (z - a.begin());
			}
			if(a[i] * a[i] <= m) rtn--;
		}
		return rtn / 2;
	};
	
	const ll INF = 1.1e18;
	ll lf = -INF, rg = INF;
	while(rg - lf >1){
		ll md = (rg + lf) / 2;
		ll wk = fnc(md);
		if( wk >= k ) rg = md; else lf = md; 
	}
	cout <<rg <<"\n";
	
	return 0;
}


Measured memory_bytes: 1792
k, x = gets.chomp.split.map(&:to_i)
ary = []

mae_count = k - 1
ushiro_count = k - 1

(k - 1).times do
  ary.unshift(x - mae_count)

  mae_count -= 1
end

ary.push(x)

(k - 1).times do
  ary.push(x + ushiro_count)

  ushiro_count -= 1
end

puts ary.sort.join(' ')

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

const int INF = 9999999;
const int MAXN = 1e5+7;

int N,M;
vector<int> vi[MAXN];
vector<int> re[MAXN];
vector<int> tpsort;
int dp[MAXN];
bitset<MAXN> ok;

void dfs(int p){
    if(ok[p])return;
    ok[p] = true;
    for(auto u : vi[p]){
        dfs(u);
    }
    tpsort.push_back(p);
}

int main(){
    cin >> N >> M;
    for(int i = 0;i <= N;++i)dp[i] = 0;
    for(int i = 0; i < M;++i){
        int x,y;
        cin >> x >> y;
        --x,--y;
        vi[x].push_back(y);
        re[y].push_back(x);
    }

    //TOPOSORT
    ok.reset();
    for(int i = 0;i < N;++i){
        if(re[i].size() == 0){
            dfs(i);
        }
    }
    reverse(tpsort.begin(),tpsort.end());

    for(auto u : tpsort){
        cerr << u << " ";
        for(auto v : vi[u]){
            dp[v] = max(dp[v],dp[u]+1);
        }
    }
    cerr << "\n";
    cout << *max_element(dp,dp+N) << "\n";
}


Measured memory_bytes: 16896
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private Scanner stdin;
    private PrintWriter stdout;

    public void execute() {
        this.stdin = new Scanner(new BufferedInputStream(System.in));
        this.stdout = new PrintWriter(new BufferedOutputStream(System.out));

        while (this.stdin.hasNext()) {
            int n = stdin.nextInt();
            int threshold = stdin.nextInt();
            int foo = -1;
            for (int i = 0; i < n; ++i) {
                int x = stdin.nextInt();
                int y = stdin.nextInt();
                if (y <= threshold) {
                    if (foo == -1 || foo > x) {
                        foo = x;
                    }
                }
            }
            if (foo >= 0) {
                stdout.printf("%d\n", foo);
            } else {
                stdout.printf("TLE\n");
            }
        }

        this.stdin.close();
        this.stdout.close();
    }

    public static void main(String[] args) throws Exception {
        Main instance = new Main();
        instance.execute();
    }

}


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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D), c(D);
  rep(i, D)
    cin >> p.at(i) >> c.at(i);
  
  int result = 1000;
  
  for (int i = 0; i < (1 << D); i++) {
    bitset<10> s(i);
    int sum = 0, solved = 0;
    rep(j, D) {
      if (s.test(j)) {
        sum += (j + 1) * 100 * p.at(j) + c.at(j);
        solved += p.at(j);
      }
    }
    
    if (sum >= G) 
      result = min(result, solved);
    
    else {
      auto t = ~s;
      int sum_2 = sum;
      int solved_2 = solved;
      rep(j, D) {
        if (t.test(j)) {
          rep(k, p.at(j)) {
            sum_2 += (j + 1) * 100;
            solved_2 += 1;
            if (k == p.at(j) - 1) {
              sum_2 += c.at(j);
            }
            
            if (sum_2 >= G) {
              result = min(result, solved_2);
              break;
            }
          }
        }
        sum_2 = sum;
        solved_2 = solved;
      }
    }
  }
  cout << result << endl;
}
      


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

int dp[100010];
int A[110];

int N;


long long int q(int k) {
    int i, count, game;
    if (dp[k] != -1) return dp[k];
    else {
        count = 0;
        game = 0;
        for (i = 0; i < N; i++) {
            if (k - A[i] >= 0) {
                count++;
                if (q(k-A[i]) == 0) game++;
            }
        }
        if (count == 0) dp[k] = 0;
        else if (game > 0) dp[k] = 1;
        else dp[k] = 0;
    }

    return dp[k];
}

int main() {
    int i, K, min, game;

    cin >> N >> K;
    min = 1000010;
    for (i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] < min) min = A[i];
    }

    for (i = 0; i <= K; i++) {
        dp[i] = -1;
    }

    game = q(K);

    if (game == 1) cout << "First" << endl;
    else cout << "Second" << endl;
}


Measured memory_bytes: 5376