akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main(void){
  int a, b;
  std::cin >> a;
  std::cin >> b;
  if(a>=1 && a<=9 && b>=1 && b<=9){
    std::cout << a*b;
  }else{
    std::cout << -1;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e9 + 7;
int main( ){
    int n;
    scanf("%d", &n);
    int num[n];
    for(auto &i : num)
        scanf("%d", &i);
    vector<int> dp(n, maxN);
    dp[0] = 0;
    for(int i = 0; i < n; i++)
        for(auto j : {i + 1, i + 2})
            if(j < n)
                dp[j] = min(dp[j], abs(num[j] - num[i]) + dp[i]);
    cout << dp[n - 1] << '\n';
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,dp[100010][2];
bool used[100010];
vector<int>v[100010];
void dfs(int x){
	if(used[x])return;
	used[x]=true;
	dp[x][0]=dp[x][1]=1;
	for(int i:v[x]){
		if(used[i])continue;
		dfs(i);
		dp[x][0]*=(dp[i][0]+dp[i][1]);
		dp[x][1]*=dp[i][0];
		dp[x][0]%=MOD;
		dp[x][1]%=MOD;
	}
}
signed main(){
	cin>>n;
	rep(i,n-1){
		int x,y;
		cin>>x>>y;
		x--,y--;
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(0);
	cout<<(dp[0][0]+dp[0][1])%MOD;
	return 0;
}


Measured memory_bytes: 11648
#include <stdio.h>

#define TWO_EVEN 2												/*2???????????????*/
#define TRUE 1													/*??£??????*/
#define FALSE 0													/*?????????*/
#define INIT 0													/*?????????*/
#define INIT_INPUT 0											/*??\?????????????????????*/
#define INIT_CALC 3												/*?¨??????¨?????°?????????*/
#define EXIT_SUCCESS 0											/*????????????????????????*/
#define EVEN_DISC( x ) x % 2									/*??¶??°?????\?????????*/

static unsigned char prime_disc( unsigned long ulW_Dtestcase	/*?????\????±????????´?*/
);	/*?´???°?????\??¢??°*/

int main( void )
{
	unsigned long ulW_Dtestcase;								/*?????\????±????????´?*/
	unsigned short usW_Darray_count;							/*????´???°*/
	unsigned short usW_Cinput_cnt;								/*??\??????????????¨????????????*/
	unsigned short usW_Cprime_cnt = INIT;						/*?´???°????????????*/
	unsigned char ubW_Fcnt_flug;								/*?´???°??????????????¨????????°*/

	scanf("%d", &usW_Darray_count);								/*????´???°??\???*/
	/*????´???\?????¨?????????*/
	for( usW_Cinput_cnt = INIT_INPUT; usW_Cinput_cnt < usW_Darray_count; usW_Cinput_cnt++ ){
		scanf("%ld", &ulW_Dtestcase );							/*?????\????±????????´???\???*/
		ubW_Fcnt_flug = prime_disc( ulW_Dtestcase );			/*?´???°?????????????????\*/
		/*?????\????±?????´???°?????£?????´???*/
		if( ubW_Fcnt_flug == TRUE ){
			usW_Cprime_cnt++;									/*?´???°????????????????????????????????????*/
		}
		else{
			/*else?????????????????????????????\*/
		}
	}
	printf("%d\n", usW_Cprime_cnt);								/*?´???°?????°?????????*/
	return EXIT_SUCCESS;
}

static unsigned char prime_disc( unsigned long ulW_Dtestcase )
{
	unsigned long ulW_Fbool_flug;								/*?´???°?????\??¨????????°*/
	unsigned long ulW_Dcalc;									/*?¨??????¨?????°*/
	unsigned long ulW_Dcalc_sub;								/*????????¨?????°*/

	ulW_Dcalc = EVEN_DISC( ulW_Dtestcase );						/*??¶??°?????????????????\*/
	/*?????\????±????2?????´???*/
	if( ulW_Dtestcase == TWO_EVEN ){
		return TRUE;											/*?´???°??????????????£???????????????*/
	}
	/*?????\????±????2???????°???????????????¶??°?????£?????´???*/
	else if( ( ulW_Dtestcase < TWO_EVEN ) || ( ulW_Dcalc == INIT ) ){
		return FALSE;											/*?´???°??§????????????????????????????????????*/
	}
	ulW_Dcalc = INIT_CALC;										/*?¨??????¨?????°????????????*/
	ulW_Dcalc_sub = ulW_Dcalc * ulW_Dcalc;						/*????????¨?????°????¨??????¨?????°???2????????£??\*/
	/*?¨??????¨?????°???2???????????\????±???\????????´????????????*/
	while( ulW_Dcalc_sub <= ulW_Dtestcase ){
		ulW_Fbool_flug = ulW_Dtestcase % ulW_Dcalc;				/*?????\????±?????¨??????¨?????°??§?????????????????´???????????°???true???*/
		/*?´???°?????\??¨????????°???false?????´???*/
		if( ulW_Fbool_flug == FALSE ){
			return FALSE;										/*?´???°??§????????????????????????????????????*/
		}
		else{
			/*else?????????????????????????????\*/
		}
		ulW_Dcalc += TWO_EVEN;									/*?¨??????¨?????°???2?????????*/
		ulW_Dcalc_sub = ulW_Dcalc * ulW_Dcalc;					/*????????¨?????°????¨??????¨?????°???2????????£??\*/
	}
	return TRUE;												/*?´???°??????????????£???????????????*/
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[533333],b[533333];
struct node
{
	int val;
	node *next;
}*head[533333],*tail[533333],pool[533333];
set<int> bl;
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[a[i]]=i;
	}
	head[0]=tail[0]=&pool[0];
	for(int i=1;i<=n;i++)
	{
		head[i]=tail[i]=&pool[i];
		head[i]->val=b[i];
	}
	bl.insert(0);
	for(int i=1;i<=k;i++)bl.insert(a[i]);
	for(int i=1;i<=n;i++)
	{
		bl.erase(a[i]);
		auto pos=*--bl.lower_bound(a[i]);
//		cerr<<"found "<<i<<' '<<pos<<endl;
		tail[pos]->next=head[a[i]];
		tail[pos]=tail[a[i]];
		if(i+k<=n)bl.insert(a[i+k]);
	}
	int top=0;
	for(node *u=head[0];u;u=u->next)
	{
		b[top++]=u->val;
	}
	for(int i=1;i<=n;i++)a[b[i]]=i;
	for(int i=1;i<=n;i++)cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 47744
#include <stdio.h>
int main(){
    int trump[4][13]={{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,},{0,0,0,0,0,0,0,0,0,0,0,0,0}};
    char a;
    int b,n,i;
    scanf("%d ",&n);
    
    for(i=0;i<n;i++){
        scanf("%c %d\n",&a,&b);
        
        if(a=='S')
            trump[0][b-1]=1;
        else if(a=='H')
            trump[1][b-1]=1;
        else if(a=='C')
            trump[2][b-1]=1;
        else if(a=='D')
            trump[3][b-1]=1;
    }
    int c,d,e,f;
    
    for(c=1;c<=13;c++)
        if(trump[0][c-1]!=1)
            printf("S %d\n",c);
    
    for(d=1;d<=13;d++)
        if(trump[1][d-1]!=1)
            printf("H %d\n",d);
    
    for(e=1;e<=13;e++)
        if(trump[2][e-1]!=1)
            printf("C %d\n",e);
    
    for(f=1;f<=13;f++)
        if(trump[3][f-1]!=1)
            printf("D %d\n",f);
    }
    



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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  llvec h(N);
  rep(i, N)cin >> h[i];
  ll ok=1e9;
  ll ng= 0;
  while(abs(ok-ng)>1){
    ll m = (ok+ng)/2;
    ll ans = 0;
    rep(i, N){
      ans += max(0LL, (h[i]-m * B + A - B - 1)/(A-B));
    }
    //cerr << ok << " " << ng << " " << m << " " << ans <<endl;
    if(ans<=m){
      ok = m;
    }else{
      ng=m;
    }
  }
  cout << ok<<endl;
  return 0;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
 
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
const ll inf=1e15;
#define pb push_back
const int INF=(0x3f3f3f3f);

ll dp[N][3];
int X[N];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  
  int n,k;
  cin>>n>>k;
  ll R,S,P;
  cin>>R>>S>>P;
  string t;
  cin>>t;
  for(int i=0;i<k;i++){
    if(t[i]=='s'){
      dp[i][1]+=R;
    }else if(t[i]=='r'){
      dp[i][2]+=P;
    }else if(t[i]=='p'){
      dp[i][0]+=S;
    }
    if(i>0){
      dp[i][0]+=max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2]));
      dp[i][1]+=max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2]));
      dp[i][2]+=max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2]));
    }
  }
  for(int i=k;i<n;i++){
    if(t[i]=='s'){
      dp[i][1]+=R;
      if(t[i-k]=='s'&&X[i-k]==0){dp[i][1]-=R;X[i]=1;}
      else if(t[i-k]=='s')X[i]=0;
    }else if(t[i]=='r'){
      dp[i][2]+=P;
      if(t[i-k]=='r'&&X[i-k]==0){dp[i][2]-=P;;X[i]=1;}
      else if(t[i-k]=='r')X[i]=0;
    }else if(t[i]=='p'){
      dp[i][0]+=S;
      if(t[i-k]=='p'&&X[i-k]==0){dp[i][0]-=S;;X[i]=1;}
      else if(t[i-k]=='p')X[i]=0;
    }
    if(i>0){
      dp[i][0]+=max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2]));
      dp[i][1]+=max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2]));
      dp[i][2]+=max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2]));
    }
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<'\n';
}

