akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b , 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I>
inline void read(I &x) {
	int f = 0, c;
	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
	x = c & 15;
	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
	f ? x = -x : 0;
}

const int N = 5000 + 7;
const int P = 1e9 + 7;

int n, m;
int siz[N], dp[N][N][2], f[N][2], ffac[N];

struct Edge { int to, ne; } g[N << 1]; int head[N], tot;
inline void addedge(int x, int y) { g[++tot].to = y, g[tot].ne = head[x], head[x] = tot; }
inline void adde(int x, int y) { addedge(x, y), addedge(y, x); }

inline int smod(int x) { return x >= P ? x - P : x; }
inline void sadd(int &x, int y) { x += y; x >= P ? x  -= P : x; }

inline void dfs(int x, int fa = 0) {
	siz[x] = 1, dp[x][1][0] = 1;
	for fec(i, x, y) if (y != fa) {
		dfs(y, x);
		for (int i = 1; i <= siz[x]; ++i)
			for (int j = 1; j <= siz[y]; ++j) {
				sadd(f[i + j][0], ((ll)dp[x][i][0] * dp[y][j][0] + (ll)dp[x][i][1] * dp[y][j][1]) % P);
				sadd(f[i + j][1], ((ll)dp[x][i][0] * dp[y][j][1] + (ll)dp[x][i][1] * dp[y][j][0]) % P);
				sadd(f[i][0], ((ll)dp[x][i][0] * dp[y][j][1] % P * ffac[j - 1] + (ll)dp[x][i][1] * dp[y][j][0] % P * ffac[j - 1]) % P);
				sadd(f[i][1], ((ll)dp[x][i][0] * dp[y][j][0] % P * ffac[j - 1] + (ll)dp[x][i][1] * dp[y][j][1] % P * ffac[j - 1]) % P);
			}
		siz[x] += siz[y];
		for (int i = 1; i <= siz[x]; ++i) dp[x][i][0] = f[i][0], dp[x][i][1] = f[i][1], f[i][0] = f[i][1] = 0;
	}
}

inline void work() {
	ffac[1] = 1;
	for (int i = 3; i <= n; i += 2) ffac[i] = (ll)ffac[i - 2] * i % P;
	dfs(1);
	int ans = 0;
	for (int i = 2; i <= n; i += 2) sadd(ans, (ll)(dp[1][i][0] - dp[1][i][1] + P) * ffac[i - 1] % P);
	printf("%d\n", ans);
}

inline void init() {
	read(n);
	for (int i = 1; i < n; ++i) {
		int x, y;
		read(x), read(y);
		adde(x, y);
	}
}

int main() {
#ifdef hzhkk
	freopen("hkk.in", "r", stdin);
#endif
	init();
	work();
	fclose(stdin), fclose(stdout);
	return 0;
}

