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

int inputint(void){int n;cin>>n;return n;}
string inputstr(void){string s;cin>>s;return s;}
vector<int> inputvecint(int n){vector<int> vec(n);for(int i=0;i<n;i++)cin>>vec.at(i);return vec;}
vector<string> inputvecstr(int n){vector<string> vec(n);for(int i=0;i<n;i++)cin>>vec.at(i);return vec;}

int main(){
  int N=inputint();
  vector<int> d=inputvecint(N);

  sort(d.begin(),d.end());

  int x=1;
  for(int i=0;i<N-1;i++){
    if(d.at(i+1)>d.at(i)) x++;
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma once
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(vs) (vs).begin(),(vs).end()
#define roundup(A,B) (A)/(B)+((A)%(B)==0?0:1)
using namespace std;


/*
  予想と答えをすべて比較するのが最速。O(n)
*/
void A() {
	string s, t;
	cin >> s >> t;
	int answer = 0;
	rep(i, s.length()) {
		if (s[i] == t[i])answer++;
	}
	cout << answer << endl;
}

/*
  タップを使うごとにA-1ずつ増える。Bと1の距離をA-1で割った（切り上げ）のが答え。
  A,Bの値によらないのでO(1)の解法である。
*/
void B() {
	int A, B; cin >> A >> B;
	cout << roundup(B-1, A-1) << endl;
}

/*
  左から走査することで最大長を求めることができる。最大長を0で初期化し、
  左端からスタートする。右に進める限り現在の長さをincrementし、進めなくなったところで最大長を更新する。
  そして止まったところからリセットして再開する。これを繰り返すことで最大長を求めることができる。
  計算量はO(n)、空間量はO(1)となる。
*/
void C() {
	int n; cin >> n;
	int length = 0, max_length = 0;
	int prev = 0, current;
	rep(i, n) {
		cin >> current;
		if (prev >= current) {
			length++;
		} else {
			max_length = max(max_length, length);
			length = 0;
		}
		prev = current;
	}
	max_length = max(max_length, length);
	cout << max_length << endl;
}

int main() { C(); }



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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

int h[1501];
int w[1501];
int sh[1501];
int sw[1501];


void solve(int N, int M) {

    REP(i, N) {
        cin >> h[i];
    }
    REP(i, M) {
        cin >> w[i];
    }

    sh[0] = 0;
    sw[0] = 0;
    REP(i, N) {
        sh[i+1] = sh[i] + h[i];
    }
    REP(i, M) {
        sw[i+1] = sw[i] + w[i];
    }

    map<int, int> hmap;
    REP(i, N) REPS(j, i+1, N+1){
        hmap[sh[j]-sh[i]]++;
    }

    int ans = 0;
    REP(i, M) REPS(j, i+1, M+1){
        ans += hmap[sw[j]-sw[i]];
    }

    cout << ans << endl;

}

signed main() {
    int N, M;
    while(true) {
        cin >> N >> M;
        if(N == 0 && M == 0) {
            break;
        } else {
            solve(N, M);
        }
    }

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々


Measured memory_bytes: 20908
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str;
    cin>>str;
    if(str.size()<2){
        cout<<"-1 -1";
    }
    for(int i=0;i+2<=str.size();i++){
        if(str[i]==str[i+1]){
            cout<<i+1<<" "<<i+2;
            return 0;
        }
    }
    for(int i=0;i+3<=str.size();i++){
        if(str[i]==str[i+2]){
            cout<<i+1<<" "<<i+3;
            return 0;
        }
    }
    cout<<"-1"<<" "<<"-1";
    return 0;
}


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

int main() {
  
  long long a, b;
  cin >> a >> b;
  
  long long aa, bb, r;
  aa=max(a, b);
  bb=min(a, b);
  r=aa%bb;
  while(r!=0){
    aa=bb;
    bb=r;
    r=aa%bb;
  }
  
  cout << a*b/bb << endl;
}

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

int main() {
  char C;
  cin >> C;
  if((C == 'a')||(C == 'i')||(C == 'u')||(C == 'e')||(C == 'o'))
    cout << "vowel\n";
  else
    cout << "consonant\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using Point = pair<int, int>;
const int INF = (int)1e9;

int H, W;
char A[1000][1000];

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

int main(void){
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> A[i][j];
        }
    }

    int res = 0;
    queue<Point> que;
    int num;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(A[i][j] == '#'){
                que.push(Point(i, j));
                num++;
            }
        }
    }

    while(num > 0){
        int tmp = 0;
        for(int i = 0; i < num; i++){
            Point p = que.front(); que.pop();
            int y = p.first, x = p.second;
            for(int j = 0; j < 4; j++){
                int ny = y + dy[j], nx = x + dx[j];
                if(ny < 0 or H <= ny or nx < 0 or W <= nx) continue;

                if(A[ny][nx] == '.'){
                    A[ny][nx] = '#';
                    que.push(Point(ny, nx));
                    tmp++;
                }
            }
        }
        num = tmp;
        if(num > 0) res++;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 9360
#include <bits/stdc++.h>
#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++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
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);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

