akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

X = int(readline().rstrip())

lim = 0
N = 0
while True:
    N += 1
    tmp = (N ** 5) - (N - 1) ** 5
    if tmp > X:
        lim = N
        break

for A in range(0, N):
    for B in range(-N, N):
        tmp = (A ** 5) -  (B ** 5)
        if tmp == X:
            print(A, B)
            exit()

Measured memory_bytes: 9136
//lover~ 
#include<bits/stdc++.h>
using namespace std;
int n,a[105];
int main() {
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]-a[0];
	return 0;
}

Measured memory_bytes: 256
inf = 10 ** 9
n = int(input())
a = [int(input()) for x in range(n)]
m1 = -inf
m2 = -inf
for i in range(n):
    if a[i] >= m1:
        m2 = m1
        m1 = a[i]
    elif a[i] > m2:
        m2 = a[i]
for i in range(n):
    if m1 != a[i]:
        print(m1)
    else:
        print(m2)

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

long long N, M, V, P;
long long A[1 << 18], B[1 << 18];

int main() {
	cin >> N >> M >> V >> P;
	for (int i = 1; i <= N; i++) cin >> A[i];
	sort(A + 1, A + N + 1);
	for (int i = 1; i <= N; i++) B[i] = B[i - 1] + A[i];
	
	vector<int> vec;
	for (int i = 1; i <= N; i++) {
		int pos1 = lower_bound(A + 1, A + N + 1, A[i] + 1) - A;
		int cl = pos1, cr = N - (P - 1);
		if (cl > cr) {
			vec.push_back(i);
		}
		else {
			long long target = A[i] + M;
			long long rem = 1LL * M * max(0LL, V - (N - (cr - cl + 1)));
			int pos2 = lower_bound(A + 1, A + N + 1, target + 1LL) - A;
			if (pos2 > cr) {
				long long val = 1LL * (cr - (cl - 1)) * target - (B[cr] - B[cl - 1]);
				if (val >= rem) vec.push_back(i);
			}
		}
	}
	cout << vec.size() << endl;
	return 0;
}

Measured memory_bytes: 5476
#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        r: usize,
        d: usize,
        mut x: usize,
    }
    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}


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

int main(){
  string s,s_rev;
  bool ans = false;
  cin >> s;
  int N = s.size();
  s_rev = s;
  reverse(s_rev.begin(),s_rev.end());
  if(s == s_rev && s.substr(0,(N-1)/2) == s.substr((N+1)/2,(N-1)/2) )  ans = true;
  puts(ans ? "Yes" : "No");
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli a,b,c;
    cin3(a,b,c);
    cout << min(c, b/a) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        int N=scanner.nextInt();
        int Y=scanner.nextInt()/1000;
        int x=-1,y=-1,z=-1;
        for(int i=0;i<=N;i++){
            if(Y-N<9*i){
                break;
            }
            if((Y-N-9*i)%4==0&&N>=(Y-N-9*i)/4+i){
                y=(Y-N-9*i)/4;
                x=i;
                z=N-y-x;
                break;
            }
        }
        System.out.println(x+" "+y+" "+z);

    }
}


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

int main() {
    ll N,r=0;
    cin >> N;
    vector<ll> A(N),B(N),C(N),pB(N);

    rep(i,N)
        cin >> A.at(i);
    rep(i,N)
        cin >> B.at(i);
    rep(i,N)
        cin >> C.at(i);
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    rep(i,N)
        pB.at(i) = C.end() - upper_bound(C.begin(), C.end(), B.at(i));

    rep(i,N-1)
        pB.at(N-2-i) += pB.at(N-1-i);
    
    rep(i,N) {
        ll t = upper_bound(B.begin(), B.end(), A.at(i))-B.begin();
        if(t == N)
            continue;
        r += pB.at(t);
    }

    cout << r << endl;
}

Measured memory_bytes: 3328
/*************************************************************************
  >         File: C.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sun 27 Nov 2016 12:07:33 AM JST
*************************************************************************/
#include <bits/stdc++.h>

const int N = 2e5 + 5;
std::vector<int> edges[N];
bool visited[N];