Measured memory_bytes: 4176
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

ll power(ll a, ll b) {
	if (b == 0) return 1;
	ll pp = power(a, b/2);
	pp = (pp*pp) % mod;
	if(b%2 == 0) return pp;
	return (pp*a)%mod;
}

int N, K;
ll NP[1<<20], ND[1<<20], dp[1<<20];


int main() {

//  freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

  cin >>  N >> K;

  for(int i = 1;i <= K;i++) {
    ND[i] = K/i;
  }

  // debug(N);


  dp[K] = 1;
  ll ans = 0;
  for(int i = K-1;i >= 1;i--) {
    dp[i] = power(ND[i], N);
    int j = i+i;
    while(j <= K) {
      dp[i] = (dp[i]-dp[j]+mod)%mod;
      j += i;
    }

  }

  for(int i = 1;i <= K;i++) {
    ans = (ans + i*dp[i]%mod)%mod;
  }

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 5140
#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 rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct Seg{
  vector<ll>mx;
  vector<ll>sum;
  Seg(){
    sum.resize(1<<19, 0);
    mx.resize(1<<19, 0);
  }

  void add_val(ll l, ll r, ll val, ll bottom=0, ll top=1<<18, ll pos=1){
    if(l<= bottom && top <= r){
      sum[pos] += val;
      return;
    }
    if(l>=top || r<= bottom)return;

    ll mid = (bottom+ top)/2;
    add_val(l, r, val, bottom, mid, pos*2);
    add_val(l, r, val, mid, top, pos*2+1);
    mx[pos] = max<ll>( mx[pos*2]+sum[pos*2], mx[pos*2+1]+sum[pos*2+1] );
  }

  ll max_val(ll l, ll r, ll bottom=0, ll top=1<<18, ll pos=1){
    if(l<= bottom && top <= r) return mx[pos]+sum[pos];
    if(l>=top || r<= bottom)return -INF;

    ll mid = (bottom+ top)/2;
    return max<ll>(
      max_val(l, r, bottom, mid, pos*2),
      max_val(l, r, mid, top, pos*2+1)
    )+sum[pos];
  }
};