//snuke
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n,k;
  cin >> n >> k;
  if(k==0){cout<<1<<endl; return 0;}
  vector<ll> a(n);
  rep(i,n){ cin >> a[i]; }
  vector<vector<mint>> dp(110, vector<mint>(mx,0));
  vector<mint> cum(mx); //cum[x]: sum(dp[i][0~x)) ruisekiwa
  dp[0][0]=1;
  
  rep(i,n){ 
    cum[0]=0;
    rep(p,k+1){ cum[p+1]=cum[p]+dp[i][p]; }
    rep(j,k+1){ 
      dp[i+1][j] += cum[j+1]-cum[max(0LL,j-a[i])];
    }
  }
  cout << dp[n][k].x << endl;
  return 0;
}

Measured memory_bytes: 87296
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
  int a,b;
  cin >> a >> b;
  if ( a >= 13 ){
    cout << b << endl;
  }else if( 6 <= a ) {
    cout << b/2 << endl;
  }else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] w = new int[N];
		int[] v = new int[N];
		for (int i = 0; i < N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		long[] dp = new long[W + 1];
		for (int i = 0; i < N; i++) {
			for (int j = W - w[i]; j >= 0; j--) {
				dp[j + w[i]] = Math.max(dp[j + w[i]], dp[j] + v[i]);
			}
		}
		System.out.println(dp[W]);
	}

}


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

int main()
{
    int n,m,sum = 0;
    cin >> n;
    int t[n];
    for(int i = 0; i < n; i++){
        cin >> t[i];
        sum += t[i];
    }
    cin >> m;
    int p[m],x[m];
    for(int i = 0; i < m; i++)
        cin >> p[i] >> x[i];
        
    for(int i = 0; i < m; i++)
        cout << sum - (t[p[i]-1] - x[i]) << endl;

    return 0;
}

Measured memory_bytes: 256
b1,b2,b3=map(int,input().split())
if b1==1 and b2==1 and b3==0:
 print('Open')
elif ((b1==1 and b2==0) or (b1==0 and b2==1)) and b3==0:
 print('Close')
elif b1==0 and b2==0 and b3==1:
 print('Open')
else:
 print('Close')


Measured memory_bytes: 5592
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A+1):
    for b in range(B+1):
        x = X - (a*500+b*100)
        if x < 0:
            break
        if (x % 50 == 0) and (x / 50 <= C):
            count += 1
print(count)


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

int main() {
  int N, odd;
  cin >> N;
  odd = (N+1)/2;
  double A = odd,B = N;
  
  cout << A/N << endl;
}


Measured memory_bytes: 256
s=0
t=0
m=list(map(int,input().split()))
if(m[0]==1):
  s=s+300000
  t=t+1
if(m[1]==1):
  s=s+300000
  t=t+1
if(m[0]==2):
  s=s+200000
if(m[1]==2):
  s=s+200000
if(m[0]==3):
  s=s+100000
if(m[1]==3):
  s=s+100000
if(t==2):
  s=s+400000
print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	int K = 0;
	while(K*(K-1)/2 < N) K++;
	if(K*(K-1)/2 != N) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n" << K << "\n";
	vector< vector<int> > sets(K);
	int cur = 1;
	for(int i = 0; i < K; i++) for(int j = i+1; j < K; j++) {
		sets[i].push_back(cur);
		sets[j].push_back(cur++);
	}
	for(int i = 0; i < K; i++) {
		cout << sets[i].size();
		ALL_THE(sets[i], it) cout << " " << *it;
		cout << "\n";
	}
	return 0;
}

