akhauriyash/Code-Regression huggingface dataset:
n = int(input())
v = list(map(int, input().split()))

l0 = [0 for i in range(10**5+1)]
l1 = [0 for i in range(10**5+1)]

a0 = [v[i] for i in range(0, n, 2)]
a1 = [v[i] for i in range(1, n, 2)]

for i in a0:
    l0[i] += 1
for i in a1:
    l1[i] += 1

first0 = 0
index0 = 0
for i in range(len(l0)):
    if l0[i] > first0:
        first0 = l0[i]
        index0 = i

l0[index0] = 0
second0 = max(l0)

first1 = 0
index1 = 0
for i in range(len(l1)):
    if l1[i] > first1:
        first1 = l1[i]
        index1 = i

l1[index1] = 0
second1 = max(l1)

if index0 != index1:
    print(n - first0 - first1)
else:
    print(min(n - first0 - second1, n - first1 - second0))



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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int countT;
    int countA;
    for (int i = 0; i < 1000; i++) {
        A = A - D;
        if (A <= 0) {
            countT = i;
            break;
        }
    }
    for (int i = 0; i < 1000; i++) {
        C = C - B;
        if (C <= 0) {
            countA = i;
            break;
        }
     
    }
    if (countT >= countA) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
let n=Int(readLine()!)!
var arr:[Int]=[]
for _ in 0..<n {
	arr.append(Int(readLine()!)!)
}
#if swift(>=3.0)
arr=arr.sorted()
#else
arr=arr.sort()
#endif
var r=1
var t=arr[0]
for i in 1..<n {
	if t != arr[i] {
		t=arr[i]
		r+=1
	}
}
print(r)

Measured memory_bytes: 768
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

typedef long long ll;
// #define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int a, b; cin >> a >> b;
  cout << max({2*a-1, a+b, 2*b-1}) << endl;

  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, k;
  cin >> a >> b >> k;
  set<int> s;
  int cnt = 1;
  int i = a;
  int j = b;
  while(a <= i && i <= b) {
    s.insert(i);
    i++;
    cnt++;
    if(cnt > k) break;
  }
  cnt = 1;
  while(a <= j && j <= b) {
    s.insert(j);
    j--;
    cnt++;
    if(cnt > k) break;
  }
  for(auto x : s) {
    cout << x << endl;
  }
  return 0;
}

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

int main(){
	int n;
	cin>>n;
	int a[n+5][3];
	for(int i=1; i<=n; i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
	int dp[n+5][3];
	memset(dp,0,sizeof(dp));
	for(int i=1; i<=n; i++){
		for(int j=0; j<=2; j++){
			for(int k=0; k<=2; k++){
				if(k==j) continue;
				dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][k]);
			}
		}
	}
	cout<<max(dp[n][0], max(dp[n][1],dp[n][2]));
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main() {
	int n, date, kazu,dai;
	cin >> n;
	kazu = 0;
	dai = 0;
	for (int i = 1; i <= n; i++) {
		cin >> date;
		if (date == 0) {
			kazu = 0;
		}
		if (date == 1) {
			kazu = kazu + 1;
		}
		if (kazu > dai) {
			dai = kazu;
		}
	}
	cout << dai + 1 << endl;
}


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

int main()
{
    int k;
    cin>>k;
    
    if(k%2==0||k%5==0)
    {
        cout<<-1<<endl;
    }
    else
    {
        int x=7;
        int c=1;
        while(1)
        {
            if(x%k==0)
            {
                break;
            }
            else
            {
                x=(x*10+7)%k;
                
            }
            c++;
        }
        cout<<c<<endl;
    }
}

Measured memory_bytes: 3596
n,*a=map(int,open(0).read().split())
MOD=10**9+7
from fractions import gcd

def lcm(x,y):return x*y//gcd(x,y)
def inv(x):return pow(x,MOD-2,MOD)