int main(){
  int n,m;cin>>n>>m;
  vector<pll> score[n+1];
  rep(i, m){
    ll l,r,a;cin>>l>>r>>a;
    score[r].push_back({l, a});
  }

  Seg seg;

  rep1(i, n){
    ll mx = seg.max_val(0, i);
    seg.add_val(i, i+1, mx);
    for(auto p:score[i]){
      ll l = p.first;
      ll a = p.second;
      seg.add_val(l, i+1, a);
    }
  }

  cout<<seg.max_val(0, n+1);

  return 0;
}

Measured memory_bytes: 22548
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
};
ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
typedef vector<vector<Edge>> Graph;


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

	int cou = 0;

	int ac = 0, bc = 0, wc = 0;
	REP(i, n)
	{
		string str;
		cin >> str;
		char bef = ' ';
		for (auto itr : str) {
			if (bef == 'A' && itr == 'B') {
				cou++;
			}
			bef = itr;
		}
		if (str[0] == 'B' && str.back() == 'A') wc++;
		else if (str[0] == 'B') ac++;
		else if (str.back() == 'A') bc++;
	}

	cou += max(0,wc - 1);
	int buf = min(ac, bc);
	if (buf && wc)
		cou += 1;
	cou += buf;

	if (buf == 0 && wc && (ac-buf > 0 || bc-buf > 0)) {
		cou++;
	}
	cout << cou << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
ll gcd(ll a, ll b); 
  
// To compute x raised to power y under modulo m 
ll power(ll x,ll y, ll m); 
  
// Function to find modular inverse of a under modulo m 
// Assumption: m is prime 
ll modInverse(ll a, ll m) 
{ 
    return power(a, m-2, m);  
} 
  
// To compute x^y under modulo m 
ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
  
// Function to return gcd of a and b 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b%a, a); 
} 
int main()
{
	ll h,n,maxm,minm,i,j;
   cin>>h>>n;
   maxm=0;
   ll a[n+10];
   ll b[n+10];
   for(i=0;i<n;i++)
   {
   	cin>>a[i]>>b[i];
   	maxm=max(maxm,a[i]);
   }
   ll dp[h+maxm+10];
   for(i=0;i<h+maxm+10;i++)
   dp[i]=1000000000;
   minm=1000000000;
   for(i=1;i<h+maxm;i++)
   {
   	   for(j=0;j<n;j++)
   	   {
   	   	  if(i-a[j]<=0)
   	   	  dp[i]=min(dp[i],b[j]);
   	   	  else
   	   	  dp[i]=min(dp[i-a[j]]+b[j],dp[i]);
		}
		if(i>=h)
		minm=min(minm,dp[i]);
   }
   cout<<minm<<endl;
}

