akhauriyash/Code-Regression huggingface dataset:
program test
integer :: N, i, j, M
read(*, *) N
M = N - mod(N, 2)
write(*, '(i0)') M*(M - 2)/2 + mod(N, 2)*M
do i = 1, M
    do j = i + 1, M
        if(j /= M - i + 1) write(*, "(i0, a, i0)") i, " ", j
    enddo 
enddo
if (mod(N, 2) == 1)then
    do i = 1, M
        write(*, "(i0, a, i0)") i, " ", N
    enddo 
endif

end program test

Measured memory_bytes: 256
import sys
dictionary = {}
for i in sys.stdin.readlines():
	word, page = i.split()
	if word in dictionary:
		dictionary[word].append(int(page))
	else:
		dictionary[word] = [int(page)]
dictionary = sorted(dictionary.items()) #???????????????????????????
for i in dictionary:
	print(i[0]) #??????
	print(*sorted(i[1]))

Measured memory_bytes: 7532
n, m=map(int, input().split())
a=list(map(int, input().split()))
d={1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
memo=[0]*(n+1)
memo[0]=0
memo[1]=-10**10
for i in range(2, n+1):
    res=-10**10
    for ai in a:
        if d[ai]>i:
            continue
        res=max(res, ai+memo[i-d[ai]]*10)
    memo[i]=res
print(memo[n])

Measured memory_bytes: 14388
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int x; cin >> x;
    if(x < 600) cout << 8 << endl;
    else if(x < 800) cout << 7 << endl;
    else if(x < 1000) cout << 6 << endl;
    else if(x < 1200) cout << 5 <<endl;
    else if(x < 1400) cout << 4 << endl;
    else if(x < 1600) cout << 3 << endl;
    else if(x < 1800) cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3652
A[2001],B[4001];main(a,b){
	for(a=0;a<1001;a++)for(b=0;b<1001;b++)A[a+b]++;
	for(a=0;a<2001;a++)for(b=0;b<2001;b++)B[a+b]+=A[a]*A[b];
	for(;~scanf("%d",&a);)printf("%d\n",B[a]);
exit(0);}

Measured memory_bytes: 624
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

import std.math;

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);
    a = [0] ~ a ~ [0];

    long s;
    foreach (i ; 1 .. n + 2) {
        s += abs(a[i] - a[i-1]);
    }

    foreach (i ; 1 .. n + 1) {
        writeln(s - abs(a[i+1] - a[i]) - abs(a[i] - a[i-1]) + abs(a[i+1] - a[i-1]));
    }
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

alice = []
bob = []

while A != []:
	alice.append(max(A))
	A.remove(max(A))
	if A != []:
		bob.append(max(A))
		A.remove(max(A))
	else: 
		break
print(sum(alice)-sum(bob))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;

vector<int> adj[100000], dp;

void dfs(int curr, vector<bool>& visited) {
	visited[curr] = true;
	for (int node : adj[curr]) {
		if (!visited[node]) {
			dfs(node, visited);
		}
		dp[curr] = max(dp[curr], dp[node] + 1);
	}
}


int main() {
	int n, m, x, y;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		adj[x].push_back(y);
	}
	dp.resize(n + 1);
	vector<bool> visited(n + 1);
	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (!visited[i]) {
			dfs(i, visited);
		}
	}
	for (int i = 1; i <= n; i++)
		res = max(dp[i], res);
	cout << res;
	return 0;
}

Measured memory_bytes: 12336
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
Dc = Counter(D)
mod = 998244353
ans = 1

if Dc[0]!=1 or D[0]!=0:
    print(0)
else:
    for i in range(max(D)):
        ans = ans*pow(Dc[i],Dc[i+1])%mod
    print(ans%mod)

Measured memory_bytes: 24312
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {

	
	int a, b;
	cin >> a >> b;
	cout << max(a - b, 0) << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int N,V[100],C[100],c,sum=0,i,j,sum1=0,sum2=0;
    cin>>N;
    for(i=0;i<N;i++)
    {
        cin>>V[i];
    }
    for(j=0;j<N;j++)
    {
        cin>>C[j];
    }
    for(i=0,j=0;i<N,j<N;i++,j++)
    {
        if((V[i]-C[j])>0)
        {
            sum1+=V[i];
            sum2+=C[j];
            sum=sum1-sum2;
        }
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdint>
#include<cstdio>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); ++i)
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(v) begin(v), end(v)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  list<int> b;
  rep(i, n) {
    if (i % 2 == 0) {
      b.push_back(a[i]);
    } else {
      b.push_front(a[i]);
    }
  }

  int i = 0;
  if (n % 2 == 1) {
    reverse(all(b));
  }

  for(int k : b) {
    i++;
    cout << k;
    if (i == n) cout << endl;
    else cout << " ";
  }


  return 0;
}


Measured memory_bytes: 9216
#include <stdio.h>
#define N 100
#define K (1<<21)

int main(){
  int i,j,k,l,n,p[N+1],m[N+1][N+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++){
    m[i][i]=0;
  }

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=K;
      for(k=i;k<=j-1;k++){
	if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]){
	  m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	}
      }
    }
  }
    printf("%d\n",m[1][n]);

    return 0;
  }
    



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

