akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
constexpr long INF = 1LL << 62;

int n;
long a[300010], L[300010], R[300010];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i=0; i < n * 3; ++i) cin >> a[i];

    // (sum of N from left) - (sum of N from right)
    
    // from left, maximize
    priority_queue<long, vector<long>, greater<long>> pq_max;
    for(int i=0; i < n * 3; ++i) {
        if(pq_max.size() < n) {
            L[i+1] = L[i] + a[i];
            pq_max.push(a[i]);
        } else {
            if(pq_max.top() < a[i]) {
                L[i+1] =  L[i] + a[i] - pq_max.top();
                pq_max.pop();
                pq_max.push(a[i]);
            } else {
                L[i+1] = L[i];
            }
        }
    }

    // from right, minimize
    priority_queue<long> pq_min;
    for(int i=n * 3 - 1; i >= 0; --i) {
        if(pq_min.size() < n) {
            R[i] = R[i+1] + a[i];
            pq_min.push(a[i]);
        } else {
            if(pq_min.top() > a[i]) {
                R[i] = R[i+1] + a[i] - pq_min.top();
                pq_min.pop();
                pq_min.push(a[i]);
            } else {
                R[i] = R[i+1];
            }
        }
    }

    long ans = -INF;
    for(int i=n; i <= n * 2; ++i) 
        ans = max(ans, L[i] - R[i]);

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


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


int main(){
        int D,N;
        cin >> D >> N;
        if(D==0) {
                if(N==100) {
                        cout << 101 << endl;
                }else{
                        cout << N << endl;
                }
        }else if(D==1) {
                if(N==100) {
                        cout << 10100 << endl;
                }else{
                        cout << 100*N << endl;
                }
        }else if(D==2) {
                if(N==100) {
                        cout << 1010000 << endl;
                }else{
                        cout << 10000*N << endl;
                }
        }

        return 0;
}


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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;


const int MAX_H = 800, MAX_W = 800;
int h,w,k;
char grid[MAX_H][MAX_W];
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
bool kr[MAX_H][MAX_W] = {};

bool is_edge(int i, int j)
{
  return i == 0 || i == h-1 || j == 0 || j == w-1;
}

int ceil(int a, int b)
{
  return a / b + (a % b != 0 ? 1 : 0);
}

int main()
{
  cin >> h >> w >> k;
  int si,sj;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> grid[i][j];
      if (grid[i][j] == 'S') {
        si = i;
        sj = j;
      }
    }
  }

  queue<pair<pii,int> > q({{{si,sj},k}});
  kr[si][sj] = true;
  while (!q.empty()) {
    auto p = q.front(); q.pop();
    if (p.second == 0) break;
    for (int i = 0; i < 4; i++) {
      int new_x = p.first.first + dx[i];
      int new_y = p.first.second + dy[i];
      if (!kr[new_x][new_y] && grid[new_x][new_y] != '#') {
        if (is_edge(new_x, new_y)) {
          cout << 1 << endl;
          return 0;
        }
        q.push({{new_x,new_y},p.second-1});
        kr[new_x][new_y] = true;
      }
    }
  }

  int c = INT_MAX;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (kr[i][j]) {
        c = min({c, ceil(i,k), ceil(h-1-i,k), ceil(j,k), ceil(w-1-j,k)});
      }
    }
  }
  cout << c+1 << endl;

  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	re ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