Measured memory_bytes: 384
import heapq
def solve():
  N = int(input())
  ans = 0
  left,right = [ [] for i in range(N) ],[ [] for i in range(N) ]
  for _ in range(N):
    k,l,r = map(int,input().split())
    ans += min(l,r)
    if l>r:
      left[k-1].append(l-r)
    else:
      if k >= N: continue
      right[k].append(r-l)

  # left
  pq = []
  for i in range(N-1,-1,-1):
    for l in left[i]:
      heapq.heappush(pq,-l)
    if pq:
      ans += -heapq.heappop(pq)

  # right
  pq = []
  for i in range(N):
    for r in right[i]:
      heapq.heappush(pq,-r)
    if pq:
      ans += -heapq.heappop(pq)

  print(ans)

for i in range(int(input())):
  solve()

Measured memory_bytes: 103964
#include <stdio.h>

int main(void){
    int n,k,p;
    scanf("%d",&n);
    while(n){
        scanf("%d %d",&k,&p);
        if(k%p == 0)
            printf("%d\n",p);
        else
            printf("%d\n",k%p);
        n--;
    }
    return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string S;

  std::cin >> S;

  long long C = 0;

  for (int i = 0, l = -1, size = S.size(); i < size; i ++) {
    char c = S[i];

    if (l >= 0) {
      if (c == 'W') {
        C += i - l;

        l ++;
      }
    }
    else {
      if (c == 'B')
        l = i;
    }
  }
  
  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
ll sum1[14], sum2[14];
ll arr[27];
void call(int pos, int taken, ll ssum)
{
    if(pos>=13)
    {
        //cout<<taken<<" "<<ssum<<endl;
        sum1[taken]=(sum1[taken]+ssum)%mod;
        //cout<<sum1[taken]<<endl;
        return;
    }
    call(pos+1, taken, ssum);
    call(pos+1, taken+1, (ssum*arr[pos])%mod);
}
void call2(int pos, int taken, ll ssum)
{
    if(pos>=26)
    {
        sum2[taken]=(sum2[taken]+ssum)%mod;
        return;
    }
    call2(pos+1, taken, ssum);
    call2(pos+1, taken+1, (ssum*arr[pos])%mod);
}
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0; i<n; i++)
    {
        arr[s[i]-'a']++;
    }
    call(0, 0, (ll)1);
    call2(13, 0, (ll)1);
//    for(int i=0; i<6;  i++)
//        cout<<sum1[i]<<endl;
//    for(int i=0; i<6;  i++)
//        cout<<sum2[i]<<endl;
    ll ans=0;
    for(int i=1; i<=26; i++)
    {
        for(int j=max(i-13, 0); j<=min(13, i); j++)
        {
            int k=i-j;
            //cout<<j<<" "<<k<<endl;
            //cout<<sum1[j]<<" "<<sum2[k]<<endl;
            ll temp=(sum1[j]*sum2[k])%mod;
            ans=(ans+temp)%mod;
            //cout<<ans<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
using System;

namespace abc154_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ST = Console.ReadLine().Split(" ");
            string[] ABstr = Console.ReadLine().Split(" ");
            string U = Console.ReadLine();
            int A = int.Parse(ABstr[0]);
            int B = int.Parse(ABstr[1]);

            if (U.Equals(ST[0]))
            {
                A -= 1;
            }
            else
            {
                B -= 1;
            }

            Console.WriteLine(A + " " + B);
        }
    }
}


