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

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

int main(){
  int a,b;
  cin >> a >> b;
  ll x = b;
  for (int i = 1; i < a; i++) {
    x += b * pow(10,i);
  }

  ll y = a;
  for (int i = 1; i < b; i++) {
    y += a * pow(10,i);
  }
  if (to_string(x) < to_string(y)) cout << x << endl;
  else cout << y << endl;
}


Measured memory_bytes: 4016
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
int a[114514];
int rwa[114514];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, n)rwa[i + 1] = a[i];
	rep(i, n)rwa[i + 1] += rwa[i];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] > 2 * rwa[i]) {
			cout << n - i << endl;
			return 0;
		}
	}
	cout << n << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

struct edge{
    int src, to, cost;
};
using Edges = vector<edge>;
using WeightedGraph = vector<Edges>;

int bfs(WeightedGraph &G, int st){
    vector<int> dist(G.size(), -1);
    vector<bool> used(G.size(), 0);
    deque<int> que;
    dist[st] = 0;
    que.push_back(st);
    while(!que.empty()){
        int v = que.front(); que.pop_front();
        used[v] = 1;
        repe(i, G[v]){
            if(used[i.to]) continue;
            dist[i.to] = dist[v] + i.cost;
            if(i.cost == 0) que.push_front(i.to);
            else que.push_back(i.to);
        }
    }
    return dist[0] + 1;
}

int main(){
    int k;
    cin >> k;
    WeightedGraph G(k);
    rep1(i, k+1){
        G[i%k].push_back((edge){i%k, (i+1)%k, 1});
        G[i%k].push_back((edge){i%k, (i*10)%k, 0});
    }
    cout << bfs(G, 1) << endl;
}


Measured memory_bytes: 6400
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll SORT(int n, vector<pair<ll, ll>> &v, int start){
  sort(v.begin()+start, v.end());
  return v[n-1].first;
}

