akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    ll cur = N;
    deque<char> s;
    while(cur > 0){
        ll r = cur % 26;
        //string a = {char(r+ll('a')-1LL)};
        if(r > 0){ 
            s.push_front(char(r+ll('a')-1LL));
        }else{
            s.push_front('z');
            cur--;
        }
        cur /= 26;
    }
    rep(i,s.size()){
        cout << s[i];// <<endl;
    }
    cout << endl;
}


Measured memory_bytes: 3620
n = int(input())
h = [int(i) for i in input().split()]
m = 0
tmp = 0
for i in range(n-1):
  if h[i]>=h[i+1]:
    tmp += 1
  else:
    m = max(m, tmp)
    tmp = 0
m = max(m, tmp)
print(m)

Measured memory_bytes: 14252
def pre_combi1(n, p):
  fact = [1]*(n+1)  # fact[n] = (n! mod p)
  factinv = [1]*(n+1)  # factinv[n] = ((n!)^(-1) mod p)
  inv = [0]*(n+1)  # factinv 計算用
  inv[1] = 1
  # 前処理
  for i in range(2, n + 1):
    fact[i]= fact[i-1] * i % p
    inv[i]= - inv[p % i] * (p // i) % p
    factinv[i]= factinv[i-1] * inv[i] % p
  return fact, factinv

def combi1(n, r, p, fact, factinv):
  """
  k<n<10**7でpが素数のときのnCr % pを求める
   """
  # 本処理
  if r < 0 or n < r:
    return 0
  r = min(r, n-r)
  return fact[n] * factinv[r] * factinv[n-r] % p
 
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
sfs=0
p=1000000007
fact,factinv=pre_combi1(n,p)
for i in range(1,n+1):
  sfs+=a[i-1]*combi1(i-1,k-1,p,fact,factinv)
  sfs-=a[i-1]*combi1(n-i,k-1,p,fact,factinv)
  sfs %= p
  #print(i,a[i-1],n-i,k-1,sfs)
print(sfs%p)

Measured memory_bytes: 63344
//28, 04, 2018, 09:16:31 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
map<ll, int>mp;
const int N = int(2e5 + 100);
ll a[N];

int main(){
    int n;

    cin >> n;

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

        if(i){
            a[i] += a[i - 1];
        }

        mp[a[i]]++;
    }   
    
    ll sum = 0LL;
    ll cnt = 0LL;

    for(int i = 0 ; i < n; i++){
        if(i){
            if(mp[sum])
                mp[sum]--;
        }

        cnt += mp[sum];
        
        sum = a[i];    
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 14336
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;

class CFlow{
private:
    struct edge{
        ll to;
        ll cap;
        ll rev;
        ll cost;
    };
    
    struct node{
        ll cost;
        ll flow;
        ll number;
        ll from;
        ll edge;
        
        //cost::smaller flow::bigger
        bool operator < (const node &a) const {
            if(a.cost<this->cost){return true;}
            else if(a.cost==this->cost && a.flow>this->flow){return true;}
            return false;
        }
    };
    
    ll INF;
    ll v;
    vector<vector<edge>> e;
    
public:
    CFlow(ll v):v(v){
        e.resize(v);
        INF=1e18+7;
    }
    
    void add_edge(ll from,ll to,ll cap,ll cost){
        e[from].push_back((edge){to,cap,(ll)e[to].size(),cost});
        e[to].push_back((edge){from,0,(ll)e[from].size()-1,-1*cost});
    }
    
    pll min_cost(ll s,ll t,ll flow){
        vector<vector<edge>> ed=e;
        ll cost=0;
        ll D=flow;
        vector<ll> h(v,0);
        while(flow>0){
            priority_queue<node> q;
            vector<node> V(v,{INF,0,-1,-1,-1});
            V[s]={0,flow,s,s,-1};
            q.push({0,flow,s,s,-1});
            while(!q.empty()){
                node N=q.top(); q.pop();
                ll w=N.number;
                if(N<V[w]){continue;}
                for(int i=0;i<e[w].size();i++){
                    edge &E=e[w][i];
                    node New={V[w].cost+E.cost+h[w]-h[E.to],min(N.flow,E.cap),E.to,w,i};
                    if(E.cap>0 && V[E.to]<New){
                        V[E.to]=New;
                        q.push(New);
                    }
                }
            }
            if(V[t].flow==0){break;}
            for(int i=0;i<v;i++){h[i]+=V[i].cost;}
            flow-=V[t].flow;
            ll w=t;
            while(w!=s){
                ll to=w;
                w=V[w].from;
                edge &E=e[w][V[to].edge];
                E.cap-=V[t].flow;
                e[E.to][E.rev].cap+=V[t].flow;
                cost+=V[t].flow*E.cost;
            }
            if(flow==0){break;}
        }
        e=ed;
        return {D-flow,cost};
    }
};



int main(){
    ll v,e,f;
    cin>>v>>e>>f;
    CFlow F(v);
    for(int i=0;i<e;i++){
        ll s,t,cap,cost;
        cin>>s>>t>>cap>>cost;
        F.add_edge(s,t,cap,cost);
    }
    pll P=F.min_cost(0,v-1,f);
    if(P.F!=f){cout<<-1<<endl;}
    else{cout<<P.S<<endl;}
    
    
    return 0;
}


Measured memory_bytes: 3284
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n;
    cin>>n;
    vector<int> c(n);
    rep(i,n)cin>>c[i];
    sort(ALL(c),greater<int>());
    if(n%2==1)c.push_back(0);
    int res = 0;
    for(int i=0;i<n;i+=2){
        res+=c[i]-c[i+1];
    }
    cout<<res<<endl;

}

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

using namespace std;

string S;

int main()
{
    cin >> S;

    bool succeed = true;
    for (int i = S.size();;) {
        if (i > 4 && (S.substr(i - 5, 5) == "dream" || S.substr(i - 5, 5) == "erase")) {
            i -= 5;
        }
        else if (i > 5 && S.substr(i - 6, 6) == "eraser") {
            i -= 6;
        }
        else if (i > 6 && S.substr(i - 7, 7) == "dreamer") {
            i -= 7;
        }
        else {
            succeed = i == 0;;
            break;
        }
    }

    cout << (succeed ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 512
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

struct UnionFind {
    vector<int> par, rank, _size;
    
    UnionFind(int n) : par(n), rank(n, 1), _size(n, 1) {
        for (int i=0; i<n; i++) par[i] = i;
    }
    
    int find(int x) {
        if (par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

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

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;

        _size[x] = _size[y] = _size[x] + _size[y];
        if(rank[x] == rank[y]) rank[y]++;

        if(rank[x] > rank[y]) par[y] = x;
        else par[x] = y;
    }

    int size(int x) {
        return _size[find(x)];
    }
};


int main() {

    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    
    UnionFind uf(n);
    vector<ll> ans;
    
    ll cur = n *(n-1)/2;
    for(int i=m-1; i>=0; i--) {
        ans.push_back(cur);
        if(uf.same(a[i], b[i])) continue;
        ll sa = uf.size(a[i]);
        ll sb = uf.size(b[i]);
        cur -= sa * sb;
        uf.unite(a[i], b[i]);
    }
    
    for(int i=m-1; i>=0; i--) cout << ans[i] << endl;
    return 0;
}

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

int main() {
  string s;
  while (true) {
    cin >> s;
    if (s == "-") break;
    int m;
    cin >> m;
    int top{};
    for (int i{}; i < m; ++i) {
      int h;
      cin >> h;
      top += h;
    }
    top %= s.size();
    cout << s.substr(top) << s.substr(0, top) << endl;
  }

  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int N,M ,X,Y ;
  cin >> N >> M >> X >> Y ;
  int x[110],y[110] ;
  cinf(N,x) ;
  cinf(M,y) ;
  int xmax=x[0];
  int ymin=y[0] ;
  for(int i=0;i<N;i++){
    if(x[i] > xmax)
      xmax = x[i] ;
  }
  for(int i=0;i<M;i++){
    if(y[i] < ymin)
      ymin = y[i] ;
  }
  if( xmax < ymin && xmax < Y && ymin > X)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}
    


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
	int N;
	int x[500];
	int num[500];
	int need[2][500];
	int free[2][500];
	
	scanf("%d",&N);
	int *ans;
	ans=(int *)calloc(N*N,sizeof(int));
	for(int i=0; i<N; i++){
		scanf("%d",&x[i]);
		ans[x[i]-1]=i+1;
	}
	
	int cnt=0;
	for(int i=0; i<N; i++){
		while(ans[cnt] == 0){
			cnt++;
		}
		need[0][i]=ans[cnt]-1;
		need[1][i]=N-ans[cnt];
		free[0][i]=cnt-i;
		free[1][i]=N*N-cnt+i-N;
		num[i]=ans[cnt];
		cnt++;
	}
	
	/*for(int i=0; i<N; i++){
		printf("%d %d  ",need[0][i],need[1][i]);
	}
	printf("\n");
	for(int i=0; i<N; i++){
		printf("%d %d  ",free[0][i],free[1][i]);
	}
	printf("\n");*/
	int left=0;
	int right=N*N-1;
	while(ans[left]!=0)left++;
	while(ans[right]!=0)right--;
	int leftconf=0,rightconf=0;
	for(int i=0; i<N; i++){
		//printf("%d,",right);
		//printf("%d,%d  %d,%d  %d,%d\n",need[0][i],free[0][i],need[1][N-1-i],free[1][N-1-i],leftconf,rightconf);
		if(need[0][i]>free[0][i]-leftconf || need[1][N-1-i]>free[1][N-1-i]-rightconf){
			printf("No\n");
			return 0;
		}
		
		for(;need[0][i]>0;need[0][i]--){
			while(ans[left]!=0)left++;
			ans[left]=num[i];
			leftconf++;
		}
		for(;need[1][N-1-i]>0;need[1][N-1-i]--){
			while(ans[right]!=0)right--;
			ans[right]=num[N-1-i];
			rightconf++;
		}
	}
	printf("Yes\n%d",ans[0]);
	for(int i=1; i<N*N; i++){
		printf(" %d",ans[i]);
	}
	printf("\n");
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int N, M;
vvi G;
vi rankv, par;
int n;

int visit(int v) {
	if (rankv[v] != -1) return rankv[v];
	int r = -1;
	for (int w: G[v]) {
		int temp = visit(w);
		if (temp > r) {
			par[v] = w;
			r = temp;
		}
	}
	return rankv[v] = n++;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> N >> M;
	G.resize(N);
	rep(i, N + M - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[b].push_back(a);
	}
	rankv.resize(N, -1);
	par.resize(N, -1);
	rep(i, N) {
		visit(i);
	}
	rep(i, N) {
		cout << par[i] + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll H,W,K;
    cin>>H>>W>>K;
    vector<string> S(H);
    rep(i,H){
        cin>>S[i];
    }
    ll ans=INF2;
    rep(i,1<<(H-1)){
        vector<ll> A(H,0);
        vector<ll> B(H,0);
        ll buf=0;
        ll now=0;
        rep(j,H){
            if(i>>j&1) ++buf;
        }
        ll doko=0;
        bool ng=false;
        rep(j,W){
            ll doko=0,ima=0;
            rep(k,H){
                ima+=S[k][j]-'0';
                if(k==H-1 or (i>>k&1)){
                    B[doko]=ima;
                    ima=0;
                    ++doko;
                }
            }
            bool ok=true;
            rep(k,doko){
                if(A[k]+B[k]>K) ok=false;
                if(B[k]>K) ng=true;
            }
            if(!ok){
                ++buf;
                A=B;
            }
            else{
                rep(k,doko){
                    A[k]+=B[k];
                }
            }
        }
        if(ng) continue;
        mini(ans,buf);
    }
    cout<< ans <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 256
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<int,int> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;
void MAIN()
{
	#define int ll
	int a,b,c,d;
	read(a,b,c,d);
	int k=max((a+b)/(b+1),(a+b)/(a+1));
	auto check=[&](int x)->bool
	{
		bool flag=x%(k+1)==0;
		int qwq=x-x%(k+1);
		int c1=qwq/(k+1)*k;
		int c2=qwq/(k+1);
		c1+=x%(k+1);
		int A=a-c1;
		int B=b-c2;
		if(A<0||B<0) return false;
		if(flag)
		{
			return k-1+k*A>=B&&k*(B+1)>=A;
		}
		else
		{
			return k*(A+1)>=B&&k*(B+1)>=A;
		}
	};
	int l=0,r=a+b;
	while(l<r)
	{
		int mid=(l+r+1)>>1;
		if(check(mid)) l=mid;
		else r=mid-1;
	}
	fprintf(stderr,"@ %lld %d %lld\n",l,check(2),k);
	int tot=a+b;
	int cnt=(tot-l)%(k+1);
	auto get=[&](int x)->char
	{
		if(x<=l)
		{
			if(!(x%(k+1))) return 'B';
			return 'A';
		}
		else
		{
			if(!cnt)
			{
				x-=l;
				if(!(x%(k+1))) return 'A';
				return 'B';
			}
			else
			{
				if(x-l<=cnt+1) return x-l<=cnt?'B':'A';
				else
				{
					x-=l;
					x-=cnt+1;
					if(!(x%(k+1))) return 'A';
					return 'B';
				}
			}
		}
	};
	for(int i=c;i<=d;++i)
	{
		putchar(get(i));
	}
	putchar('\n');
	#undef int
}
int main()
{
	int _;
	read(_);
	while(_--) MAIN();
	return 0;
}


Measured memory_bytes: 384
N = int(input())
ss = [input() for _ in range(N)]
cnt = 0
ba = 0
b = 0
a = 0
o = 0
import re
for s in ss:
    cnt += len(re.findall('AB', s))
    if s[-1] == 'A' and s[0] == 'B':
        ba += 1
    elif s[-1] == 'A':
        a += 1
    elif s[0] == 'B':
        b += 1
    else:
        o += 1

if ba > 0:
    if b > 0 and a > 0:
        cnt += ba + 1 + min(a-1, b-1)
    elif b == 0 and a == 0:
        cnt += ba - 1
    else:
        cnt += ba
else:
    cnt += min(a, b)

print(cnt)


Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int A = sc.nextInt();
		int count = 0;
		while(H > 0) {
			H = H - A;
			count++;
			}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for(int i = 0; i < n; i++)
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
using namespace std;
 
int gcd(int a, int b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
int main(void){
  int n,t;
  vector<int> a;
  cin>>n;
  REP(i, n){
    cin>>t;
    a.push_back(t);
  }
  vector<int> left(n+1, 0), right(n+1, 0);
  REP(i, n)
    left[i+1] = gcd(left[i], a[i]);
  for(int i = n-1; i >= 0; --i){
    right[i] = gcd(right[i+1], a[i]);
  }
  int ans = 0;
  REP(i, n){
    int l = left[i];
    int r = right[i+1];
    chmax(ans, gcd(l, r));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1528
S = str(input())
for i in range(1, int(len(S) / 2)):
    T = S[0: len(S) - 2 * i]
    clear = 0
    m = int(len(T) / 2)
    for j in range(m):
        if T[j] == T[m + j]:
            clear += 1
    if clear == m:
        print(len(T))
        break


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

using namespace std;

long long solve(long long h, unordered_map<long long, long long> &UM) {
    if (UM.count(h) == 1) return UM[h];
    if (h == 1) return 1;
    long long res = solve(h / 2, UM) * 2 + 1;
    UM[h] = res;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long h;
    cin >> h;
    unordered_map<long long, long long> UM;
    cout << solve(h, UM) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll ans[100005]={0};
vector<P> node[100005];
ll cnt[100005]={0};
bool used[100005]={false};
void dfs(ll pos,ll par_col){
  int now_col=1;
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i].first;
    if(!used[to]){
      used[to]=true;
      if(now_col==par_col) now_col++;
      ans[node[pos][i].second]=now_col;
      dfs(to,now_col);
      now_col++;
    }
  }
}
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<=100005;i++) used[i]=false;
  for(int i=1;i<n;i++){
    ll a,b;
    cin>>a>>b;
    cnt[a]++;
    cnt[b]++;
    node[a].push_back(P(b,i));
    node[b].push_back(P(a,i));
  }
  ll col=0;
  for(int i=1;i<=n;i++) col=max(col,cnt[i]);
  cout<<col<<endl;
  used[1]=true;
  dfs(1,0);
  for(int i=1;i<n;i++) cout<<ans[i]<<endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll long long

int dp[3][100010];

int main() {
	//入力
	int n;
	cin >> n;
	vector<int> a(n+1),b(n+1),c(n+1);
	rep(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}

	//答え
	dp[0][0] = a[0];
	dp[1][0] = b[0];
	dp[2][0] = c[0];
	for (int i = 1;i < n;++i) {
		dp[0][i] = a[i] + max(dp[1][i - 1], dp[2][i - 1]);
		dp[1][i] = b[i] + max(dp[0][i - 1], dp[2][i - 1]);
		dp[2][i] = c[i] + max(dp[0][i - 1], dp[1][i - 1]);
	}
	int ans = max(dp[0][n - 1], dp[1][n - 1]);
	ans= max(ans, dp[2][n - 1]);

	cout << ans << endl;
}


Measured memory_bytes: 5636
n=int(input())
s=[]
for i in range(n):
  s.append(input())
cnt_a=0
cnt_b=0
cnt_ab=0
for j in range(n):
  if s[j][0]=='B' and s[j][len(s[j])-1]=='A':
    cnt_ab+=1
  elif s[j][0]=='B':
    cnt_b+=1
  elif s[j][len(s[j])-1]=='A':
    cnt_a+=1
cnt_a+=cnt_ab
cnt_b+=cnt_ab
cnt_2=0
for l in range(n):
  cnt_2+=s[l].count('AB')
if cnt_a==0 and cnt_b==0:
  print(cnt_2)
elif cnt_ab-cnt_a==0 and cnt_ab-cnt_b==0:
  print((cnt_ab+cnt_2)-1)
else:
  print(min(cnt_a,cnt_b)+cnt_2)

    
    
    
    
                 
  


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

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    s, w = list(map(int, input().split()))
    if w >= s:
        print("unsafe")
    else:
        print("safe")

    #print('\33[32m' + 'end' + '\033[0m') # debug


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

int main(){
    string s;
    cin >> s;
    map<char,int> m;
    for(int i=0;i<s.size();i++){
        m[s[i]]++;
    }
    int ans=0;
    ans+=s.size()/2-m['p'];
    cout << ans << endl;
}

Measured memory_bytes: 512
// Created by Junedkhan2
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define     mod             1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     isOn(S, j)      (S & (1 << j))
#define     setBit(S, j)    (S |= (1 << j))
#define     clearBit(S, j)  (S &= ~(1 << j))
#define     toggleBit(S, j) (S ^= (1 << j))
#define     lowBit(S)       (S & (-S))
#define     setAll(S, n)    (S = (1 << n) - 1)
#define     isPowerOfTwo(S) (!(S & (S - 1)))
#define     nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define     turnOffLastBit(S) ((S) & (S - 1))
#define     turnOnLastZero(S) ((S) | (S + 1))
#define     turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define     turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int N=1e5;
 
int32_t main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    IOS;
 //Code starts from here //
    int x;
    cin >> x;
    if(x >= 30){
        cout << "Yes";
    } else {
        cout << "No";
    }
 //Code End from here //   
}

Measured memory_bytes: 3624
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score=-1000000000;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    int v=randxor()%d;
    int w=randxor()%d;
    swap(ans1[v],ans1[w]);
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
void solve1(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    ans1[randxor()%d]=randxor()%26;
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  vector<P> e(26);
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
    e.push_back(P(c[i],i));
  }
  std::sort(e.begin(), e.end(), std::greater<P>() );
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=e[i%26].second;
    ans[i]=ans1[i];
  }
  while(clock()-ti<198.2*CLOCKS_PER_SEC/100){
    solve();
    solve1();
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3900
#include<iostream>

int main()
{
    int n, m;
    std::cin >> n >> m;
    int maxMod = 1;
    if(n==1){
        std::cout << m << std::endl;
        return 0;
    }
    for(int mod = 2; mod <= m; mod++){
        int x = m - mod*(n-1);
        if( x >= mod){
            if(x % mod == 0) maxMod = mod;
        }else break;
    }
    std::cout << maxMod << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int a,b;
  cin>>a>>b;
  for(int i=a-1;i>0;i--)
  {
      cout<<b-i<<" ";
  }
  cout<<b<<" ";
  for(int i=1;i<a;i++)
  {
      cout<<b+i<<" ";
  }
}

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

int main(){
int K;
  cin>>K;
  
  if(K%2!=0){cout<<((K+1)/2)*(K/2)<<endl;} // 実際に1～10まで数えて掛けるとこの式になる
  else{cout<<(K/2)*(K/2)<<endl;}
}

Measured memory_bytes: 256
package main

// Solution for https://atcoder.jp/contests/abc073/tasks/abc073_d

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

const INF = 1 << 32

func (con *contest) main() error {
	var N, M, R int
	con.Scan(&N, &M, &R)
	r := make([]int, R)
	for i := 0; i < R; i++ {
		con.Scan(&r[i])
		r[i]--
	}
	E := make([][]int, N)
	for i := 0; i < N; i++ {
		E[i] = make([]int, N)
		for j := 0; j < N; j++ {
			E[i][j] = INF
		}
	}
	for i := 0; i < N; i++ {
		E[i][i] = 0
	}
	for i := 0; i < M; i++ {
		var a, b, c int
		con.Scan(&a, &b, &c)
		E[a-1][b-1] = c
		E[b-1][a-1] = c
	}
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				x := E[i][k] + E[k][j]
				if x < E[i][j] {
					E[i][j] = x
				}
			}
		}
	}
	P := make([][]int, R)
	for i := 0; i < R; i++ {
		P[i] = make([]int, 1<<R)
		for j := 0; j < 1<<R; j++ {
			P[i][j] = INF
		}
	}
	var dfs func(int, int)
	dfs = func(p int, x int) {
		for q := 0; q < R; q++ {
			y := x | (1 << q)
			if x == y {
				continue
			}
			a := E[r[p]][r[q]]
			if P[p][x]+a < P[q][y] {
				P[q][y] = P[p][x] + a
				dfs(q, y)
			}
		}
	}
	for i := 0; i < R; i++ {
		P[i][1<<i] = 0
		dfs(i, 1<<i)
	}
	min := INF
	for i := 0; i < R; i++ {
		if P[i][(1<<R)-1] < min {
			min = P[i][(1<<R)-1]
		}
	}
	con.Println(min)
	return nil
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n<=k){
        cout << x*n << endl;
    }else{
        cout << x*k+y*(n-k) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  int x=0;
  cin>>n>>k;
  vector<int>vec (n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);}
  
  sort(vec.begin(),vec.end());
  for (int i=0;i<k;i++){
    x+=vec.at(i);}
  cout<<x<<endl;}
    


Measured memory_bytes: 3600
#include<cstdio>
int min(int x,int y) {return x>y?y:x;}
int main()
{
	int n,k,x,ans=0;
	scanf("%d%d",&n,&k);
	while(n--)
	{
		scanf("%d",&x);
		ans+=min(x,k-x);
	}
	printf("%d\n",ans*2);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
set<pair<int, int>>s;
int a[1234567];
signed main() {
	int n, q; cin >> n >> q;
	for1(i, n)s.insert(mp(0, n - i));
	for1(valsqotch, q) {
		int id, v; cin >> id >> v;
		s.erase(s.find(mp(a[id], n - id)));
		a[id] += v;
		s.insert(mp(a[id], n - id));
		auto itr = s.end(); itr--;
		cout << n - (*itr).second << ' ' << (*itr).first << endl;
	}
}


Measured memory_bytes: 73424
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var C = cin.ReadInt;
            var D = cin.ReadInt;

            var lower = Max(A, C);
            var upper = Min(B, D);

            var ans = Max(0, upper - lower);

            WriteLine(ans);
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let modulo: i64 = 998244353;
    let n: i64 = sc.read();
    let m: i64 = sc.read();
    let k: i64 = sc.read();
    let comb = CombinationMod::new(n as usize, modulo);
    let mut ans: i64 = 0;
    for i in 0..=k {
        let mut add: i64 = 1;
        add = add * comb.query(n - 1, i) % modulo;
        add = add * m % modulo;
        add = add * modpow(m - 1, n - i - 1, modulo) % modulo;
        ans = (ans + add) % modulo;
    }
    if ans < 0 {
        ans = (ans + modulo) % modulo;
    }
    println!("{}", ans);
}

fn modpow(a: i64, x: i64, m: i64) -> i64 {
    if x == 0 {
        1
    } else if x % 2 != 0 {
        a * modpow(a, x - 1, m) % m
    } else {
        let half = modpow(a, x / 2, m);
        half * half % m
    }
}

struct CombinationMod {
    fac: Vec<i64>,
    inv_fac: Vec<i64>,
    modulo: i64,
}
impl CombinationMod {
    pub fn new(size: usize, modulo: i64) -> CombinationMod {
        let mut fac = vec![1; size + 1];
        let mut inv_fac = vec![1; size + 1];
        let mut inv = vec![1; size + 1];
        for i in 2..=size {
            fac[i] = fac[i - 1] * i as i64 % modulo;
            inv[i] = modulo - inv[modulo as usize % i] * (modulo / i as i64) % modulo;
            inv_fac[i] = inv_fac[i - 1] * inv[i] % modulo;
        }
        CombinationMod {
            fac: fac,
            inv_fac: inv_fac,
            modulo: modulo,
        }
    }
    fn query(&self, n: i64, r: i64) -> i64 {
        self.fac[n as usize] * self.inv_fac[r as usize] % self.modulo
            * self.inv_fac[(n - r) as usize]
            % self.modulo
    }
    fn hoge() {
        println!("hoge");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 6744
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;

	int ans=1;
	for(int i=1; i<n; i++){
		ans*=2;
		if(ans>n){
			ans /=2;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

string s;

int main()
{
	cin >> s;
	int lef = 0, rig = int(s.length()) - 1;
	int res = 0;
	while (lef < rig)
		if (s[lef] == s[rig]) lef++, rig--;
		else if (s[lef] == 'x') { res++; lef++; }
		else if (s[rig] == 'x') { res++; rig--; }
		else { printf("-1\n"); return 0; }
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 512
k, a, b = map(int, input().split())

if b > a + 1:
    ans = (k - a + 1) // 2 * (b - a) + a
    print(ans if (k - a + 1) % 2 == 0 else ans + 1)
if b <= a + 1:
    print(k + 1)


Measured memory_bytes: 2940
#include<stdio.h>
int main(void)
{
    int m,n,i;
    scanf("%d %d",&m,&n);
    if(m>=n){
        for(i=0;i<m;i++)
            printf("%d",n);
    }
    else{
        for(i=0;i<n;i++)
            printf("%d",m);
    }
    return 0;
}

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

int main()
{
  int n,m,ans;
  ans=0;
  cin>>n>>m;
  vector<pair<int,int>> a(m);
  if(m==0)
  {
    if(n==1)
      ans=0;
    if(n==2)
      ans=10;
    if(n==3)
      ans=100;
  }
  else
  {
    for(int i=0;i<m;i++)
    {
      cin>>a.at(i).first>>a.at(i).second;
    }
    sort(a.begin(),a.end());

    if(n!=1)
    {
      if((a.at(0).first==1)&&(a.at(0).second==0))
        ans=-1;
    }
    if(m!=1)
    {
      for(int i=0;i<m-1;i++)
      {
        if(a.at(i).first==a.at(i+1).first)
        {
          if(a.at(i).second!=a.at(i+1).second)
          {
            ans=-1;
            break;
          }
        }
      }
    }
    if(m!=1)
    {
      for(int i=0;i<m-1;i++)
      {
        if((a.at(i).first==a.at(i+1).first)&&(a.at(i).second==a.at(i+1).second))
          a.at(i).first=100;
      }
    }

    if(ans!=-1)
    {
      if(n==1)
        ans=a.at(0).second;
      else if(n==2)
      {
        for(int i=0;i<m;i++)
        {
          if(a.at(i).first==1)
            ans+=a.at(i).second*10;
          if(a.at(i).first==2)
            ans+=a.at(i).second;
        }
        if(ans<10)
        {
          ans+=10;
        }
      }
      else
      {
        for(int i=0;i<m;i++)
        {
          if(a.at(i).first==1)
            ans+=a.at(i).second*100;
          if(a.at(i).first==2)
            ans+=a.at(i).second*10;
          if(a.at(i).first==3)
            ans+=a.at(i).second;
        }
        if(ans<100)
        {
          ans+=100;
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

ll sz[51];
ll p[51];

ll rec(int n, ll x){
    if(n == 0) return max(0LL, x);
    if(sz[n] == x) return p[n];
    ll res = 0;
    res += rec(n - 1, min(sz[n - 1], x - 1));
    if(sz[n - 1] + 1 < x) res += 1;
    if(sz[n - 1] + 2 < x) res += rec(n - 1, min(sz[n - 1], x - (sz[n - 1] + 2)));
    return res;
}

signed main(){
    int n;
    ll x;
    cin >> n >> x;
    sz[0] = 1;
    for(int i = 1; i <= 50; i++){
        sz[i] = sz[i - 1] * 2 + 3;
    }
    p[0] = 1;
    for(int i = 1; i <= 50; i++){
        p[i] = p[i - 1] * 2 + 1;
    }
    cout << rec(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
nums = list(map(int, input().split()))
al = 0
part = {}
for i in range(N):
    if nums[i] in part:
        al += part[nums[i]]
        part[nums[i]] += 1
    else:
        part[nums[i]] = 1

for i in range(N):
    print(al - part[nums[i]] + 1)


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n;cin >> n;
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}

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

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

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

	int INF=1<<28;
	double EPS=1e-12;

	int n, m, limit, s, t;
	boolean[] freeze;
	ArrayList<E>[] es;

	@SuppressWarnings("unchecked")
	void run(){
		for(;;){
			n=sc.nextInt();
			limit=sc.nextInt();
			int k=sc.nextInt();
			m=sc.nextInt();
			s=sc.nextInt();
			t=sc.nextInt();
			if((n|limit|k|m|s|t)==0){
				break;
			}

			freeze=new boolean[n];
			for(int i=0; i<k; i++){
				freeze[sc.nextInt()]=true;
			}
			freeze[s]=freeze[t]=true;
			es=new ArrayList[n];
			for(int i=0; i<n; i++){
				es[i]=new ArrayList<E>();
			}
			for(int i=0; i<m; i++){
				int u=sc.nextInt(), v=sc.nextInt(), w=sc.nextInt();
				es[u].add(new E(v, w));
				es[v].add(new E(u, w));
			}
			solve();
		}
	}

	void solve(){
		int[][] d=new int[n][limit+1];
		for(int i=0; i<n; i++){
			fill(d[i], INF);
		}
		d[s][limit]=0;
		PriorityQueue<P> que=new PriorityQueue<P>();
		que.offer(new P(s, limit, 0));
		for(; !que.isEmpty();){
			P p=que.poll();
			if(p.cost>d[p.v][p.t]){
				continue;
			}
			if(freeze[p.v]){
				for(int i=1; p.t+i<=limit; i++){
					if(p.cost+i<d[p.v][p.t+i]){
						P q=new P(p.v, p.t+i, p.cost+i);
						que.offer(q);
						d[q.v][q.t]=q.cost;
					}
				}
			}
			for(E e : es[p.v]){
				if(p.t-e.cost>=0&&p.cost+e.cost<d[e.to][p.t-e.cost]){
					P q=new P(e.to, p.t-e.cost, p.cost+e.cost);
					que.offer(q);
					d[q.v][q.t]=q.cost;
				}
			}
		}
		int min=INF;
		for(int i : d[t]){
			min=min(min, i);
		}
		println(min<INF?(""+min):"Help!");
	}

	class P implements Comparable<P>{
		int v, t, cost;

		P(int v, int t, int cost){
			this.v=v;
			this.t=t;
			this.cost=cost;
		}

		@Override
		public int compareTo(P p){
			return cost-p.cost;
		}
	}

	class E{
		int to, cost;

		E(int to, int cost){
			this.to=to;
			this.cost=cost;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 159920
object Main {
  // NOTE: Destructive: arr
  def printInsertSort(arr: Array[Int]): Unit= {
    for (i <- (1 until arr.length)) {
      // Print arr
      println(arr.mkString(" "))
      val v = arr(i)
      var j = i - 1
      while(j >= 0 && arr(j) > v) {
        arr(j+1) = arr(j)
        j -= 1
      }
      arr(j+1) = v
    }
    // Print arr
    println(arr.mkString(" "))
  }

  def main(args: Array[String]): Unit = {
    // Skip n
    io.StdIn.readLine()

    // Read arry string
    var arrString: String = io.StdIn.readLine()
    // Convert it to real int array
    val arr: Array[Int] = arrString.split(" ").map(_.toInt)

    // Print insert sort step
    printInsertSort(arr)
  }
}


Measured memory_bytes: 45784
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#define SS(i) scanf("%s",i)
#define SC(i) scanf("%d",&i)
#define SCC(i,j) scanf("%d%d",&i,&j)
#define SCCC(i,j,z) scanf("%d%d%d",&i,&j,&z)
#define PR(i) printf("%d\n",i)
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define CL(i,x) memset(i,x,sizeof(i))
#define IN freopen("in.txt","r",stdin)
#define OUT  freopen("out.txt","w",stdout)
#define PB(i) push_back(i)
#define min(x,y) ((x>y)?(y):(x))
#define max(x,y) ((x<y)?(y):(x))
#define abs(i) (i<0?(-i):i)
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
using namespace std;
const int N=200000+10;
const int inf = 1e9;
int a[45], b[45], c[45];
int d[41][410][410];
int main()
{
#ifndef ONLINE_JUDGE

#endif


    int n, ma, mb;
    SCCC(n, ma, mb);
    int to1 = 0, to2 = 0;
    FF(i, 1, n){
        SCCC(a[i], b[i], c[i]);
        to1 += a[i]; to2 += b[i];
    }
    ///

    FF(k, 0, n) FF(i, 0, to1) FF(j, 0, to2)
    d[k][i][j] = inf;

    int ans = inf;

    d[0][0][0] = 0;

    FF(k, 1, n)
    {
        FF(i, 0, to1)
        {
            FF(j, 0, to2)
            {
                if(i-a[k]>=0 && j-b[k]>=0)
                    d[k][i][j] = min(d[k-1][i][j], d[k-1][i-a[k]][j-b[k]]+c[k]);
                else
                    d[k][i][j] = d[k-1][i][j];
                if(i*mb==j*ma && i && j)
                    ans = min(ans, d[k][i][j]);
            }
        }
    }
    if(ans == inf) puts("-1");
    else PR(ans);
    return 0;
}


Measured memory_bytes: 17408