Measured memory_bytes: 27360
#include <iostream>
#include <vector>
#include <map>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		
		bool flag = true;
		int count = 0;
		while(flag)
		{
			map<int, int> Map;
			for(int i = 0; i < n; ++i)
			{
				Map[Vec[i]]++;
			}
			vector<int> Vec_buf(n);
			for(int i = 0; i < n; ++i)
			{
				for(map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
				{
					if((*Ite).first == Vec[i])
					{
						Vec_buf[i] = (*Ite).second;
					}
				}
			}
			if(Vec == Vec_buf)
			{
				flag = false;
			}
			Vec = Vec_buf;
			count++;
		}
		count--;
		cout << count << endl;
		for(int i = 0; i < n - 1; ++i)
		{
			cout << Vec[i] << " ";
		}
		cout << Vec[n - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  string s; cin >> s;
  int now = 0;
  vector<int> dis;
  rep(i,N) { 
    if (s[i]=='1') now++;
    else { dis.push_back(now); now = 0; }
  }
  dis.push_back(now); dis.push_back(0);
  int S = dis.size();

  int dp[S][3] = {}; dp[0][1] = -1; dp[0][2] = -1;
  rep(i,S-1) {
    // 取らない 右いっぱい-1の補正をする
    dp[i+1][0] = max(dp[i+1][0], dp[i][0]);
    dp[i+1][0] = max(dp[i+1][0], dp[i][1]);
    dp[i+1][0] = max(dp[i+1][0], dp[i][2] + (i&&dis[i-1]>=1?1:0));
    // 左いっぱい-1, 右1
    if (dis[i]==0||dis[i+1]==0) dp[i+1][1] = -1;
    else {
      dp[i+1][1] = max(dp[i+1][1], dp[i][0] + dis[i]);
      dp[i+1][1] = max(dp[i+1][1], dp[i][1] + (dis[i]-1));
      dp[i+1][1] = max(dp[i+1][1], dp[i][2] + 1);
    }
    // 左1, 右いっぱい-1
    if (dis[i]==0||dis[i+1]==0) dp[i+1][2] = -1;
    else {
      dp[i+1][2] = max(dp[i+1][2], dp[i][0] + dis[i+1]-1);
      dp[i+1][2] = max(dp[i+1][2], dis[i]==1 ? 0 : (dp[i][1]+dis[i+1]-1));
      dp[i+1][2] = max(dp[i+1][2], dp[i][2] + dis[i+1]-1);
    }
  }
  // debug(all(dis));
  // rep(i,S) debug(dp[i],dp[i]+3);
  ll result = *max_element(dp[S-1],dp[S-1]+3);
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 8824
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;


int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int ans = k;
    for (int i = 2; i <= n; ++i)
        ans *= k-1;
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

L = list(S)

O = []

for i in range(len(L)):
  O.append(ord(L[i]))
#print(O)
for i in range(len(L)):
  O[i] = O[i] + N
  if O[i] > 90:
    a = O[i] - 90
    O[i] = 64 + a

R = []

for i in range(len(L)):
  R.append(chr(O[i]))

for i in range(len(L)-1):
  R[0] = R[0] + R[i+1]


#print(N)
#print(S)
#print(L)
#print(O)
#print(R)
print(R[0])

Measured memory_bytes: 3316
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import math

N = int(input())
H = defaultdict(int)

for i in range(N):
    s = "".join(sorted(input()))
    H[s] += 1

ret = 0
for v in H.values():
    if v >= 2:
        ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ret)

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

typedef long long ll;
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; }

ll dp[1010][10010];

int main(){
        int h,n;
        cin>>h>>n;
        vector<int>a(n),b(n);
        for(int i=0;i<n;i++){
                cin>>a[i]>>b[i];
        }
        for(int i=0;i<1010;i++){
                for(int j=0;j<10010;j++){
                        dp[i][j]=1000000000;
                }
        }
        dp[0][0]=0;
        for(int i=0;i<n;i++){
                for(int j=0;j<=h;j++){
                        dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
                        dp[i+1][min(j+a[i],h)]=min(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i]);
                }
        }
        cout<<dp[n][h]<<endl;
        return 0;
}


Measured memory_bytes: 79232
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

#define rep(i, n) for(int i=0;i<n;i++)

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	int x[] = { 0,1,2,1,3,1,3,1,1,3,1,3,1 };

	if (x[a] == x[b])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int A;
 string op;
 int B;
 cin>>A;
 cin>>op;
 cin>>B;
 
 if(op=="+"){
     cout<<A+B<<endl;
 }
     else if(op=="-"){
     cout<<A-B<<endl;
     }
}




Measured memory_bytes: 3576
N = int(input())
A = input()
B = input()
C = input()
a = 0
for i in range(N):
    if A[i] == B[i] == C[i]:
        continue
    elif A[i] != B[i] and B[i] != C[i] and C[i] != A[i]:
        a += 2
    else:
        a += 1