// look at my code
// my code is amazing


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>         vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)            for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 998244353;

const int N = 2e5, T = 4 * N + 10;
vector<ll> st(T), lazy(T), pw(N, 1), accpw(N + 1, 1);

void build(int id, int l, int r) {
  if (l == r) st[id] = 1;
  else {
    int mid = avg(l, r);
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    st[id] = ((st[id << 1] * pw[r - mid]) % mod + st[id << 1 | 1]) % mod;
  }
};

void prop(int id, int l, int r) {
  if (lazy[id]) {
    st[id] = lazy[id] * accpw[r - l] % mod;
    if (l != r) {
      lazy[id << 1] = lazy[id];
      lazy[id << 1 | 1] = lazy[id];
    }
    lazy[id] = 0;
  }
}

void update(int id, int l, int r, int a, int b, int d) {
  prop(id, l, r);
  if (r < a or l > b) return;
  if (a <= l and r <= b) lazy[id] = d, prop(id, l, r);
  else {
    int mid = avg(l, r);
    update(id << 1, l, mid, a, b, d);
    update(id << 1 | 1, mid + 1, r, a, b, d);
    st[id] = ((st[id << 1] * pw[r - mid]) % mod + st[id << 1 | 1]) % mod;
  }
}

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

  int n, q;
  cin >> n >> q;
  for (int i = 1;i <= n;i++) {
    pw[i] = pw[i - 1] * 10 % mod;
    accpw[i] = (accpw[i - 1] + pw[i]) % mod;
  }
  build(1, 0, n - 1);
  int l, r, d;
  loop(q) {
    cin >> l >> r >> d;
    update(1, 0, n - 1, l - 1, r - 1, d);
    cout << st[1] << endl;
  }
  return 0;
}



Measured memory_bytes: 18688
import numpy as np
from itertools import combinations

N, D = map(int, input().split())
X = [np.array(input().split(), dtype=np.int64) for _ in range(N)]

ans = 0
for x, y in combinations(X, 2):
  d = pow((x-y), 2).sum()
  if (d**0.5).is_integer():
    ans += 1
print(ans)

Measured memory_bytes: 12496
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    int N;
    cin>>N;
    int x;
    x=800*N;
    int b,y;
    b=N/15;
    y=b*200;
    cout<<x-y<<endl;
}

Measured memory_bytes: 256
S = list(input())
if S[0] == 'A':
    if S[2 : len(S) - 1].count('C') == 1:
        S[S.index('C')] = 'a'
        S[0] = 'a'

        l = list(map(ord, S))
        i = 0
        while i < len(l):
            if l[i] >= 97 and l[i] <= 122:
                i += 1
            else:
                print('WA')
                break
        if i == len(l):
            print('AC')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 3064
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	static final int MOD = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		//入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		//処理
		int ans = a + b;
		if(ans >= 24){
			ans -= 24;
		}

		//出力	
		out.println(ans);
		out.flush();
	}
}

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

using namespace std;

int main(){
    int n, k, a;
    cin >> n >> k;
    vector<bool> dp(k+1, false);
    vector<int> V;
    
    for (int i = 0; i < n; i++){
        cin >> a;
        V.push_back(a);
    }
    
    for (int i = 0; i < dp.size(); i++){
        for (int x : V){
            if (x <= i){
                if (!dp[i-x]){
                    dp[i] = true;
                }
            }
        }
    }
    cout << (dp[k] ? "First" : "Second");
}

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

int l[9];
int n,A,B,C;
const int inf=1000000000;