int main() {
  std::ios::sync_with_stdio(0);
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j < x; ++j) {
      int y;
      scanf("%d", &y);
      edges[i + 1].push_back(y + n);
      edges[y + n].push_back(i + 1);
    }
  }
  std::queue<int> q;
  q.push(1);
  visited[1] = 1;
  while (!q.empty()) {
    int x = q.front(); q.pop();
    for(auto &y: edges[x]) {
      if (!visited[y]) {
        visited[y] = 1;
        q.push(y);
      }
    }
  }
  for (int i = 1; i <= n; ++i) if (!visited[i]) {
    puts("NO");
    return 0;
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
ll MOD=1e9+7;
ll add(ll x, ll y)
{
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}
ll sub(ll x, ll y)
{
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}
ll mult(ll x, ll y)
{
    return (x * y) % MOD;
}
ll bin_pow(ll x, ll p)
{
    if (p == 0)
        return 1;
    if (p & 1)
        return mult(x, bin_pow(x, p - 1));
    return bin_pow(mult(x, x), p / 2);
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    cout<<(bin_pow(10,n)+bin_pow(8,n) +10*MOD - 2*bin_pow(9,n))%MOD<<endl; 
    return 0;
}

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

int main() {
  int N, T, A;
  cin >> N >> T >> A;

  int min_val = INT_MAX;
  int Ans = 0;
  rep( i, 1, N+1 ) {
    int H;
    cin >> H;
    int temp = ( T*1000 - H*6 ) - A*1000;
    if ( temp < 0 ) temp = -temp;
    if ( temp < min_val ) {
      min_val = temp;
      Ans = i;
    }
  }

  cout << Ans << endl;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        a: u16,
        b: u16,
        c: u16,
        x: u16,
    }
    let mut res = 0;
    for i in 0..=a {
        for j in 0..=b {
            for k in 0..=c {
                if 500 * i + 100 * j + 50 * k == x {
                    res += 1;
                } else if 500 * i + 100 * j + 50 * k > x {
                    break;
                }
            }
        }
    }
    println!("{}", res)
}