Measured memory_bytes: 194688
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 main() {
    input! {
        num: usize
    };

    let suffix = match num % 10 {
        0 => "pon",
        1 => "pon",
        2 => "hon",
        3 => "bon",
        4 => "hon",
        5 => "hon",
        6 => "pon",
        7 => "hon",
        8 => "pon",
        9 => "hon",
        _ => panic!(),
    };
    println!("{}", suffix);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 25000000 + 5;

int n;
int ga, gb, sa, sb, ba, bb;
long long dp[N];

long long solve(long long rem)
{
  dp[0] = 0;
  for(int i = 1 ; i <= rem ; i++){
    dp[i] = i;
    for(auto cur : { mp(ga, gb), mp(sa, sb), mp(ba, bb) }){
      if(cur.first <= i){
        dp[i] = max(dp[i], cur.second + dp[i - cur.first]);
      }
    }
  }
  return dp[rem];
}

int main()
{
  cin >> n;
  cin >> ga >> sa >> ba;
  cin >> gb >> sb >> bb;
  long long soFar = n;
  for(int it = 0 ; it < 2 ; ++it){
    soFar = solve(soFar);
    swap(ga, gb);
    swap(sa, sb);
    swap(ba, bb);
  }
  cout << soFar << endl;
  return 0;
}


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

int main( ){
  while(1){
    int n,s,sum=0;
    string a;
    cin>>a>>n;
    if(a=="-")break;
    for(int i=0;i<n;i++){
      cin>>s;
      sum+=s;
    }
    sum%=a.size();
    a=a+a.substr(0,sum);
    a=a.erase(0,sum);
    cout<<a<<endl;
  }
  return 0;
}

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


int main(){

int a,b,k;
cin>>a>>b>>k;
int c= 2*k;

if((b-a+1)<=c )
{
    while(a<=b){
        cout<<a<<endl;
        a++;
    }
}else{
    int d=a+k-1;
    while(a<=d){
        cout<<a<<endl;
        a++;
    }
    a= b-k+1;
    while(a<=b){
        cout<<a<<endl;
        a++;
    }
}

}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define re cin>>
#define pr cout<<
#define in(x) scanf("%d",&x)
#define inn(x,y) scanf("%d%d",&x,&y)
#define innn(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)

const int N=1100;
const int mod=1e9+7;

int n,m,k;
int grid[N][N];

int par[N],sum[15];
int getMinCuts(int mask){
    par[1]=1;
    for(int i=0;i<n-1;i++) {
        par[i+2]=int(bool(mask&(1<<i)))+par[i+1];
    }

    // cerr<<mask<<":";
    // rep1(i,n) cerr<<par[i]<<" ";cerr<<"\n";

    rep1(i,10) sum[i]=0;
    int breaks=0;
    rep1(i,m){
        bool tobreak=0;
        for(int j=1;j<=n;j++) {
            sum[par[j]]+=grid[j][i];
            if(sum[par[j]]>k) tobreak=1;
        }
        if(!tobreak) continue;
        breaks++;
        rep1(j,10) sum[j]=0;
        for(int j=1;j<=n;j++) {
            sum[par[j]]+=grid[j][i];
            if(sum[par[j]]>k) return n*m;
        }
    }
    return breaks;
}

int main(){
    re n>>m>>k;
    rep1(i,n) {
        string s; re s;
        rep1(j,m) grid[i][j]=(s[j-1]=='1');
    }

    int mn=INT_MAX;
    for(int i=0;i<(1<<(n-1));i++) {
        int temp=getMinCuts(i)+__builtin_popcount(i);
        if(temp<mn) mn=temp;
    }
    pr mn;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

h, w = map(int, input().split())

if w == 1 or h == 1:
    print(1)
elif w % 2 == 0:
    print(w * h // 2)
else:
    if h % 2 == 0:
        print(((w // 2) * (h // 2)) + ((w // 2 + 1) * (h // 2)))
    else:
        print(((w // 2) * (h // 2)) + ((w // 2 + 1) * (h // 2 + 1)))


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll h,w,n;
ll x,y;
string s;
string t;
ll dp[e5];
ll pd[e5];

bool solve1(ll h,ll x){

  dp[n] = h+1;
  for(ll i = n-1;i >= 0;i--){
    dp[i] = dp[i+1];
    if(s[i] == 'R' && t[i] != 'L') dp[i]--;
    else if(s[i] != 'R' && t[i] == 'L') dp[i]++;
    else if(s[i] == 'R' && t[i] == 'L' && dp[i] == h+1) dp[i]--;
    dp[i] = min(dp[i],h+1);
  }
  pd[n] = 0;
  for(ll i = n-1;i >= 0;i--){
    pd[i] = pd[i+1];
    if(s[i] == 'L' && t[i] != 'R') pd[i]++;
    else if(s[i] != 'L' && t[i] == 'R') pd[i]--;
    else if(s[i] == 'L' && t[i] == 'R' && pd[i] == 0) pd[i]++;
    pd[i] = max(pd[i],0ll);
  }
  if(dp[0] <= x || pd[0] >= x) return false;
  // cerr << x << endl;
  for(ll i = 0;i <= n;i++){
    // cerr << dp[i] << " " << pd[i] << endl;
    if(dp[i] - pd[i] < 2) return false;
  }
  return true;
}
bool solve2(ll h,ll x){

  dp[n] = h+1;
  for(ll i = n-1;i >= 0;i--){
    dp[i] = dp[i+1];
    if(s[i] == 'D' && t[i] != 'U') dp[i]--;
    else if(s[i] != 'D' && t[i] == 'U') dp[i]++;
    else if(s[i] == 'D' && t[i] == 'U' && dp[i] == h+1) dp[i]--;
    dp[i] = min(dp[i],h+1);
  }
  pd[n] = 0;
  for(ll i = n-1;i >= 0;i--){
    pd[i] = pd[i+1];
    if(s[i] == 'U' && t[i] != 'D') pd[i]++;
    else if(s[i] != 'U' && t[i] == 'D') pd[i]--;
    else if(s[i] == 'U' && t[i] == 'D' && pd[i] == 0) pd[i]++;
    pd[i] = max(pd[i],0ll);
  }
  if(dp[0] <= x || pd[0] >= x) return false;
  // cerr << x << endl;
  for(ll i = 0;i <= n;i++){
    // cerr << dp[i] << " " << pd[i] << endl;
    if(dp[i] - pd[i] < 2) return false;
  }
  return true;

}
int main(){
  cin >> h >> w >> n;
  cin >> x >> y;
  cin >> s >> t;
  if(solve2(h,x) && solve1(w,y)) cout << "YES" << endl;
  else cout << "NO" << endl;

}


Measured memory_bytes: 4360
#include <stdio.h>
#define N 100
#define INF (1<<21)
#define WHITE 0
#define GRAY  1
#define BLACK 2

int n, M[N][N];
int color[N], d[N];

void dijkstra();

int main(){
  int i, j;
  int u, k, v, c;
  scanf("%d", &n);
  for( i = 0; i < n; i++ ){
    for( j = 0; j < n; j++ ){
      M[i][j] = INF;
    }
  }

  for( i = 0; i < n; i++ ){
    scanf("%d", &u);
    scanf("%d", &k);
    for( j = 0; j < k; j++ ){
      scanf("%d", &v);
      scanf("%d", &c);
      M[u][v] = c;
    }
  }

  dijkstra();
  
  return 0;
}

void dijkstra(){
  int i, u;
  int v, mincost;
  for( i = 0; i < n; i++ ){
    d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;

  while( 1 ){
    mincost = INF;
    u = -1;
    for( i = 0; i < n; i++ ){
      if( mincost > d[i] && color[i] != BLACK ){
	    mincost = d[i];
	    u = i;
      }
    }
    if( u == -1 ){
      break;
    }
    color[u] = BLACK;
    for( v = 0; v < n; v++ ){
      if( color[v] != BLACK && M[u][v] != INF ){
	      if( M[u][v] + d[u] < d[v] ){
	        d[v] = d[u] + M[u][v];
	        color[v] = GRAY;
	      }
      }
    }
  }

  for( i = 0; i < n; i++ ){
    printf("%d %d\n", i, d[i] == INF ? -1 : d[i] );
  }
}


Measured memory_bytes: 2112
import sys

N, M = map(int, sys.stdin.readline().split())

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    two = 2
    three = N * M - two
    print(three)
else:
    four = 4
    six = (N - 2) * 2 + (M - 2) * 2
    nine = N * M - four - six
    print(nine)

Measured memory_bytes: 9056
N, M = map(int, input().split())
H = list(map(int, input().split()))
L = [1] * N
for i in range(M):
	A, B = map(int, input().split())
	a, b = A-1, B-1
	if H[a] >= H[b]:
		L[b] = 0
	if H[b] >= H[a]:
		L[a] = 0
print(sum(L))

Measured memory_bytes: 20120
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    int n;
    cin>> n;
    set<string>s;
    while(n--){
    	string ss;
    	cin >> ss;
    	s.insert(ss);
    }
    cout<<s.size()<<endl;
    
}


Measured memory_bytes: 19256
def o()
  a = [K/2 + 1] * N
  (N/2).times do |i|
    a[-1] -= 1
    if a[-1].zero?
      a.pop
    else
      a << K until a.size==N
    end
  end
  a*" "
end

def e()
  ([K/2] + [K]*(N-1))*" "
end

K, N = gets.split.map &:to_i
puts K.odd? ? o : e


Measured memory_bytes: 11260
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100
#define INF (1e+9)

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    fget_array(arr, num);

    int i;
    int sum = 0;
    for(i = 0; i < num; i++) {
        sum += arr[i];
    }
    int ave = sum / num;
    int n;
    int mmin = INF;
    for(n = ave-1; n <= ave+1; n++) {
        int res = 0;
        for(i = 0; i < num; i++) {
            res += (arr[i] - n) * (arr[i] - n);
        }
        mmin = min(res, mmin);
    }
    printf("%d\n", mmin);
    return 0;
}

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

using namespace std;

const int N = 3000 + 77;
int n , a[N];
long long dp[N][N][2];
int main(){
   ios::sync_with_stdio(0);cin.tie(0);
   cin >> n;
   for(int i = 1;i <= n;++ i)
      cin >> a[i];
   for(int i = 1;i <= n;++ i)
      dp[i][i][0] = a[i] , dp[i][i][1] = - a[i];
   for(int d = 1;d <= n;++ d){
      for(int i = 1;i + d <= n;++ i){
         int le = i , ri = i + d;
         dp[le][ri][0] = max(dp[le + 1][ri][1] + a[le] , dp[le][ri - 1][1] + a[ri]);
         dp[le][ri][1] = min(dp[le + 1][ri][0] - a[le] , dp[le][ri - 1][0] - a[ri]);
      }
   }
   cout << dp[1][n][0];
   return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S)
{
    if (S.length() % 2 == 1)
    {
        cout << NO << endl;
        return;
    }

    int len = S.length() / 2;
    if (S.substr(0, len) == S.substr(len, len))
    {
        cout << YES << endl;
    }
    else
    {
        cout << NO << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
def resolve():
	x=int(input())
	ans=0
	if x==1:
		ans=1
	else:
		for b in range(1,x-1):
			p=2
			while True:
				if b**p>x or p>x:
					break
				else:
					t=b**p
				p+=1
			ans=max(ans,t)
	print(ans)
resolve()

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<double,double> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;

int main(){
    int N,K;
    cin >> N >> K;
    int a[N];
    int p=0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        if(a[i]==1) p=i;
    }
    int ans=INF;
    for(int i=0;i<=K-1;i++){
        int t=1;
        if((p-i)%(K-1)==0) t+=(p-i)/(K-1);
        else t+=(p-i)/(K-1)+1;
        if((N-1-p-(K-i-1))%(K-1)==0) t+=(N-1-p-(K-1-i))/(K-1);
        else t+=(N-1-p-(K-1-i))/(K-1)+1;
        ans=min(ans,t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

H, W = map(int, input().split())

for i in range(H):
    S = input()
    print(S)
    print(S)


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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif
typedef pair<string, pair<int, int>> Type;

bool cmp(Type a, Type b)
{
	if (a.f == b.f)
		return a.s > b.s;
	return a.f < b.f;
}
void solve()
{
	int n;
	cin >> n;
	vector<Type> V(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> V[i].f >> V[i].s.f;
		V[i].s.s = i + 1;
	}
	sort(V.begin(), V.end(), cmp);
	for(auto x:V)
		cout << x.s.s << '\n';
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

Measured memory_bytes: 256
using System;
using System.Linq;
class program{
  static void Main(){
    int a = int.Parse(Console.ReadLine());
    a %= 10;
    if(a==2||a==4||a==5||a==7||a==9)Console.Write("hon");
    else if(a==3)Console.Write("bon");
    else Console.Write("pon");
  }
}

Measured memory_bytes: 27432
from collections import deque
def bfs(G,s,N):
    dist=[[-1]*N for i in range(3)]
    d=deque()
    dist[0][s]=0
    d.append((0,s))
    while(len(d)!=0):
        p,v=d.popleft()
        for np,nv in G[p][v]:
            if(dist[np][nv]!=-1):
                continue
            dist[np][nv]=dist[p][v]+1
            d.append((np,nv))
    return dist

N,M=map(int,input().split())
G=[[[] for i in range(N)] for i in range(3)]
for i in range(M):
    u,v=map(lambda x:int(x)-1,input().split())
    G[0][u].append((1,v))
    G[1][u].append((2,v))
    G[2][u].append((0,v))
S,T=map(lambda x:int(x)-1,input().split())
dist=bfs(G,S,N)
ans=dist[0][T]
print(ans//3 if ans!=-1 else ans)

Measured memory_bytes: 91832
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
ll t,n,z,x,s;
int main()
{
    string a,b,c;
    cin>>a>>b;
    cin>>z>>x;
    cin>>c;
    if(c==b)x--;
    else if(c==a)z--;
    cout<<z<<" "<<x<<endl;

}


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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> P(4);
    vector<ll> T(4);
    FOR(i, 0, 4){
        cin >> P.at(i);
    }
    FOR(i, 0, 4){
        cin >> T.at(i);
    }

    ll min_price = inf;
    FOR(i, 0, N/T[0]+2){
        FOR(j, 0, N/T[1]+2){
            FOR(k, 0, N/T[2]+2){
                FOR(l, 0, N/T[3]+2){
                    ll num = T[0]*i + T[1]*j + T[2]*k + T[3]*l;
                    if(num>=N){
                        ll price = P[0]*i + P[1]*j + P[2]*k + P[3]*l;
                        chmin(min_price, price);
                    }
                }
            }
        }
    }
    p(min_price);
    
    return 0;
}


Measured memory_bytes: 3208
#include <stdio.h>
int main(void)
{
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    int aa,bb;
    if((x-a)>=0)
      aa=x-a;
    else
      aa=a-x;
    if((x-b)>=0)
      bb=x-b;
    else
      bb=b-x;
    if(aa>bb)
      printf("B");
    else if(aa<bb)
      printf("A");
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
//#include<string>
//#include<set>
//#include<vector>
//#include<iomanip>
using namespace std;
int main(){

    int n;
    cin>>n;
    int x,m=0,k=0,in;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x>=m){k=m;m=x;in=i;}
        else if(x>=k){k=x;}
    }
    for(int i=0;i<n;i++){
        if(i==in){cout<<k;}
        if(i!=in){cout<<m;}
        if(i!=n-1){cout<<endl;}
    }
    return 0;
}


Measured memory_bytes: 3524
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a%b)
N,M = map(int,input().split())
l = gcd(N,M)
S,T = input(),input()
OK = True
for i in range(l):
    ns = i*(N//l)
    nt = i*(M//l)
    if not S[ns]==T[nt]:
        OK = False
print((N*M)//l if OK else -1)

Measured memory_bytes: 40944
import itertools
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = [sorted(input()) for i in range(n)]
l = []
for i in a:
    l.append("".join(i))

ans = 0
dic = {}

for i in range(n):
    if l[i] in dic:
        dic[l[i]] +=1
    else:
        dic[l[i]] =1

for i in dic.values():
    if i>=2:
        ans += combinations_count(i, 2)
print(ans)

Measured memory_bytes: 40812
#include <iostream>
#include <cstdio>
#include <algorithm>

#define ABS(X) ((X) < 0 ? (X) * -1 : (X))
#define MIN(X, Y) (X < Y ? X : Y)

using namespace std;

int n;
long long a[200005];
long long num[200005];
long long d[200005];
long long sum[200005] = {};
long long ans = 1ll << 60;


int main()
{

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    for (int i = 0; i < n; i++) {
        num[i] = i + 1;
    }

    
    for (int i = 0; i < n; i++) {
        d[i] = a[i] - num[i];
    }
    
    sort(d, d + n);
    for (int i = 0; i < n; i++) {
        sum[i + 1] = sum[i] + d[i];
    }

    for (int i = 0; i < n; i++) {
        ans = MIN(ans, ABS(sum[i] - (i * d[i])) + ABS(sum[n] - sum[i] - (n - i) * d[i]));
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main() {
  int x,a,b;
  cin>>x>>a>>b;
  if(b-a<=0) cout<<"delicious"<<endl;
  else if(b-a>0 && b-a<=x) cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,a,k;
  scanf("%d %d",&n,&m);
  int cnt[30]={};
  for(int i=0;i<n;i++){
    scanf("%d",&k);
    for(int j=0;j<k;j++){
      scanf("%d",&a);
      cnt[a-1]++;
    }
  }
  int anw=0;
  for(int i=0;i<m;i++){
    if(cnt[i] == n){
      anw++;
    }
  }
  printf("%d",anw);
}

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

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

	{
		int _;
		cin >> _;
	}

	string s;
	vector<vector<int>> a;

	cin >> s;
	int state = 0, len = 0;
	vector<int> b;

	s += "000";

	for (char x : s) {
		if (x == '0') {
			if (state == 0) {
				state = 0;
				len = 0;
				b.clear();
			} else if (state == 1) {
				state = 0;
				len = 0;
				a.push_back(b);
				b.clear();
			} else if (state == 2) {
				state = 1;
				b.push_back(len);
				len = 0;
			}
		} else {
			if (state == 0) {
				state = 2;
				len = 1;
			} else if (state == 1) {
				state = 2;
				len = 1;
			} else if (state == 2) {
				len++;
			}
		}
	}

	int sol = 0;

	for (auto b : a) {
		
		/*
		for (int x : b) {
			cerr << x << ' ';
		}
		cerr << '\n';
		*/

		/// 20 11111011110101100111

		vector<int> nope(b.size());
		vector<int> desno(b.size());
		vector<int> levo(b.size());

		nope[0] = 0;
		levo[0] = b[0];
		desno[0] = 0;

		for (size_t i=1; i<b.size(); i++) {
			nope[i] = max(nope[i-1], max(levo[i-1], desno[i-1] + b[i]));
			if (b[i] == 1) {
				levo[i] = nope[i-1] + b[i];
				desno[i] = nope[i-1];
			} else {
				desno[i] = max(nope[i-1], max(levo[i-1], b[i] - 1 + desno[i-1]));
				levo[i] = max(nope[i-1] + b[i], levo[i-1] + b[i] - 1);
			}

			// cerr << nope[i] << ' ' << levo[i] << ' ' << desno[i] << '\n';
		}

		sol += nope[b.size() - 1];
	}

	cout << sol;
}

Measured memory_bytes: 7316
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            SortedDictionary<int,int> dic = new SortedDictionary<int, int>();
            for (int i = 0; i < N; i++)
            {
                dic.Add(r[i],i + 1);
            }

            Console.WriteLine(string.Join(" ",dic.Select(x => x.Value)));
        }

    }
}

Measured memory_bytes: 33532
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 998244353, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n, k;
	cin >> n >> k;
	vector<int> ls(k), rs(k);
	for(int i = 0; i < k; i++) {
		cin >> ls[i] >> rs[i];
		rs[i]++;
	}

	vector<ll> dp(n);
	dp[0] = 1;
	ll sm = 0;
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < k; j++) {
			{
				int cr = i - ls[j];
				if(cr >= 0) sm = (sm + dp[cr]) % MOD;
			}
			{
				int cr = i - rs[j];
				if(cr >= 0) sm = (MOD + sm - dp[cr]) % MOD;
			}
		}
		dp[i] = sm;
	}
	debug(dp);
	cout << dp.back() << '\n';

}



Measured memory_bytes: 4808
N=int(input())
A=[int(x) for x in input().split()]
B=[]
cou=0
for i in A:
  if i%2==0:
    B.append(i)
for i in B:
  if i%3!=0 and i%5!=0:
    cou+=1
if cou==0:
  print ('APPROVED')
else:
  print ('DENIED')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
int n,m,a,b;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>a>>b;
	cout<<(n-a)*(m-b);
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

typedef long long llong;

const int INF = 2e9 + 999;
const llong LINF = 2e18 + 999;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// Atcoder 2018

// Code below

int n;

llong H;

vector<pair<llong, llong> > arr;

void inp() {
    cin >> n >> H;
    arr.resize(n);
    for (auto & x : arr) {
        cin >> x.se >> x.fi;
    }
}

void solve() {
    llong mx = -1;
    int id = -1;
    for (int i = 0; i < n; ++i) {
        if (arr[i].se >= mx) {
            mx = arr[i].se;
            id = i;
        }
    }
    llong ans = 0;
    llong total = 0;
    sort(rall(arr));
    for (int i = 0; (total < H && i < n); ++i) {
        if (arr[i].fi > mx) {
            total += arr[i].fi;
            ++ans;
        }
    }
    if (total >= H) {
        cout << ans;
        return;
    }
    ans += (H - total + mx - 1) / mx;
    cout << ans;
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("palindrome.in", "r", stdin);
            freopen("palindrome.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
    cout << endl;
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


Measured memory_bytes: 1792
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <memory.h>

// pi = atan(1)*4;

#define INTMAX 2100000000
const int Mod = 100000007;

using namespace std;

long long int memo[100001];
int main(void)
{
	int n, t;
	vector <int> a, b, c;
	long long int res = 0;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> t;
		a.push_back(t);
	}
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		b.push_back(t);
	}
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		c.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	
	for (int i = 0; i < n; i++)
	{
		long long int x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		long long int y = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
		//cout << x << ' ' << y << endl;
		res += x*(n - y);
	}

	cout << res << endl;
	return 0;
}

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

def accmulate(arr):
    global cs
    N = len(arr)
    cs = [0]*(N+1)
    for i in range(N):
        cs[i+1] = cs[i] + arr[i]

# [l,r)
def query(l,r):
    return cs[r] - cs[l]

A = sorted(A)
accmulate(A)

ans = N

for i in range(N-1,0,-1):
    if not A[i] <= 2*query(0,i):
        ans -= i
        break

print(ans)

Measured memory_bytes: 14320
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);


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

  int n;
  cin >> n;

  ll ans_t = 1;
  ll ans_a = 1;

  rep(i, n) {
    ll t, a; cin >> t >> a;
    ll count = max((ans_t + t - 1) / t, (ans_a + a - 1) / a);
    ans_t = t * count;
    ans_a = a * count;
  }

  cout << ans_t + ans_a << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
int main(void){
    int a,b,c,x;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&x);


    int i,j,k,y,z,count=0;
    
    for(i=0;i<=a;i++){
        y = x - i * 500;
        if(y<0)continue;
        for(j=0;j<=b;j++){
            z = y - j * 100;
            if(z<0)continue;
            if(z<=c*50){
                count ++;
            }
        }
    }
    printf("%d",count);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){

    int N,W;
    cin >> N >> W;
    vi w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    
    vvl dp(N+1,vl(W+1,0));
    
    rep(i,N){
        rep(j,W+1){
            dp[i+1][j] = dp[i][j];
            if(j-w[i] >= 0) chmax(dp[i+1][j],dp[i][j-w[i]]+(ll)v[i]);
        }
    }
    
    cout << dp[N][W] << endl;
    
    

    return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int h, w, n;
    cin >> h >> w >> n;
    if(h > w) swap(h, w);
    cout << (n+w-1)/w << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long,long long>
#define ppp pair<long long, pair<long long,long long> >
#define f first	
#define s second
#define pd pair<double,long long>
void solveTestCase() {
	ll n,i,j,k,l;
	cin>>n;
	ll ans=0;
	for (i=1;i<=n;i++) {
		ll op;
		if (n%i==0)
			op=(n/i)-1;
		else
			op=(n/i);
		ans+=op;
	}
	cout<<ans<<'\n';
}
int main() {
	ll t,n,i,j,k,l,m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll p;
	t=1;
	//cin>>t;
	for (ll T=1;T<=t;T++) {
		solveTestCase();
	}
	return 0;
}

Measured memory_bytes: 3688
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int n, o = 0, e = 0;
	cin >> n;
	while (n--)
	{
		int p; cin >> p;
		(p&1 ? o : e)++;
	}
	int ans = pow(3, o+e) - pow(2, e);
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[])throws Exception{
    // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    // n = Integer.parseInt(br.readLine());
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int B[] = new int[n];
    int max = 0;
    StringBuilder builder = new StringBuilder();
    // String s[] = br.readLine().split("\\s+");
    for(int i = 0; i<n; i++){
      // A[i] = Integer.parseInt(s[i]);
      A[i] = sc.nextInt();
      max=Math.max(max,A[i]);
    }
    sort(A,B,max);
    // for(int i = 0; i<n; i++){
    //   if(i>0)System.out.print(" ");
    //   System.out.print(B[i]);
    // }
    // System.out.println();
    builder.append(B[0]);
    for (int i = 1; i < n; i++) {
        builder.append(' ').append(B[i]);
    }
    System.out.println(builder);

  }
  static void sort(int A[] , int B[] , int max){
    int C[] = new int[max+1];
    for(int i = 0; i<A.length; i++){
      C[A[i]]++;
    }
    for(int i = 1; i<=max; i++){
      C[i] += C[i-1];
    }
    for(int i = A.length-1; i>-1; i--){
      B[C[A[i]]-1] =A[i];
      C[A[i]]--;
    }
  }
}


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

int main(){
  int a[3][3];
  bool m[3][3];
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> a[i][j];
      m[i][j] = false;
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int b;
    cin >> b;
    for (int i = 0; i < 3; i++)
    {
      for (int j = 0; j < 3; j++)
      {
        if(b==a[i][j]) m[i][j] = true;
      }
    }
  }
  bool flg = false;
  for (int i = 0; i < 3; i++)
  {
    flg = flg || (m[i][0]&&m[i][1]&&m[i][2]);
  }
  for (int i = 0; i < 3; i++)
  {
    flg = flg || (m[0][i]&&m[1][i]&&m[2][i]);
  }
  flg = flg || (m[0][0]&&m[1][1]&&m[2][2]);
  flg = flg || (m[0][2]&&m[1][1]&&m[2][0]);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int k,n;
    cin >> k >> n ;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    ll ans = a[n-1] - a[0];
    for(int i=1;i<n;i++){
        ll dis = k - (a[i] - a[i-1]);
        chmin(ans,dis);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
#include<map>
#include<time.h>
using namespace std;
const int N = 3e5 + 10;
using ll = long long;
const int INF = 2e9 + 10;
using pii = pair<int, int>;
using vi = vector<int>;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mp make_pair 
#define pb push_back
#define clr(x, v) memset(x, v, sizeof (x))
#define all(x) x.begin(), x.end()
#define fi first
#define se second
int n, k;
int main() {
    while (cin >> n >> k) {
        long long c = n / k;
        long long res = c * c * c;
        if (k % 2 == 0 && n >= k / 2) {
            c = (n - k / 2) / k + 1;
            res += c * c * c;
        }
        cout << res << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<array>

using namespace std;
#define int long long int

int mod=1e9+7;
const int N=51;

array<array<int,N>,N> C;
array<array<int,N>,N> Mul(array<array<int,N>,N> &A,array<array<int,N>,N> &B)
{
    int c,d;
    for(int i=0;i<N;i++)
    C[i].fill(0);

    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            c=0;
            for(int k=0;k<N;k++)
            {
                c+=(A[i][k]*B[k][j]);
                if(c>=mod)
                    c%=mod;
            }
            C[i][j]=c;
        }
    }
    // for(int i=0;i<N;i++)
    //     for(int j=0;j<N;j++)
    //         if(C[i][j]>=mod)
    //             C[i][j]%=mod;
    return C;
}
array<array<int,N>,N> fp(array<array<int,N>,N> &a,int b)
{
        array<array<int,N>,N> res;
        for(int i=0;i<N;i++)
        {
            res[i].fill(0);
            res[i][i]=1;
        }

        while(b>0)
        {
            if(b&1)
            {
                res=Mul(res,a);
            }
            a=Mul(a,a);
            b>>=1;
        }
       return res;
}


signed main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n,k;
cin>>n>>k;

array<array<int,N>,N> v;
for(int i=0;i<N;i++)
v[i].fill(0);

for(int i=0;i<n;i++)
{
    for(int j=0;j<n;j++)
        cin>>v[i][j];
}

auto r=fp(v,k);

int ans=0;
for(int i=0;i<n;i++)
{
    for(int j=0;j<n;j++)
    {
        ans+=r[i][j];
        if(ans>=mod)
            ans-=mod;
    }
}

cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int n,k;
	cin>>n>>k;
	long int i,c,a[n],s=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		
	}
	for(i=0;i<n;i++)
	{
		c=abs(k-a[i]);
		if(c<=a[i])
		{
			s=s+c;
		}
		else
		{
			s=s+a[i];
		}
	}
	cout<<s*2<<endl;
}

Measured memory_bytes: 3556
def resolve():
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        if i%2 == 1:
            count = 0
            for j in range(1, i+1):
                if i%j == 0:
                    count += 1
            if count == 8:
                ans += 1
    print(ans)
resolve()

Measured memory_bytes: 3060
def one_stroke_path(N: int, M: int, edges: list) -> int:
    g = [[] for _ in range(N)]
    for u, v in edges:
        g[u-1].append(v-1)
        g[v-1].append(u-1)

    visited = [False] * N
    visited[0] = True

    def dfs(current: int, visited_num: int) -> int:
        if not visited[current] and visited_num + 1 == N:
            return 1

        visited[current] = True

        total = sum(dfs(to, visited_num + 1)
                    for to in g[current] if not visited[to])

        visited[current] = False

        return total

    return dfs(0, 0)


if __name__ == "__main__":
    M = 0
    N, M = map(int, input().split())
    edges = [tuple(int(s) for s in input().split()) for _ in range(M)]
    ans = one_stroke_path(N, M, edges)
    print(ans)


Measured memory_bytes: 3064
#include<iostream> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){cout<<"1407 38"<<endl;int t=2;rep(i,38){cout<<1<<" ";rep(j,37){cout<<t<<" ";t++;}cout<<endl;}rep(i,37){rep(j,37){cout<<i+2<<" ";rep(l,37)cout<<2+37*(l+1)+(j+i*l)%37<<" ";cout<<endl;}}}

Measured memory_bytes: 3428
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;
typedef pair<int,double> Pa;

struct E{
	int to, r, l;
};

int w, h;
char brd[60][10];
bool saw[60][10];
int num[60][10];
double g[1000];
int r[1000], l[1000];
vector<int> ed[1000];

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

Pa f(int c, double G, int p){
	Pa ret = Pa(4,g[p]);
	rep(i,ed[p].size()){
		Pa tmp = f(0,0.0,ed[p][i]);
		ret.first += tmp.first;
		ret.second += tmp.second;
	}
	return ret;
}

void solve(){
	rep(i,1000) ed[i].clear();
	rep(i,1000) g[i] = 0.0;
	rep(i,h) rep(j,w) saw[i][j] = false;
	rep(i,h) rep(j,w) num[i][j] = INF;
	int cnt = 0;
	rep(i,h) rep(j,w) cin >> brd[i][j];
	rep(i,h){
		rep(j,w){
			if(saw[i][j]) continue;
			if(brd[i][j] == '.') continue;
			queue<P> que;
			que.push(P(i,j));
			while(true){
				if(que.size() == 0) break;
				P q = que.front();
				que.pop();
				if(saw[q.first][q.second]) continue;
				g[cnt] += q.second+0.5;
				num[q.first][q.second] = cnt;
				saw[q.first][q.second] = true;

				rep(k,4){
					if(0>q.first+dx[k]||q.first+dx[k]>=h||0>q.second+dy[k]||q.second+dy[k]>=w) continue;
					if(brd[q.first+dx[k]][q.second+dy[k]] != brd[q.first][q.second]) continue;
					if(saw[q.first+dx[k]][q.second+dy[k]]) continue;
					que.push(P(q.first+dx[k],q.second+dy[k]));
				}
			}
			cnt++;
		}
	}
	rep(i,h) rep(j,w) saw[i][j] = false;
	cnt = 0;
	rep(i,h){
		rep(j,w){
			if(saw[i][j]) continue;
			if(brd[i][j] == '.') continue;
			r[cnt] = INF, l[cnt] = -1;
			int to = -1;
			queue<P> que;
			que.push(P(i,j));
			while(true){
				if(que.size() == 0) break;
				P q = que.front();
				saw[q.first][q.second] = true;
				que.pop();
				if(q.first == h-1){
					r[cnt] = min(r[cnt],q.second);
					l[cnt] = max(l[cnt],q.second+1);
				} else{
					if(brd[q.first+1][q.second] != '.' && brd[q.first+1][q.second] != brd[q.first][q.second]){
						r[cnt] = min(r[cnt],q.second);
						l[cnt] = max(l[cnt],q.second+1);
						to = num[q.first+1][q.second];
					}
				}

				rep(k,4){
					if(0>q.first+dx[k]||q.first+dx[k]>=h||0>q.second+dy[k]||q.second+dy[k]>=w) continue;
					if(brd[q.first+dx[k]][q.second+dy[k]] != brd[q.first][q.second]) continue;
					if(saw[q.first+dx[k]][q.second+dy[k]]) continue;
					que.push(P(q.first+dx[k],q.second+dy[k]));
				}
			}
			if(to != -1) ed[to].push_back(cnt);
			cnt++;
		}
	}
	
	rep(i,cnt){
		Pa x = f(0,0.0,i);
		x.second /= x.first;
		if(r[i]+EPS > x.second || x.second+EPS > l[i]){
			puts("UNSTABLE");
			return;
		}
	}
	puts("STABLE");
}

int main(){
	while(cin >> w >> h){
		if(w==0&&h==0) break;
		solve();
	}
}

Measured memory_bytes: 1220