print(a)


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn] , ans[maxn];
int main(){
	int n , k , x , y;cin >> n >> x >> y;
	fo(i,1,n-1){
		fo(j,i+1,n){
			if(i <= x && j >= y)a[i][j] =j-i-(y-x-1), a[j][i] = j-i-(y-x-1);
			else a[i][j] = a[j][j] = min(j - i , abs(x-i) + abs(y-j)+1);
		}
	}
	fo(i,1,n){
		fo(j,i+1,n){
			ans[a[i][j]]++;
		}
	}
	fo(i,1,n-1){
		cout << ans[i] << endl;
	}
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	int a[101];
	for (int i=1; i<=n; i++)
		cin>>a[i];

	vector<int> ans;
	for(; n>0; n--) {
		int pos = n;
		while(pos > 0 && a[pos] != pos)
			pos--;
		if (pos > 0) {
			ans.push_back(pos);
			while(pos+1 <= n) {
				a[pos] = a[pos+1];
				pos++;
			}
		}else
			break;
	}
	if (n)
		cout<<-1<<endl;
	else {
		for (int i=ans.size()-1; i>=0; i--)
			cout<<ans[i]<<" ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()

ans = 0
ans_tmp = 0

x = {'A', 'G', 'C', 'T'}

for s in S:
  if s in x:
      ans_tmp += 1
  else:
    ans = max(ans_tmp, ans)
    ans_tmp = 0
ans = max(ans_tmp, ans)

print(ans)

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, Y: int):
    for nm in range(Y // 10000 + 1):
        N2 = N - nm
        Y2 = Y - nm * 10000
        # ng * 5000 + ns * 1000 == Y2
        # ng + ns == N2
        ng = (Y2 // 1000 - N2) // 4
        ns = N2 - ng
        if ng < 0 or ns < 0:
            continue
        if ng * 5000 + ns * 1000 != Y2:
            continue
        print(nm, ng, ns)
        return
    print(-1, -1, -1)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, Y)


if __name__ == '__main__':
    main()


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

// Caution: 1-indexed
struct BIT {
    vector<ll> bit;
    int N;

    BIT(int N) : bit(vector<ll>(N + 1, 0)), N(N) {}

    // return sum in [0, `i`] in log(n)
    ll sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i - (i & -i));
    }

    // add `x` at `i`
    void add(int i, ll x) {
        if (i > N) return;
        bit[i] += x;
        add(i + (i & -i), x);
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> c(n + 1);
    rep(i, n) {
        cin >> c[i + 1];
    }
    vector<vector<int>> rli(q, vector<int>(3, 0));
    rep(i, q) {
        cin >> rli[i][1] >> rli[i][0];
        rli[i][2] = i;
    }
    sort(rli.begin(), rli.end());

    BIT fwt(n);
    vector<int> lastApp(n + 1, -1);
    int r = 0;
    vector<int> ans(q, 0);

    rep(i, q) {
        int ri = rli[i][0], li = rli[i][1], ii = rli[i][2];
        for (int nr = r + 1; nr <= ri; nr++) {
            if (lastApp[c[nr]] != -1) {
                fwt.add(lastApp[c[nr]], -1);
            }
            lastApp[c[nr]] = nr;
            fwt.add(nr, 1);
        }
        r = ri;
        ans[ii] = fwt.sum(ri) - fwt.sum(li - 1);
    }
    rep(i, q) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 40940
N = int(input())
A = list(map(int, input().split()))

while len(A) > 1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for a in A:
        mod = a % minA
        if mod > 0:
            tempA.append(mod)
    A = tempA

print(A[0])


Measured memory_bytes: 14252
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

main(){
  int n;

  while( cin >> n && n != -1){
    double x = 1.0, y = 0.0, r = 1.0, th = 0;
    for ( int i = 1; i < n; i++ ){
      double r2 = sqrt(r*r+1);
      th += acos((r2*r2+r*r-1)/(2*r2*r));
      r = r2;
      x = r*cos(th);
      y = r*sin(th);
    }
    cout << x << endl << y << endl;
  }
}

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

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	dice(int top,int front,int right,int left,int back,int bottom) {
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	int& operator[] (FACE f) { return id[f]; }
	const int& operator[] (FACE f) const { return id[f]; }
	bool operator==(const dice &b) const {
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
	void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
	void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
	void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
	vector<dice> all_rolls(){
		vector<dice> ret;
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				ret.push_back(*this);
		return ret;
	}
	bool equivalent_to(const dice& di){
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				if (*this == di) return true;
		return false;
	}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int main(){
	int n;
	string s;
	for(;cin>>n,n;){
		dice di(1,5,4,3,2,6);
		for(;n--;){
			cin>>s;
			if(s[0]=='n')di.roll_north();
			if(s[0]=='e')di.roll_east();
			if(s[0]=='w')di.roll_west();
			if(s[0]=='s')di.roll_south();
		}
		cout<<di[TOP]<<endl;
	}
}

Measured memory_bytes: 1200
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

signed main() {
	int n;
	cin >> n;
	int a[n];
	REP (i,n) cin >> a[i];
	int gcd = a[0];
	FOR (i,1,n) gcd = GCD(gcd,a[i]);
	cout << gcd << endl;
}

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

int main(){
  int n;
  cin>>n;
  ll ans=0;
  ll vec[n],vecb[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  for(int i=0;i<n;i++){
    cin>>vecb[i];
    if(vecb[i]<vec[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  for(int q=0;q<60;q++){
  for(int i=0;i<n;i++){
    if(vecb[i]>vecb[(i+1)%n]&&vecb[i]>vecb[(i+n-1)%n]&&vecb[i]!=vec[i]){
      if(vecb[i]<vec[i]+vecb[(i+1)%n]+vecb[(i+n-1)%n]){
        cout<<-1<<endl;
        return 0;
      }
      ll x=(vecb[i]-max(vecb[(i+1)%n],vecb[(i+n-1)%n])+vecb[(i+1)%n]+vecb[(i+n-1)%n]-1)/(vecb[(i+1)%n]+vecb[(i+n-1)%n]);
      x=min(x,(vecb[i]-vec[i]+vecb[(i+1)%n]+vecb[(i+n-1)%n]-1)/(vecb[(i+1)%n]+vecb[(i+n-1)%n]));
      vecb[i]-=(vecb[(i+1)%n]+vecb[(i+n-1)%n])*x;
      ans+=x;
    }
  }
  }
  
  for(int i=0;i<n;i++){
    if(vecb[i]!=vec[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
string n;
int k;

long long dp[102][100][2];

long long int solve(int i, int j, int tight)
{
    if (i < 0)
    {
        return j == k;
    }
    if (dp[i][j][tight] != -1 && tight != 1)
        return dp[i][j][tight];
    int k = (tight) ? n[i]-'0' : 9;
    long long int r=0;
    for (int g = 0; g <= k; g++)
    {
        int newTight = (n[i]-'0' == g) ? tight : 0;
        int nj = (g == 0) ? 0 : 1;
        r+=solve(i-1,j+nj,newTight);
    }
    if(!tight)
        dp[i][j][tight]=r;
    return r;
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n >> k;
    reverse(n.begin(),n.end());
    cout<<solve(n.size()-1,0,1);
}

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

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

int main() {
  int H,W;
  cin>>H>>W;
  vector<vector<char>> data(H+2,vector<char>(W+2,'.'));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>data[i][j];
    }
  }
  rep(i,H){
    rep(j,W){
      if(data[i+1][j+1]=='#'){cout<<'#';}
      else{
        int count=0;
        rep(k,8){
          if(data[i+1+dx[k]][j+1+dy[k]]=='#'){count++;}
        }
        cout<<count;
      }
    }
    cout<<endl;
  }
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<deque>
using namespace std;
int main() {
  deque<int> stk;
  int n,a;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >>a;
    stk.push_back(a);
  }

  for(int i=0; i<n; i++){
    cout << stk.back();
    if(i != n-1) cout << ' ';
    stk.pop_back();
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3092
p[1<<21];a,I,J,x,y,j;main(n){for(*p=scanf("%d",&n);~scanf("%d",&a);j=++j%n)for(I=J=j?J:J*2+1;I<1<<n;y+=x=I&-I,I=(I&~y)/x/2|y)x=I&a<<j,p[y=I]+=x?p[I&~x]:0,p[I]%=x=1e9+7;printf("%d",p[J]);}

Measured memory_bytes: 8320
import math

n = int(input())
mat = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for idx in range(n-1, -1, -1):
    a,b = mat[idx]
    if a == 0: continue
    a += ans
    if a <= b:
        score = b - a
    else:
        score = b*math.ceil(a/b) - a
    ans += score

print(ans)

Measured memory_bytes: 27508
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  string ans="";
  rep(i,s.size()){
    if(s[i]=='0')ans+='0';
    if(s[i]=='1')ans+='1';
    if(s[i]=='B'){
      if(ans.size())ans.pop_back();
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
 int N;
  cin>>N;
  int X=N/1.08;
   int Y=X*1.08;
   int Z=(X+1)*1.08;
   int J=(X-1)*1.08;
  if(Y==N){cout<<X<<endl;}
   else if (Z==N){cout<<X+1<<endl;}
    else if (J==N){cout<<X-1<<endl;}
      else{cout<<":("<<endl;}
  return 0;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 1e9+7;

const double PI = 3.14159265359;

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

	int r; cin >> r;
	cout << setprecision(8) << fixed << 2*PI*r << '\n';

 	return 0;
}

Measured memory_bytes: 3796
N, K = map(int, input().split())

e = []
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        e.append((i, j))

s = N * (N - 1) // 2 - K
if s < N - 1:
    print(-1)
else:
    print(s)
    for idx, (i, j) in enumerate(e, 1):
        print(i, j)
        if idx == s:
            break


Measured memory_bytes: 43120
/*
ID: vamaddu1
LANG: C++11
TASK: cowfood
*/

#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <deque>
#include <string.h>
#include <sstream>
#include <bitset>
#include <math.h>
#include <assert.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define epsilon 1e-9
#define INF 5000000000000000000
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N;
long long M, down [100010], up [100010], pref [100010], suf [100010];
vector<int> adjacency [100010];

void dfsDown(int curr, int prevy){
    down[curr] = 1;
    for(int nexty : adjacency[curr]){
        if(nexty == prevy) continue;
        dfsDown(nexty, curr);
        down[curr] *= (down[nexty]+1)%M; down[curr] %= M;
    }
}

void dfsUp(int curr, int prevy){
    pref[0] = 1;
    for(int i = 0; i < adjacency[curr].size(); i++){
        int nexty = adjacency[curr][i]; pref[i+1] = pref[i];
        if(nexty == prevy) continue;
        pref[i+1] *= (down[nexty]+1)%M; pref[i+1] %= M;
    }
    suf[adjacency[curr].size()+1] = 1;
    for(int i = adjacency[curr].size()-1; i > -1; i--){
        int nexty = adjacency[curr][i]; suf[i+1] = suf[i+2];
        if(nexty == prevy) continue;
        suf[i+1] *= (down[nexty]+1)%M; suf[i+1] %= M;
    }
    for(int i = 0; i < adjacency[curr].size(); i++){
        int nexty = adjacency[curr][i];
        if(nexty == prevy) continue;
        up[nexty] = (((pref[i]*suf[i+2])%M)*((up[curr]+1)%M))%M;
        down[nexty] *= (up[nexty]+1)%M; down[nexty] %= M;
    }
    for(int nexty : adjacency[curr])
        if(nexty != prevy)
            dfsUp(nexty, curr);
}

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N >> M;
    for(int i = 1; i < N; i++){
        int a, b; cin >> a >> b;
        adjacency[a].pb(b); adjacency[b].pb(a);
    }
    dfsDown(1, 0); dfsUp(1, 0);
    for(int i = 1; i <= N; i++) cout << down[i] << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/


Measured memory_bytes: 15360
//       THIS IS MY NINJA WAY
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ctime>
#include<vector>
#include<algorithm>

#define str string
#define dbl double
#define ll long long int
#define ull unsigned long long int
#define vl vector<ll> 
#define vs vector<str>
#define pll pair<ll,ll> 
#define vll vector<pll>
#define sl set<ll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define BS binary_search
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,a,b) for(long long i=a; i<b; i++)
#define nfr(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>
#define lcm(a,b) (a*b)/__gcd(a,b)
#define ALL(a) a.begin(),a.end()
#define stl stack<ll>
#define coml complex<ll>
#define INF 0x3f3f3f3f3f3f3f3f
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define read(v,n) fr(i,0,n)cin>>v[i]
//#define dp(i,j) dp[i][j]
#define print(x) fr(i,0,x.size())cout<<x[i]<<"\n";cout<<"\n"
const ll MOD = 1e9+7;
const ll N = 2e5 + 5;
using namespace std;
using namespace __gnu_pbds;
void solve(){
	ll n,w;
	cin>>n>>w;
	vl weight(n), value(n), dp(110000,0);
	fr(i,0,n)cin>>weight[i]>>value[i];
	fr(i,0,n){
		for(ll j=w; j>=0; j--){
			if(j+weight[i]<=w)dp[j+weight[i]]=max(dp[j+weight[i]],dp[j]+value[i]);
		}
	}
	ll ans=0;
	fr(i,0,w+1){
		ans=max(ans,dp[i]);
	}
	cout<<ans;
}
int main()
{
	fast
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt", "r" , stdin);
	//	freopen("output.txt", "w" , stdout);
	//#endif
	ll t;
	t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn][maxn], ptr[maxn];
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		ptr[i] = 1;
		for(int j = 1; j <= n - 1; j++){
			scanf("%d", &a[i][j]);
		}
	}
	set<int> good, ngood;
	auto extends = [&](int i){	
		int to = a[i][ptr[i]];
		if(a[to][ptr[to]] == i){
			good.insert(i);
			good.insert(to);
		}
	};
	for(int i = 1; i <= n; i++){
		extends(i);
	}
	for(int i = 1; ; i++){
		ngood = good;
		good.clear();
		for(int v : ngood){
			ptr[v]++;
			if(ptr[v] < n){
				extends(v);
			}	
		}
		if(good.empty()){
			for(int j = 1; j <= n; j++){
				if(ptr[j] != n){
					cout << -1 << endl;
					return 0;
				}
			}
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main()
{
long long a,b,c,k;
cin>>a>>b>>c>>k;
long long ans=0;
if(k<=a){
    ans=k;
}
if(k>a&&k<=a+b){
    ans=a;
}
if(k>a+b){
    ans=a-(k-a-b);
}
cout<<ans;
    return 0;
}


Measured memory_bytes: 3580