int dfs(int cnt,int a,int b,int c)
{
  //a,b,cはそれぞれの長さを表す
  if(cnt==n)
  {
    if(min(a,min(b,c))>0) return abs(a-A)+abs(b-B)+abs(c-C)-30;
    else return inf;
  }

  int ret0=dfs(cnt+1,a,b,c); //使わない
  int ret1=dfs(cnt+1,a+l[cnt],b,c)+10; //aに使う
  int ret2=dfs(cnt+1,a,b+l[cnt],c)+10;
  int ret3=dfs(cnt+1,a,b,c+l[cnt])+10;

  return min(ret0,min(ret1,min(ret2,ret3)));
}
int main()
{
  cin>>n>>A>>B>>C;
  for(int i=0;i<n;i++) cin>>l[i];

  //それぞれの竹について，aに使う,bに使う,cに使う,使わないの4通りを全施行する
  //深さ優先探索dfsを行う

  cout<<dfs(0,0,0,0)<<endl;
}

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

using namespace std;


/*
    FILE *f=fopen("data.txt","w");
    fprintf(f,);
    fclose(f);
*/

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)
#define scan(a) scanf("%d",&a)
#define scanll(a) scanf("%lld",&a)
#define print(a) printf("%d\n",a)
#define printll(a) printf("%lld\n",a)
#define stll(a) stoll(a,nullptr,10)
#define PII pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define EL printf("\n")
#define ff first
#define ss second

typedef long long ll;
typedef unsigned long long ull;

ll ar[100];
int main()
{
    ll n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            ans+=(ar[i]*ar[j]);
        }
    }
    cout<<ans<<endl;

}






Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define e cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m;
ll x,y;
ll ans=0;
ll a[100005],b[100005];
ll sum=0;
ll num=0;
ll sita=0,ue=n-1;
bool used[100005];
bool flag;

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

	for(i=0;i<n-1;i++){
		if(a[i]+a[i+1]>=l){
			num=i+1;
			flag=true;
			break;
		}
	}
	
	if(!flag){
		p("Impossible");
	}else{
		p("Possible");
		for(i=1;i<num;i++){
			p(i);
		}
		for(i=n-1;i>=num+1;i--){
			p(i);
		}
		p(num);
	}
	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	int b = 0;
	int cnt = 0;
	for (;;) {
		//ボタンをつける
		b = a[b];
		cnt++;
		//もしボタン2なら終了
		if (b == 1) {
			dunk(cnt);
			return 0;
		}
		//もしnこより上なら間違い
		if (cnt > n) break;
	}
	dunk(-1);
	return 0;
}

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

#define rep(a,b) for(int ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'

int main()
{
  fst_io;
  int a;
  ll s=0;
  cin>>a;
  cout<<a+a*a+a*a*a;
  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;
unsigned long long popCount64bitB(unsigned long long x) 
{ 
    x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) 
      +  (x & 0x5555555555555555UL); 
    x = ((x & 0xccccccccccccccccUL) >> 2) 
      +  (x & 0x3333333333333333UL); 
    x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) 
      +  (x & 0x0f0f0f0f0f0f0f0fUL); 
    x = ((x & 0xff00ff00ff00ff00UL) >> 8) 
      +  (x & 0x00ff00ff00ff00ffUL); 
    x = ((x & 0xffff0000ffff0000UL) >> 16) 
      +  (x & 0x0000ffff0000ffffUL); 
    x = ((x & 0xffffffff00000000UL) >> 32) 
      +  (x & 0x00000000ffffffffUL); 
    return x; 
} 

int main(void){
    string s,ans="";
    int k=0;
    map<char,int>m;
    cin>>s;
    for(char x='a';x<='z';x++)m[x]=0;
    for(int i=0;i<s.length();i++)m[s[i]]++;
    for(char x='a';x<='z';x++){
        if(m[x])k++;
    }
    if(k<26){
        for(char x='a';x<='z';x++){
            if(m[x]==0){
                s.push_back(x);
                break;
            }
        }
        cout<<s<<endl;
    }
    else{
        set<char>al;
        al.insert(s[25]);
        for(int i=24;i>=0;i--){
            char x=s[i];
            for(auto itr=al.begin();itr!=al.end();++itr){
                if(x<(*itr)){
                    ans=s.substr(0,i);
                    ans.push_back((*itr));
                    cout<<ans<<endl;
                    return 0;
                }
            }
            al.insert(x);
        }
        cout<<-1<<endl;
    }
}

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