signed main(){
	int a[4];
	rep(i,4)scanf("%lld", &a[i]);
	printf("%lld\n",max(a[0]*a[1], a[2]*a[3]));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define SZ(vvv) ((int)vvv.size())
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 1e5 + 5, M = 5e4 + 9, INF = 1e9, MOD = 998244353;

vector<int> vec[N];

void runtestcase() {
	int n, m, a, b;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		vec[a].push_back(b);
	}
	for (int i = 0; i <= m; ++i)
		sort(vec[i].begin(), vec[i].end());
	int total = 0;
	priority_queue<int> pq;
	for (int i = 1; i <= m; ++i) {
		for(auto it: vec[i])
			pq.push(it);
		if(pq.empty()) continue;
		total += pq.top();
		pq.pop();
	}
	cout << total;
}


int main() {
    fastIO;
#ifdef LOCAL
    freopen("input.in", "rt", stdin);
//    freopen("cache.out", "wt", stdout);
#endif
  int t = 1, tt = 1;
//	cin >> t;
  while(t) {
//		cout << "Case #" << tt << ':' << ' ';
    runtestcase();
		cout << '\n';
    --t, ++tt;
  }
}


Measured memory_bytes: 8952
#include <stdio.h>

char S[200200], T[200200];

int main()
{
	scanf ("%s %s", S, T);
	int A = 0;
	for (int i = 0; S[i]; i++) if (S[i] != T[i]) A++;
	printf ("%d\n", A);
	return 0;

}

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

const int N = 900005;
const int md = 1e9 + 7;

int n, m, k;
int fact[N], inv[N], pw3[N];
int ans;

int pw(int a, int b) {
	int res = 1;
	while(b) {
		if (b & 1) res = 1LL * res * a % md; a = 1LL * a * a % md;
		b >>= 1;
	}
	return res;
}

int C(int n, int k) {
	if (n == k) return 1;
	if (n < 0 || k < 0 || n < k) return 0;
	return 1LL * fact[n] * (1LL * inv[k] * inv[n - k] % md) % md;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m >> k;

	pw3[0] = 1; for (int i = 1; i < N; ++i) pw3[i] = 3LL * pw3[i - 1] % md;
	fact[0] = 1; for (int i = 1; i < N; ++i) fact[i] = 1LL * fact[i-1] * i % md;
	for (int i = 0; i < N; ++i) inv[i] = pw(fact[i], md - 2);

	int f = 0;
	for (int i = n; i <= n + m + k; ++i) {
		if (i == n) {
			for (int j = i - n - k; j <= m; ++j) f = (f + C(i - n, j)) % md;
		} else {
			f = 2LL * f % md; 
			f = (f - C(i - 1 - n, i - 1 - n - k)) % md; if (f < 0) f += md;
			f = (f - C(i - 1 - n, m)) % md; if (f < 0) f += md;
 		}
 		int cur = 1LL * C(i - 1, n - 1) * pw3[n + m + k - i] % md;
 		cur = 1LL * cur * f % md;
 		ans = (ans + cur) % md;
	}

	cout << ans << '\n';
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c1, c2, c, x, y, sum, mn = 999999999, avg, pos, dif, j, dis, mx, xi, yi, q;
vector<ll>v;
set<int>s;
map<string, ll >mp;
bool PE ( int x )
{
    for ( int i = 2; i * i <= x; i++ )
        if ( x % i == 0 )
            return false;
    return true;
}
bool PR ( string s )
{
    int n = s.length();
    for ( int i = 0; i < n / 2; i++ )
        if ( s[i] != s[n - i - 1] )
            return false;
    return true;
}

int main ( void )
{ 
    SpeeD
    ll n;
    cin>>n;
    c=0;
    while (n % 2 == 0)
    {
            n/=2;
            c++;
        
    }
    //cout<<c;
   
    ll dif = (-1 + sqrt(1 + 8*c)) / 2 ;
    
   
   for (ll i = 3; i * i <= n;i++){
   c1=0;
    while (n%i == 0){
    c1++, n/=i;
    }

        dif += (-1 + sqrt(1 + 8*c1)) / 2 ;}
       // cout<<n;
    if (n>2)
    dif++;
    
    
cout<<dif;
     
    
   
}


Measured memory_bytes: 3700
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input!{
        s: chars,
    }
    let mut s = s;
    let n = s.len();
    s.insert(0, '+');
    let mut ok = true;
    if s[n] == '1' {
        ok = false;
    }
    if s[1] == '0' || s[n - 1] == '0' {
        ok = false;
    }
    for i in 1 .. n {
        if s[i] != s[n - i] {
            ok = false;
        }
    }
    if !ok {
        puts!("-1\n");
        return;
    }
    let mut edges = vec![];
    let mut pool = vec![];
    for i in 1 .. n + 1 {
        if s[i] == '1' {
            for p in pool.drain(..) {
                edges.push((p, i));
            }
        }
        pool.push(i);
    }
    for p in pool {
        if p != n {
            edges.push((p, n));
        }
    }
    for (x, y) in edges {
        puts!("{} {}\n", x, y);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 13692
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define spc printf(" ")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007
#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///#define triangle_area(a,b,m,n,x,y) (a*(n-y)+m*(y-b)+x*(b-n))/2.0
///int ax[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ay[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///using namespace __gnu_pbds;
using namespace std;

///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //FI;
    //FO;
    #endif
    //ios_base::sync_with_stdio(0); cin.tie(0);
    ll N;
    while(sl(N)==1)
    {
        ll mn=INF;
        for(ll i=1;i<=sqrt(N);i++)
        {
            if(N%i==0)
            {
                ll x=N/i;
                ll xx=(x-1)+(i-1);
                mn=min(xx,mn);
            }
        }
        pf("%lld\n",mn);
    }
    return 0;
}







Measured memory_bytes: 256
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        Deque<String> numDeque = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                numDeque.addFirst(sc.next());
            } else {
                numDeque.addLast(sc.next());
            }
        }
        Iterator<String> i = n % 2 == 0 ? numDeque.descendingIterator() : numDeque.iterator();
        while (i.hasNext()) {
            System.out.print(" " + i.next());
        }
    }
}