int ans = 0;

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

  vector<pair<ll, ll>> v(n);

  REP(i, n){
    ll a, b;
    cin>>a>>b;
    v[i] = make_pair(b, a);
  }
  sort(v.begin(), v.end());

  ll sum = 0;
  REP(i, n){
    sum += v[i].second;
    if(sum > v[i].first){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;


}

Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	char a[105];
	long long k;
	int flag=1;
	int i;
	cin>>a>>k;
	for(i=0;a[i]!='\0';i++)
	{
		if(a[i]!='1')
		{
			flag=0;
			break;
		}
	}
	if(flag) cout<<1;
	else
	{
		if(k<=i) cout<<1;
		else cout<<a[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int num;
    int jnum=0;
    cin>>num;
    for(int i=num;i>0;i--)
    {
		int j=i,sum=0;
    	while(j>=1) 
    	{
    		sum++;
    		j=j/10;
		}
		if(sum%2==1) jnum++;
    }
    cout<<jnum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#define ll long long
#define mo 1000000007
using namespace std;
ll n;
map<ll,ll>a;
ll work(ll n)
{
	if(!n)return 1;
	if(n==1)return 2;
	if(a[n])return a[n];
	return a[n]=(work(n>>1)+work((n-1)>>1)+work((n-2)>>1))%mo;
}
int main()
{
	cin>>n;
	cout<<work(n)<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		String[] line = br.readLine().split(" ");
		Deque<Integer> stack = new ArrayDeque<Integer>();
		
		for (String s : line) {
			if (s.equals("+"))
				stack.push(stack.pop() + stack.pop());
			else if (s.equals("-"))
				stack.push(-stack.pop() + stack.pop());
			else if (s.equals("*"))
				stack.push(stack.pop() * stack.pop());
			else
				stack.push(Integer.parseInt(s));
		}
		
		System.out.println(stack.pop());
	}
}

Measured memory_bytes: 17060
#include<iostream>

using namespace std;

static const int MAX = 100005;
int n;
int A[MAX];

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

	long long ans1 = 0;
	long long sum = 0;
	for(int i = 0; i < n; i++){
		if(i % 2 == 1){
			if(sum + A[i] >= 1){
				sum += A[i];
				continue;
			}else{
				ans1 += 1 - (sum + A[i]);
				sum = 1;
			}
		}else{
			if(sum + A[i] <= -1){
				sum += A[i];
				continue;
			}else{
				ans1 += (sum + A[i]) - (-1);
				sum = -1;
			}
		}
	}

	sum = 0;
	long long ans2 = 0;
	for(int i = 0; i < n; i++){
		if(i % 2 == 0){
			if(sum + A[i] >= 1){
				sum += A[i];
				continue;
			}else{
				ans2 += 1 - (sum + A[i]);
				sum = 1;
			}
		}else{
			if(sum + A[i] <= -1){
				sum += A[i];
				continue;
			}else{
				ans2 += (sum + A[i]) - (-1);
				sum = -1;
			}
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}



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

#define IOS cin.tie(0);ios::sync_with_stdio(0)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?' ':'\n'); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);}//最小公倍数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//void print(){}

//----------------------library------------------------//

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

const int NMAX = 200;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

void f(int &n){
    if(n%2==0) n/=2;
    else n=n*3+1;
}

signed main(){
//    IOS;
    CIN(s);
    set<int> st;
    while(st.count(s)==0){
        st.insert(s);
        f(s);
    }
    printf("%d\n",st.size()+1);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int n,k,ans=0;
    cin >> n >> k;
    PQ(q);
    REP(i,n){
        int a,b;
        cin >> a >> b;
        q.push(P(a,b));
    }
    int x=0;
    while(x == 0){
        P y=q.top();
        q.pop();
        k -= y.second;
        if(k<=0){
            ans = y.first;
            x = 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;

void Yes(li b){
  if(b)cout<<"Yes";
  else cout<<"No";
}
void yes(li b){
  if(b)cout<<"yes";
  else cout<<"no";
}

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

  char A,B,C;
  cin >>A>>B>>C;
  bool ans=(A==B&&B==C);
  Yes(!ans);

}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r, t;
        std::cin >> l >> r >> t;
        std::swap_ranges(v.begin() + l, v.begin() + r, v.begin() + t);
    }

    for (int i = 0; i < v.size(); ++i) {
        std::cout << v[i] << " \n"[i == v.size() - 1];
    }
}


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

int main() {

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

    if (a[4] - a[0] > k) {
        cout << ":(" << endl;
    }
    else {
        cout << "Yay!" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

int N;
ll K;
vector<vector<ll>> G(50,vector<ll>(50));

vector<vector<ll>> mulMatrix(vector<vector<ll>>& a, vector<vector<ll>>& b) {
	vector<vector<ll>> c(N, vector<ll>(N,0));
	rep(i,N) rep(j,N) rep(k,N) {
		c[i][j] += (a[i][k] * b[k][j]);
		c[i][j] %= MOD;
	}
	return c;
}

vector<vector<ll>> powMatrix(vector<vector<ll>>& a, ll times) {
	if(times == 1) {
		//cout << times << endl;
		return a;
	}
	vector<vector<ll>> b = powMatrix(a, times/2);
	vector<vector<ll>> c = mulMatrix(b,b);
	//cout << times << endl;
	if(times % 2 == 0) {
		return c;
	}
	else {
		return mulMatrix(a,c);
	}
}

int main() {
	cin >> N >> K;
	rep(i,N) rep(j,N) cin >> G[i][j];
	vector<vector<ll>> c = powMatrix(G, K);
	ll sum = 0;
	rep(i,N) rep(j,N) {
		sum += c[i][j];
		sum %= MOD;
	}
	cout << sum << endl;

  return 0;
}


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

int main(){
int N; cin >> N;
int love[N];
int count = 0;

for(int i = 1;i <= N;i++){
    cin >> love[i];
    cout << endl;
}

for(int i = 1; i <= N; i++){
        if(i == love[love[i]]){
            count ++;
        }
    }
    cout << count / 2 << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = modu(a); b; a = modu(a * a) , b >>= 1){
        if (b & 1) res = modu(res * a);
    }
    return res;
}
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int D = in(),G = in()/100;
    vector<pair<int,int>> p(D+1);
    REP(i,D){
        p[i+1].first = in();
        p[i+1].second = in()/100;
    }
    int answer = INT32_MAX;
    REP(i,modpow(2,D)){
        vector<int> where;
        int counter = 1;
        int tmpe = i;
        while(tmpe != 0){
            if(tmpe %2 == 1)where.push_back(counter);
            tmpe = tmpe >> 1;
            counter++;
        }
        int solved = 0;
        int point = 0;
        REP(i,where.size()){
            solved += p[where[i]].first;
            point += p[where[i]].first * where[i] + p[where[i]].second;
        }
        if(point >= G){
            answer = min(solved,answer);
        }else{
            int which = 0;
            REP(i,D){
                if(vector_finder(where,D-i) == 0){
                    which = D-i;
                    break;
                }
            }
            if(which != 0){
                if((G-point + which - 1)/which < p[which].first)answer = min(solved + (G-point + which - 1)/which,answer);
            }
        }
    }
    cout << answer << "\n";
}

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

const int N = 105;
const int mod = 1e9 + 7;

int f[N][N << 6];
int g[N][N << 6];

void upd(int &a, int b) {
	a = (a + b) % mod;
}

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

	g[n + 1][0] = 1;	
	for(int i = n + 1; i > 1; -- i)
		for(int j = 0; j < 6000; ++ j) if(g[i][j])
			for(int cur = 0; cur <= k; ++ cur) {
				if(cur > i - 1) {
					upd(g[i - 1][j], g[i][j]);
					upd(f[i - 1][j], (f[i][j] + 1ll * (cur + j) * g[i][j]) % mod);
				}
				else {
					int k = (cur + j) / (i - 1);
					upd(g[i - 1][j + k], g[i][j]);
					upd(f[i - 1][j + k], (f[i][j] + 1ll * ((cur + j) % (i - 1)) * g[i][j]) % mod);
				}
			}

	cout << accumulate(f[1], f[1] + 6000, 0ll) % mod << '\n';
}


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

void Swap(int &a, int &b){
    int tmp;
    tmp = a;
    a = b;
    b = tmp;
}

int main(int argc, const char * argv[]) {
    int a, b, c;
    cin >> a>> b>> c;
    Swap(a, b);
    Swap(a, c);
    cout << a<<" "<< b<<" "<<c;
    return 0;
}


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

int cnt[26];

int main() {
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    for (int i = 0; i < str.size(); ++i) cnt[str[i] - 'a']++;

    bool flag = true;
    for (int i = 0; i < 26; ++i)
        if (cnt[i] % 2 != 0)
            flag = false;

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//ΔARC099E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 777;
int n,m,a[N][N];
int c[N],s[3];
int f[N],g[N];
void dfs(int u,int cc){
	if(c[u]){
		if(c[u]!=cc){
			cout<<-1;
			exit(0);
		}
		return;
	}
	c[u]=cc;
	s[cc]++;
	int i;
	for(i=1;i<=n;i=i+1)
		if(u!=i&&!a[u][i])
			dfs(i,cc^3);
}
int main()
{
	int i,x,y;
	scanf("%d%d",&n,&m);
	while(m--){
		scanf("%d%d",&x,&y);
		a[x][y]=1,a[y][x]=1;
	}
	f[0]=1;
	for(i=1;i<=n;i=i+1){
		if(c[i])
			continue;
		s[1]=0,s[2]=0;
		dfs(i,1);
		for(x=0;x<=n;x=x+1)
			if(f[x])
				g[x+s[1]]=1,g[x+s[2]]=1;
		for(x=0;x<=n;x=x+1)
			f[x]=g[x],g[x]=0;
	}
	x=N*N;
	for(i=1;i<=n;i=i+1)
		if(f[i])
			x=min(x,i*(i-1)+(n-i)*(n-i-1));
	cout<<x/2;
	return 0;
}

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

int main(){
  int a, b, c, x, y, ans;
  cin >> a >> b >> c >> x >> y;
  
  if(a+b>2*c){
    if(max(x,y)*2*c<(min(x,y)*2*c+abs(x-y)* ((x>y)?a:b))){
      ans = max(x,y)*2*c;
    }else{
      ans = min(x,y)*2*c+abs(x-y)* (x>y?a:b);
    }
  }else{
    ans = x*a + y*b;
  }
  cout << ans << endl;
  return 0;

}


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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
using i64 = int_fast64_t;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(15);

    int n; cin >> n;
    ll length = 0LL;
    vll a(n);
    vll l(n);
    rep(i,n) {
        cin >> a[i];
        length += a[i];
        l[i] = length;
    }
    ll answer = infll;
    rep(i,n) {
        chmin(answer, abs(l[i] - (length-l[i])));
    }

    cout << answer << '\n';
}

Measured memory_bytes: 3328
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
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; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
#define vecP vector<P>
// cout << setprecision(15) << std::fixed;

int main()
{
	ll n;
	cin >> n;
	vec dp;
	dp.push_back(0);
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		if (a == dp[dp.size() - 1] + 1) dp.push_back(a);
	}
	if (dp.size() == 1) {
		cout << -1 << endl;
	}
	else {
		cout << n - (dp.size() - 1) << endl;
	}
}


Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using namespace std;

#define int long long

int aaa[10000000] = {};
vector<int> tmp;
int mod = 1000000007;
signed main() {
	int N;
	cin >> N;
	int tmp = 1;

	for (int k = 1; k <= N; k++) {
		tmp = k;
		for (int i = tmp;;) {
			int flag = false;
			for (int j = 2; j <= i; j++) {
				if (i%j == 0) {
					i = i / j;
					flag = true;
					aaa[j]++;
					break;
				}
			}
			if (flag == false) break;
		}
	}

	int ans = 1;
	for (int i = 0; i < 10000; i++) {
		if (aaa[i] > 0) {
			ans *= (aaa[i] + 1);
		}
		ans %= mod;
	}
/*
	for (int i = 1; i <= N; i++) {
		tmp *= i;
		tmp %= mod;
	}

	*/

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int a,b,c,d,cnt=0;
cin>>a>>b>>c>>d;
//for(int i=0;i<100;i++)
for( int i=100;i>0;i--)
if(a<i && b>=i && c<i && d>=i){
    cnt++;
}
cout<<cnt<<"\n";
}

Measured memory_bytes: 512
#include <stdio.h>

void Seireki(int );
void Wareki(int ,int );

int main(void) {
  int E, Y;

  scanf("%d %d", &E, &Y);

  if(E == 0) Seireki(Y);
  else Wareki(E, Y);

  return 0;
}

void Seireki(int y) {
  if(y <= 1911) {
    printf("M%d", y-1867);
  } else if(y <= 1925) {
    printf("T%d", y-1911);
  } else if(y <= 1988) {
    printf("S%d", y-1925);
  } else {
    printf("H%d", y-1988);
  }

  printf("\n");
}

void Wareki(int e,int y) {
  switch(e) {
    case 1: printf("%d", y+1867);
            break;
    case 2: printf("%d", y+1911);
            break;
    case 3: printf("%d", y+1925);
            break;
    case 4: printf("%d", y+1988);
            break;
  }

  printf("\n");
}



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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int m, minn, maxn;
	while (1) {
		cin >> m >> minn >> maxn;
		if (!m) break;
		vector<int> v(m);
		REP(i, m) {
			cin >> v[i];
		}
		int gap = -INF, ans = 0;
		FOR(i, minn, maxn + 1) {
			if (gap <= v[i - 1] - v[i]) {
				gap = v[i - 1] - v[i];
				ans = i;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#Input
N, W = map(int, input().split())
w = [0] * N
v = [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

DP = [[0 for j in range(W + 1)] for i in range(N + 1)]
# print(DP)
#Initialization
for i in range(W):
    DP[0][i] = 0

for i in range(1, N + 1):
    for j in range(W + 1):
        if w[i - 1] > j:
            DP[i][j] = DP[i - 1][j]
        else:
            # print("i, j:", i, j)
            DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - w[i - 1]] + v[i - 1])

# print(DP)
print(DP[N][W])


Measured memory_bytes: 217932
import java.util.*
import java.math.*
import java.lang.Math.*

val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1_000_000_007L
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2


fun solve(X: Int, P: IntArray): Int {
    var cand = ArrayList<Int>()
    for (i in 0..101) {
        if (P.contains(i)) continue
        else cand.add(i)
    }

    var res = 0
    var dist = INF
    for (c in cand) {
        if (dist > abs(c - X)) {
            dist = abs(c-X)
            res = c
        }
    }

    return res
}


fun main(args: Array<String>){
    val (X,N) = readIntArray()
    if (N == 0) {
        println(X)
        return
    }

    val P = readIntArray()

    val ans = solve(X, P)

    println(ans)
}


Measured memory_bytes: 40144
import java.util.*;
public class Main{
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      long n = sc.nextLong();

      long m = (long)Math.sqrt(n);

      long c = n+2;

      for (long i = 1; i < m+1; i++) {
         if (n % i == 0) {
            if(i + n/i < c){
               c = i + n/i;
            }
         }
      }
      System.out.println(c-2);
   }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; ll C;
	cin >> n >> C;
	vector<ll> h(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> h[i];
	vector<ll> dp(n + 1);
	deque<int> dq(1, 1);
	auto X = [&](int i) {
		return -2 * h[i];
	};
	auto Y = [&](int i) {
		return h[i] * h[i] + dp[i];
	};
	auto F = [&](int i, int j) {
		return h[i] * X(j) + Y(j) + C + h[i] * h[i];
	};
	auto cross = [](ll x1, ll y1, ll x2, ll y2) {
		return x1 * y2 - x2 * y1;
	};
	for (int i = 2; i <= n; i++) {
		while (dq.size() >= 2) {
			if (F(i, dq[0]) >= F(i, dq[1]))
				dq.pop_front();
			else break;
		}
		dp[i] = F(i, dq[0]);
		while (dq.size() >= 2) {
			int j = dq.back(), k = dq[dq.size()-2];
			if (cross(X(j)-X(k), Y(j)-Y(k), X(i)-X(j), Y(i)-Y(j)) >= 0)
				dq.pop_back();
			else break;
		}
		dq.push_back(i);
	}
	cout << dp[n] << "\n";
	return 0;
}

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

struct edge{int to; double cost;};
typedef pair<double,int> P;
const double INF = 1e12;
const int MAX_V = 2e3;

vector<edge> G[MAX_V];
double d[MAX_V];
int V;

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  rep(i,V) d[i] = INF;
  d[s] = 0.0;
  que.push(P(0.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(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  double xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  V = n+2;
  vector<double> x(n+2), y(n+2), r(n+2);
  x[0] = xs; y[0] = ys; r[0] = 0.0;
  x[n+1] = xt; y[n+1] = yt; r[n+1] = 0.0;
  rep(i,n) cin >> x[i+1] >> y[i+1] >> r[i+1];
  rep(i,n+2) {
    for(int j = i+1; j < n+2; j++){
      double d = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])) - r[i] - r[j];
      if(d < 0.0) {
        G[i].push_back(edge{j,0.0});
        G[j].push_back(edge{i,0.0});
      } else {
        G[i].push_back(edge{j,d});
        G[j].push_back(edge{i,d});
      }
    }
  }
  dijkstra(0);
  printf("%.12f\n",d[n+1]);
  return 0;
}

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

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
  int i, j, k, l;
  unsigned long long H, W;
  unsigned long long m, n;
  scanf("%llu %llu", &H, &W);
  if(W == 1 || H == 1) {
    puts("1");
  } else {
    m = max(H, W);
    n = min(H, W);
    printf("%llu", (unsigned long long)ceil(m / 2.0 * n));
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<ios>
#include <cmath>
using namespace std;
using ll = long long;
const ll INF=INT64_MAX>>3;
template<class T> inline T gcd(T x, T y) {
    T bigger = max(x,y);
    T smaller = min(x,y);
    for(T p = smaller; p >= 1; p--) {
        if(bigger%p==0 && smaller%p == 0) return p;
    }
    return -1;
}

int main(){
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    ll ans = 0;
    for(int a = 1; a <= K; a++ ) {
        for(int b = 1; b <= K; b++) {
            for(int c = 1; c <= K; c++){
                   ans+=gcd(gcd(a,b),c);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    String t = sc.next();
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    String u = sc.next();
    
   
    if(s.equals(u)){
      a = a - 1;
    }else if(t.equals(u)){
      b = b - 1;
    }
    
    System.out.println(a + " " + b);
    
    sc.close();
    
  }
}


Measured memory_bytes: 21716
# include <bits/stdc++.h>
using namespace std;
int main ()
{
  string s;
  cin>>s;
  int flag=0;
  for (int i=0;i<s.length()-1;++i)
     {
     	if (s[i]==s[i+1])
     	  {
     	  	flag=1;
     	  	break;
		  }
	 }
	if (flag==1) printf ("Bad\n");
	else printf("Good\n");
  return 0;
} 

Measured memory_bytes: 256
alfa=['z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y']
n = int(input())
ans=''
while n>0:
    ans+=alfa[n%26]
    n=n-1
    n=n//26

print(ans[::-1])


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  vector<int> b(N), w(N);
  rep(i, N) {
    b[i] = (i ? b[i - 1] : 0) + (S[i] == '#');
    w[N - i - 1] = (i ? w[N - i] : 0) + (S[N - i - 1] == '.');
  }
  int ans = w[0];
  rep(i, N) {
    ans = min(ans, b[i] + (i < N - 1 ? w[i + 1] : 0));
  }
  cout << ans << endl;
}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int k,n; cin >> k >> n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    ll ma=k-a[n-1]+a[0];
    ll ans = 0;
    rep(i,1,n){
        ma = max(ma,a[i]-a[i-1]);
    }
    cout << k-ma << endl;
}

Measured memory_bytes: 1792
from collections import deque

def bfs(sx, sy, maze):
    INF = 100000000
    visit = [[-INF for i in range(w + 2)] for j in range(h + 2)]
    queue = deque([])
    queue.append([sx, sy])
    visit[sx][sy] = 0
    res = 0
    while len(queue):
        x, y = queue.popleft()
        for k in range(0, 4):
            nx, ny = x + dx[k], y + dy[k]
            if maze[nx][ny] != '#' and visit[nx][ny] == -INF:
                queue.append([nx, ny])
                visit[nx][ny] = visit[x][y] + 1
                res = max(res, visit[nx][ny])
    return res


h, w = map(int, input().split())
maze = [list("#" * (w + 2))]
for _ in range(h):
    maze.append(["#"] + list(input()) + ["#"])
maze += [list("#" * (w + 2))]

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

ans = 0
for i in range(h + 2):
    for j in range(w + 2):
        if maze[i][j] == ".":
            ans = max(ans, bfs(i, j, maze))
print(ans)


Measured memory_bytes: 43756
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
   ll x,y;
   int k;
   while(cin>>x>>y)
   {
       if(x==1||y==1)
       {
           cout<<"1\n";continue;
       }
       ll x1=x/2;
       ll x2=x1;
       if(x%2>0)x1++;
       ll y1=y/2;
       ll y2=y1;
       if(y%2>0)y1++;
       cout<<x1*y1+x2*y2<<'\n';
   }
}

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

using namespace std;

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


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

int main(void){
    int i;
    scanf("%d", &i);
    if(400<=i&&i<=599){printf("8");}
    else if(600<=i&&i<=799){printf("7");}
    else if(800<=i&&i<=999){printf("6");}
    else if(1000<=i&&i<=1199){printf("5");}
    else if(1200<=i&&i<=1399){printf("4");}
    else if(1400<=i&&i<=1599){printf("3");}
    else if(1600<=i&&i<=1799){printf("2");}
    else{printf("1");}
}


Measured memory_bytes: 1648
#include<bits/stdc++.h>
#define N 2001001
#define re register
using namespace std;
typedef unsigned long long ll;
typedef double db;
inline void read(re ll &ret)
{
	ret=0;re char c=getchar();re bool pd=false;
	while(!isdigit(c)){pd|=c=='-';c=getchar();}
	while(isdigit(c)){ret=(ret<<1)+(ret<<3)+(c&15);c=getchar();}
	ret=pd?-ret:ret;
	return;
}
ll base=10007,bas[N];
char s[N];
ll n;
ll num[N],ans;
map<ll,bool>vis;
int main()
{
    bas[0]=1;
    for(re ll i=1;i<=N-5;i++)
        bas[i]=bas[i-1]*base;
    read(n);
    for(re ll t=1;t<=n;t++)
    {
        scanf("%s",s+1);
        re ll now=0;
        for(re int i=1;i<=strlen(s+1);i++)
        	now=now*bas[i-1]+ll(s[i]);
        ans+=!vis[now];	
        vis[now]=true;
        
    }
    printf("%lld\n",ans);
    exit(0);
}

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

int main() {
  long N;
  
  cin >> N;
  
  unsigned long ans = 0;
  
  //for(int i = 1;i < N;i++){
    //ans += i;
  //}
  if(N != 1){
    ans = N * (N - 1) / 2;
  }
  
  cout << ans << endl;
}


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

    int main(){
        int a, k;
        bool flag = true;
        cin>>a;

        for (int i = 0; i < a; i++)
        {
            
            cin>> k;
            if(!flag) continue;
            if( (k%2==0) ){
                if(k%3 == 0 || k%5 == 0) continue;
            else
            {
                flag = false;
            }

            }
                
            
        }
        if(flag) cout<<"APPROVED\n";
        else cout<<"DENIED\n";
    }

Measured memory_bytes: 256
from itertools import permutations
from bisect import bisect_left

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

permutation = list(permutations(range(1, n+1)))
a = bisect_left(permutation, p)
b = bisect_left(permutation, q)

print(abs(a - b))

Measured memory_bytes: 8052
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<int,int> P;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)

int main(){
  ll n,m;cin>>n>>m;
  int l = 0;
  int r = n;
  fr(i,m){
    int a,b;
    cin >> a >> b;
    l = max(l,a);
    r = min(r,b);
  }
  int ans = max(0,r-l+1);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<pii> ans;
    set<pii> exclude;
    int n;
    cin >> n;
    if (n % 2 == 0) {
        for (int a = 1, b = n; a < b; a++, b--) {
            exclude.insert(MP(a, b));
        }
        for (int a = 1; a <= n; a++) {
            for (int b = a + 1; b <= n; b++) {
                if (!exclude.count(MP(a, b))) ans.push_back(MP(a, b));
            }
        }
    } else {
        for (int a = 1, b = n - 1; a < b; a++, b--) {
            exclude.insert(MP(a, b));
        }
        for (int a = 1; a <= n; a++) {
            for (int b = a + 1; b <= n; b++) {
                if (!exclude.count(MP(a, b))) ans.push_back(MP(a, b));
            }
        }
    }

    cout << ans.size() << endl;
    rep(i, ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;

int n, k;
int a[N];

bool isPos(int x) {

	int moves = k;

	for (int i = 0; i < n; i++) {
		int req = ((a[i] + x - 1) / x) - 1;
		// dbg(req);
		moves -= req;

		if (moves < 0 or (moves == 0 and i != n - 1))
			return false;
	}

	return true;
}

void solve() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(a, a + n);

	int mi = 1, ma = a[n - 1];
	int ans = ma;
	while (mi <= ma) {
		int mid = mi + (ma - mi) / 2;
		// dbg(mid);
		if (isPos(mid)) {
			ans = mid;
			ma = mid - 1;
		} else mi = mid + 1;
	}

	cout << ans << endl;
}

// you should probably see down .. believe me it would help
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

// COME ON DUDE .... GIVING UP NOT GONNA HELP
// JUST GET YOUR ASS TO WORK ALREADY ..
// AND FOR FUCKING SAKE ... DONT PANIC !!


Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+10;
const ll mod =   1e9+7;
ll n;
ll arr[N];
int main()
{  fast
cin>>n;
for(int i=1;i<=n+1;i++)cin>>arr[i];
ll x=1;ll sum=0;
bool valid=true;
if(!arr[n+1])
valid=false;
for(int i=1;i<=n+1;i++){
	if(x<arr[i])
	valid=false;
	 x-=arr[i];
	x*=2;
	x=min(1ll<<30,x);
//	cout<<x<<endl;
   if(x<0)
   valid=false;
	sum+=arr[i];
}

if(!arr[n+1]){
	valid=false;
}
if(arr[1]){
	if(n==0&&arr[1]==1){
		cout<<1;return 0;
	}
	cout<<-1;
	return 0;
}
if(!valid){
	cout<<-1;return 0;
}
ll ans=0;ll val=1;
for(int i=1;i<=n+1;i++){
	val=min(val,sum);
	ans+=val;
	val-=arr[i];sum-=arr[i];
	val*=2;
	
	if(!val&&(i!=n+1)){
		cout<<-1;
		return 0;
	}
	if(i==n+1)
	if(val){
		cout<<-1;
		return 0;
	}
}if(sum!=0||val!=0)
{
	cout<<-1;
	return 0;
}
cout<<ans;
}

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

# dp = [float("inf")] * n
dp = [0] * n

for i in range(1, n):
    j = max(0, i - k)
    e = L[i]
    dp[i] = min([DP + abs(e - COST) for DP, COST in zip(dp[j:i], L[j:i])])

print(dp[-1])


Measured memory_bytes: 13876
#include <iostream>
#include<algorithm>
#include <string>
using namespace std;
int main() {
	int c,a[32] = {
	1, 1, 1, 2, 1, 2, 1, 5, 
	2, 2, 1, 5, 1, 2, 1, 14, 1,
	5, 1, 5, 2, 2, 1, 15, 2
	, 2, 5, 4, 1, 4, 1, 51
	};
	cin >> c;
	cout << a[c-1];


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int n;
string s;
int main(){
    cin >> n;
    cin >> s;
    map<char,int> mp;
    for(int i = 0; i < n; i++){
        mp[s[i]]++;
    }
    if(mp['R'] > mp['B']){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LOOP(val, times)   for(val = 0; val < (times); val++)
int main(){
  int a,s;
  cin>>a>>s;
  if(1<=a && a<=9 && 1<=s && s<=9){
    cout<<a*s<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int ans=1,n,i,p,a[1000]={0},c1=0,c,b,a1,d;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&p);
		ans = ans/__gcd(p,ans);
		ans*=p;
	}
	printf("%lld",ans);
	
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;

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

    for(int via = 0; via < n; via++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i == j) continue;
                if(i == via) continue;
                if(j == via) continue;
                if(a[i][j] == -1 || a[i][via] == -1 || a[via][j] == -1) continue;
                if(a[i][j] > a[i][via] + a[via][j]){
                    cout << -1 << endl;
                    return 0;
                } else {
                    if(a[i][j] == a[i][via] + a[via][j]){
                        a[i][j] = -1;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(a[i][j] != -1) ans += a[i][j];
        }
    }
    cout << ans << endl;
}   

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

int main() {
   int sx,sy,tx,ty;
   cin >> sx >> sy >> tx >> ty;
   for (int i=0; i<tx-sx; i++) {
       cout << "R" ;
   }
   for (int i=0; i<ty-sy; i++) {
       cout << "U";
   }
   for (int i=0; i<tx-sx; i++) {
       cout << "L";
   }
   for (int i=0; i<ty-sy+1; i++) {
       cout << "D";
   }
   for (int i=0; i<tx-sx+1; i++) {
       cout << "R" ;
       }
   for (int i=0; i<ty-sy+1; i++) {
       cout << "U";
   }
   cout << "LU";
   for (int i=0; i<tx-sx+1; i++) {
       cout << "L";
   }
   for (int i=0; i<ty-sy+1; i++) {
       cout << "D";
   }
   cout << "R" << endl;
}


Measured memory_bytes: 3592
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

graph = [[] for _ in range(N + 1)]
arrow = [0] * (N + 1)

for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
    
def bfs(st, graph):
    INF = 10 ** 18
    dist = [0] * len(graph)
    dist[st] = 1
    queue = deque([st])
    while queue:
        q = queue.popleft()
        for r in graph[q]:
            if dist[r] == 0:
                dist[r] = q
                queue.append(r)
    return dist

answer = bfs(1, graph)[2:]
print("Yes")
for a in answer:
    print(a)

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

int main () {
    vector<char> b;

    string keys;
    cin >> keys;

    for (char cmd : keys){ //for each key pressed
        switch(cmd){
        case '0':
            b.push_back('0');
            break;
        case '1':
            b.push_back('1');
            break;
        case 'B':
            if(!b.empty()){
                b.pop_back();
            break;}
        }
    }
    
    string output(b.begin(), b.end());
    cout << output;

    return 0;
}

Measured memory_bytes: 256