//ABC172E
//ABC172D
int main(void) {
  long long n, k, i, cou=0, tmp;
  scanf("%lld", &n);
  int *c;
  c=(int *) malloc((n+1)*sizeof(int));
  c[1]=1;
  for(i=2; i<=n; i++){
    c[i]=0;
  }
  for(i=2; i<=n; i++){
    if(c[i]==0){
      c[i]=i;
      tmp=i;
      while(tmp<=n){
        if(c[tmp]==0)c[tmp]=i;
        tmp+=i;
      }
    }
  }
  int x, check=0, tcou=0, tcou2=1;
  for(i=2; i<=n; i++){
    tmp=i, x=i, check=c[i], tcou=0, tcou2=1;
    while(1){
      tmp/=c[tmp];
      if(check==c[tmp]){
        tcou++;
      }else{
        check=c[tmp];
        tcou2*=(tcou+2);
        tcou=0;
      }
      if(tmp==1){
        cou+=i*tcou2;
        //printf("%3d  %3lld     %5lld\n",i, tcou2, c[i]);
        break;
      }
    }

  }

  printf("%lld", cou+1);
}


Measured memory_bytes: 40768
from collections import defaultdict
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N = int(readline())
C = tuple(map(lambda x: int(x)-1, readline().split()))

temp = map(int,read().split())
temp = zip(temp,temp)

adj = [list() for _ in range(N)]
for a,b in temp:
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)


parent = [None]*N
parent[0] = -1

stack = [0]
order = []
while stack:
    p = stack.pop()
    order.append(p)
    for c in adj[p]:
        if parent[c] is None:
            parent[c] = p
            stack.append(c)

def merge(a,b):
    if len(a) > len(b):
        a,b = b,a
    for k,v in a.items():
        b[k] += v
    return b

dp = [defaultdict(int) for _ in range(N)] # color-wise counter
subtreesize = [0]*N
cnt = [N*(N+1)//2]*N

for c in reversed(order):
    p = parent[c]
    if p >= 0:
        dp[c][C[c]] = subtreesize[c]+1
        x = subtreesize[c]-dp[c][C[p]]+1
        cnt[C[p]] -= x*(x+1)//2
        subtreesize[p] += subtreesize[c]+1

        dp[p] = merge(dp[c],dp[p])
        dp[c] = None

dp[0][C[0]] = subtreesize[0]+1
for c in range(N):
    x = subtreesize[0]-dp[0][c]+1
    cnt[c] -= x*(x+1)//2

print(*cnt, sep='\n')


Measured memory_bytes: 126916
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<stack>
#include<iomanip>
#include<functional>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    ll h,w;
    cin>>h>>w;
    if(h==1 || w==1)
    {
        cout<<1<<endl;
        return 0;
    }
    ll wodd=(w-1)/2+1;
    ll wgu=w-wodd;
    ll hodd=(h-1)/2+1;
    ll hgu=h-hodd;
    cout<<wodd*hodd+wgu*hgu;
    
}

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

int main() {
  int S, s1, s2, s3 ;
  cin >> S ;
  s1 = S/100;
  s2 = (S-s1*100)/10;
  s3 = (S-s1*100-s2*10);
  cout << s1+s2+s3 << endl; 
}


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

#define CFOR(i, str) for(int (i) = 0; (str)[i]!='\0'; (i)++)
#define FOR(i, s, r) for(int (i) = (s); (i) < (r); i++)
#define INF 1e9
#define NINF -1e9
#define SUM(a) accumulate(a.begin(), a.end(), 0)
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.rbegin(), v.rend())
#define vmax(v) *max_element(v.begin(), v.end())
#define cnt(v, n) count(v.begin(), v.end(), (n))
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>

using namespace std;

typedef long long ll;


void solve(){
    int n, k, d, a, c = 0;
    cin>>n>>k;
    vi ar(n+1);
    FOR(i, 0, k){
        cin>>d;
        FOR(j, 0, d){
            cin>>a;
            ar[a]++;
        }
    }
    FOR(i, 1, n+1){
        if(ar[i]==0) c++;
    }
    cout<<c;

}


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

    // // COMMENT BEFORE SUBMISSION /////////////////////////////////////////////////
    // clock_t start = clock();
    // //

    int t;
    // cin>>t;

    // while(t--){
        solve();
    // }

    // //COMMENT BEFORE SUBMISSION /////////////////////////////////////////////////
    // clock_t stop = clock();
    // double elapsed = (double) (stop - start) / CLOCKS_PER_SEC;
    // cout<<setprecision(5)<<fixed;
    // cout<<"\nProcess finished in: "<<elapsed<<"s\n";
    
    return 0;

}



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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(string S, string T) {
    for (int i = 0; i < S.size(); i++) {
        if (S == T) {
            cout << "Yes" << endl;
            return;
        }
        rotate(S.begin(), S.begin() + 1, S.end());
    }
    cout << "No" << endl;
}


