akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //数列の数
		int k = stdIn.nextInt(); //個数
		int s = stdIn.nextInt(); //条件
		
		int[] a = new int[n];
		Arrays.fill(a, s);
		
		if(s == (int)1e9) {
			for(int i = 0; i < k; i++) {
				System.out.print(s+" ");
			}
			for(int i = 0; i < n-k; i++) {
				System.out.print(s-1+" ");
			}
			
		}else {
			
			for(int i = 0; i < k; i++) {
				System.out.print(s+" ");
			}
			for(int i = 0; i < n-k; i++) {
				System.out.print(s+1+" ");
			}
			
			
			
		}
		
		
		
	}

}


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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

int gcd(int a, int b)
{
	return !b ? a : gcd(b, a % b);
}

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

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				int z=gcd(i,j);
				z=gcd(z,k);
				ans+=z;
			}
		}
	}
	cout<<ans<<endl;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


Measured memory_bytes: 3504
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <bitset>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 101;

int N, cnt;
LL a[MAXN], ans, sum;
bitset<MAXN> mul[MAXN], vis;

void test() {
    LL all = 0;
    bitset<MAXN> take = vis;
    for (int i = 1; i <= N; i++) {
        if (take[i]) {
            all += a[i];
        }
        else if (i > 33) {
            if (i * 2 > N) {
                if (a[i] < 0) {
                    all += a[i];
                }
            }
            else {
                if (take[i * 2]) {
                    if (a[i] < 0) {
                        all += a[i];
                    }
                }
                else {
                    if (a[i] < 0 and a[i] + a[i * 2] < 0) {
                        all += a[i];
                        take.set(i * 2);
                    }
                }
            }
        }
    }
    ans = max(ans, sum - all);
}

void dfs(int x) {
    // cout << "DFS " << x << "\n";
    if (x > 33 || x > N) {
        cnt++;
        test();
        return;
    }

    dfs(x + 1);
    if (!vis[x] && a[x] < 0) {
        bitset<MAXN> temp = vis;
        vis |= mul[x];
        dfs(x + 1);
        vis = temp;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        sum += a[i];
    }

    for (int i = 1; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j += i) {
            mul[i].set(j);
        }
    }

    ans = sum;
    dfs(1);
    // cout << cnt << "\n";

    cout << ans << "\n";
}


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


def solve(N: int, a: "List[int]"):
    from functools import reduce
    assert N % 2 == 0
    b = reduce(lambda a, b: a ^ b, a)
    return [aa ^ b for aa in a]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()



Measured memory_bytes: 42896
N,M = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(M)]
adj = [[] for _ in range(N)]
for a,b in R:
  adj[a-1].append(b-1)
  adj[b-1].append(a-1)
for i in range(N):
  print(len(adj[i]))

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define MAX_N 100005

using namespace std;

int n,ans=0;
int a[MAX_N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=0;i<=n;i++) ans+=abs(a[i]-a[i+1]);
	for(int i=1;i<=n;i++)
	{
		if((a[i-1]<a[i])^(a[i+1]<a[i])) printf("%d\n",ans);
		else printf("%d\n",ans-(min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))<<1));
	}
	return 0;
}


Measured memory_bytes: 1664
s = str(input())
z = 'YES'
while len(s) != 0:
    if s[:11] == 'dreameraser':
        s = s[11:]
    elif s[:10] == 'dreamerase':
        s = s[10:]
    elif s[:13] == 'dreamereraser':
        s = s[13:]
    elif s[:12] == 'dreamererase':
        s = s[12:]
    elif s[:7] == 'dreamer':
        s = s[7:]
    elif s[:5] == 'dream':
        s = s[5:]
    elif s[:6] == 'eraser':
        s = s[6:]
    elif s[:5] == 'erase':
        s = s[5:]
    else:
        z = 'NO'
        break
print(z)

Measured memory_bytes: 8980
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<ll, ll> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll sum(vector<ll> &a){
	ll ans = 0;
	for(auto &x : a)
		ans += x;
	return ans;
}

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, m;
	cin >> n >> m;
	
	vector<ll> a(n);
	
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	sort(a.begin(), a.end());
	
	vector<pii> ops;
	
	for(int i = 0; i < m; i++){
		ll b, c;
		cin >> b >> c;
		ops.push_back({c, b});
	}
	
	sort(ops.rbegin(), ops.rend());
	
	int lo = 0;
	for(int i = 0; i < m && lo < n; i++){
		
		for(ll j = 0; j < ops[i].second && lo < n; j++){
			if(ops[i].first > a[lo]){
				a[lo] = ops[i].first;
				lo++;
			}
			else lo++, j--;
		}
		
	}
	
	cout << sum(a) << endl;

	return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,a[200000];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans[200000]={};
    for(int i=0;i<30;i++){
        int cnt=0;
        for(int j=0;j<n;j++)
            if(a[j]&(1ll<<i))
                cnt++;
        for(int j=0;j<n;j++)
            if(a[j]&(1ll<<i)){
                if(cnt%2==0)
                    ans[j]|=(1ll<<i);
            }else
                if(cnt%2==1)
                    ans[j]|=(1ll<<i);
    }
    for(int i=0;i<n;i++)
        cout<<ans[i]<<(i+1==n?'\n':' ');
}