L=1
for i in a:L=lcm(L,i)
L=L%MOD
ans=0
for i in a:ans=(ans+L*inv(i))%MOD
  
print(ans)

Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(LL, n);
	LL ans = 0;
	inc1(i, n) {
		LL x = n / i;
		ans += x * (x + 1) * i / 2;
	}
	OUT(ans);
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n,l;cin>>n>>l;
	vector<string>s(n);
	rep(i,n)cin>>s[i];
	sort(all(s));
	deque<char>t;
	rep(i,n){
		rep(j,l){
			t.PB(s[i][j]);
		}
	}
	rep(i,t.size())cout<<t[i];
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst) : src(src), dst(dst), weight(1) {}
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int main(){
  int N, Q;
  cin >> N >> Q;
  Graph g(N);
  REP(i, N-1) {
    int a, b;
    cin >> a >> b; a--; b--;
    g[a].push_back(Edge(a, b));
    g[b].push_back(Edge(b, a));
  }
  vector<int> cnt(N, 0);
  REP(i,Q) {
    int p, x;
    cin >> p >> x; p--;
    cnt[p] += x;
  }

  queue<Edge> que;
  que.push(Edge(-1, 0));  // prev, curr
  while(!que.empty()) {
    Edge q = que.front(); que.pop();
    for (Edge e: g[q.dst]) {
      if (e.dst == q.src) continue;
      cnt[e.dst] += cnt[e.src];
      que.push(e);
    }
  }

  REP(i,N) {
    if(i) cout << " ";
    cout << cnt[i];
  }
  cout << endl;
  return 0;
}



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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> ans(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    ans.at(a-1)++;
    ans.at(b-1)++;
  }
  for(int i=0;i<n;i++)cout << ans.at(i) << endl;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


n = int(input())
mod = 10**9 + 7
dic = {}
for i in range(2, n + 1):
    tmp = prime_factorize(i)
    for j in tmp:
        if j in dic:
            dic[j] += 1
        else:
            dic[j] = 1

ans = 1
for i in dic.values():
    ans *= i + 1

if ans == 1:
    print(1)
else:
    print(ans % mod)


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