void main_(istream &cin) {
    string S;
    string T;
    cin >> S;
    cin >> T;
    solve(S, T);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n,k;
    cin>>n>>k;
    int a[n];
    loop(i,0,n) cin>>a[i];

    loop(i,k,n)
    {
        if(a[i] > a[i-k]) cout<<"Yes\n";
        else cout<<"No\n";
    }

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


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

int main(){
      int d;cin >> d;
      if(d == 22)cout << "Christmas Eve Eve Eve";
      else if(d == 23)cout << "Christmas Eve Eve";
      else if(d == 24)cout << "Christmas Eve";
      else if(d == 25)cout << "Christmas";
}

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

using namespace std;

int main(){
	string c;
	cin >>c;
	deque<char> duq;
	bool isreversed=false;
	for(int i=0;i<c.size();i++){
		duq.push_back(c[i]);
	}
	int q;
	cin >> q;
	while(q){
		int tmp;
		cin >> tmp;
		if (tmp==1){
			isreversed=!isreversed;
		}else{
			cin >> tmp;
			char tmpc;
			cin >>tmpc;
			if((tmp == 2) == isreversed){
				duq.push_front(tmpc);
			}else{
				duq.push_back(tmpc);
			}
		}
		q--;
	}
	if(isreversed)
	for(int i=duq.size()-1;i>=0;i--){
		cout <<duq[i];
	}
	else
	for(int i=0;i<duq.size();i++){
		cout <<duq[i];
	}
	cout << endl;

}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int n;
  int a,t;
  int h[1000];
  cin >> n;
  cin >> t >> a;
  int po = 1000000000;
  int result = -1;
  REP(i,n) {
    double x;
    cin >> x;
    if (po > abs(1000*a - 1000*t + x * 6)) {
      po = abs(1000*a - 1000*t + x * 6);
      result = i + 1;
    }
  }

  cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

long long X(long long N) {
    long long M = 2LL * ((long long) sqrt((float) N) + 1LL);
    long long sum = 0LL;
    long long count = 0LL;
    for (long long i = 1; i < M; i++) {
        sum += i;
        count++;
        if (sum == N) {
            return count;
        }
        else if (sum > N) {
            count--;
            return count;
        }
    }
}

int main() {
    FAST;
    long long N;
    cin >> N;
    long long result = 0;
    const auto &res = prime_factorize(N);
    for (auto p : res) {
        result += X(p.second);
    }
    cout << result << endl;
}

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

if x == sum(sweets):
    print(N)
else:
    # 少ないものから順に取っていく
    sweets.remove(max(sweets))
    ans = N - 1
    while True:
        if x >= sum(sweets):
            print(ans)
            break

        sweets.remove(max(sweets))
        ans -= 1


Measured memory_bytes: 38512
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod = 998244353;
long double PI = acosl(-1);
const ll infl = 1e18;
const int inf = 2e9;
const int nmax = 2e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

ll upay[nmax];
int L[15], R[15];

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

    int n,k;
    cin>>n>>k;
    for(int i=1; i<=k; i++) cin>>L[i]>>R[i];
    upay[1] = 1;
    for(int i=2; i<=n; i++){
        for(int j=1; j<=k; j++){
            int bam = i-R[j], dan = i-L[j];
            if(dan<1) continue;
            bam = max(bam, 1);
            dan = max(dan, 1);
            upay[i] = (upay[i] + upay[dan] - upay[bam-1] + mod) % mod;
        }
        upay[i] =  (upay[i] + upay[i-1])%mod;
    }
    cout<<(upay[n]-upay[n-1]+mod)%mod<<endl;
//    for(int i=1; i<=n; i++){
//        cout<<upay[i]-upay[i-1]<<endl;
//    }
}
/*
*/