Measured memory_bytes: 6704
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+100;
ll a[maxn];
void solve()
{
	int n;scd(n);
	ll ans=INF;
	ll sum=0;
	rep1(i,n){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	ll now=0;
	rep1(i,n-1){
		now+=a[i];
		ans=min(ans,abs(sum-2*now));
	}ac;
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n;char a[N];long long ans,cnt;
int main(){
	ios::sync_with_stdio(false);
	cin>>a+1;n=strlen(a+1);
	for(int i=1;i<=n;++i){
		if(a[i]=='B')++cnt;
		else ans+=cnt;
	}cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
import kotlin.math.roundToInt

fun main() {
    nextInt()
    val arr = nextIntList()
    val n = arr.average().roundToInt()
    println(arr.map {
        val a = (it - n)
        a * a
    }.sum())
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 38096
import java.util.*;

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


		char[] c = new char[s.length()];

		for(int i = 0; i < s.length(); i ++){
			c[i] = s.charAt(i);
		}

		int[] a = new int[s.length()];
		int sum = 0;

		for(int i = 0; i < s.length(); i ++){
			a[i] = Character.getNumericValue(c[i]);
		}

		for(int i = 0; i < s.length(); i ++){
			sum += a[i];
		}
		if(sum % 9 == 0)
		System.out.println("Yes");
		else
		System.out.println("No");

	}
}

Measured memory_bytes: 41372
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double lxd;
typedef vector<ll> vll ;
 
#define INF (ll)1e11 + 7 
#define mem(dp,a) memset(dp,a,sizeof dp)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) ;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define f(i,n) for (ll i=0;i<n;i++)
#define fo(i,n,x) for (ll i=x;i<=n  ;i++)
#define mp(a,b) push_back(make_pair(a,b))
#define pb(x) push_back(x)
#define make_graph(a,b) adj[a].pb(b) ; adj[b].pb(a);
#define tr(c,it) for(((c).begin())it=(c).begin();it!=(c).end();it++)
#define test ll t; cin>>t; label: while(t--)
#define fls fflush(stdout)
#define F first
#define S second

vll arr(100001);
vll dp(100001,-1) ;
ll k ;
ll fn(ll id){
    if(id == 0)return 0 ;
    
    if(dp[id] != -1)return dp[id] ;
    
    ll x = INF ;
    
    fo(i,min(id,k),1){
        x = min(x, abs(arr[id] - arr[id - i]) + fn(id - i)) ;
    }
    
    return dp[id] = x ;
}

main(){
    ll n ; 
    cin>>n>>k ; 
    f(i,n)cin>>arr[i] ;
    cout<<fn(n-1) ;
}

Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
/*
int main(){
    int n;
	cin >> n;
    if(n >= 0 && n < 100){
		cout << "00" << endl;
    } else if(n >= 100 && n <= 5000){
		if((int)n/100<10){
			cout << "0" << n/100 << endl;
		} else{
			cout << n/100 << endl;
		}
    } else if(n >= 6000 && n<=30000){
		cout << (n/1000)+50 << endl;
    } else if(n >= 35000 && n<=70000){
	    cout <<  (n/1000-30)/5+80 << endl;
    } else if(n > 70000){
		cout << 89 << endl;
    }
	
    return 0;
}*/

int main(){
	int n;
	int hoge[100];
	int sum=0;
	cin >> n;
	for(int i=0; i<n; ++i){
		cin >> hoge[i];
	}

	for(int i=0; i<n-1; ++i){
		int min_index = i;
		for(int j=i+1; j<n ;++j){
			if(hoge[min_index]> hoge[j]){
				min_index = j;
			}
		}
		if(min_index != i){
			int tmp = hoge[i];
			hoge[i] = hoge[min_index];
			hoge[min_index] = tmp;
			++sum;
		}
	}
	for(int i=0; i<n; ++i){
		if(i+1 != n)
			cout << hoge[i] << " ";
		else 
			cout << hoge[i] << endl;
	}
	cout << sum << endl;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(Math.min(n * a, b));

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 22996
#include <stdio.h>
#define MAX 100
#define INF (1<<22)

int G[MAX][MAX];

void spanning(int);

int main(){
  int n,i,j,ans[MAX],sowa = 2000,a;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      scanf("%d",&a);
      if(a <= -1) G[i][j] = INF;
      else G[i][j] = a;
    }
  }

  spanning(n);
  
  return 0;
}

void spanning(int n){
  int color[MAX],parent[MAX],weight[MAX],i,min,sum = 0,hen;

  for(i = 0;i < n;i++){
    color[i] = 0;
    parent[i] = -1;
    weight[i] = INF;
  }
  weight[0] = 0;
  

  while(1){
    min = INF;
    hen = -1;
    for(i = 0;i < n;i++){
      if(color[i] != 2 && weight[i] < min){
	min = weight[i];
	hen = i;
      }
    }
    if(hen <= -1) break;
    color[hen] = 2;
    for(i = 0;i < n;i++){
      if(color[i] != 2 && G[hen][i] != INF){
	if(weight[i] > G[hen][i]){
	  parent[i] = hen;
	  color[i] = 1;
	  weight[i] = G[hen][i];
	}
      }
    }
  }
  for(i = 0;i < n;i++) if(parent[i] != -1) sum += G[i][parent[i]];
  printf("%d\n",sum);
}



Measured memory_bytes: 2104
import java.util.*;
public class Main {
	
	static int pos=0;
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int H=in.nextInt(),W=in.nextInt();
		int field[][]=new int[H][W],max=0;
		
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				field[i][j]=Integer.parseInt(in.next())==1 ? 0 : 1;
				if(i>0 && field[i][j]>0)field[i][j]=field[i-1][j]+1;
			}
		}
		
		for(int i=0;i<H;i++) {
			Stack<Rect> stk=new Stack<>();
			for(int j=0;j<W;j++) {
				if(stk.isEmpty() || field[i][j]>stk.peek().h) {
					stk.push(new Rect(field[i][j],j));
				}
				else if(field[i][j]<stk.peek().h) {
					max=Math.max(max,createRect(stk,field[i][j],j));
					stk.push(new Rect(field[i][j],pos));
				}
			}
			max=Math.max(max, createRect(stk,0,W));
		}
		
		System.out.println(max);
	}
	
	static int createRect(Stack<Rect> stk,int h,int i) {
		int max=0;
		while(!stk.isEmpty()) {
			Rect crect=stk.peek();
			if(crect.h<h)break;
			
			max=Math.max(max, crect.h*(i-crect.i));
			pos=crect.i;
			stk.pop();
		}
		return max;
	}
	
}