int a[110];
int ans;
int main()
{
	int n=read(),m=read();
	double sum=0;
	fo(i,1,n)
	{
		a[i]=read();
		sum+=a[i]; 
	}
	int minn=ceil(sum/(4*m));
	fo(i,1,n)
	{
		if(a[i]>=minn)
		{
			ans++;
		}
		if(ans>=m)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0; 
}


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

//Taro's Obsession
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt(), n = sc.nextInt();
		boolean[][] e = new boolean[m+1][m+1];
		int[] deg = new int[m+1];
		while(n--!=0){
			int x = sc.nextInt(), y = sc.nextInt();
			e[y][x] = true;
			deg[y]++;
		}
		for(int i=0;i<m;i++){
			for(int j=1;j<=m;j++)if(deg[j]==0){
				if(i!=m-1 && j==2)continue;
				System.out.println(j);
				deg[j] = -1;
				for(int k=1;k<=m;k++)if(e[k][j])deg[k]--;
			}
		}
	}
	
	void debug(Object...o){
		System.out.println(Arrays.deepToString(o));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 18392
using System;
namespace ITP1_7_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string[] S = Console.ReadLine().Split();
                int m = int.Parse(S[0]);
                int f = int.Parse(S[1]);
                int r = int.Parse(S[2]);
                if(m == -1 && f == -1 && r == -1)
                {
                    break;
                }
                if(m == -1 || f == -1 || (m + f) < 30)
                {
                    Console.WriteLine("F");
                }
                else if((m + f) >= 80)
                {
                    Console.WriteLine("A");
                }
                else if((m + f) < 80 && (m + f) >= 65)
                {
                    Console.WriteLine("B");
                }
                else if((m + f) < 65 && (m + f) >= 50)
                {
                    Console.WriteLine("C");
                }
                else if((m + f) < 50 && (m + f) >= 30 && r >= 50)
                {
                    Console.WriteLine("C");
                }
                else if((m + f) < 50 && (m + f) >= 30 && r < 50)
                {
                    Console.WriteLine("D");
                }
            }
        }
    }
}


Measured memory_bytes: 15948
#include <bits/stdc++.h>
#define L "\n"
#define S " "
#define ll long long
#define pb push_back
#define mp make_pair
#define vi std::vector<int>
#define si std::set<int>
#define vl std::vector<long long>
#define qi std::queue<int>
#define s1(a) scanf("%d", &a)
#define s2(a, b) scanf("%d %d", &a, &b)
#define s3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define de(a) cout << #a << "  ------>  " << a << "\n"
#define SIZE 100002
#define MOD 1000000007
#define black 1
#define white 0
#define INF INT_MAX
#define rep(i, n) for (i = 0; i < n; i++)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;
ll dp[SIZE][2];
bool flag[SIZE][2];
vi adj[SIZE];

ll dfs(int v, int col, int parent)
{
    ll a;
    ll now = 1;

    for (int u : adj[v])
    {

        if (u != parent)
        {
            if (col == black)
            {
                if (flag[u][white])
                {
                    now = (now * dp[u][white]) % MOD;
                }
                else
                {
                    now = (now * dfs(u, white, v)) % MOD;
                }
            }
            else
            {
                if (flag[u][white])
                    a = dp[u][white];
                else
                    a = dfs(u, white, v);
                if (flag[u][black])
                    a = (a + dp[u][black]) % MOD;
                else
                    a = (a + dfs(u, black, v)) % MOD;
                now = (now * a) % MOD;
            }
        }
    }
    flag[v][col] = 1;

    return dp[v][col] = now;
}