Measured memory_bytes: 5208
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin,(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int n,m,c;
vector<int> b;
vector<vector <int>> a;

bool sign(int i){
  int sum=c;
  rep(j,m)sum+=a[i][j]*b[j];
  return sum>0;
}

int main(){
  cin >> n >> m >> c;
  //aはn行m列,bはm次元配列
  b.resize(m);a.resize(n);rep(i,n)a[i].resize(m);
  rep(i,m)cin >> b[i];
  rep(i,n)
    rep(j,m) cin >> a[i][j];
  int ans=0;
  rep(i,n){
    if(sign(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100000],dp[100001][30][2],two[30],x=0,y,cnt=0,f[30]={};
int main(){
    scanf("%d",&n);
    two[0]=2;
    for(int i=1;i<30;i++){
        two[i]=2*two[i-1];
    }
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        x=x^a[i];
        y=a[i]^(a[i]-1);
        for(int j=0;j<30;j++){
            if(y+1==two[j]){
                f[j]=1;
            }
        }
    }
    for(int i=29;i>=0;i--){
        if(f[i]){
            if((x^(two[i]-1))<x){
                x=x^(two[i]-1);
                cnt++;
            }
        }
    }
    if(x){
        printf("-1\n");
    }
    else{
        printf("%d\n",cnt);
    }
}

Measured memory_bytes: 512
#include <stdio.h>          // printf(), scanf()
#include <string.h>         // memset()
#include <stdbool.h>

#define MAX_N 120409
#define MAX_SQRT_N 347
#define MAX_P 11400

int p;
bool f[MAX_N + 1];
int primes[MAX_P];

int
main(int argc, char **argv)
{
	int n;
	int i, j;

	memset(f, 0xff, sizeof(f));
	p = 0;
	for (i = 2; i <= MAX_N; ++i)
	{
		if (f[i])
		{
			primes[p++] = i;
			if (i <= MAX_SQRT_N)
			{
				for (j = i + i; j <= MAX_N; j += i)
					f[j] = false;
			}
		}
	}

	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		int sum = 0;
		for (i = 0; i < n; ++i)
			sum += primes[i];

		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 768
import numpy as np
N=int(input())
A = list(map(int, input().split()))


dp =[[0,0] for _ in range(len(A)+1) ]

dp[0][0] = A[0]
dp[0][1] = -A[0]

max_value= sum(A)
for y in range(len(A)-1):
    dp[y+1][0] = max(dp[y][0]+A[y+1], dp[y][1]-A[y+1])
    dp[y+1][1] = max(dp[y][1]+A[y+1], dp[y][0]-A[y+1]) 

print(dp[N-1][0])

Measured memory_bytes: 36496
#include <iostream>

using namespace std;

int f(int a, int b, int c, int d) {
    return min(a, b) + min(c, d);
}

int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int result = f(a, b, c, d);
    cout << result << 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);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int P = sc.nextInt();
      int Q = sc.nextInt();
      int R = sc.nextInt();
      System.out.println(P + Q + R - Math.max(P, Math.max(Q,R)));
	}
}


Measured memory_bytes: 22612
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to; lint cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;
const double Pi = acos(-1.0);

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * modpow(fact[n - r], mod - 2, mod) % mod * modpow(fact[r], mod - 2, mod) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

lint gcd(lint a, lint b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

lint xor128() {
	static lint x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	lint t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

double dis(D a, D b) {
	double x = a.first - b.first, y = a.second - b.second;
	return sqrt(x * x + y * y);
}

class unionfind {
private:
	int par[2 * 100010], ranks[2 * 100010], sizeth[2 * 100010];
public:
	void init(int n) {
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			ranks[i] = 0;
			sizeth[i] = 1;
		}
	}

	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (ranks[x] < ranks[y]) {
			par[x] = y;
			sizeth[y] += sizeth[x];
		}
		else {
			par[y] = x;
			if (ranks[x] == ranks[y]) ++ranks[x];
			sizeth[x] += sizeth[y];
		}
	}
};

lint n, p, ans = 1;
map<lint, lint>mp;
int main() {
	cin >> n >> p;
	mp = factring(p);
	for (P q : mp) {
		if (n <= q.second) {
			ans *= modpow(q.first, q.second / n, inf);
		}
	}
	cout << ans << endl;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {
  string s;
  cin >> s;

  int ans = s.size();

  REP(i, s.size() - 1) {
    if (s[i] != s[i + 1]) {
      ans = min(ans, max(i + 1, (int)s.size() - (i + 1)));
    }
  }

  /*
  int ans = 0;

  int center = s.size() / 2;
  if (s.size() % 2) {
    char c = s[center];
    int a = 0;
    REP(i, s.size()) {
      if (s[center - i] != c or s[center + i] != c)
        break;
      else
        a = i;
    }
    ans = (center + 1) + a;
  } else {
    int a = 0;
    char cl = s[center - 1];
    char cr = s[center];
    if (cl == cr) {
      REP(i, s.size()) {
        if (s[center - 1 - i] != cl or s[center + i] != cr)
          break;
        else
          a = i;
      }
      a++;
    }
    ans = center + a;
  }
  */

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


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <set>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <vector>

using namespace std;
int main(){
    string s;
    cin >> s;
    int count = 0, maxi = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            count++;
        }
        else{
            maxi = max(maxi, count);
            count = 0;
        }
    }

    maxi = max(maxi, count);
    cout << maxi << endl;
}

Measured memory_bytes: 256
from collections import deque
d = deque()
S = input()
d.append(S)
N = int(input())
direct = 1
for i in range(N):
  X = input().split()
  if len(X) == 1:
    direct *= -1
  else:
    if (X[1] == "1" and direct == 1) or (X[1] == "2" and direct == -1):
      d.appendleft(X[2])
    else:
      d.append(X[2])
      
S = "".join(list(d))
print(S) if direct == 1 else print(S[::-1])

Measured memory_bytes: 6900
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

		int R;
		cin >> R;
		int s = R;
		if (R>999) {
			
			cout << "ABD"<< endl;
		}
		else {
			cout << "ABC" << endl;
		}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) REP(i,0,n)