class Rect{
	int h,i;
	Rect(int a,int b){
		h=a;i=b;
	}
}



Measured memory_bytes: 181700
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[n];
  int dp[n];
  for(int i = 0 ; i <n ; i++){
    cin >> h[i] ;
    dp[i] = INT_MAX ;
  }
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2 ; 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-1] << endl ;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<char> vec1(n);
    vector<char> vec2(n);
    for (int i=0; i<n; i++){
        if(i%2==0) {
            vec1[i] = '1';
            vec2[i] = '0';
        }
        else {
            vec1[i] = '0';
            vec2[i] = '1';
        }
    }

    int cnt1=0, cnt2=0;

    for (int i=0; i<n; i++){
        if(s[i] != vec1[i]) cnt1++;
        if(s[i] != vec2[i]) cnt2++;
    }
    out(min(cnt1, cnt2));
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
int bit[200020];
int b[200010],h[200010];
int n;

void upd(int i,int v)
{
    while(i<=n)
    {
         bit[i] = max(bit[i],v);
         i+=i&-i;
    }
}
int qry(int i)
{
    int s=0;
    while(i)
    {
          s = max(bit[i],s);
           i-=i&-i;
    }
    return s;
}


int32_t main()
{
   cin >> n;
  
   for(int i=0;i<n;i++)
   {
       cin >> h[i];
   }
   for(int i=0;i<n;i++)
   {
       cin >> b[i];
   }
   int ans=0;
   int best=0;
   for(int i=0;i<n;i++)
   {
         ans = qry(h[i])+b[i];
         best = max(best,ans);
         upd(h[i],ans);
   }
   cout<<best<<"\n";


}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
//g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG caddi/c.cpp
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define scint(x) scanf("%d", &x)
#define scll(x) scanf("%lld", &x)

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll N, P;
    cin >> N;
    cin >> P;
    ll ans = 1;

    if(N == 1){
        cout << P << "\n";
        return 0;
    }else{
        double a = 1.0/N;
        double lim = pow(P, a);
        ll i;
        for(i = (ll)(lim); i >= 2; i--){
            // cout << (i ^ N) << "\n";
            // cout << P % (i ^ N) << "\n";
            // cout << (i ^ 4) << "\n";
            ll den = pow(i, N);
            lldiv_t k = lldiv(P, den);
            if(k.rem == 0){
                ans *= i;
                P = P/den;
                // cout << P % ((i + 1)^N) << "\n";
            }
        }
    }

    cout << ans << "\n";
    
    return 0;
}

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