Measured memory_bytes: 82676
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 26712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
#define LL long long
#define MAXN 100000
#define Pr pair<int,int>
#define X first
#define Y second
int n,m,p,cont;
vector<Pr> G[2][MAXN+5];
int vis[MAXN+5][2];
LL d[MAXN+5];
int F,v[MAXN+5],cnt[MAXN+5];
void dfs(int x,int kdf){
	vis[x][kdf]=1;
	for(int i=0;i<G[kdf][x].size();i++){
		int nxt=G[kdf][x][i].X;
		if(!vis[nxt][kdf]){
			dfs(nxt,kdf);
		}
	}
}
bool SPFA() 
{
	queue<int>Q;
    Q.push(1); 
    d[1]=0; 
    while(!Q.empty()) 
    { 
        int x=Q.front(); 
        Q.pop(); 
        v[x]=0;
        for(int i=0;i<G[0][x].size();i++) 
        { 
            int xnt=G[0][x][i].X;
            if(!vis[xnt][0]||!vis[xnt][1])
            continue;
            if(d[x]+G[0][x][i].Y>d[xnt]) 
            {
            	d[xnt]=d[x]+G[0][x][i].Y;
                if(!v[xnt]) 
                {
                	cnt[xnt]++;
                	if(cnt[xnt]==n)
                		return 0;
                    Q.push(xnt); 
                    v[xnt]=true; 
                } 
            } 
        } 
    }
    return 1;
} 
int main()
{
	memset(d,-0x3f,sizeof(d));
	scanf("%d%d%d",&n,&m,&p);
	for(int i=1;i<=m;i++)
	{
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		G[0][u].push_back(Pr(v,c-p));
		G[1][v].push_back(Pr(u,c-p));
	}
	dfs(1,0);dfs(n,1);
	if(SPFA())printf("%lld",max(d[n],0LL));
	else printf("-1");
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
map <long long, long long > cnt;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
    long long n,i,j,k;
    long double n1,a,b,c;
	cin>>n;
	if (n%2==0)
	{
		cout<<n<<" "<<n<<" "<<n/2<<endl;
		return 0;
	}
	if (n%4==3)
	{
		for (i=1;i<=3500;i++)
		{
			if (4*i>n)
			{
				cout<<2*n*i<<" "<<i<<" "<<2*n*i<<endl;
				return 0;
			}
		}
	}
	//cout<<n1<<endl;
	for (i=1;i<=3500;i++)
	{
		if (4*i>n)
		{
			for (j=1;j<4*i-n;j++)
			{
				if ((n*i)%(j)==0 && (n*i)%(4*i-n-j)==0)
				{
					cout<<n*i/(4*i-n-j)<<" "<<n*i/j<<" "<<i<<endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 4;
int X , Y , a , b , c;
int p[MAXN] , q[MAXN] , r[MAXN];
ll ans , res;
int main(){
    ans = 0 ;
    scanf("%d%d%d%d%d",&X,&Y,&a,&b,&c);
    for(int i=1;i<=a;i++)scanf("%d",&p[i]);
    for(int i=1;i<=b;i++)scanf("%d",&q[i]);
    for(int i=1;i<=c;i++)scanf("%d",&r[i]);
    sort(p+1,p+a+1,greater<int>());
    sort(q+1,q+b+1,greater<int>());
    sort(r+1,r+c+1,greater<int>());
    int tp = X, tq = Y;
    for(int i=1;i<=X;i++) ans += p[i];
    for(int i=1;i<=Y;i++) ans += q[i];
    res = ans;
    for(int i=1;i<=c;i++){
        int o = r[i];
        int v , g;
        if(tp == 0 && tq == 0){
            break;
        }
        if(tp != 0 && tq != 0){
            if(p[tp] < q[tq]){
                g = 0;
                v = p[tp];
            }
            else {
                g = 1;
                v = q[tq];
            }
            ans += o - v;
            if(g) tq --;
            else tp --;
            res = max(res , ans);
            continue;
        }
        if(tp != 0){
            ans += o - p[tp];
            tp --;
            res = max(res , ans);
            continue;
        }
        if(tq != 0){
            ans += o - q[tq];
            tq --;
            res = max(res , ans);
            continue;
        }
    }
    printf("%lld\n",res);
    return 0;
}


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

int main(){
  int a,b,c,d ;
  cin >> a >> b >> c >> d ;
  if(abs(a-c) <= d)
    cout << "Yes" << endl ;
  else if (abs(a-b) <= d && abs(b-c) <= d )
    cout << "Yes" << endl ;
  else
    cout << "No" << endl ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int h[n+1];

    for(int i=1;i<=n;i++)
      cin>>h[i];
  h[0]=0;
  int dp[n+1];
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(h[1]-h[2]);
  for(int i=3;i<=n;i++)
  {
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
              cout<<dp[n]<<endl;
              return 0;

}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int
def comb(n, k):
    k = min(n-k,k)
    ans = 1
    for i in range(1, k + 1):
        ans = (ans * (n + 1 - i) // i)
    return ans

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)

    return table

def solve(N: int, M: int):
    from collections import Counter
    primes = prime_decomposition(M)

    counter = Counter(primes)
    answer = 1
    for count in counter.values():
        answer *= comb(count+N-1,count)
        answer %= MOD
    
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int dpx[8]={1,1,1,-1,-1,-1,0,0};
int dpy[8]={-1,1,0,1,-1,0,-1,1};

int32_t main()
{
	fastIO
	inp_out();
	 /* 
	 AC x 3
WA x 1
TLE x 2
RE x 0
8   */
	int n; 
	cin >> n; 
	string s; 
	int a = 0, b = 0, c = 0, d = 0; 
	for(int i = 0; i < n;  ++ i)
	{
		cin >> s; 
		if(s == "AC")
			 ++ a; 
		else if(s == "WA")
			 ++ b; 
		else if(s == "TLE")
			 ++ c; 
		else
			 ++ d; 


	}

	cout << "AC x " << a << "\n";
	cout << "WA x " << b << "\n";
	cout << "TLE x " << c << "\n";
	cout << "RE x " << d << "\n";

	return 0;
}

Measured memory_bytes: 3656
# encoding: utf-8


import sys

__input = sys.stdin.readlines()
length_1 = int(__input[0])
array_1 = list(map(int, __input[1].split()))
length_2 = int(__input[2])
array_2 = list(map(int, __input[3].split()))

record = [False] * 2000


def solution():
    # print(length_1, array_1, length_2, array_2)
    assert length_1 == len(array_1) and length_2 == len(array_2)

    for i in array_1:
        # record[i] = True
        for j in range(2000 - i, 0, -1):
            if record[j]:
                # print(j, i + j)
                record[i + j] = True
        record[i] = True

    for index in array_2:
        if record[index]:
            print("yes")
        else:
            print("no")


if __name__ == '__main__':
    solution()

Measured memory_bytes: 7768
d, g = gets.chop.split.map(&:to_i)
ps = []
cs = []
d.times do
  tmp = gets.chop.split.map(&:to_i)
  ps << tmp[0]
  cs << tmp[1]
end

ans = 100000000000000000000
(0..2**d-1).each do |bits|
  solve = [] # 全て解く問題を求める
  num = 0
  (0..d-1).each { |i| solve << i if bits[i] == 1 }
  score = 0
  solve.each do |i|
    score += (i + 1) * 100 * ps[i] + cs[i]
    num += ps[i]
  end
  if score >= g
    ans = num if num < ans
    next
  else
    (d-1).downto(0).each do |i|
      next if solve.include?(i)
      if g - score > (i + 1) * 100 * (ps[i] - 1)
        num += ps[i]
        score += (i + 1) * 100 * (ps[i] - 1)
      else
        if g == score
          ans = num if num < ans
          break
        end
        num += ((g - score).to_f / ((i + 1) * 100)).ceil
        ans = num if num < ans
        break
      end
    end
  end
end

puts ans

Measured memory_bytes: 2044
#include<iostream>
#include<string>
#include<stdlib.h>
#include<algorithm>
#define INF 1000000002
#define MIN -1000000002
#define MAX 1000000002
using namespace std;

int main()
{
	int n;
	while (cin >> n && n != 0)
	{
		long a[1000 + 1];
		long mn = MIN;
		long mx = MAX;
		for (int i = 1; i <= n; i++)
		{
			string s;
			cin >> s;
			if (s.compare("x") == 0)
			{
				a[i] = INF;
			}
			else
			{
				a[i] = atol(s.c_str());
			}
		}
		for (int i = 1; i <= n; i++)
		{
			if (i + 1 <= n && a[i] == INF&& a[i + 1] == INF)
			{
				mn = MAX;
				mx = MIN;
				break;
			}
			if (a[i] == INF)continue;
			if (i % 2 == 0)
			{
				if ((i - 1 >= 1 && a[i - 1] == INF) || (i + 1 <= n&& a[i + 1] == INF))
				{
					mx = min(mx, a[i] - 1);
				}
				else
				{
					if ((i + 1 <= n && a[i] <= a[i + 1]) || (i - 1 >= 1 && a[i] <= a[i - 1]))
					{
						mn = MAX;
						mx = MIN;
						break;
					}
				}
			}
			else
			{
				if ((i - 1 >= 1 && a[i - 1] == INF) || (i + 1 <= n&& a[i + 1] == INF))
				{
					mn = max(mn, a[i] + 1);
				}
				else
				{
					if ((i + 1 <= n && a[i] >= a[i + 1]) || (i - 1 >= 1 && a[i] >= a[i - 1]))
					{
						mn = MAX;
						mx = MIN;
						break;
					}
				}
			}
		}
		if (mx == mn)
		{
			cout << mx << endl;
		}
		else if (mx < mn)
		{
			cout << "none" << endl;
		}
		else if (mn < mx)
		{
			cout << "ambiguous" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = [0] + input_int_list()  # 1-indexed
    ans = 0
    cusum = [0] * (n + 1)
    MOD = (10**9) + 7

    for i in range(1, n + 1):
        cusum[i] = (A[i] + cusum[i - 1]) % MOD

    ans = 0

    for i in range(1, n):
        ans += (A[i] * (cusum[n] - cusum[i]))
        ans %= MOD
    print(ans)
    return


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;

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

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

  if (n % 2 == 0)
    printf("%.10f\n", 0.5);
  else
    printf("%.10f\n", (double)(n / 2 + 1) / n);
  return 0;
}


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

bool isEvenString(string S) {
    if (S.size() & 1) return false;
    string str0 = S.substr(0, S.size() / 2);
    string str1 = S.substr(S.size() / 2, S.size() / 2);
    return str0 == str1;
}

int main() {
    string S;
    cin >> S;
    
    rep(i, S.size()) {
        string str = S.substr(0, S.size() - 1 - i);
        if (isEvenString(str)) {
            cout << S.size() - 1 - i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
 
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

struct edge
 {
 	int to,cost,enemy;
 }; 

 struct P
 {
 	int from, money, enemy;
 	bool operator >(const P &p) const{
 		return enemy>p.enemy;
 	}
 };

int main() {
	int N,M,L;
	while(cin >> N >> M >> L, N|M|L){
		vector<vector<edge> > E=vector<vector<edge> >(N+1);
		REP(i, M){
			int from, to, cost, enemy;
			cin >> from >> to >> cost >> enemy;
			E[from].push_back((edge){to, cost, enemy});
			E[to].push_back((edge){from, cost, enemy});
		}

		priority_queue<P, vector<P>, greater<P> > que;
		vector<int> costs=vector<int>(N+1);
		REP(i, costs.size()){
			costs[i]=-1;
		}

		que.push((P){1, L, 0});
		int res=-1;
		while(!que.empty()){
			P p=que.top();que.pop();
			if(p.money<=costs[p.from])continue;
			costs[p.from]=p.money;
			if(p.from==N){
				res=p.enemy;
				break;
			}
			REP(i, E[p.from].size()){
				edge e=E[p.from][i];
				if(p.money>=e.cost){
					que.push((P){e.to, p.money-e.cost,p.enemy});
				}
				que.push((P){e.to, p.money, p.enemy+e.enemy});
			}
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/detail/standard_policies.hpp>

// common
#define endl     "\n"
#define M_PI     3.14159265358979323846

// fast input output
#define fast_io  ios_base::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL)

// fixed float field
#define fix_prec cout.setf( std::ios::fixed, std:: ios::floatfield ); cout.precision(0);

// vector
#define vi       vector<int>
#define vvi      vector<vector<int>>
#define vpii     vector<pair<int,int>>
#define pb(v,x)  v.push_back(x)

// pair
#define pii      pair<int,int>
#define mp(a,b)  make_pair(a,b)
#define F        first
#define S        second

// sort
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

// bound
#define lb(v,x)  lower_bound(v.begin(),v.end(),x)
#define ub(v,x)  upper_bound(v.begin(),v.end(),x)

using namespace std;
//using namespace __gnu_pbds;

//typedef tree < int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;
typedef long long int lli;
typedef unsigned long long int ulli;

// constants
lli const mod  = 1e9+7;
lli const modl = 1e18;

// helper functions
// calculate gcd
lli gcd(lli x, lli y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

// calculate fibonacci number
lli fib(int n)
{
    lli a,b,c,i;
    a=0,b=1;
    if(n == 0)
        return a;
    for(i=2;i<=n;i++)
    {
    	c=a+b;
    	a=b;
    	b=c;
    }
    return b;
}

// check if number if prime
bool isprime(lli n)
{
	if(n<=1)
		return false;
	else if(n==2)
		return true;
	else if(n%2==0)
		return false;
	else
	{
		int i;
		for(i=3;i*i<=n;i++)
		{
			if(n%i==0)
				return false;
		}
		return true;
	}
}

// read from and write to text file
void readwrite()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
} 

// seive
vector<lli>prime(100000+7,1);
void buildprime(lli n)
{
	lli i,j;
	prime[0]=prime[1]=0;
	for(i=2;i*i<=n;i++)
	{
		if(prime[i])
		{
			for(j=i*i;j<=n;j+=i)
				prime[j]=0;
		}
	}
}

// nCr
lli dp[1005][1005];
lli comb[1005][1005];
lli ncr(lli n,lli r)
{
	if(n==r)
		return 1;
	if(r==0)
		return 1;
	if(r==1)
		return n;
	if(dp[n][r]!=0)
		return dp[n][r];
	return dp[n][r] = (ncr(n-1,r)%mod+ncr(n-1,r-1)%mod)%mod;
}

void ncrm()
{
	comb[0][0]=1;
	for(int i=1;i<1001;i++)
	{
		comb[i][0]=1;
		for(int j=1;j<=i;j++)
		{
			comb[i][j]=(comb[i-1][j]%mod+comb[i-1][j-1]%mod)%mod;
		}
	}
}

// binary exponentiation
lli binpowm(lli a,lli b)
{
	lli res=1;
	a%=mod;
	while(b)
	{
		if(b&1)
			res=((res%mod)*(a%mod))%mod;
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return res%mod;
}
 
// factorial
lli fact(lli n)
{
	lli i,res=1;
	for(i=1;i<=n;i++)
		res=((res%mod)*(i%mod))%mod;
	return res%mod;
}

// driver code
void solve()
{
	int a,b;
	cin>>a>>b;
	a--;
	b--;
	cout<<ceil(1.0*b/a);
}

int main()
{
  fast_io;
  fix_prec;
  //readwrite();
  int t=1;
  //cin>>t;
  while(t--)
  {
    solve();
    cout<<endl;     
  }
  return 0;	
}

/*
Kab Khoon khaulega tera jab sabka internship lag jayega tab
Shame on you if you do not get internship
*/

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

int parent[10005];

int getp(int x)
{
    if(parent[x] == x) return (x);
    return (parent[x] = getp(parent[x]));
}

int main()
{
    int N, Q, A, B, C;
    cin >> N >> Q;
    for(int i = 0; i < N; i++) parent[i] = i;
    while(Q--) {
        cin >> A >> B >> C;
        if(A == 0) parent[getp(B)] = getp(C);
        else if(getp(B) == getp(C)) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return (0);
}

Measured memory_bytes: 3256
#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; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<pair<int,int>> vpi;

const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);

vi e[N];
vector<bool> vis;
void dfs(int u){
    vis[u]=1;
    for(auto i:e[u]){
        if(!vis[i]) dfs(i);
    }
}

void solve(){
    int n,m;
    cin>>n>>m;
    FOR(i,0,m){
        int a,b;
        cin>>a>>b;
        e[a].pb(b);
        e[b].pb(a);
    }
    ll ans=0;
    vis.assign(n+1,0);
    FOR(i,1,n+1){
        if(!vis[i]){
            ans++;
            dfs(i);
        }
    }
    
    cout<<ans-1<<"\n";
    

}




int main() {
   
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
    
   #ifndef ONLINE_JUDGE 
   freopen("input.txt", "r", stdin);  
   freopen("output.txt", "w", stdout); 
   #endif 

    int t=1;
    //cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
        
    }
    
    return 0;
    
    
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}



Measured memory_bytes: 11968
n=int(input())
A=list()
B=list(map(int,input().split()))
A.append(B[0])
for i in range(1,n):
  
  if i==n-1:
    A.append(B[i-1])
    break

  if B[i]<B[i-1]:
    A.append(B[i])
  else:
    A.append(B[i-1])
print(sum(A))

Measured memory_bytes: 3060
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

 
int main(int argc, char* argv[])
{
    vector<long> a(1000000);
    scanf("%ld", &(a[1]));

    set<long> ss;
    ss.insert(a[1]);
    long i;
    for(i=2; i<=1000000; i++) {
        a[i]=(a[i-1]%2==0? a[i-1]/2: a[i-1]*3+1);
        if( !ss.insert(a[i]).second) {
            printf("%ld\n", i);
            return 0;
        }
    }
 
    return 0;
}


Measured memory_bytes: 8192
package main

import (
	"container/heap"
	"fmt"
)

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] } // max heap
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	h := make(IntHeap, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	heap.Init(&h)
	heap.Fix(&h, 0)

	for i := 0; i < m; i++ {
		max := heap.Pop(&h).(int)
		heap.Push(&h, max/2)
	}

	total := 0
	for _, price := range h {
		total += price
	}
	fmt.Println(total)
}


Measured memory_bytes: 5504
import sys
import heapq
input = sys.stdin.readline
N,M = map(int,input().split())
AB = [[] for i in range(M+1)]
for i in range(N):
    a,b = list(map(int,input().split()))
    if a <= M:
        AB[a].append(-b)
work = 0
AB2 = []
heapq.heapify(AB2)
for i in range(1,M+1):
    for j in AB[i]:
        heapq.heappush(AB2,j)
    if len(AB2) > 0:
        b = heapq.heappop(AB2)
        work += -b
print(work)

Measured memory_bytes: 23752
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
ll num = 0;
ll solve(ll n, ll p)
{
    ll res = 1;
    ll cnt = 0;
    while(p % 2 == 0)
    {
        num++;
        cnt++;
        p /= 2;
    }
    if(cnt >= n) res *= pow(2, cnt / n);
    for(ll i = 3; i * i <= p; i += 2)
    {
        cnt = 0;
        while(p % i == 0)
        {
            num++;
            cnt++;
            p /= i;
        }
        if(cnt >= n) res *= pow(i, cnt / n);
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p;
    cin >> n >> p;
    ll ans = solve(n, p);
    if(n == 1) cout << p << endl;
    else if(n > num) cout << 1 << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}


signed main()
{
	int N;
	cin>>N;
	if(N==1){
		cout<<0<<endl;
		return 0;
	}
	int ans=0;
	for(int i=1;i*i<=N;i++){
		if((N-i)%i==0){
			int t = (N-i)/i;
			if(N/t==N%t)ans+=t;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++)
    cin >> H[i];
  int now = H[0] - 1;
  string ans = "Yes";
  for(int i=1; i<N; i++){
    if(H[i] - 1 >= now){
      now = H[i] - 1;
    }else if(H[i] >= now){
      now = H[i];
    }else {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
int main()
{
	int m=read(),d=read();
	int ans=0;
	for(int i=2;i<=9;++i)	
		for(int j=2;j<=9;++j)
			if(i*10+j<=d && i*j<=m)
				++ans;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 764
N = int(input())
A = list(map(int,input().split()))
money = 1000
cab = 0
lowprice = A[0]
check = True
for i in range(1,N):
    if(lowprice>A[i]):
        lowprice = A[i]
        check= True
    elif((lowprice<A[i]) and (check == True)):
        high_price = A[i]
        if(i<N-1):
            if(high_price > A[i+1]):
                cab=money//lowprice
                money-=(lowprice*cab)
                money+=(high_price*cab)
                cab = 0
                check = False
                lowprice = high_price
        else:
            cab=money//lowprice
            money-=(lowprice*cab)
            money+=(high_price*cab)
            cab = 0
            check = False
            lowprice = high_price
print(money)


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

bool compare_by_sec(pii a, pii b)
{
    if (a.second != b.second)
        return a.second > b.second; // > ならsecondの昇順
    else
        return a.first < b.first;
}

vector<pii> even(100001), odd(100001);

int main()
{
    int n;
    cin >> n;
    int v[n];
    rep(i, n) cin >> v[i];

    rep(i, 100001) even[i].first = i, odd[i].first = i;

    rep(i, n)
    {
        if (i & 1)
            odd[v[i]].second++;
        else
            even[v[i]].second++;
    }

    sort(ALL(even), compare_by_sec);
    sort(ALL(odd), compare_by_sec);

    if (odd[0].first == even[0].first)
        OP(min(n - odd[0].second - even[1].second, n - odd[1].second - even[0].second));

    else
        OP(n - odd[0].second - even[0].second);

    return 0;
}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    for(int x=0; x<d-b; x++){
        cout<<"U";
    }
    for(int x=0; x<c-a; x++){
        cout<<"R";
    }
    for(int x=0; x<d-b; x++){
        cout<<"D";
    }
    for(int x=0; x<c-a+1; x++){
        cout<<"L";
    }
    for(int x=0; x<d-b+1; x++){
        cout<<"U";
    }
    for(int x=0; x<c-a+1; x++){
        cout<<"R";
    }
    cout<<"DR";
    for(int x=0; x<d-b+1; x++){
        cout<<"D";
    }
    for(int x=0; x<c-a+1; x++){
        cout<<"L";
    }
    cout<<"U";
    return 0;
}


Measured memory_bytes: 888
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let _n: usize = util::get();
    let a: Vec<usize> = util::gets();

    let (m2, m4, o) = a.iter().fold((0, 0, 0), |(m2, m4, o), &x| if x % 4 == 0 {
        (m2, m4 + 1, o)
    } else if x % 2 == 0 {
        (m2 + 1, m4, o)
    } else {
        (m2, m4, o + 1)
    });

    if (o - 1 + (if m2 > 0 && o > 0 { 1 } else { 0 })) <= m4 {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

class BigInt{
public:
  vector<int> value;
  int sign;

  void set(int n){
    value.clear();
    if(n==0){
      sign = 0;
      value.push_back(0);
    }else if(n<0){
      sign = -1;
      n *= -1;
    }else{
      sign = 1;
    }
    while(n){
      value.push_back(n%10);
      n/=10;
    }
  }

  void set(string str){
    value.clear();
    if(str[0]=='-')sign = -1;
    else if(str[0]=='0')sign = 0;
    else sign = 1;
    int a = 0;
    if(sign<0)a = 1; 
    for(int i=str.size()-1;i>=a;i--){
      value.push_back(str[i]-'0');
    }
  }

  void print(void){
    if(sign<0)cout << '-';
    for(int i=value.size()-1;i>=0;i--)cout << value[i];
    cout << endl;
  }

  BigInt add(BigInt x){
    int max,min;
    BigInt ans;

    if(sign == 0)return x;
    if(x.sign == 0)return *this;
       
    ans.sign = 1;
    ans.value.clear();
    if(value.size()>x.value.size()){
      max = value.size();
      min = x.value.size();
      for(int i=0;i<min;i++)ans.value.push_back(value[i]+x.value[i]);
      for(int i=min;i<max;i++)ans.value.push_back(value[i]);
    }else{
      max = x.value.size();
      min = value.size();
      for(int i=0;i<min;i++)ans.value.push_back(value[i]+x.value[i]);
      for(int i=min;i<max;i++)ans.value.push_back(x.value[i]);
    }
    for(int i=0;i<(int)ans.value.size()-1;i++){
      while(ans.value[i]>=10){
	ans.value[i]-=10;
	ans.value[i+1]++;
      }
    }
    if(ans.value[ans.value.size()-1]>=10){
      ans.value[ans.value.size()-1]-=10;
      ans.value.push_back(1);
    }
    return ans;
  }

};

int main(){
  int n;
  string n1,n2;
  BigInt a1,a2,res;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> n1;
    cin >> n2;

    a1.set(n1);
    a2.set(n2);

    res = a1.add(a2);

    if(res.value.size()>80)cout << "overflow" << endl;
    else res.print();
  }
}

Measured memory_bytes: 0