Measured memory_bytes: 2192
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define MOD 1000000007
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int h, w;
    int a[26];
    fill(a, a + 26, 0);
    cin >> h >> w;
    imfor(i, h * w) {
        char c;
        cin >> c;
        a[c - 'a'] += 1;
    }
    int f = 0;
    if (h % 2 == 0 && w % 2 == 0) {
        imfor(i, 26) {
            if (f == 1) {
                cout << "No" << endl;
                return 0;
            }
            if (a[i] % 4 != 0) {
                f++;
            }
        }
    }
    else if (h % 2 == 1 && w % 2 == 0) {
        imfor(i, 26) {
            if (a[i] % 2 != 0) {
                cout << "No" << endl;
                return 0;
            }
            if (a[i] % 4 != 0) {
                f++;
            }
            if (f > w / 2) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else if (h % 2 == 0 && w % 2 == 1) {
        imfor(i, 26) {
            if (a[i] % 2 != 0) {
                cout << "No" << endl;
                return 0;
            }
            if (a[i] % 4 != 0) {
                f++;
            }
            if (f > h / 2) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else {
        int ff = 0;
        imfor(i, 26) {
            if (a[i] % 2 != 0) {
                ff++;
                if ((a[i] - 1) % 4 != 0) {
                    f++;
                }
            }
            else if (a[i] % 4 != 0) {
                f++;
            }


            if (ff > 1) {
                cout << "No" << endl;
                return 0;
            }
            if (f > ((h - 1) / 2) + ((w - 1) / 2)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a,b,graph[20][20]={0};
  char s[LIMIT1];
  vector<int> v;
  
  scanf("%lld %lld",&n,&m);
  rep(i,m){
    scanf("%d %d",&a,&b);
    a--;b--;
    graph[a][b]=1;
    graph[b][a]=1;
  }
  rep(i,n-1) v.push_back(i+1);
  do{
    rep(i,n-1){
      if(graph[(i==0 ? 0 : v[i-1])][v[i]]==0) break;
    }
    if(i>=n-1) result++;
  }while(next_permutation(v.begin(),v.end()));
  
  printf("%lld\n",result);
  return 0;
}

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

using namespace std;

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

    if(s == t){
        cout << "Yes" << endl;
        return 0;
    }   

    for(int i = 0; i < s.length(); i++){
        
        char temp = s[s.length() - 1];
        s.pop_back();
        s = temp + s;

        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>

using namespace std;

bool check(vector<int> &v, vector<int> &a) {
	vector<int> tmp;
	for (int x: v) {
		if (x > v.size() + 1) {
			return false;
		}

		tmp.insert(tmp.begin() + x - 1, x);
	}

	for (int i = 0; i < tmp.size(); i++) {
		if (tmp[i] != a[i]) {
			return false;
		}
	}
	return true;
}

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

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

	vector<int> ans;
	for (int i = 0; i < n; i++) {
		if (a[i] > ans.size() + 1) {
			cout << -1 << endl;
			return 0;
		}

		auto ans2 = ans;
		ans2.emplace_back(a[i]);
		bool ok = false;
		for (int j = ans2.size() - 1; j >= 0; j--) {
			bool ret = check(ans2, a);
			if (ret) {
				ans = ans2;
				ok = true;
				break;
			}

			if (j >= 1) {
				swap(ans2[j - 1], ans2[j]);
			}
		}

		if (!ok) {
			cout << -1 << endl;
			return 0;
		}

	}

	for (auto x: ans) {
		cout << x << endl;
	}

	return 0;
}


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

#define R (long long)(1e9 + 7)
#define INF (long long)(1e16L + 5)
#define ll long long
#define grid vector<vector<ll>>

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
  

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(ll& x : a)
        cin >> x;
    ll ans = 0, mx = a[0];
    for(int i = 1; i < n; i++)
    {
        if(mx >= a[i])
            ans += (mx - a[i]);
        mx = max(mx, a[i]);
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
	string f; cin >> f;
	int a; cin >> a;
	int n = f.size() / 2;
	int l = f[0] - '0';
	for(int i = 0; i < n; i++){
		if(f[i*2+1] == '+'){
			l += f[i*2+2] - '0';
		}else{
			l *= f[i*2+2] - '0';
		}
	}
	vector<int> v;
	v.push_back(f[0] - '0');
	for(int i = 0; i < n; i++){
		if(f[i*2+1] == '+'){
			v.push_back(f[i*2+2] - '0');
		}else{
			v[v.size() - 1] *= f[i*2+2] - '0';
		}	
	}
	int m = 0;
	for(auto i: v) m += i;
	if(a==m && a==l) cout << 'U' << endl;
	if(a!=m && a==l) cout << 'L' << endl;
	if(a==m && a!=l) cout << 'M' << endl;
	if(a!=m && a!=l) cout << 'I' << endl;
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second

using namespace std;
typedef long long ll;

ll cnt[5005];
ll f(int backs, int len){

}
int main()
{
    int a[4];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a, a + 4);
    if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

const int MAXN = 100005;
int n, q;
long long m;
vector<pair<int, int> > con[2];
int p[MAXN];
int find(int i) {
	if (p[i] == -1 || p[i] == i) return i;
	return p[i] = find(p[i]);
}
bool un(int u, int v) {
	u = find(u);
	v = find(v);
	if (u == v) return false;
	p[u] = v;
	return true;
}
int main() {
	memset(p, -1, sizeof(p));
	scanf("%d %lld %d", &n, &m, &q);
	bool tree = true;
	for (int i = 0; i < q; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		con[c].push_back({a, b});
		if (c) tree = false;
	}
	for (int i = 0; i < con[0].size(); i++) {
		un(con[0][i].first, con[0][i].second);
	}
	for (int i = 0; i < con[1].size(); i++) {
		if (find(con[1][i].first) == find(con[1][i].second)) {
			printf("No\n");
			return 0;
		}
	}
	int comp = 0;
	for (int i = 0; i < n; i++) if (find(i) == i) comp++;
	long long minM = n-1;
	if (!tree) {
		minM = n;
		if (comp <= 2) {
			printf("No\n");
			return 0;
		}
	}
	long long maxM = n-comp + (comp * 1ll * (comp - 1)) / 2;
	if (minM <= m && m <= maxM) {
		printf("Yes\n");
	} else printf("No\n");
}


Measured memory_bytes: 2040
r, D, x_2000 = map(int, input().split())

x_2001 = r *x_2000 -D

memo = {2000: x_2000, 2001: x_2001}


def zen(n, x, r, D):
    x.append(r *x[n -1] -D)
    return x

x = []
x.append(x_2000)
for i in range(1, 11):
    print(zen(i, x, r, D)[-1])



Measured memory_bytes: 9136
using System;
using System.Linq;

public class HelloWorld
{    
    static long[] A;
    static long N;
    static long[] left;
    static long[] right;
    
    static public void Main ()
    {
        //
        N = long.Parse(Console.ReadLine());
        A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
        left = new long[N];
        right = new long[N];
        
        var ans = 1L;
        lgcd(0);
        rgcd(N-1);
        //Console.WriteLine(String.Join(" ",right));
        for(int i = 0;i < N;i++){
            
            long l = 1;
            long r = 1;
            
            //左のループ
            if(i != 0){
                l = left[i-1];
            }

            //右のループ
            if(i != N-1){
                r = right[i+1];
            }else{
                r = l;
            }
            //Console.WriteLine('a');
            if(i == 0){
                l = r;
            }
           // Console.WriteLine(l+""+r);
            var tmp = GCD(l,r);
            //Console.WriteLine('a');
            if(ans < tmp){
                ans = tmp;
            }
        }
        
        Console.WriteLine(ans);
        
    }
    
    static void lgcd(long n){
        if(n == N-1){
            return ;
        }else if(n ==0){
            left[n] = A[0];
            lgcd(n+1);
            return ;
        }
        else{
            left[n] = GCD(left[n-1],A[n]);
            lgcd(n+1);
            return ;
        }
        
    }
    
    
    static void rgcd(long n){
        if(n == N-1){
            right[n] = A[N-1]; 
            rgcd(n-1);
            return ;
        }else if(n ==0){
            return ;
        }
        else{
            right[n] = GCD(right[n+1],A[n]);
            rgcd(n-1);
            return ;
        }
        
    }
    
    static long GCDP(long s ,long g){
        var res = A[s];
        for(long i = s+1;i <= g;i++){
            res = GCD(res,A[i]);
        }
        
        return res;
    }
    
    static long GCD(long A,long B){
        if(A < B){
            GCD(B,A);
        }
        
        long r = A%B;
        while(A%B != 0){
            r = A%B;
            A=B;
            B=r;
        }
        return B;
    }
    
}


Measured memory_bytes: 26464
H=int(input())
s=1 #sはモンスターの数
t=0
while H>1:
    H=H//2
    s=s*2
    t=t+1

list=[]
u=1
while u<=t:
    list.append(u)
    u=u+1

z=0
for i in list:
    z=z+2**(i-1)

print(str(z+s))

Measured memory_bytes: 9132
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define ull unsigned long long
using namespace std;
void io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

const int MAXN = 1e6 + 5;
const ll INF = 0x3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

ll a, b;

bool vis[MAXN];
vector<ll> prime;

void euler() {
    for (ll i = 2; i < MAXN; i++) {
        if (!vis[i]) {
            prime.push_back(i);
        }
        for (int p : prime) {
            if (i * p > MAXN) {
                break;
            }
            vis[i * p] = true;
            if (i % p == 0) {
                break;
            }
        }
    }
}

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

int main() {
    io();
    euler();
    cin >> a >> b;
    ll t = gcd(a, b);
    ll cnt = 1;
    for (ll u : prime) {
        if (u > t) {
            break;
        }
        if (t % u == 0) {
            cnt++;
        }
        while (t % u == 0) {
            t /= u;
        }
    }
    if (t != 1) {
        cnt++;
    }
    cout << cnt;
}


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

int main() {
    double a, b, C, d;
    cin >> a >> b >> C;
    d = acos(-1.0) * C  / 180.0; 
    double S;
    S =  sin(d) * a * b / 2.0;
    double L;
    L = a + b + sqrt( a * a + b * b - 2 * a * b * cos(d) );
    double h;
    h = S * 2.0 / a;
    printf("%lf\n%lf\n%lf\n", S, L ,h);
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int desc(const void *a, const void *b)
{
	if (*(int *)a < *(int*)b)
		return 1;
	if (*(int *)b < *(int*)a)
		return -1;
	return 0;
}
int main()
{
	int n, m;
	cin >> n >> m;
	int a[n];
	int sum  = 0;
	rep(i, n)
	{
		cin >> a[i];
		sum += a[i];
	}
	// qsort(a, sizeof a / sizeof *a, sizeof *a, desc);
	int cnt = 0;
	float b = sum / ((4*m));
	rep(i,n)
	{
		if ((float)a[i]*(4*m) >= sum)
			cnt++;
	}
	if (cnt >= m)
		cout << "Yes\n";
	else
		cout << "No\n";
	return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lli N, X;
  cin >> N >> X;
  vector< lli > P(N);
  vector< lli > S(N);
  P[0] = 1, S[0] = 1;
  REP(i, N - 1) {
    P[i + 1] = 2 * P[i] + 1;
    S[i + 1] = 2 * S[i] + 3;
    // cout << P[i + 1] << " " << S[i + 1] << "\n";
  }
  //  int i = N - 1;
  X--;
  lli ans = 0;
  REPR(i, N - 1) {
    if (X == 0) {
      break;
    } else if (1 <= X && X <= S[i]) {
      X--;
      if (i == 0)
        ans++;
    } else if (S[i] + 1 == X) {
      ans += P[i] + 1;
      break;
    } else if (S[i] + 2 <= X && X <= 2 * S[i] + 1) {
      X -= S[i] + 2;
      ans += P[i] + 1;
      if (i == 0)
        ans++;
    } else {
      ans += 2 * P[i] + 1;
      break;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
const int maxn = 1e6 + 10;
ll sum(ll x){
    ll re = 0;
    while(x > 0){
        re += x % 10;
        x /= 10;
    }
    return re;
}
int main(){
    FAST_IO
    int N;
    cin>>N;
    ll ans = 1,p = 1;
    for(int i = 1; i <= N; i++){
        cout<<ans<<endl;
        ll ans1 = ans + p;
        ll ans2 = ans + p * 10;
        if(ans1 * sum(ans2) <= ans2 * sum(ans1)) ans = ans1;
        else {
            ans = ans2;
            p *= 10;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n,i;
    cin>>n;
    int a[n],p=n-1,ans=0;
    for(i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n,greater<int>());
    for(i=0;i<n;i++)
    {
        if(p==0)
        break;
        if(i==0)
        {
            ans+=a[i];
            p--;
            continue;
        }
        if(p>=2)
        {
            ans+=(a[i]*2);
            p-=2;
        }
        else
        {
            ans+=a[i];
            p--;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, P;
  	cin >> A >> P;
  	//vector< pair<string, long> > p;
	//vector<long> A(N);
  	int idx = 0;
  	//while(cin >> A[idx]) idx++;
  	//vector<long> elem;
  	cout << (A*3 + P) /2 << endl;
  	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, A, a[51];
long long f[2][51][2510];
int main() {
	cin >> n >> A;
	for (int i = 1; i <= n; ++ i) cin >> a[i];
	f[0][0][0] = 1;
	for (int i = 1; i <= n; ++ i) {
		memset(f[i & 1], 0, sizeof(f[i & 1]));
		for (int j = 0; j <= i; ++ j) {
			for (int k = 0; k <= 2500; ++ k) {
				f[i & 1][j][k] = ((k - a[i] >= 0 && j > 0) ? f[i & 1 ^ 1][j - 1][k - a[i]] : 0) + f[(i & 1) ^ 1][j][k];
			}
		}
	}
	long long ans = 0;
	for (int i = 1; i <= n; ++ i) {
		ans += f[n & 1][i][i * A];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::vector;
using std::cin;
using std::map;
using std::multimap;
using std::set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}

int main() {
	ll n, m;
	cin >> n >> m;
	auto all = prime_decomposition(m);

	set<ll> memo;
	ll ans = 1;
	REPC(x, all) {
		if (memo.find(x) != memo.end()) { continue; }
		memo.emplace(x);
		ll c = all.count(x);
		ans *= comb(c + n - 1, c);
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

const int N=2e5+100;
ll a[N];
ll dp[N];
int32_t main(){
    ll n;
    cin >> n;

    cout << n*(n-1)/2;


}


Measured memory_bytes: 256
N , M = input().split()
M = int(M)
N = int(N)
ans = ['0' for i in range (N)]
fl = True

for i in range (M) :
    s , c = input().split()
    s = int(s) - 1
    if (s == 0 and c == '0' and N != 1) :
        fl = False
    if (ans[s] != '0') :
        if (ans[s] != c) :
            fl = False
    else :
        ans[s] = c

res = ''

if (ans[0] == '0' and N != 1) :
    ans[0] = '1'

for i in ans :
    res += i

print (res if fl else -1)


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

int main(){
    int n; cin>>n;
    map<int, int> even;
    map<int, int> odd;
    for (int i=0; i<n; i++){
        int v; cin>>v;
        if(i%2==0){
            if(even.count(v)){
                even[v]=even[v]+1;
            }
            else even[v]=1;
        }
        if(i%2!=0){
            if(odd.count(v)){
                odd[v]=odd[v]+1;
            }
            else odd[v]=1;
        }
    }
    auto even_begin = even.begin(), even_end = even.end();
    auto odd_begin = odd.begin(), odd_end = odd.end();
    ll even1 = 0, even2=0, even1_idx=-1, even2_idx=-1;
    ll odd1 = 0, odd2=0, odd1_idx=-1, odd2_idx=-1;

    for(auto iter = even_begin; iter != even_end; iter++){
        int key = iter->first, value = iter->second;
        if(value>even1){
            even2=even1; even2_idx=even1_idx; even1=value, even1_idx=key;
        }
        else if(value>even2){
            even2 = value; even2_idx=key;
        }
        //cout << key << " " << value << endl;
    }

    for(auto iter = odd_begin; iter != odd_end; iter++){
        int key = iter->first, value = iter->second;
        if(value>odd1){
            odd2=odd1; odd2_idx=odd1_idx; odd1=value, odd1_idx=key;
        }
        else if(value>odd2){
            odd2 = value; odd2_idx=key;
        }
        //cout << key << " " << value << endl;
    }

    ll ans = n;
    if(even1_idx != odd1_idx) ans -= (even1+odd1);
    else ans -= max(even1+odd2, even2+odd1);


    cout << ans << endl;
}

Measured memory_bytes: 8180
N = int(input())

Sdict = dict()
max = 0
for _ in range(N):
    s = input()
    if s in Sdict:
        Sdict[s] += 1
    else:
        Sdict[s] = 0
    
maxi = 0
lis = []
for k,v in Sdict.items():
    if v > maxi:
        lis = [k]
        maxi = v
    elif v == maxi:
        lis.append(k)
lis.sort()
for k in lis:
    print(k)

Measured memory_bytes: 32096
#include<bits/stdc++.h>
#define ll long long
const ll INF = 1e+9;
using namespace std;

int main(){
  ll field[201][201];
  ll n, m, r, tp;

  cin >> n >> m >> r;
  vector<ll> pos(r);
  vector<bool> used(r, false);

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(i!=j)
        field[i][j] = INF;
      else
        field[i][j] = 0;
    }
  }
  for(int i=0;i<r;i++){
    cin >> tp;
    pos[i] = --tp;
  }

  ll a,b,c;
  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    a--;b--;
    field[a][b] = c;
    field[b][a] = c;
  }

  // WF
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        field[i][j] = min(field[i][j], field[i][k] + field[k][j]);
  
  sort(pos.begin(), pos.end());
  ll ans = INF;
  do{
    tp = 0;
    for(int i=1;i<r;i++){
      tp += field[pos[i-1]][pos[i]];
    }
    ans = min(ans, tp);
  }while(next_permutation(pos.begin(), pos.end()));
  cout << ans << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

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

const int N = 1e5+23;
vector<int> g[N];

int bio[N];
void dfs(int u, int d=1) {
	bio[u] = d;
	for (int v: g[u]) {
		if (bio[v]) {
			bio[v] = min(bio[v], d+1);
			continue;
		}
		dfs(v, d+1);
	}
}

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int t; scanf("%d", &t);
		g[i].push_back(--t);
	}
	dfs(0);
	printf("%d", bio[1]-1);
}	

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 9216
<?php
    fscanf(STDIN, "%d", $total);
    $input = trim(fgets(STDIN));
    $numbers = explode(" ", $input);
    $two = 0;
    $four = 0;
    for ($i = 0; $i < $total; $i++) {
        if (($numbers[$i] % 4) == 0) {
            $four++;
        } else {
            if (($numbers[$i] % 2) == 0) {
                $two++;
            }
        }
    }
    if ($total % 2) {$total = $total-1;}
    $output = "No\n";
    if (($two + ($four * 2)) >= $total) {$output = "Yes\n";}
	echo $output;
?>


Measured memory_bytes: 21928
from math import atan2
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:atan2(x[1],x[0]))
ans=0
for i in range(n):
    x,y=0,0
    for j in range(n):
        x1,y1=l[(i+j)%n]
        x+=x1
        y+=y1
        ans=max(x**2+y**2,ans)
print(ans**0.5)

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

int n;
int a[100010];
bool b[100010]; int d(int i);
int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = d(0);
	if (b[1])cout << ans << endl;
	else cout << -1;
	return 0;
}
int d(int i) {
	if (b[i])return 0;
	b[i] = true;
    if(i==1)return 0;
	return d(a[i]-1)+1;
}


Measured memory_bytes: 768
#include<stdio.h>
int search(int A[],int n,int key){
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i != n;
}

int main(){
    int n,i,A[100001];
    int q,key,sum = 0;

scanf("%d",&n);
for(i = 0;i < n;i++){
scanf("%d",&A[i]);
}
scanf("%d",&q);
for(i = 0;i < q;i++){
    scanf("%d",&key);
if(search(A,n,key)){
    sum++;
    }
}
printf("%d\n",sum);

return 0;
}



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }


// 一次元累積和
template<class T>
class Ruiseki
{
private:
	int num;

public:
	vector<T> sumVal;
	Ruiseki(const vector<T> &srcVal)
	{
		num = srcVal.size();
		sumVal.resize(num + 1, 0);
		for (int i = 0; i < num; i++) {
			sumVal[i + 1] = sumVal[i] + srcVal[i];
		}
	}

	T GetSumAll()
	{
		return sumVal[num];
	}

	// [start, endIdx) ※endIdxは含まない
	T GetSumRange(int startIdx, int endIdx)
	{
		return sumVal[endIdx] - sumVal[startIdx];
	}

	// [0, endIdx) ※endIdxは含まない
	T GetSumFromTop(int endIdx)
	{
		return sumVal[endIdx] - sumVal[0];
	}

	// [startIdx, N] ※startIdxは含む
	T GetSumFromEnd(int startIdx)
	{
		return sumVal[num] - sumVal[startIdx];
	}
};

void Solve()
{
	ll N, M;
	cin >> N >> M;
	VL SA(N);
	REP(i, N) cin >> SA[i];
	sort(ALL(SA), greater<ll>());
	VL GA = SA;
	reverse(ALL(SA));

	// a   = aa,                                = 2
	// ab  = aa, ab,     ba, bb,                = 4
	// abc = aa, ab, ac, ba, bb, bc, ca, cb, cc = 6

	auto compExec = [&](ll mid, ll &res) {
		ll cnt = 0;
		for (auto &g : GA) {
			ll nokori = mid - g;
			ll numOne = SA.end() - lower_bound(ALL(SA), nokori);
			if (numOne == 0) break;
			cnt += numOne;
		}
		res = cnt;
		return (M <= cnt);
	};

	ll lb = SA[0] * 2 - 10;
	ll lu = GA[0] * 2 + 10;
	ll mid = 0;
	ll res;
	while ((lb + 1) != lu) {
		mid = (lb + lu) / 2;
		if (compExec(mid, res)) {
			lb = mid;
		} else {
			lu = mid;
		}
	}

	ll ans = 0;
	ll cnt = 0;
	Ruiseki<ll> rui(SA);
	for (auto &g : GA) {
		ll nokori = lu - g;
		auto it = lower_bound(ALL(SA), nokori);
		if (it == SA.end()) continue;
		ll pos = it - SA.begin();
		ll ansOne = rui.GetSumFromEnd(pos);
		ans += (ansOne + g * (N - pos));
		cnt += (N - pos);
	}

	ll nokori = M - cnt;
	ans += nokori * lb;

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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;

  mint ans = 0;
  rep2(i, k, n+2){
    ll l = (ll)i*(i-1)/2;
    ll r = (ll)(n)*(n+1)/2 - (ll)(n-i)*(n+1-i)/2;
    // cerr << l << " " << r << endl;
    ans += r - l + 1;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>


#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;

typedef long long ll;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
     int n,k,l,c,d,p,nl,np;
    ll a,b;
    cin>>a>>b;
    if((a+b)%2==0)
        cout<<(a+b)/2;
    else
        cout<<"IMPOSSIBLE";



}


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

int main() {
  int a,b,c,d;
  int l,r;

  cin>>a>>b>>c>>d;
  l=a+b;
  r=c+d;

  if(l>r) cout<<"Left"<<endl;
  else if(l<r) cout << "Right" << endl;
  else cout << "Balanced" << endl;
  
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
 ll n, p; cin >> n >> p;
 ll ans=0;
 for(ll i=pow(p, 1.0/n)+1; 1<=i; i--){
   ll tmp = pow(i, n);
   if(p%tmp!=0) continue;
   ans = i; break;
 }
 cout << ans << endl;
}


Measured memory_bytes: 256
import collections
import bisect

s = input()
t = input()
s_index = {}
	
for pos, el in enumerate(s):
	if el in s_index:
		s_index[el].append(pos)
	else:
		s_index[el] = [pos]
check = all([i in s_index for i in t])
if not check:
	ans = -1
else:
	ans = 0
	t_size = len(t)
	s_size = len(s)
	for i in range(t_size):
		target = t[i]
		cursor = ans % s_size
		find = False
		if cursor > s_index[target][-1]:
			find = False
		else:
			j = bisect.bisect_left(s_index[target], cursor)
			find = True
		diff = s_index[target][j] - cursor + 1 if find else s_index[target][0] + s_size - cursor + 1
		ans += diff
		
print(ans)
	

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

using namespace std;

int hist[26];
int main()
{
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    hist[S[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (hist[i] % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
import os
from collections import deque

INF = 10**5
H, W = map(int,input().split())
S = ["" for _ in range(H)]
cntSharp = 0
for i in range(H):
    S[i] = input()
    cntSharp += S[i].count("#")

dp = [[INF for _ in range(W)] for _ in range(H)]
dp[0][0] = 0
#移動用のベクトル
dx = [1,0,-1,0]
dy = [0,1,0,-1]
P = deque([])
P.append((0,0))
while P:
    p = P.popleft()
    s,t = p[0], p[1]
    for i in range(4):
        nx,ny = s + dx[i], t + dy[i]
        if 0 <= nx and 0 <= ny and nx <= H-1 and ny <= W-1 and S[nx][ny] =="." and dp[nx][ny] == INF:
            dp[nx][ny] = dp[s][t] + 1
            P.append((nx,ny))
if dp[H-1][W-1] == INF:
    print(-1)
else:
    print(H*W - dp[H-1][W-1] - cntSharp - 1)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>

using namespace std;

// dp[何個の鍵を使ったか][開けた宝箱のパターン]
const int INF = 1e9;
int dp[1010][(1 << 12)] = {INF};

int main(void) {
    int N, M;
    cin >> N >> M;

    for(int m = 0; m < M + 1; ++m) {
        for(int i = 0; i < (1 << N); ++i) {
            dp[m][i] = INF;
        }
    }

    dp[0][0] = 0;

    // 使える鍵を増やしていく
    for(int m = 0; m < M; ++m) {
        int a, b;
        cin >> a >> b;
        unsigned int mask = 0;
        for(int i = 0; i < b; ++i) {
            int c;
            cin >> c;
            --c;
            mask |= (1 << c);
            // ooxxo
            // 11001
        }

        // dp tableを更新
        for(unsigned int before = 0;
            before < (1 << N);
            ++before) {

                // 鍵mを使わない場合
                dp[m + 1][before] = min(dp[m + 1][before], dp[m][before]);

                // 鍵mを使う場合
                auto after = before | mask;
                dp[m + 1][after] = min(dp[m + 1][after],
                                       dp[m][before] + a);
            }

    }

    auto ans = dp[M][(1 << N) - 1];
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////////////////

ll cal(vector<ll>v,ll s){
    ll sum=0;for(auto x:v)sum+=x;
    ll res=(v.size()-1)*10+abs(sum-s);
    return res;
}

int main(){fastio;
    
    ll n,a[3];cin>>n;rep(i,0,2)cin>>a[i];
    ll l[n];rep(i,0,n-1)cin>>l[i];
    ll ans=inf;
    rep(i,0,(1<<(2*n))-1){
        vector<ll>x[4];
        for(ll j=0;j<=2*n-2;j+=2){
            ll k=(i>>j)&3;
            x[k].pb(l[j/2]);
        }
        ll sum=0;
        rep(u,0,2){
            if(x[u].size()==0)sum=inf;
            else sum+=cal(x[u],a[u]);
        }
        Min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256