mod = 10 ** 9 + 7
f = [1]
for i in range(1,N+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    return f[n] * (pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod) % mod

for i in range(1,K+1):
    ans = (comb(N-K+1, i) * comb(K-1, i-1)) % mod
    ans %= mod
    if i > N-K+1:
        ans = 0
    print(ans)

Measured memory_bytes: 3444
using System;
using System.IO;
using System.Linq;
class E { static void Main() => new _K(); }
class _K
{
	int[] G => Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
	public const long Mod = 924844033;
	int N, K;
	long[,] comb;
	public _K()
	{
		var I = G;
		N = I[0]; K = I[1];
		var M = N / K + 10;
		comb = new long[M, M];
		for (var i = 0; i < M; i++) comb[i, 0] = 1;
		for (var i = 1; i < M; i++) for (var j = 1; j <= i; j++) comb[i, j] = (comb[i - 1, j] + comb[i - 1, j - 1]) % Mod;
		var p = Convolution(Pow(Chain(N / K), 2 * (K - N % K)), Pow(Chain(N / K + 1), 2 * (N % K)));
		var fact = new long[N + 1];
		fact[0] = 1;
		for (var i = 1; i <= N; i++) fact[i] = (i * fact[i - 1]) % Mod;
		long ans = 0, s = 1;
		for (var i = 0; i <= N; i++)
		{
			ans = (ans + s * fact[N - i] * p[i] % Mod) % Mod;
			s *= -1;
		}
		if (ans < 0) ans += Mod;
		Console.WriteLine(ans);
	}
	long[] Chain(int n)
	{
		var p = new long[N + 1];
		for (var k = 0; 2 * k <= n; k++) p[k] = comb[n - k, k];
		return p;
	}
	long[] Pow(long[] a, int n)
	{
		var p = new long[N + 1];
		p[0] = 1;
		var x = a;
		while (n > 0)
		{
			if ((n & 1) == 1) p = Convolution(p, x);
			n >>= 1;
			x = Convolution(x, x);
		}
		return p;
	}
	long[] Convolution(long[] a, long[] b)
	{
		var c = new long[N + 1];
		for (var i = 0; i <= N; i++)
			if (a[i] != 0)
				for (var j = 0; j <= N - i; j++)
					c[i + j] = (c[i + j] + a[i] * b[j] % Mod) % Mod;
		return c;
	}
}


Measured memory_bytes: 25816
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

void chmin(int &a, int b) { a = min(a, b); }

int INF = 1e+15;
int n, m;
int c[16];
int x[20000];
int dp[20001][256];

signed main() {
	int i, j, k;
	
	while (cin >> n >> m) {
		if (!n) break;
		rep(i, m) cin >> c[i];
		rep(i, n) cin >> x[i];
		
		rep(i, n + 1) rep(j, 256) dp[i][j] = INF;
		dp[0][128] = 0;
		
		rep(i, n) {
			rep(j, 256) {
				rep(k, m) {
					int y = j + c[k];
					if (y < 0) y = 0;
					if (y > 255) y = 255;
					chmin(dp[i + 1][y], dp[i][j] + (x[i] - y) * (x[i] - y));
				}
			}
		}
		
		int ans = INF;
		rep(i, 256) chmin(ans, dp[n][i]);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 43244
def ABC089D():
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(H)]
    Q = int(input())
    LR = [list(map(int, input().split())) for i in range(Q)]
    number_place = [[] for i in range(H * W)]
    for i in range(H):
        for j in range(W):
            number_place[A[i][j] - 1] = [i, j]
    d = [0 for i in range(H * W)]
    for i in range(D):
        d[i] = 0
    for i in range(D, H * W):
        past_y = number_place[i - D][0]
        past_x = number_place[i - D][1]
        now_y = number_place[i][0]
        now_x = number_place[i][1]
        d[i] = abs(now_x - past_x) + abs(now_y - past_y) + d[i - D]
    for i, j in LR:
        print(d[j - 1] - d[i - 1])
ABC089D()


Measured memory_bytes: 42308
n,k,*d=map(int,open(0).read().split())

for p in range(n,10**5):
    tmp=p
    d1=tmp%10

    while tmp>0 and d1 not in d:
        tmp//=10
        d1=tmp%10
    
    if tmp==0:
        print(p)
        exit(0)

Measured memory_bytes: 66832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC086C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var strlist = new List<string>();
            for (var i = 0; i < n; i++)
            {
                strlist.AddRange(Console.ReadLine().Split(' ').ToList());
            }

            var intlist = strlist.ConvertAll(int.Parse);
            var timelist = new List<int>() {0};
            var xlist = new List<int>() {0};
            var ylist = new List<int>() {0};
            for (var i = 0; i < intlist.Count; i++)
            {
                var assigner = i % 3;
                switch (assigner)
                {
                    case 0:
                        timelist.Add(intlist[i]);
                        break;
                    case 1:
                        xlist.Add(intlist[i]);
                        break;
                    case 2:
                        ylist.Add(intlist[i]);
                        break;
                }
            }

            var flag = true;
            for (int i = 0; i < n; i++)
            {
                int difft = timelist[i + 1] - timelist[i];
                int diffx = xlist[i + 1] - xlist[i];
                int diffy = ylist[i + 1] - ylist[i];
                diffx = Math.Abs(diffx);
                diffy = Math.Abs(diffy);

                if (diffx+diffy>difft||(diffx+diffy)%2!=difft%2)
                {
                    flag = false;
                    break;
                }

            }

            Console.WriteLine(flag ? "Yes" : "No");
            Console.ReadLine();

        }
    }
}


Measured memory_bytes: 36152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