void solve()
{
    int n, i, a, b; 
    ll res = 0;
    cin >> n;
    rep(i, n - 1)
    {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    res = dfs(1, black, -1);
    res = (res + dfs(1, white, -1)) % MOD;
    cout << res << L;
}
int main()
{
    FASTIO;
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
// #endif
    int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>
int main(){
  char S[100],T[100];
  scanf("%s",&S);
  scanf("%s",&T);
  if(strlen(S) == strlen(T)){
    for(int i = 0;i < strlen(S);i++){
      int c = 1;
      for(int j = 0;j < strlen(S);j++){
        if(S[j] != T[(j + i) % strlen(S)]){
          c = 0;
        }
      }
      if(c == 1){
        printf("Yes");
        return 0;
      }
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 998244353
const int N=300005;
ll fac[N]={1,1},inv[N]={1,1},f[N]={1,1};
ll C(ll a,ll b){
    if(b>a)return 0;
    return fac[a]*inv[b]%M*inv[a-b]%M;
}
void init(){//快速计算阶乘的逆元
    for(int i=2;i<N;i++){
        fac[i]=fac[i-1]*i%M;
        f[i]=(M-M/i)*f[M%i]%M;
        inv[i]=inv[i-1]*f[i]%M;
    }
}
int main(){
     init();
     int n;
     scanf("%d",&n);
     ll a,b,k;
     scanf("%lld%lld%lld",&a,&b,&k);
     long long ans=0;
     for(int i=0;i<=n;i++){
          long long sum=1ll*i*a;
          if((k-sum)>=0&&(k-sum)%b==0){
               long long j=(k-sum)/b;
               if(j>n)continue;
               ans+=(C(n,i)*C(n,j));
               ans%=M;
          }
     }
     printf("%lld\n",ans);
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int a, b;
  cin >> a >> b;
  if (a + b == 3) {
    cout << 3 << endl;
  } else if (a + b == 4) {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
import sys
import itertools
import math
n = int(sys.stdin.readline())

pos = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
a = list(itertools.permutations(pos, n))
#print(pos)
ans = 0
for ele in a:
    #print(ele)
    for i in range(n-1):
        ans += math.sqrt((ele[i][0] - ele[i+1][0])**2 + (ele[i][1] - ele[i+1][1])**2)
print(ans/len(a))

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

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (s.at(i) == s.at(j)) {
        count++;
      }
    }
  }
  if (count == 8) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main () {
  int N;
  string s;
  cin >> N >> s;
  
  
  for (int i = 0; i < N; i++)
    cin >> s.at(i);
  
  int count = 0;
  
  for (int i = 0; i < N; i++)
  {
    if (s.at(i) == 'R')
    {
      count++;
    }
  }
  
  if (count > (N / 2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(void){
  int n;
  int i,j,k;

  int ans;

  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  ans=n;

  for(i=0;i<n;i=i+k+1){
    k=0;
    while(s[i+k]==s[i+1+k]&&i+1+k<n){
      k++;
      //printf("i=%d;hitosiidesu\n",i);
    }
    ans=ans-k;
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=3e5+5,Mod=1e9+7;
const int nxt[2][9]={{1,3,4,1,6,7,4,8,7},{2,0,5,1,2,5,4,5,7}};
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}inline int Add(int&x,int y){x+=y,x>=Mod?x-=Mod:0;}
char s[MAXN];
int F[MAXN][9],n;
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	scanf("%s",s+1),n=strlen(s+1),F[0][0]=1;
	Rep(i,1,n)Rep(j,0,8)if(F[i-1][j]){
		if(s[i]!='0')Add(F[i][nxt[1][j]],F[i-1][j]);
		if(s[i]!='1')Add(F[i][nxt[0][j]],F[i-1][j]);
	}cout<<(1ll*F[n][2]+F[n][7]+F[n][8]+F[n][5])%Mod<<'\n';
	return 0;
}




Measured memory_bytes: 11136
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, n;
	cin >> h >> w >> n;
	int minh = 1;
	int maxh = h;
	int minw = 1;
	int maxw = w;
	int r, c;
	cin >> r >> c;
	string s, t;
	cin >> s >> t;
	for (int i = n-1; i >= 0; i--) {
		if (t[i] == 'U')maxh = min(maxh + 1, h);
		if (t[i] == 'D')minh = max(minh-1,1);
		if (t[i] == 'L')maxw = min(maxw + 1, w);
		if (t[i] == 'R')minw=max(minw -1, 1);
		if (s[i] == 'D')maxh -= 1;
		if (s[i] == 'U')minh += 1;
		if (s[i] == 'R')maxw -= 1;
		if (s[i] == 'L')minw += 1;
		if (maxh < minh || minw> maxw) {
			cout << "NO";
			return 0;
		}
	}
	if (r >= minh&&r<=maxh&&c>=minw&&c<=maxw) {
		cout << "YES";
	}
	else cout << "NO";
}

Measured memory_bytes: 920
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
int n,k;

int solve(int N){
    if(N==0){
        return 1;
    }
    return min(solve(N-1)+k,solve(N-1)*2);
}

int main(){
    cin>>n>>k;
    int ans=solve(n);
    cout<<ans<<endl;
}

Measured memory_bytes: 3600
s = list(input())
s= s[::-1]
s += list("qqqqqqqq")
li = [list("maerd"),list("remaerd"),list("esare"),list("resare")]
#print(li)
memo = 0
while(1):
    a = s[memo:memo+5]
    b = s[memo:memo+6]
    c = s[memo:memo+7]
    #print(a,b,c,memo)
    if a==li[0] or a==li[2]:
        memo += 5
        continue
    elif b==li[3]:
        memo += 6
        continue
    elif c==li[1]:
        memo += 7
        continue
    elif memo >= len(s)-8:
        print("YES")
        break
    else:
        print("NO")
        break
    



    pass

Measured memory_bytes: 4652
#include <iostream>

using namespace std;

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

    int max_val = 1;

    for (int b = 2; b < x; b++)
    {
        int val = b * b;
        while (val <= x)
        {
            max_val = max(max_val, val);
            val *= b;
        }
    }
    cout << max_val << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <vector>
#include<valarray>
#include<map>

#include <utility>

#include <deque>
#include <queue>


using namespace std;
long long a[10001];
int main()
{
long long n;
cin>>n;
long long x,y,z;
long long counter;
set<long long >numbers;
for(int i=1;i<=n;i++)
{

    numbers.insert(i);
}


    for(x=1;x<=98;x++)
    {
        
        for (y = 1; y <= 98; y++)
        {
            for (z = 1; z <= 98; z++)
            {
                long long c=(x * x) + (y * y) + (z * z) + (x * y) + (z * x) + (z * y);

                auto it=numbers.find(c);
                if(it!=numbers.end())
                {
                    a[c]++;
                }
            }
        }

    }
    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }



    return 0;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
#include <math.h>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}
int func(int n) {
	int i, count = 0;
	/* 約数を求める */
	for (i = 1; i <= n; ++i) {
		if (n%i == 0)
			count++;
	}
	return count;
}
int main() {
	int n,count=0;
	cin >> n;
	
	if (IsPrime(n) == true || n == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (n<1||n>200) {
		return 0;
	}
	for (int i = 1; i <= n; i=i+2) {
		if (func(i) == 8) {
			count++;
		}
	}

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


Measured memory_bytes: 256
def f(a,b,c):
  ans=0
  s=[0]*n
  for i in range(n):
    s[i]=l[i][0]*a+l[i][1]*b+l[i][2]*c
  s=sorted(s)
  return sum(s[n-m:n])

n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
print(max(f(1,1,1),f(1,1,-1),f(1,-1,1),f(1,-1,-1),f(-1,1,1),f(-1,1,-1),f(-1,-1,1),f(-1,-1,-1)))

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

#define int long long

vector<vector<int>>edge(1e5+1);
vector<vector<int>>cost(1e5+1);
vector<int>root(1e5+1,0);
vector<bool>have_been(1e5+1,false);

void dfs(int node,int cnt){
    if(have_been[node]==true) return;
    // cout <<"node:" << node << endl;
    have_been[node] = true;

    for(int i=0;i<edge[node].size();i++){
        if(have_been[edge[node][i]]==false){
            have_been[node]=true;
            // cout << "cost:" << cost[node][i] << ' ';
            root[edge[node][i]] = cnt + cost[node][i];
            dfs(edge[node][i],root[edge[node][i]]);
        }
    }
    return;
}

signed main(void){
    int n; cin >> n;
    for(int i=0;i<n-1;i++){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        // cout << a << ' ' << b << endl;
        edge[a].push_back(b);
        edge[b].push_back(a);
        cost[a].push_back(c);
        cost[b].push_back(c);
    }
    int q,k; cin >> q >> k;
    k--;

    // for(int i=0;i<n-1;i++){
    //     cout << "edge:" << i << ": ";
    //     for(int j=0;j<edge[i].size();j++){
    //         cout << edge[i][j] << ' ';
    //     }cout << endl;
    // }cout << endl;

    dfs(k,0);


    // for(int i=0;i<n;i++){
    //     for(int j=0;j<edge[i].size();i++){
    //         cout << root[edge[i][j]] << ' ';
    //     }
    // }cout << endl;


    for(int i=0;i<q;i++){
        int x,y; cin >>x >> y;
        x--;y--;
        cout << root[x]+root[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 19840
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Monad
import Data.List

main :: IO ()
main = do
    n <- read <$> getLine :: IO Int
    ns <- sort . map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    -- print $ ns
    print $ last ns - head ns

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64


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

    llong left=0,right=n+1;
    llong mid;
    while(left+1 < right){
        mid=(left + right) /2;
        if( mid * mid <=n) left=mid;
        else right = mid;
    }
    cout << left * left << endl;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    H, W = LI()
    if H == 1 or W == 1:
        print(1)
        return
    if H * W % 2 > 0:
        cnt = (H * W + 1) // 2
    else:
        cnt = H*W//2
    print(cnt)

main()



Measured memory_bytes: 6736
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<iostream>
#define N 75
#define eps 1e-6
#define ll long long
#define db double
#define inf 0x3fffffff
#define A(a) printf("a==%d",a);
#define CC(x,y) memset(x,y,sizeof(x))
#define lson l,mid,rt<<1
#define rson mid+1,r,(rt<<1)+1
#define M 1000000009
using namespace std;
struct node
{
    ll a[77][77];
} a,b,c,d,e;
int i,j,k,m,n,x,y,z;
ll h;
struct node2
{
    ll x,y;
}f[50];
node mul(node a,node b)
{
    CC(d.a,0);
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
          for (int k=0;k<n;k++)
    {
          d.a[i][j]=(d.a[i][j]+a.a[i][k]*b.a[k][j])%M;
    }
    return d;
}
node work(ll x)
{
    c=b;
    CC(e.a,0);
    for (i=0;i<n;i++) e.a[i][i]=1;
    while (x)
    {
        if (x&1)e=mul(e,c);
        c=mul(c,c);
        x=x>>1;
    }
    return e;
}
bool cmp(node2 a,node2 b)
{
    return a.y<b.y;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int cas=1;
    while (scanf("%d%lld%d",&n,&h,&z),n)
    {
        CC(a.a,0);CC(b.a,0);
        a.a[0][0]=1;
        for (i=0; i<n; i++)
            for (j=0; j<n; j++)
                if ((abs(j-i))<=1) b.a[i][j]=1;
        c=b;
        CC(f,0);
        f[0].y=1;
        for (i=1;i<=z;i++)
            scanf("%lld%lld",&f[i].x,&f[i].y);
        f[z+1].y=h;f[z+1].x=-1;
        sort(f,f+z+2,cmp);
        for (int i=1;i<=z+1;i++)
        {
            ll x=f[i].y-f[i-1].y;
            e=work(x);
            a=mul(a,e);
            if (f[i].x!=-1) a.a[0][f[i].x-1]=0;
        }
        printf("Case %d: %lld\n",cas++,a.a[0][n-1]);
    }
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
using namespace std;
int main(void){
     long r,d,x;
     cin >> r >> d >> x;
     long ans[11];
     ans[0] = x;
     for(int i = 1;i <= 10;i++){
         ans[i] = ans[i - 1] * r - d;
         cout << ans[i] << endl;
     }
    
}


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

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

	string input;
	int arr[4] = {0, 0, 0, 0};

	while(n--){
		cin >> input;
		if(input == "AC")
			arr[0] += 1;
		else if(input == "WA")
			arr[1] += 1;
		else if(input == "TLE")
			arr[2]  += 1;
		else
			arr[3] += 1;
	}

	cout << "AC x " << arr[0] << endl;
	cout << "WA x " << arr[1] << endl;
	cout << "TLE x " << arr[2] << endl;
	cout << "RE x " << arr[3];
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    char s;
    cin >> s;
    if (s - 'A' >= 0 && s - 'A' <= 26)
    {
        cout << "A\n";
    }
    else
    {
        cout << "a\n";
    }
}
int main()
{
    func();
}

Measured memory_bytes: 3628
using System;

namespace AtCoder.Problems
{
    public class ProblemA
    {
        public static void Main(string[] args)
        {
            var s = new SolveA();
            s.Solve();
        }

        public class Scanner
        {
            private string[] _s;
            private int _i;
            private readonly char[] _separators = new char[] { ' ' };

            public Scanner()
            {
                _s = new string[0];
                _i = 0;
            }

            public string Next()
            {
                if (_i < _s.Length) return _s[_i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                _s = st.Split(_separators, StringSplitOptions.RemoveEmptyEntries);
                if (_s.Length == 0) return Next();
                _i = 0;
                return _s[_i++];
            }

            public int NextInt() => int.Parse(Next());
            public long NextLong() => long.Parse(Next());
            public ulong NextULong() => ulong.Parse(Next());
            public double NextDouble() => double.Parse(Next());

            public int[] GetIntArray(int n, int add = 0)
            {
                int[] array = new int[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextInt() + add;
                }
                return array;
            }

            public long[] GetLongArray(int n, long add = 0)
            {
                long[] array = new long[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextLong() + add;
                }
                return array;
            }

            public double[] GetDoubleArray(int n, double add = 0)
            {
                double[] array = new double[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextDouble() + add;
                }
                return array;
            }
        }
    }

    public class SolveA
    {
        public void Solve()
        {
            var cin = new ProblemA.Scanner();
            var r = cin.NextInt();

            var result = GetAnswer(r);
            Console.WriteLine(result);
        }

        public double GetAnswer(int r)
        {
            return r * 2 * Math.PI;
        }
    }
}


Measured memory_bytes: 27636
#include<stdio.h>
     
    int main(){
      int i,a[101]={},n,m,x,box[101]={},left=0,right=0;
      scanf("%d %d %d",&n,&m,&x);
      for(i=0;i<m;i++){
        scanf("%d",&a[i]);
        box[a[i]]=1;
      }
      for(i=0;i<=n;i++){
        if(i<x) left+=box[i];
        else right+=box[i];
      }
      if(left<right) printf("%d\n",left);
      else printf("%d\n",right);
    }

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int n, m, k, p;
char a[10000][10000];
int b[10000];

int main() {
	for (int i = 0; i < 10000; i++)b[i] = 100;
	cin >> n >> m;
	p = 0;

	for (int i = 0; i < n; i++) {
		k = 0;
		cin >> a[p];
		for (int j = 0; j < m; j++) {
			if (a[p][j] == '.')k++;
		}
		if (k == m)p--;
		p++;
	}
	n = p;
	
	p = 0;
	for (int j = 0; j < m; j++) {
		k = 0;
		for (int i = 0; i < n; i++) {
			if (a[i][j] == '.')k++;
		}
		if (k == n) {
			b[p] = j;
			p++;
		}
	}
	for (int i = 0; i < n; i++) {
		p = 0;
		for (int j = 0; j < m; j++) {
			if (b[p] != j) {
				cout << a[i][j];
			}
			else {
				p++;
			}
		}
		cout << '\n';
	}
	cin >> n;
	return 0;

}

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

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(n) printf("%d\n", (n))
#define COUTLL(n) printf("%lld\n", (n))
#define CIN(n) scanf("%d", &(n))
#define CINLL(n) scanf("%lld", &(n))
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

void infile(){
	freopen("input.in", "r", stdin);
}

void outfile(){
	freopen("output.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
	if(b == 0)
		return 1;
	if(b == 1)
		return a;
	ll tmp = modex(a, b/2, mod);
	tmp = (tmp * tmp) % mod;
	if(b & 1)
		tmp = (tmp * a) % mod;
	return tmp;
}

//End of template

int n, m;
vi adjlist[100005];
int indeg[100005];
int dist[100005];
vi starts;
vi sorted;

void toposort(){
	queue<int> q;
	FORE(i, 1, n){
		//cout << indeg[i] << nl;
		if(indeg[i] == 0){
			starts.pb(i);
			q.push(i);
		}
	}
	int front, sz;
	while(q.empty() == false){
		front = q.front();
		q.pop();
		sz = adjlist[front].size();
		sorted.pb(front);
		FOR(i, 0, sz){
			indeg[adjlist[front][i]]--;
			if(indeg[adjlist[front][i]] == 0){
				q.push(adjlist[front][i]);
			}
		}
	}
}

int main(){
	init();

	cin >> n >> m;
	int u, v;
	MEM(indeg, 0);
	FOR(i, 0, m){
		cin >> u >> v;
		adjlist[u].pb(v);
		indeg[v]++;
		//cout << indeg[v] << nl;
	}
	toposort();
	MEM(dist, -1);
	int ans = INT_MIN;
	int ssz, asz;
	asz = starts.size();
	FOR(i, 0, asz){
		dist[starts[i]] = 0;
	}
	ssz = sorted.size();
	FOR(i, 0, ssz){
		asz = adjlist[sorted[i]].size();
		FOR(j, 0, asz){
			dist[adjlist[sorted[i]][j]] = max(dist[adjlist[sorted[i]][j]], dist[sorted[i]] + 1);
			ans = max(ans, dist[adjlist[sorted[i]][j]]);
		}
	}
	cout << ans << nl;
	return 0;	
}

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

int main() {
  double n,m,d;
  cin >> n >> m >> d;
  double ans;
  if(d == 0) ans = (m-1)/n;
  else ans = (m-1)*2*(n-d)/(n*n);
  cout << fixed;
  cout << setprecision(9) << ans << endl;

}

Measured memory_bytes: 3756
import numpy as np
n, d = map(int, input().split())
x = np.empty((n, d))
for i in range(n):
    x[i, :] = np.array(list(map(int, input().split())))

count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        distance = np.linalg.norm(x[i, :] - x[j, :])
        if float(distance).is_integer():
            count += 1
print(count)


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

using namespace std;
#define eps = (1e-10);
//点
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    double norm(){return x*x+y*y;}//模的平方
    double ABS() {return sqrt(norm());}//模
};
//线段
struct Segment{
    Point p1,p2;
};
//点积
double dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}
//叉积
double cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}
int main(){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    Point p0={x1,y1};Point p1={x2,y2};
    int T;scanf("%d",&T);
    double x,y;
    while(T--){
        scanf("%lf %lf",&x,&y);
        Point p2={x,y};
        Point a=p2-p0;
        Point b=p1-p0;
        double jud=cross(a,b);
        if(jud<0){
            puts("COUNTER_CLOCKWISE");
        }
        if(jud>0){
            puts("CLOCKWISE");
        }
        if(jud==0){
            double op=dot(a,b);
            if(op<0){
                puts("ONLINE_BACK");
            }else{
                if(a.norm()>b.norm()){
                    puts("ONLINE_FRONT");
                }else{
                    puts("ON_SEGMENT");
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3228
#include <iostream>

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

    if (a <= 5) {
        std::cout << 0 << std::endl;
    } else if (a <= 12) {
        std::cout << (b / 2) << std::endl;
    } else {
        std::cout << b << std::endl;
    }
}


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

using namespace std;

void solve()
{
	int N, H, W;
	cin >> N >> H >> W;
	cout << (N - H + 1) * (N - W + 1) << endl;
}

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


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


int main() {
    int n;
    cin >> n;
    long long f[300][300];
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> f[i][j];
        }
    }
    bool valid = 1;

    for (int i = 0; i < n && valid; i++) {
        for (int j = 0; j < n && valid; j++) {
            bool important = 1;
            for (int k = 0; k < n && valid; k++) {
                if (f[i][k] + f[k][j] < f[i][j]) valid = 0;
                if (f[i][k] + f[k][j] == f[i][j] && i != k && j != k) {
                    important = 0;
                    break;
                }
            }
            if (important) ans += f[i][j];
        }
    }
    if (valid) {
        cout << ans / 2 << endl;
    } else {
        cout << "-1\n";
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<long int> x(N), y(N), h(N);
  for(int i=0;i<N;i++){
    cin >> x[i] >> y[i] >> h[i];
  }
  for(int i = 0;i<=100;i++){
    for(int j = 0;j<=100;j++){
      long int height = 0;
      for(int n = 0;n<N;n++){
        if(h[n] != 0){
          height = h[n] + abs(x[n] - i) + abs(y[n] - j);
        }
      }
      int check = 1;
      for(int n = 0;n<N;n++){
        if(h[n] != 0){
          if(height != h[n] + abs(x[n] - i) + abs(y[n] - j)) check = 0;
        }
        else if (height > abs(x[n] - i) + abs(y[n] - j)) check = 0;
      }
      if(check) cout << i << " " << j << " " << height << endl;
    }
  }
}

Measured memory_bytes: 256
n,x = map(int,input().split())

xl = list(map(int,input().split()))



xl = [i-x for i in xl]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


ans = abs(xl[0])
for xx in xl:
    ans = abs(gcd(ans, xx))

print(ans)    

Measured memory_bytes: 63128
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}



int main() {
	ll K, X;
	cin >> K >> X;


	for (int i = X - K + 1; i <= X + K - 1; i++) {
		cout << i << " ";
	}


	return 0;
}

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

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

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 LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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 rep(i,b) FOR(i, 0, b)
#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")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

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
    string s; cin >> s;
    if(s=="Sunny"){
      p("Cloudy");
    }else if(s=="Cloudy"){
      p("Rainy");
    }else{
      p("Sunny");
    }
    
    return 0;
}

Measured memory_bytes: 256
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;

int main(void) {
	// in = fopen("A.in", "rt");
	
    long long n, p;
    fscanf(in, "%lld %lld", &n, &p);
    
    long long ans = 1;
    for (long long d = 2; d * d <= p; d++) {
        if (p % d == 0) {
            int cnt = 0;
            while (p % d == 0) {
                p /= d;
                cnt++;
            }
            cnt /= n;
            for (int i = 0; i < cnt; i++)
                ans *= d;
        }
    }
    if (p > 1 && n == 1) {
        ans *= p;
    }
    fprintf(out, "%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372026854775807
#define    ninf   -inf
#define    ima   2047483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(12)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
#define    fbo    find_by_order
#define    ook    order_of_key
#define    upb    upper_bound
#define    lowb   lower_bound 
#define    lte(v,x)   upb(all(v),x)-v.be()
#define    gte(v,x)   v.end()-lowb(all(v),x)
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(x==0)return 0;if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}




int main()
{       io 
int testcases=1;      //  cin>>testcases;
while(testcases--)
{

int n;
cin>>n;

ll a[n],b[n];

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

sort(a,a+n);
sort(b,b+n);

if(n%2==1)
cout<<b[n/2]-a[n/2]+1;

else
cout<<(b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1);


}return 0;}


Measured memory_bytes: 6816
a, b = map(int, input().split())

if a ==1 and b == 1:
    print("Draw")
elif a==1:
    print("Alice")
elif b==1:
    print("Bob")
else:
    if a == b:
        print("Draw")
    elif a > b:
        print("Alice")
    else:
        print("Bob")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  int N; cin >> N;
  string S; cin >> S;
  rep(i,(int)S.size()) {
    if ('Z' < S[i]+N) {
      S[i] = (char)(S[i]+N-26);
    } else {
      S[i] = (char)(S[i]+N);
    }
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N, M = map(int, input().split())
d = defaultdict(int)
for i in range(N):
  A = list(map(int, input().split()))
  for i in range(1, A[0]+1):
    d[A[i]] += 1
ans = 0
for v in d.values():
  if v == N:
    ans += 1
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    string s;
    cin>>s;
    int r=0;
    rep(i,(int)s.size()){
        r+=s[i]-'0';
        r%=9;
    }
    if(r==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using namespace std;

int main()
{
    long long int ans=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        ans+=(s[i]-'0');
    }
    if(ans%9==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;

    if(x%y == 0) {
        cout << -1;
    }
    else {
        cout << x;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256