#define REP(i,l,r) for(int i=l;i<r;i++)
#define int long long
using namespace std;
typedef pair<int,int> P;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
struct edge{
    int to,cost;
};
class dijkstra{
    int V;
    int d[100002];
    priority_queue<P,vector<P>,greater<P>>que;
    void update(int s,vector<edge> G[]){
        fill(d,d+V+1,100000000000ll);
        d[s]=0;
        que.push(make_pair(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            rep(i,G[v].size()){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
    }
public:
    dijkstra(int v,int s,vector<edge> G[]){
        V=v;
        update(s,G);
    }
    int find(int e){
        return d[e];
;    }
};
signed main(){
    int n,k,h[100000],dp[100000];
    cin>>n>>k;
    rep(i,n)cin>>h[i];
    dp[n-1]=0;
    REP(i,2,n+1){
        int cnt=INT_MAX;
        REP(j,1,min(i,k+1)){
            cnt=min(cnt,dp[n-i+j]+abs(h[n-i]-h[n-i+j]));
        }
        dp[n-i]=cnt;
    }
    cout<<dp[0]<<endl;
    return 0;
}



Measured memory_bytes: 1792
from collections import deque

h, w = map(int, input().split())
s = [input() for _ in range(h)]

cnt = 0
for i in s:
    cnt += i.count('.')

queue = deque([[0, 0]])
visited = [[1] * w for _ in range(h)]
visited[0][0] = 0

def bfs():
    while len(queue) > 0:
        h1, w1 = queue.popleft()
        if h1 == h - 1 and w1 == w - 1:
            return visited[h1][w1]
        for k, l in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            n_h, n_w = h1 + k, w1 + l
            if n_h < 0 or n_w < 0 or n_h >= h or n_w >= w:
                continue
            if visited[n_h][n_w] == 1 and s[n_h][n_w] == '.':
                queue.append([n_h, n_w])
                visited[n_h][n_w] += visited[h1][w1]
    return -1
    
bfs = bfs()
ans = 0
if bfs == -1:
    ans = -1
else:
    ans = cnt - bfs - 1
print(ans)


Measured memory_bytes: 9432
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(k<=a) ans=k;
    else if(k<=a+b) ans=a;
    else ans=a-(k-a-b);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3600