template <class C>
struct SegmentTree {
    struct Node {
        Node operator+(const Node& o) const {
            return *this < o ? *this : o;
        }
        bool operator<(const Node& o) const {
            return C()(v, o.v);
        }
        int v, i;
    };
    SegmentTree(int n, Node o) : n(n) {
        for (m = 2; m < n; m *= 2);
        data = vector<Node>(m + n, o);
    }
    void construct() {
        int l = m + n;
        for (int k = m; k > 1; k /= 2) {
            l = (l + 1) / 2;
            for (int i = k / 2; i < l; i++) {
                data[i] = data[i * 2] + data[i * 2 + 1];
            }
        }
    }
    void update(int i, Node o) {
        for (data[i += m] = o; i /= 2, i > 0;) data[i] = data[i * 2] + data[i * 2 + 1];
    }
    vector<Node> data;
    int n, m;
};

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

    int n;
    cin >> n;

    SegmentTree<less<int>> st0(n * 2, { 1 << 30, 0 });
    SegmentTree<greater<int>> st1(n * 2, { 0, 0 });
    vector<int64_t> sum(n + 1);
    vector<int> a(n);

    int64_t s0 = 0;
    for (int i = 0; i < n; i++) {
        int j = i + st0.m;
        cin >> st0.data[j].v;
        st0.data[j].i = i;
        s0 += st0.data[j].v;
    }
    st0.construct();

    sum[0] = s0;
    for (int k = n; k < n * 2; k++) {
        cin >> a[k - n];
        int64_t d = a[k - n] - st0.data[1].v;
        if (d > 0) {
            s0 += d;
            st0.update(st0.data[1].i, { 1 << 30, 0 });
            st0.update(k, { a[k - n], k });
        }
        sum[k - n + 1] = s0;
    }

    int64_t s1 = 0;
    for (int i = 0; i < n; i++) {
        int j = i + st0.m;
        cin >> st1.data[j].v;
        st1.data[j].i = i;
        s1 += st1.data[j].v;
    }
    st1.construct();

    int64_t r = sum[n] - s1;
    for (int k = n * 2 - 1; k >= n; k--) {
        int64_t d = a[k - n] - st1.data[1].v;
        if (d < 0) {
            s1 += d;
            st1.update(st1.data[1].i, { 0, 0 });
            st1.update(k, { a[k - n], k });
        }
        r = max(r, sum[k - n] - s1);
    }

    cout << r << endl;

    return 0;
}

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

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define INIT(a) memset(a,0,sizeof(a))
#define pb push_back
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

struct edge{
  ll from,to,cost,cap,rev;
};

const ll INF = 1LL<<50;
const ll INF2 = 1LL<<60;
const ll V = 1000;
vector<edge> G[V];

void AddEdge(ll s,ll g,ll c,ll p){
  G[s].pb((edge){s,g,c,p,(ll)G[g].sz});
  G[g].pb((edge){g,s,-c,0,(ll)G[s].sz-1});
}

ll d[V];
ll h[V],pv[V],pe[V];
ll v;
bool use[V];

ll MinCostFlow(ll s,ll t,ll f){
  ll res = 0;
  fill(h,h+v,0);
  while(f>0){
    fill(d,d+v,INF2);
    memset(use,0,sizeof(use));
    d[s] = 0;

    while(true){
      int u = -1;
      rep(i,v){
	if(!use[i] && (u<0 || d[u] > d[i]))u = i;
      } 

      if(u<0 || d[u] == INF2)break;
      use[u] = true;

      rep(i,G[u].sz){
	edge &e = G[u][i];
	if(e.cap>0 && d[e.to] > d[u] + e.cost + h[u] - h[e.to]){
	  d[e.to] = d[u] + e.cost + h[u] - h[e.to];
	  pv[e.to] = u; pe[e.to] = i;
	}
      }	  
    }

    if(d[t]==INF2)return -1;
    rep(u,v)h[u] += d[u];

    ll x = f;
    for(int u=t;u!=s;u=pv[u])x = min(x,G[pv[u]][pe[u]].cap);
    f -= x;
    res += x*h[t];
    for(int u=t;u!=s;u=pv[u]){
      edge &e = G[pv[u]][pe[u]];
      e.cap -= x; G[u][e.rev].cap += x;
    }
  }
  return res;
}


ll dp[10][1<<16][10];

int main(){
  ll d,k,l;
  ll c[10][10];
  ll n,m,p;
  ll r[220][10], t[220][10];

  while(scanf("%lld%lld%lld",&d,&k,&l),d){
    rep(i,d)rep(j,k)scanf("%lld",&c[i][j]);
    scanf("%lld%lld%lld",&m,&n,&p);
    rep(i,m)rep(j,k)scanf("%lld",&r[i][j]);
    rep(i,p)rep(j,k)scanf("%lld",&t[i][j]);

    rep(i,d+1)rep(j,1<<(2*k))rep(x,l+1)dp[i][j][x] = INF;
    dp[0][0][0] = 0;

    rep(i,d)rep(j,1<<(2*k))rep(x,l+1){
      if(dp[i][j][x]==INF)continue;
      dp[i+1][j][0] = min(dp[i+1][j][0], dp[i][j][x]);
      
      if(x==l)continue;
      rep(y,k){
	if( ((j>>(2*y))&3) >= 2 )continue;
	ll& nxt2 = dp[i][j+(1<<(2*y))][x+1];
	nxt2 = min(nxt2, dp[i][j][x] + c[i][y]);
      }
    }

    v = p+m+3;
    rep(i,v)G[i].clear();

    rep(i,p)rep(j,m){
      int dif[10];
      rep(x,k)dif[x] = r[j][x] - t[i][x];
      if(*min_element(dif,dif+k)<0)continue;
      int need = 0;
      rep(x,k)need |= dif[x] << (2*x);
      if(dp[d][need][0] == INF)continue;
      AddEdge(i,p+1+j,dp[d][need][0],1);
    }
    rep(j,m){
      int need = 0;
      rep(x,k)need |= r[j][x] << (2*x);
      if(dp[d][need][0] == INF)continue;
      AddEdge(p,p+1+j,dp[d][need][0],1);
    }

    rep(i,p)AddEdge(v-2,i,0,1);
    AddEdge(v-2,p,0,INF);
    rep(j,m)AddEdge(p+1+j,v-1,0,1);

    cout << MinCostFlow(v-2,v-1,n) << endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll,pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e5) + 5;
const int MAX_V = 100005;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)