int main() {
    int a, b, c, tmp;
    cin >> a;
    cin >> b;
    cin >> c;

    if (b < a) {
        tmp = b;
        b = a;
        a = tmp;
    }
    if (c < b) {
       tmp = c;
       c = b;
       b = tmp;
    }

    if (b < a) {
        tmp = b;
        b = a;
        a = tmp;
    }

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

    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <cstdio>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n;
const int MAX_N = 100001;
const int MAX_A = 12;
double dp[MAX_N + 1][MAX_A + 1] = {0};//日にち、連続
double ans[MAX_N] = {0};

int main(void)
{
	dp[0][0] = 1;
	double sum = 0;
	for (int i = 0; i < MAX_N; i++)
	{
		for (int j = 0; j < MAX_A; j++)
		{
			if(!dp[i][j]) continue;
			sum += dp[i][j] * 1.0 / (1 << j);
			dp[i+1][j+1] = dp[i][j] * 1.0 / (1 << j);
			dp[i+1][0] += dp[i][j] * (1.0 - 1.0 / (1 << j));
		}
		ans[i] = sum;
	}
	while(cin >> n && n)
	{
		printf("%.8f\n", ans[n-1]);
	}
	return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

const ll maxn=1e3+1,mod=1e9+7;

int memo[maxn][maxn][2];
string a;
int n;
vector<int> alpha(26);

bool f(vector<int> a,vector<int> b){
    ld sum = 0;
    forn(i,a.size()){
        ll temp = a[i]-b[i];
        temp*=temp;
        sum+=temp;
    }
    // cout<<sum<<endl;
    ld s = sqrt(sum);
    // cout<<fixed<<setprecision(10)<<s<<endl
    if(s-int(s)==0) return true;
    return false;
}

int main(){
    sync
 
    int n,d;
    cin>>n>>d;
    vector<int> v[n];
    forn(i,n){
        forn(j,d){
        int x;
        cin>>x;
        v[i].pb(x);
    }
    }
    int ans = 0;
    forn(i,n){
        fore(j,i+1,n-1){
            if(f(v[i],v[j])) ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int m,n;
	string s;
	cin>>m>>n>>s;
	if(s.length()==(m+n+1))
	{
		for(int i=0;i<s.length();i++)
		{
			if(i!=m&&(s[i]<'0'||s[i]>'9'))
			{
				cout<<"No\n";
				return 0;
			}
		}
		if(s[m]=='-')
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))

edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    fr, to = map(int, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

order = []
parent = [-1] * (N + 1)
st = [1]
while st:
    now = st.pop()
    order.append(now)
    if now > 0:
        st.append(-now)
        for to in edges[now]:
            if to == parent[now]:
                continue
            st.append(to)
            parent[to] = now

L = [-10**18]
ans = [-1] * (N + 1)
st = [(-1, -1)] * (N + 1)

for now in order:
    if now < 0:
        val, idx = st[-now]
        if val == -1:
            L.pop()
        if val > 0:
            L[idx] = val
        continue

    a = A[now - 1]
    i = bisect_left(L, a)

    if len(L) == i:
        L.append(a)
    else:
        st[now] = (L[i], i)
        if L[i] > a:
            L[i] = a

    ans[now] = len(L) - 1

print(*ans[1:], sep='\n')


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

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

//------------------------------------------------------------------------------------------------------------------------------

int dp[3010][3010];
int main(void) {
    int N, T;
    cin >> N >> T;
    vector<P> AB(N);
    for(int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        AB[i].first = a, AB[i].second = b;
    }
    sort(AB.begin(), AB.end());
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < T; j++) {
            dp[i + 1][j] = dp[i][j];
            if(AB[i].first <= j){
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - AB[i].first] + AB[i].second);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans = max(ans, dp[i][T - 1] + AB[i].second);
    }
    cout << ans << endl;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define ll long long

using namespace std;

// input
int a,b,c,d;

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


    cin >> a >> b >> c >> d;

    int diff_x = c-a;
    int diff_y = d-b;

    int x = c - diff_y;
    int y = d + diff_x;

    cout << x << " " << y << " ";

    cout << x - diff_x << " " << y - diff_y << "\n";

}

Measured memory_bytes: 256
/*
2020-05-05
atcoder ABC
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int N, ans;
    string S;
    cin >> N >> S;
    rep(i, N - 2){
        if((S[i] == 'A') && (S[i + 1] == 'B') && (S[i + 2] == 'C')){
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int n; cin >> n;
  vector< pair<int, int> > nums(n);
  int x, y;
  rep_i(i, n){
    cin >> x >> y;
    nums[i] = make_pair(x, y);
  }
  sort_v(nums);
  rep_i(i, n){
    cout << nums[i].first << " " << nums[i].second << endl;
  }
}


Measured memory_bytes: 3624
import math as m
 
def main():
    n  = raw_input()
    a = map(float,raw_input().split())
    
    avg =  m.ceil( sum(a)/len(a) )
    avg2 =  m.floor( sum(a)/len(a) )

    cost = 0
    for i in a:
        cost += (avg - i) ** 2
    
    cost2 = 0
    for i in a:
        cost2 += (avg2 - i) ** 2
    
    print int(min([cost,cost2]))

if __name__ == '__main__':
    main()

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int n;
    cin >> n;
    V<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = TEN(18);
    rep(t, 2) {
        ll s = 0;
        ll need = 0;
        rep(i, n) {
            s += a[i];
            int f = (t + i) & 1;
            if (f) {
                if (s > 0) continue;
                need += abs(s - 1);
                s = 1;
            } else {
                if (s < 0) continue;
                need += abs(s + 1);
                s = -1;
            }
        }
        chmin(ans, need);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int a[N];
	int dp[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n,&k);
	f(i, n){
		scanf("%d", &a[i]);
		dp[i] = MOD;
	}
	dp[0] = 0;
	f(i, n){
		f(j, k){
			if (i + j + 1 < n){
				dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i]));
			}
		}
	}

	printf("%d\n", dp[n-1]);


	return 0;
}

Measured memory_bytes: 1280
#include<cmath>
#include<string>
#include<fstream>
#include<iostream>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){
	int A,B,C,X;
	cin >> A >> B >> C >> X;
	int cnt=0;
	rep(i,A+1) rep(j,B+1) rep(k,C+1) if(500*i+100*j+50*k==X) cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#!/ust/bin/env python

N,A,B=[int(i) for i in input().split()]

def main():
    if(A>B):
        print(0)
        return
    elif(A==B):
        print(1)
        return

    ### A<B
    Max=(A+B)+(N-2)*B
    Min=(A+B)+(N-2)*A

    if(N==1):
        print(0)
    elif(N==2):
        print((B+B)-(A+A)+1)
    elif(Max-Min+1<=0):
        print(0)
    else:
        print(Max-Min+1)

main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int Max=3e3;
const long long Mod=1e9+7;
#define int long long
int n,m,f[Max+10][Max+10]={},c[Max+10][Max+10]={},b[Max+10]={},l[Max+10]={},r[Max+10]={};
struct kk{
    int l,r,v;
} e[Max+10]={};
char a[Max+10]={};
main(){
 // freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    scanf("%lld%lld",&n,&m);
    scanf("%s",a+1);
    for(int i=1;i<=n;i++)
     b[i]=b[i-1]+(a[i]=='1');
    c[0][0]=c[0][1]=c[1][1]=1;
    for(int i=2;i<=Max;i++){
        c[0][i]=c[i][i]=1;
        for(int j=1;j<i;j++)
         c[j][i]=(c[j-1][i-1]+c[j][i-1])%Mod;
    }
    int Max=0;
    for(int i=1;i<=m;i++) {
        scanf("%d%d",&e[i].l,&e[i].r);
    }
    for(int i=1;i<=m;i++)
     for(int j=1;j<=m;j++)
      if(i!=j&&e[j].l>=e[i].l&&e[j].r<=e[i].r&&!e[i].v) e[j].v=1;
    int s=0;
    for(int i=1;i<=m;i++)
     if(!e[i].v) ++s,l[s]=e[i].l,r[s]=e[i].r;
    m=s;
    f[0][0]=1;
    for(int i=1;i<m;i++){
        if(l[i+1]>r[i]){
            for(int j=0;j<=n;j++)
             f[i][0]+=f[i-1][j]*c[j+b[r[i]]-b[max(r[i-1],l[i]-1)]][r[i]-l[i]+1]%Mod,f[i][0]%=Mod;
        }else{
            for(int j=0;j<=r[i]-l[i+1]+1;j++)
             for(int k=0;k<=n;k++)
              if(k+b[r[i]]-b[max(r[i-1],l[i]-1)]-j>=0){
                f[i][j]+=f[i-1][k]*c[k+b[r[i]]-b[max(r[i-1],l[i]-1)]-j][l[i+1]-l[i]]%Mod,f[i][j]%=Mod;
              }
        }
    }    
    int ans=0; 
     for(int i=0;i<=n;i++)
      ans+=f[m-1][i]*c[i+b[r[m]]-b[max(r[m-1],l[m]-1)]][r[m]-l[m]+1]%Mod,ans%=Mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 102656
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    // 入力処理
    ll n, c, ans = 0; cin >> n >> c;
    vector<pair<ll, ll>> l(n), r(n);
    rep(i, n){
        // 時計回りと反時計回りを同時に処理
        cin >> l[i].first >> l[i].second;
        r[i].first = c - l[i].first;
        r[i].second = l[i].second;
    }
    // 整列
    sort(all(l)); sort(all(r));

    // 累積スコアの計算
    vector<pair<ll, ll>> ls(n), rs(n);
    vi lsMax(n), rsMax(n), lss(n), rss(n);
    rep(i, n){
        if(i == 0){
            // 最初の1つ目
            ls[i] = make_pair(l[i].first, l[i].second);
            rs[i] = make_pair(r[i].first, r[i].second);
            // 地点iまでの累積スコアの最大値
            lsMax[i] = ls[i].second - ls[i].first;
            rsMax[i] = rs[i].second - rs[i].first;
            // 始点に戻った場合
            lss[i] = ls[i].second - 2*ls[i].first;
            rss[i] = rs[i].second - 2*rs[i].first;
        }
        else{
            // 累積スコア
            ls[i] = make_pair(l[i].first, ls[i-1].second + l[i].second);
            rs[i] = make_pair(r[i].first, rs[i-1].second + r[i].second);
            // 地点iまでの累積スコアの最大値
            lsMax[i] = max(lsMax[i-1], ls[i].second - ls[i].first);
            rsMax[i] = max(rsMax[i-1], rs[i].second - rs[i].first);
            // 始点に戻った場合
            lss[i] = ls[i].second - 2*ls[i].first;
            rss[i] = rs[i].second - 2*rs[i].first;
        }
    }
    // 最大スコアの算出
    for(ll i=0; i<n; i++){
        // 一方向に地点iまで進んで脱出する場合
        chmax(ans, max(lsMax[i], rsMax[i]));
        // 地点iまで進んで逆方向に進む
        if(i != n-1){
            chmax(ans, lss[i]+rsMax[n-i-2]);
            chmax(ans, rss[i]+lsMax[n-i-2]);
        }
    }

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

Measured memory_bytes: 12672
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

int main()
{
	int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
	if (std::abs(x - a) < std::abs(x - b))
		printf("A\n");
	else
		printf("B\n");
	
	return 0;
}

Measured memory_bytes: 256
class Rectangle:
    def __init__(self,H,W):
        self.H = H
        self.W = W
    
    def draw(self):
        TB = "#" * self.W
        M = "#" + "." * (self.W-2) + "#"
        print(TB)
        for h in range(self.H - 2):
            print(M)
        print(TB)

li = []
while 1:
    H, W =map(int,input().split())
    if H == W == 0:
        break
    else:
        li.append(Rectangle(H,W))

for l in li:
    l.draw()
    print("")        
            


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100005];
long long bs (bool yes)
{
    long long low=2,mid,high=1e18,ans=-1;
    while (low<=high)
    {
        mid=(low+high)/2;
        long long cur=mid;
        for (int i=0;i<n;i++)
        {
            cur-= (cur%a[i]);
        }
        if (cur==2)
        {
            ans=mid;
            if (yes)
                low=mid+1;
            else
                high=mid-1;
        }
        else if (cur>2)
            high=mid-1;
        else
            low=mid+1;
    }
    return ans;
}
int main()
{
    cin >>n;
    for (int i=0;i<n;i++)
        cin >>a[i];
    long long x=bs(0),y=bs(1);
    if (x!=-1)
        cout<<x<<" "<<y;
    else
        cout<<x;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.math.*;
class Main{
public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		long n = sc.nextLong();
		long k = sc.nextLong();
		if(n*500>=k)
			System.out.println("Yes");
		else System.out.println("No");
		
	}
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer sz;


		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (sz == null || !sz.hasMoreTokens()) {
				try {
					sz = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return sz.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}

Measured memory_bytes: 21204
n=int(input())
b=list(map(int,input().split()))

a=[0]
for i in range(n):
    a.append(b[i])
a.append(0)

minus=[0]*n
ans=abs(a[1]-a[0])
for i in range(1,n+1):
    ans+=abs(a[i+1]-a[i])
    if (a[i-1]<=a[i] and a[i]<=a[i+1]) or (a[i-1]>=a[i] and a[i]>= a[i+1]):
        continue
    else:
        minus[i-1]=2*min(abs(a[i]-a[i-1]), abs(a[i]-a[i+1]))
for i in range(n):
    print(ans-minus[i])

Measured memory_bytes: 58348
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, M;
ll cnt[50];

int main() {
  std::cin >> N >> M;

  rep( i, N ) {
    ll K;
    std::cin >> K;

    rep( j, K ) {
      ll A;
      std::cin >> A;
      --A;

      ++cnt[A];
    }
  }

  ll ans = 0;

  rep( i, M ) if( cnt[i] == N )
    ++ans;

  std::cout << ans << endl;

  return 0;
}

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

int main() {
  long n, k;
  cin >> n >> k;
  if (2 * k > n + 1) {
    cout << -1 << endl;
    return 0;
  }
  int nhalf = n / 2;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      cout << k + i / 2 << " " << k + n + nhalf + i / 2 << " " <<
        k + 2 * n + i << "\n";
    } else {
      cout << k + n - nhalf + i / 2 << " " << k + n + i / 2 << " " <<
        k + 2 * n + i << "\n";
    }
  }
}


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

using namespace std;

int main(){
    int n;
    cin >>n;
    int cnt = 0, m= n+1;
    for(int i=0;i<n;i++){
        int a;
        cin >>a;
        if(a < m){
            m = a;
            cnt++;
        }
    }

    cout << cnt;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 998244353
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


//——————— comre(n);　→　nCk=com(n,k) —————————————————

vector<ll> fact, fact_inv, inv;
/*  comre :二項係数のための前処理
    計算量:O(n)
*/
void comre(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}
/*  com :modでの二項係数を求める(前処理 comre が必要)
    計算量:O(1)
*/
ll com(ll n, ll k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

//—————————————————————————————————————————————————


int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;


  ll ans[c+1][d+1];
  memset(ans,0,sizeof(ans));
  rep(i,a+1){
    rep(j,b+1){
      ans[i][j]=1;
    }
  }

  for(int i=a;i<=c;i++){
    for(int j=b;j<=d;j++){
      if(j>b) ans[i][j]+=i*ans[i][j-1];
      if(ans[i][j]>=mod) ans[i][j]%=mod;

      if(i>a) ans[i][j]+=j*ans[i-1][j];
      if(ans[i][j]>=mod) ans[i][j]%=mod;

      if(i>a && j>b) ans[i][j]-=(i-1)*(j-1)*ans[i-1][j-1];
      if(ans[i][j]<0) ans[i][j]=ans[i][j]%mod+mod;
    }
  }

  cout << ans[c][d] << endl;
}


Measured memory_bytes: 73904
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int	
#define INF					1e6+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }

int main()
{
	int n;
	cin >> n;
	int sumL = 0;
	int sumR = 0;

	vdef w(n, 0);
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
		sumR += w[i];
	}

	int ans = sumR;


	for (int i = 0; i < n; ++i)
	{
		sumR -= w[i];
		sumL += w[i];
		int comp = abs(sumL - sumR);
		chmin(ans, comp);
	}


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define repf(i,s,e)  for(int i=s;i<e;i++)
#define repb(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


void solve(){
	int n;
	cin>>n;

	bool ok=0;
	while(n>0){
		int num=n%10;
		if(num==7) ok=1;
		n/=10;
	}

	if(ok){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	if(fopen("input.txt", "r")){
	    freopen("input.txt", "r", stdin),
	    freopen("output.txt", "w", stdout);
	}
	
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  string ans = "";
  while (n != 0) {
    int x = n % 2;
    if (x < 0) x += 2;
    ans += (char)('0' + x);
    n = (n - x) / -2;
  }
  if (ans.size() == 0) ans = "0";
  reverse(all(ans));

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


int main(){

    long long int n,p;
    cin>>n>>p;
    long long int max = 1+pow(p, 1 / (n * 1.0));
    long long int i;
    for (i = max; p % ((long long int)pow(i,n)) != 0; i--);
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = int(input())
l = [a]
d = {a: 1}
ans = 1
for _ in range(1, N):
    a = int(input())
    if a in d:
        d[a] += 1
        if l[-1] == a:
            ans += 1
        else:
            i = l.index(a) + 1
            v = l[i]
            if d[v] == 1:
                del d[v]
                l.remove(v)
            else:
                d[v] -= 1
    else:
        v = l[0]
        if v < a:
            if d[v] == 1:
                del d[v]
                l[0] = a
            else:
                d[v] -= 1
                l.insert(0, a)
        elif l[-1] > a:
            l.append(a)
            ans += 1
        else:
            left, right = 0, len(l) - 1
            while left + 1 != right:
                i = (left + right) // 2
                x = l[i]
                if x > a:
                    left = i
                else:
                    right = i
            v = l[right]
            if d[v] == 1:
                del d[v]
                l[right] = a
            else:
                d[v] -= 1
                l.insert(right, a)
        d[a] = 1
print(ans)


Measured memory_bytes: 15640
N, K = map(int, input().split())
S = list(map(int, input().strip()))

tmp = S[0]
l = [0]
for i in range(N):
    if S[i] != tmp:
        l.append(i)
        tmp = S[i]
r = len(l)
l.extend([N] * (K*2 + 1))    

x = [0] * (r)
for i in range(r):
    if S[l[i]] == 0:
        x[i] = l[i+K*2] - l[i]
    else:
        x[i] = l[i+K*2+1] - l[i]
        
print(max(x))        

Measured memory_bytes: 12092
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N; cin>>N;
	cout<< 180*(N-2)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int max = 0;
		int k;
		int [] kyogi = new int[n];
		int [] kyogi2 = new int[n];
		int [] sinsa = new int[m];
		for(int i = 0; i < n; i++) {
			kyogi[i] = sc.nextInt();
		}
		for(int j = 0; j < m; j++) {
			sinsa[j] = sc.nextInt();
		}
		for(int j = 0; j < m; j++) {
			for(int i = 0; i < n; i++) {
				if(kyogi[i] <= sinsa[j]) {
					kyogi2[i]++;
					break;
				}
			}
		}
		for(int i = 0; i < n; i++) {
			if(i == 0 || kyogi2[i] > max) {
				max = kyogi2[i];
			}
		}
		for(k = 0; k < n; k++) {
			if(max == kyogi2[k]){
				break;
			}
		}
		System.out.println(k + 1);
	}

}

Measured memory_bytes: 25436
b = list(map(int, input().split()))
mozi = str(b)
A = b[0]//1000
B = (b[0]-A*1000)//100
C = (b[0]-A*1000-B*100)//10
D = b[0]%10

if(A+B+C+D==7):
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif(A+B+C-D==7):
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif(A+B-C+D==7):
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif(A+B-C-D==7):
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif(A-B+C+D==7):
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif(A-B+C-D==7):
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif(A-B-C+D==7):
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif(A-B-C-D==7):
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Measured memory_bytes: 3064
def readinput():
    n=int(input())
    return n

def main(x):
    if 400<=x and x<=599:
        return 8
    elif 600<=x and x<=799:
        return 7
    elif 800<=x and x<=999:
        return 6
    elif 1000<=x and x<=1199:
        return 5
    elif 1200<=x and x<=1399:
        return 4
    elif 1400<=x and x<=1599:
        return 3
    elif 1600<=x and x<=1799:
        return 2
    elif 1800<=x and x<=1999:
        return 1
    else:
        return 0

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


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

int N, M;
int A[3];
vector<int> G[51];
bool used[51];
int cnts[51];
bool dp[101][51][51];  // a step, b start, c goal

int main(){

  cin>>N>>M;
  for(int i=0;i<3;i++)cin>>A[i];
  for(int i=0;i<M;i++){
    int f,t;
    cin>>f>>t;
    f--;t--;
    G[f].push_back(t);
  }
  int ite = 0;

  for(int i=0;i<N;i++)
    dp[0][i][i] = true;
  for(int i=1;i<101;i++){
    for(int j=0;j<N;j++){
      // ??????step??§??°?????????????????´??????????????????, ???????????????????????´????????????
      for(int k=0;k<N;k++){
        if(dp[i-1][j][k]){
          // k?????????????????´???
          for(int to : G[k]){
            dp[i][j][to] = true;
          }
        }
      }
    }
  }
  
  used[N-1] = true;
  cnts[N-1] = 0;
  // N step??§???????????´????????????
  while(1){
    bool ok = false;
    vector<int> idx;
    for(int i=0;i<N;i++){
      // ??????????????´?????????1step??§???????????´???????????????????????????
      if(used[i])continue;
      // ???????????????????????????
      int cnt = 0;
      int max_step = -1;
      for(int j=0;j<3;j++){
        // ???????????????step??§, goal?????´????????°?????§??????????????????
        int a = A[j];
        bool t = false;
        int min_step = 100000000;
        for(int k=0;k<N;k++){
          if(dp[a][i][k] && used[k]){
            // cnt++;
            min_step = min(min_step, cnts[k] + 1);
            t = true;
          }
        }
        if(t){
          cnt++;
          max_step=max(max_step, min_step);
        }
      }
      // OK
      if(cnt == 3){
        cnts[i] = max_step;
        // used[i]=true;
        ok=true;
        idx.push_back(i);
      }
    }
    if(ok){
      ite++;
      for(int i : idx){
        used[i]=true;
      }
      if(used[0]){
        cout<<ite<<endl;
        return 0;
      }
    }
    else{
      break;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  
  return 0;
}

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

#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")



#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n,k;

void solve()
{
	cin>>n>>k;

	set<pii> adj;

	rep(i,2,n+1)adj.insert({1,i});

	if (k>(n-1)*(n-2)/2)
	{
		cout<<-1;return;
	}

	int cur=(n-1)*(n-2)/2;
	if (cur==k)
			{
				cout<<adj.size()<<"\n";for (auto x:adj)cout<<x.ff<<" "<<x.ss<<"\n";
				return;
			}
	rep(i,2,n+1)
	{
		rep(j,i+1,n+1)
		{
			
			cur--;
			adj.insert({i,j});
			if (cur==k)
			{
				cout<<adj.size()<<"\n";for (auto x:adj)cout<<x.ff<<" "<<x.ss<<"\n";
			}
		}

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

    #ifdef local
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    #endif

    clock_t qwertyuiop = clock();
    int t=1;
    ///cin>>t;
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


Measured memory_bytes: 640
N = int(input())
x = list(map(int, input().split()))

for i in range(N):
    x[i]=(x[i]%4)

a=x.count(1)+x.count(3)
o=x.count(0)

if(o>=a):
    print('Yes')
    quit()

if(o==a-1):
    if(x.count(2)==0):
       print('Yes')
       quit()
     
print('No')


quit()

Measured memory_bytes: 14252
/*
	ID: Abhinav
	LANG: C++11
	TASK: inna and matrix
	*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;	
int main()
{
    int count =0;
    string s;
    cin>>s;
    vector<int>v;
    for(int i =0;i<s.length();++i)
    {
      if(s[i]!='S')
      {
        count++;
      }
      else
      {
         v.push_back(count);
        count=0;
       
      }
    }
    v.push_back(count);
    sort(v.begin(),v.end());
    cout<<v[v.size()-1];
    return 0;
}

Measured memory_bytes: 3628