int n;
ll a[MAX_N]{};

int main() {
    cin >> n;
    REP(i,n){
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    int li = 1, ri = 3;
    ll ans = LLINF;
    for(int i = 2; i < n-1;i++){
        ll lsum = a[i], rsum = a[n]-a[i];
        ll p=a[li],q=lsum-a[li] ,r = a[ri]-a[i],s = rsum-a[ri]+a[i];
        while(li<i-1 && abs(lsum - a[li+1]*2) < abs(p-q)){
            li++;
            p = a[li];
            q = lsum - p;
        }
        while(ri<n-1 && abs(rsum - (a[ri+1]-a[i])*2)<abs(r-s)){
            ri++;
            r = a[ri]-a[i];
            s = rsum - r;
        }
        ll mx = max(max(p,q),max(r,s)), mn = min(min(p,q),min(r,s));
        ans = min(ans,mx-mn);

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


Measured memory_bytes: 1792
X, N = map(int, input().split())
pp = list(map(int, input().split()))
pp.sort()

if N == 0:
    print(X)
    exit()
if X not in pp:
    print(X)
    exit()

ans = X
diff = 0
while True:
    diff += 1
    ans = X - diff
    if ans not in pp:
        print(ans)
        break
    ans = X + diff
    if ans not in pp:
        print(ans)
        break

# left, right = 0, 0
# for i in range(N):
#     if i == N - 1:
#         left, right = , -1
#     if pp[i] == X:
#         cur = i
#         break
#     if pp[i] > X:
#         if i == 0:
#             left, right = -1, pp[i]
#         else:
#             left, right = pp[i - 1], pp[i]

#         break




Measured memory_bytes: 62012
#n dices from left to right

import collections
def ev(pi):
	return sum([1.0/pi * p for p in range(1, pi+1)])

n,k = map(int, raw_input().split(' '))
elems = map(int, raw_input().split(' '))
q = collections.deque([])
s = 0
r = -float('inf')
for pi in elems:
	v = ev(pi)
	q.append(v)
	s += v
	if len(q) == k+1:
		s -= q.popleft()
	if len(q) == k:
		r = max(r, s )

print r

Measured memory_bytes: 48416
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0)
        cout << "Even" << endl;
    else
        cout << "Odd" << endl;
    return 0;
}

Measured memory_bytes: 256
S = int(input())
# この四角形をつくる
sqrtS = int(S**0.5)
if sqrtS**2 < S:
    sqrtS+=1
# 約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

# こいつの約分で、選ぶ
diff = sqrtS**2-S
divs = sorted(make_divisors(diff))
n = len(divs)

x0,y0 = (0,0)
if n == 0:
    x1,y1 = (0,sqrtS)
    x2,y2 = (sqrtS,0)
else:
    x1,y1 = (divs[n//2-1],sqrtS)
    x2,y2 = (sqrtS, diff//divs[n//2-1])

print(x0,y0,x1,y1,x2,y2)

# S = sqrtS**2-x1*y2
# print(S)

Measured memory_bytes: 3188
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string S,T,U;
  int A,B;

  cin >> S >> T;
  cin >> A >> B;
  cin >> U;

  if(S == U){
    A--;
  }
  if(T == U){
    B--;
  }

  cout << A << " " << B << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <numeric>
using namespace std; 

int main() {
    int N; cin >> N;
	vector<int> L(N);

	int sum = 0;
	int max = 0;

	for(int i = 0; i < N; i++){
		cin >> L[i];
		sum += L[i];
		if(max < L[i]) max = L[i];
	}
	
	cout << (max < sum - max ? "Yes": "No") << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	
	public static void main(String[] args){
		// input
		int n;
		Scanner s = new Scanner(System.in);
		n = s.nextInt();
		
		int[] t = new int[n];
		for(int i = 0; i < n; i++){
			t[i] = s.nextInt();
		}
		
		int m = s.nextInt();
		
		int[][] p = new int[m][2];
		for(int j = 0; j < m; j++){
			int[] pi = new int[2];
			pi[0] = s.nextInt();
			pi[1] = s.nextInt();
			p[j] = pi;
		}
		//System.out.println("finished");
		
		// output 
		for(int j = 0; j < m; j++){
			int sum = 0;
			for(int k = 0; k < n; k++){
				if(k + 1 != p[j][0]){
					sum += t[k];
				}else{
					sum += p[j][1];
				}
			}
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 10324
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
immutable string YES = "Yes";
immutable string NO = "No";
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long X;
    X = input.front.to!long;
    input.popFront;

    solve(X);
}

void solve(long X)
{
    writeln(30 <= X ? YES : NO);
}


Measured memory_bytes: 3688
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        char tmp = s.charAt(0);
        StringBuilder result = new StringBuilder();
        
        for(int i=1; i<n; i++){
            char c = s.charAt(i);
            if(tmp != c){
                result.append(tmp);
                tmp = c;
            }
        }
        
        if(result.length() == 0 || result.charAt(result.length()-1) != tmp){
            result.append(tmp);
        }
        
        System.out.println(result.length());
    }
}

Measured memory_bytes: 27604
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

int main() {
	int N, K, a, b, ts;
	cin >> N >> K;
	vector<pair<ll, ll>> Xf(N);
	for (int i = 0;i < N;i++) {
		cin >> a >> b;
		Xf[i] = { a,b };
	}
	sort(all(Xf));
	vector<ll> T, S;
	ll ymi, xmi, ans = LLONG_MAX;
	for (int i = 0;i < N;i++) {
		for (int j = i + 1;j < N;j++) {
			T = S;
			xmi = Xf[j].first - Xf[i].first;
			ymi = LLONG_MAX;
			for (int k = i;k <= j;k++) {
				T.push_back(Xf[k].second);
			}
			ts = T.size();
			if (ts < K)continue;
			sort(all(T));
			for (int k = 0;k + K <= ts;k++) {
				ymi = min(T[k + K - 1] - T[k], ymi);
			}
			ans = min(ans, xmi*ymi);
		}
	}
	cout << ans << endl;
}

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

int main() {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  
  ll int point = 0;
  for(char x : t) {
    if(x == 'r') point += p;
    else if(x == 's') point += r;
    else point += s;
//    cout << point << endl;
  }
  
//  cout << point << endl;
  
  for(int i = k; i < n; ++i) {
    if(t[i] == t[i-k]) {
      char w = t[i];
      if(w == 'r') point -= p;
      else if(w == 's') point -= r;
      else point -= s;
      t[i] = 'o';
    }
  }
  
  cout << point << endl;
  
    
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 100000
#define MAXM 100000
#define INF 1000000000000000
struct node
{
    int next,to;
    long long w;
}e[MAXM*2+5];
struct Qr
{
    int xr,dec;
    long long lim;
};
long long T;
int cnt,m,n;
int x,y,z,flag;
long long ri=INF,le=-INF;
long long vis[2][MAXN+5];
int b[MAXN+5];
void fpush(int u,int v,long long w)
{
    e[++cnt].next=b[u];
    e[cnt].w=w;
    e[cnt].to=v;
    b[u]=cnt;
}
int Ch(int x){if(x==-1)x=0;return x;}
void dfs(int xr,int dec,long long lim)
{
    if(flag)return ;
    for(int i=b[xr];i;i=e[i].next)
    {
        int xnext=e[i].to;
        long long nlim=e[i].w-lim;
        int FD=Ch(dec);
        if(vis[FD][xnext]!=INF)
        {
            if(vis[FD][xnext]!=nlim){flag=1;return ;}
            else continue;
        }
        vis[FD][xnext]=nlim;
        if(!FD)le=max(le,-vis[FD][xnext]);
        else ri=min(ri,vis[FD][xnext]);
        dfs(xnext,-dec,nlim);
    }
}
int main()
{
    fill(vis[0],vis[0]+MAXN+1,INF);
    fill(vis[1],vis[1]+MAXN+1,INF);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        fpush(x,y,z);fpush(y,x,z);
    }
    dfs(1,1,0);
    if(flag){printf("0\n");return 0;}
    long long T=-1;
    for(int i=1;i<=n;i++)
        if(vis[0][i]!=INF&&vis[1][i]!=INF)
        {
            long long NT=(vis[1][i]-vis[0][i])/2;
            if(NT<0){flag=1;break;}
            if(T==-1)T=NT;
            else if(T!=NT){flag=1;break;}
        }
    if(flag){printf("0\n");return 0;}
    if(T!=-1)
    {
        if(T>le&&T<ri)printf("1\n");
        else printf("0\n");
    }
    else printf("%lld",max((long long)0,ri-le-1));
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
int main(){
    long x;
    cin >> x;
    long a;
    long b;
    bool chk = false;
    for(long i=-1000;i<=1000;i++){
        for(long j=-1000;j<=1000;j++){
            if(i*i*i*i*i - j*j*j*j*j == x){
                a = i;
                b = j;
                chk = true;
                break;
            }
        }
        if(chk)break;
    }
    cout << a << " "<<b<<endl;
}

Measured memory_bytes: 3652
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	int[][] dp = new int[101][51];
	try{
	    String st; int j = 0, before = 1;
	    while((st=sc.readLine())!=null){
		String[] cp = st.split(",");
		if(j==0){
		    dp[0][0] = Integer.valueOf(cp[0]);
		    j++;
		}
		else if(before == cp.length-1){
		    dp[j][0]=dp[j-1][0] + Integer.valueOf(cp[0]);
		    for(int i=1; i<cp.length-1; i++)
			dp[j][i] = Math.max(dp[j-1][i-1], dp[j-1][i]) + Integer.valueOf(cp[i]);
		    dp[j][cp.length-1]=dp[j-1][cp.length-2] + Integer.valueOf(cp[cp.length-1]);
		    before = cp.length;
		    j++;
		}
		else{
		    for(int i=0; i<cp.length; i++)
			dp[j][i] = Math.max(dp[j-1][i], dp[j-1][i+1]) + Integer.valueOf(cp[i]);
		    j++;
		    before = cp.length;
		}
	    }
	    System.out.println(dp[j-1][0]);
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    std::cout << std::fixed;
    std::cout << std::setprecision(10);
    int n,k;
    cin>>n>>k;
    double ans =0;
    for (int ni = 1; ni <= n; ni++)
    {
        int n2=1;
        while(ni*n2 < k)
        {
            n2*=2;
        }
        ans += 1/(double)(n * n2); 
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

string X,Y;
bool ans;

int main()
{
    int i,j,a=1000000,count=0;
    cin >> X >> Y;

    rep0(i, X.size()-Y.size()+1)
    {
        rep0(j,Y.size()){
            if(X[i+j]!=Y[j])count++;
        }
        a=min(count,a);
        count=0;
    }

    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x, y) (lower_bound(vec.begin(), vec.end(), make_pair(x, y)) - vec.begin())
#define lc (v * 2)
#define rc (v * 2 + 1)
long long M = 1e9 + 7;
//>>>>>>>>>>>>>>>>>>>

const int N = 1e5 + 7;

vector <int> ad[N];
int n;
int dp[N][2];

void solve(int v, int p) {
	bool allh0 = 1, one1 = 0;
	int no0 = 0, cnt0 = 0, call = 0;
	for (auto u: ad[v])
		if (u != p) {
			call++;
			solve(u, v);
			if (!dp[u][0]) {
				allh0 = 0;
				no0 = u;
			}
			else
				cnt0++;
			if (dp[u][1])
				one1 = 1;
		}
	if (allh0)
		dp[v][1] = 1;
	if (allh0 && one1)
		dp[v][0] = 1;
	if (cnt0 == call - 1 && one1 && dp[no0][1] == 1)
		dp[v][0] = 1;
}
int main() {
	makefast;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		ad[v].push_back(u);
		ad[u].push_back(v);
	}	
	solve(1, 0);
	if (dp[1][0])
		cout << "Second";
	else
		cout << "First";
	
}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


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

  ll ans = 1e18;
  for(ll i = 1; i*i <= n; i++){
    if(n%i != 0) continue;
    else{
      ll j = n/i;
      ans = min(ans, j+i-2);
    }
  }
  cout << ans << endl;
  return 0;
}


/*





















*/


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

int main()
{
  char S[110];
  bool res=true;
  cin >> S;

  int dict[27]={0};

  rep(i,strlen(S)) {
    dict[(int)(S[i]-97)]++;
  }

  rep(i,27){
    if(dict[i]%2==1) res =false;
  }

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


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

using namespace std;

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

bool check(int x, int y);
void jump(bool f[10][10], int x, int y);

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

int px, py, n, X[10], Y[10];

bool dfs(int x, int y, int t) {
	if (!(x >= 0 && x < 10 && y >= 0 && y < 10)) return false;
	if (t > 0) {
		if (!(X[t - 1] - 1 <= x && x <= X[t - 1] + 1 && Y[t - 1] - 1 <= y && y <= Y[t - 1] + 1)) return false;
		if (t == n) return true;
	}
	
	bool res = false;
	REP(i, 12) {
		int nx = x + dx[i], ny = y + dy[i];
		if (dfs(nx, ny, t + 1)) res = true;
	}
	return res;
}

int main() {
	while (true) {
		cin >> px >> py;
		if (!px && !py) break;		
		cin >> n;
		REP(i, n) scanf("%d %d", &X[i], &Y[i]);
		
		if (dfs(px, py, 0)) puts("OK");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1204
import sys

sys.setrecursionlimit(10 ** 7)
# import bisect
# import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
#import itertools
#import heapq
import bisect


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


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    A.sort()

    #    print(A)
    pp = int(bisect.bisect_left(A,0))
    A_minus = deque(A[:pp])
    A_plus = deque(A[pp:])

    #    print(A_plus)
    #    print(A_minus)
    AA = deque([])
    AAm = deque([])
    if N == K:
        ans = 1
        for i in A:
            ans *= i % mod
            ans %=mod
        print(ans % mod)

    elif K % 2 == 0:
        ans = 1

        while len(A_minus) >= 2:
            a1 = A_minus.popleft()
            a2 = A_minus.popleft()
            AAm.append(a1 * a2)

        while len(A_plus) >= 2:
            a1 = A_plus.pop()
            a2 = A_plus.pop()
            AA.append(a1 * a2)


        for i in range(K // 2):
            if len(AAm)==0:
                temp = AA.popleft()
            elif len(AA) ==0:
                temp = AAm.popleft()
            elif AAm[0] > AA[0]:
                temp = AAm.popleft()
            else:
                temp = AA.popleft()
            ans *= temp % mod
            ans %=mod
        print(ans % mod)

    elif len(A_plus) == 0:
        ans = 1
        for i in range(K):
            ans *= A_minus.pop() % mod
            ans %=mod
        print(ans % mod)

    else:
        ans = A_plus.pop()

        while len(A_minus) >= 2:
            a1 = A_minus.popleft()
            a2 = A_minus.popleft()
            AAm.append(a1 * a2)

        while len(A_plus) >= 2:
            a1 = A_plus.pop()
            a2 = A_plus.pop()
            AA.append(a1 * a2)

        for i in range(K // 2):
            if len(AAm) == 0:
                temp = AA.popleft()
            elif len(AA) == 0:
                temp = AAm.popleft()
            elif AAm[0] > AA[0]:
                temp = AAm.popleft()
            else:
                temp = AA.popleft()
            ans *= temp
            ans %=mod
        print(ans % mod)
if __name__ == "__main__":
    main()


Measured memory_bytes: 32392