akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
ll n,W,w[110],v[110],dp[110][100010];
const ll INF=1e12;

ll wm(ll i,ll e){
  if(e<=0) return 0;
  if(dp[i][e]!=INF+1) return dp[i][e];
  if(i==0) dp[i][e]=INF;
  else dp[i][e]=min(wm(i-1,e),wm(i-1,e-v[i-1])+w[i-1]);
  return dp[i][e];
}

int main(){
  cin>>n>>W;
  fr(i,n+1) fr(e,1e5+1) dp[i][e]=INF+1;
  fr(i,n) cin>>w[i]>>v[i];
  ifr(e,1e5+1){
    if(wm(n,e)<=W){cout<<e<<endl;return 0;}
  }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    ll suma = 0;
    REP(i, M){
        ll a;
        cin >> a;
        suma += a;
    }
    if(suma <= N){
        cout << N-suma << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
using vvb=vector<vector<bool>>;
using vb= vector<bool>;
ll f(ll a,ll b,ll p){
	if(b==0) return 1;
	if(b%2==0){
		ll t=f(a,b/2,p);
		return t*t%p;
	}
	return a*(f(a,b-1,p))%p;
} 

//__builtin_popcount()
signed main(){
	ll n; cin>>n;
	ll m; cin>>m;
	vvl g(n,vl(0));
	rep(i,0,m){
		ll a,b; cin>>a>>b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vl ans(n);
	vector<bool> seen(n);
	seen[0]=1;
	queue<ll> q;
	q.push(0);
	while(!q.empty()){
		ll k=q.front(); q.pop();
		for(auto c:g[k]){
			if(seen[c])continue;
			seen[c]=1;
			ans[c]=k;
			q.push(c);
		} 
	}
	cout<<"Yes"<<endl;
	rep(i,1,n)cout<<ans[i]+1<<endl;

	return 0;
}

Measured memory_bytes: 12900
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

    int a, b, ab;
    cin>>a>>b>>ab;
    int x, y;
    cin>>x>>y;
    ll ans=a*x+b*y;
    ll ans2, ans3;
    if(x<y){
        ans2=2*ab*x+(y-x)*b;
        ans3=2*ab*y;
    }else{
        ans2=2*ab*y+(x-y)*a;
        ans3=2*ab*x;
    }
    ans=min(ans, ans2);
    ans=min(ans, ans3);
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1<<30
#define eps (1e-4)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

int n;
double dp[10001][21][21]={};
double x[21],y[21],r,s;
bool b[21][21][21]={};

double abs(int a,int b){
  return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
}

double dot(int i,int j,int k){
  return (x[i]-x[j])*(x[k]-x[j])+(y[i]-y[j])*(y[k]-y[j]);
}

int main()
{
  cin>>n>>r>>s;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	if(i==j || j==k || i==k){
	  b[i][j][k]=false;
	  continue;
	}
	double R=acos(dot(i,j,k)/(double)(abs(i,j)*abs(j,k)));
	R=R*360/(2.0*pi);
	R=min(R,360-R);
	if(((180-R)-s)<eps)b[i][j][k]=true;
	else b[i][j][k]=false;
      }
    }
  }

  for(int i=0;i<10001;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)
	dp[i][j][k]=inf;

  int ans=0;
  for(int i=1;i<n;i++){
    dp[0][0][i]=abs(0,i);
    if(dp[0][0][i]<r)ans=1;
  }

  for(int c=1;c<10001;c++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  if(b[i][j][k]){
	    dp[c][j][k]=min(dp[c][j][k],dp[c-1][i][j]+abs(k,j));
	    if(dp[c][j][k]-r<eps)ans=max(c+1,ans);
	  }
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 35768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

int main(){
    int n;
    cin >> n;
    vector<int>ten;
    vector<int>nt;
    int S = 0;
    int sten = 0;
    rep(i,n){
        int s;
        cin >> s;
        if(s%10==0){
            ten.push_back(s);
            sten+=s;
        }
        else {
            nt.push_back(s);
            S+=s;
        }
    }
    sort(nt.begin(),nt.end());
    int ans = 0;
    if(nt.size()==0){
        cout << 0 << endl;
        return 0;
    }
    else{
        if(S%10==0){
            S-=nt[0];
            cout << S+sten << endl;
        }
        else{
            cout << S+sten << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], v[200005], p[200005];
long long k;
int dfs(int u){
    if(~v[a[u]]) return a[u];
    v[a[u]] = v[u] + 1;
    p[v[a[u]]] = a[u];
    return dfs(a[u]);
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i],v[i]=-1;
    v[1]=0,p[0]=1;
    int x=dfs(1);
    int mx=*max_element(v+1,v+n+1)+1;
    int ans;
    if(k<mx) ans=p[k];
    else{
        int e=mx-v[x];
        k-=v[x];
        k%=e;
        ans=p[v[x]+k];
    }
    cout<<ans;
}


Measured memory_bytes: 5844
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
#include <map>

using namespace std;
const int INF = 1<<30;

int solve();

int main(void) {
	
	while(solve()){}

	return 0;
}


int solve() {

	
	typedef std::vector<int> vi;
	typedef vector<vi> vvi;
	typedef pair<int,int>pii;

	int N, T;
	cin >> T;
	if( T == 0 ) { return 0; }

	vi t(T,INF);
	map<int,int> mp;
	
	for( int i = 0; i < T; i++ ) {
		cin >> t[i];
	}
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		int d, m;
		cin >> d >> m;
		if( mp.find(d) != mp.end() ) {
			mp[d] = min(mp[d],m);
		} else {
			mp[d] = m;
		}
	}

	vvi dp(100+2,vi(T,INF));
		dp[1][0] = 0;	//?????????


	/*
		dp[?????¨?????\][?????????????????´???] := ????°??????°
	*/

	for( int i = 1; i+1 < dp.size(); i++ ) {
		for( int j = 0; j < dp[i].size(); j++ ) {
			//????????????????????§??´?????????
			if( dp[i][j] == INF ) { continue; }
			if( mp.find(i) != mp.end() && mp[i] < t[j] ) { continue; }
			//?£????
			dp[i+1][0] = min(dp[i+1][0],dp[i][j]+1);
			//?£??????????
			dp[i+1][(j+1)%T] = min(dp[i+1][(j+1)%T],dp[i][j]);
		}
	}
	int ans = INF;
	for(int i = 0; i<dp[0].size(); i++ ) {
		ans = min(ans,dp[dp.size()-1][i]);
	}
	cout << ans << endl;

	return 1;

}

Measured memory_bytes: 3060
n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))

now = 1
check = [-1]*(n+1)

for i in range(k):
  if check[now] == -1:
    check[now] = i
    now = a[now]
  else:
    loop = i - check[now]
    afterloop = (k-(i-loop))%loop
    print(check.index((i-loop) + afterloop))
    exit()
print(now)


Measured memory_bytes: 32216
import sys
from collections import defaultdict

n, m = map(int, input().split())
disputes = defaultdict(int)
for line in sys.stdin.readlines():
    a, b = map(int, line.split())
    if disputes[b] < a:
        disputes[b] = a
ans = 0
most_right_bridge = 0
for b in sorted(disputes.keys()):
    if most_right_bridge <= disputes[b]:
        ans += 1
        most_right_bridge = b
print(ans)


Measured memory_bytes: 17976
#include <stdio.h>
#include <math.h>

#define SQ(X) \
  ( (X) * (X) )
#define RAD(D) \
  ( (D) * M_PI / 180. )
#define degsin(D) \
  sin ( RAD( D ) )
#define degcos(D) \
  cos ( RAD( D ) )

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int a, b, c;

  scanf ( "%d%d%d", &a, &b, &c );
  printf ( "%.4f\n", a * b * degsin ( c ) / 2. );
  printf ( "%.4f\n", a + b + sqrt ( SQ( a ) + SQ( b ) - 2. * a * b * degcos ( c ) ) );
  printf ( "%.4f\n", b * degsin ( c ) );

  return ( 0 );
}


Measured memory_bytes: 2144
#include <iostream>

using namespace std;

int A[1000000], n;

int binarySearch(int key) {
    int left = 0;
    int right = n;
    int mid;
    while(left < right) {
        mid = (left + right) / 2;
        if(key == A[mid]) return 1;
        if(key > A[mid]) left = mid + 1;
        else if(key < A[mid]) right = mid;
    }
    return 0;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    int q;
    cin >> q;
    int cnt = 0;
    for(int i = 0; i < q; i++) {
        int key;
        cin >> key;
        if(binarySearch(key)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3380
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {   
    string s;
    int n;
    cin >> s >> n;
    for (int i = 0; i < s.size(); i += n) {
        cout << s[i];
    }
    cout << endl;
}




Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>void chmin(T &a,T b){a=min(a,b);}
using namespace std;

void solve(){
	int n;
	cin>>n;
	int left=0,right=n+1,mid=(left+right)/2;
	vector<string>s(20);
	rep(i,20){
		if(!i)cout<<0<<endl;
		else cout<<mid<<endl;
		cin>>s[i];
		if(s[i]=="Vacant")return;
		if(!i)continue;
		if(mid%2==0){
			if(s[0]!=s[i])right=mid;
			else left=mid;
		}
		else {
			if(s[0]!=s[i])left=mid;
			else right=mid;
		}
		mid=(left+right)/2;
	}
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 852
#include <stdio.h>

int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<b){
   if(b<c){
      printf("Yes\n");
   }else{
      printf("No\n");
}}else{
   printf("No\n");
}
return 0;
}

Measured memory_bytes: 580
from itertools import *
N = int(input())
S = [input() for n in range(N)]
D = {"M":0,"A":0,"R":0,"C":0,"H":0}
ans = 0

for s in S:
  if s[0] in "MARCH":
    D[s[0]]+=1

for a,b,c in combinations(D.values(),3):
  ans+=a*b*c

print(ans)

Measured memory_bytes: 16256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string N;

int main()
{
	in >> N;
	if (N[0] == '9' || N[1] == '9') { out << "Yes" << std::endl; }
	else { out << "No" << std::endl; }
	return 0;
}


Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break

  s, t, b = input().split()
  base = ord("A")
  blank = ord(b) - base

  dp = [[0] * 9 for _ in range(n + 1)]
  dp[0][ord(s) - base] = 1

  to = {0:(0, 0, 1, 3), 1:(0, 1, 2, 4), 2:(1, 2, 2, 5), 3:(0, 3, 4, 6), 
        4:(1, 3, 5, 7), 5:(2, 4, 5, 8), 6:(3, 6, 6, 7), 7:(4, 6, 7, 8), 8:(5, 7, 8, 8)}
  
  def update(x, i):
    for nex in to[x]:
      if nex == blank:
        dp[i][x] += dp[i - 1][x] / 4
      else:
        dp[i][nex] += dp[i - 1][x] / 4

  for i in range(1, n + 1):
    for x in range(9):
      update(x, i)
  print(dp[n][ord(t) - base])


Measured memory_bytes: 5620
N = int(input())
A = [0]*N
B = [0]*N
C = [0]*N
for i in range(N):
    A[i], B[i], C[i] = map(int, input().split())
    
dp_A = [0]*N
dp_B = [0]*N
dp_C = [0]*N

dp_A[0] = A[0]
dp_B[0] = B[0]
dp_C[0] = C[0]

for i in range(1, N):
    dp_A[i] = A[i] + max(dp_B[i-1], dp_C[i-1])
    dp_B[i] = B[i] + max(dp_C[i-1], dp_A[i-1])
    dp_C[i] = C[i] + max(dp_A[i-1], dp_B[i-1])
    
print(max(dp_A[N-1], dp_B[N-1], dp_C[N-1]))

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;
ll INF=100000000000001;
vector<ll> value; // ノードの値を持つ配列
ll N;             // 葉の数
 
void update(ll i, ll x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
ll query(ll a, ll b, ll k, ll l, ll r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}
signed main(){
    llin(h);
    ll k=1;
    while(h>0){
        h=h/2;
        k=k*2;
    }
    sal(k-1)
}

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

long a[3];
long dp[3][100001];
long sub(string s) {
  for (int k = 0; k < 3; ++k) {
    for (int i = 0; i <= s.size(); ++i) {
      dp[k][i] = 0;
    }
  }
  
  for (int i = 0; i < s.size(); ++i) {
    for (int k = 0; k < 3; ++k) {
      for (int pk = 0; pk < 3; ++pk) {
        if (pk == k) continue;
        int c = (s[i] - '0') == k ? a[k] : 0;
        dp[k][i + 1] = max(dp[k][i + 1], dp[pk][i] + c);
      }
    }
  }
  
  long mx = 0;
  for (int k = 0; k < 3; ++k) {
    mx = max(mx, dp[k][s.size()]);
  }
  return mx;
}

int main() {
  int n, k;
  string s;
  cin >> n >> k >> a[0] >> a[1] >> a[2] >> s;
  
  for (int i = 0; i < n; ++i) {
    if (s[i] == 's') s[i] = '0';
    if (s[i] == 'p') s[i] = '1';
    if (s[i] == 'r') s[i] = '2';
  }
  
  long sum = 0;
  for (int i = 0; i < k; ++i) {
    string t;
    for (int j = i; j < n; j += k) {
      t += s[j];
    }
    sum += sub(t);
  }
  cout << sum << endl;
}

Measured memory_bytes: 2944
#include <stdio.h>

int main(void) {
	int a,b,c,d,e,r;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a <= 0 && b >= 0){
		r = (0-a)*c+d+b*e;
	}
	else if(b <= 0){
		r = (b-a)*c;
	}
	else{
		r = (b-a)*e;
	}
	printf("%d\n",r);
	return 0;
}

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

using namespace std;
typedef long long int lld;

const lld mod = 998244353;
lld ans = 0,dp[222222];
lld calc(lld now,lld num){
	if(num==0) return 1;
	if(num==1) return now;
	lld now2 = calc(now,num/2);
	if(num%2==0) return (now2*now2)%mod;
	return (((now2*now2)%mod)*now)%mod;
}
lld fat(lld n,lld k){
	lld f = dp[n];
	lld s = (dp[k]*dp[n-k])%mod;
	return (f*calc(s,mod-2))%mod;
}
int main(void){
	dp[0] = 1;
	for(int e=1;e<222222;e++) dp[e] = (dp[e-1]*(lld)e)%mod;
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int e=n-k;e<=n;e++){
		lld val = fat(n-1,n-e);
		val = (val*m)%mod;
		val = (val*calc(m-1,e-1))%mod;
		ans = (ans+val)%mod;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 5564
S = input()
alp = "abcdefghijklmnopqrstuvwxyz"

if len(S) < 26:
  for i in range(len(alp)):
    c = alp[i]
    index = S.find(c)
    if index <0 :
      print(S,c,sep='')
      exit()

stack=[]
c_pre=""
for j in range(len(S)):
  c_now = S[25-j]
  #print(c_now)
  if c_now < c_pre :
    S = S[:-j-1]
    #print(S)
    c_min = "z"
    for cx in stack:
      if c_now < cx and cx <= c_min :
        c_min = cx
        #print(c_min)
    print(S,c_min,sep='')
    exit()
  else :
    stack.append(c_now)
    c_pre = c_now

print("-1")    

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
//krishrawat
 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 2e3 + 1;//                                                             |
//----------------------------------------------------------------------------------


//solution
void solve()
{   
    
    ll a,b;cin>>a>>b;
    msl m;
    for(int i=0;i<a;i++){
        ll k;cin>>k;m.pb(k);
    }
    vp v(b);
    for(int i=0;i<b;i++){
        cin>>v[i].ss>>v[i].ff;
    }
    sort(all(v));
    reverse(all(v));
    
    
    ll ans=0;
    for(auto &i:v){
        ll w=i.ss;
        while(w){
            if(!m.empty()){
                if(*m.begin()>=i.ff){
                    ans+=*m.begin();
                }
                else{
                    ans+=i.ff;
                    w--;
                }
                m.erase(m.begin());
            }
            else break;
        }
    }
    while(!m.empty()){
        ans+=*m.begin();
        m.erase(m.begin());
    }
    cout<<ans<<"\n";
    
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t; t=1;
    //cin>>t;
    while(t--) solve(); return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(6) << fixed;
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i = 0 ; i < n;i++)
        cin >> x[i];
    for(int i = 0 ; i < n;i++)
        cin >> y[i];

    double p1 = 0;
    double p2 = 0;
    double p3 = 0;
    double p4 = 0;
    for(int i = 0; i < n; i++){
        p1 += abs(x[i] - y[i]);
        p2 += pow(abs(x[i] - y[i]),2);
        p3 += pow(abs(x[i] - y[i]),3);
        p4 = max(p4,(double)abs(x[i] - y[i]));
    }
    cout << p1 << endl;
    cout << sqrt(p2) << endl;
    cout << pow(p3,(double)1/3) << endl;
    cout << p4 << endl;
    return 0;
}



Measured memory_bytes: 3508
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, Q = mapint()
abcd = [list(mapint()) for _ in range(Q)]

from itertools import combinations_with_replacement

lis = range(1, M+1)
ans = 0
for l in combinations_with_replacement(lis, N):
    tmp = 0
    for a, b, c, d in abcd:
        if l[b-1]-l[a-1]==c:
            tmp += d
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 67764
#include <iostream>
using namespace std;
int main(){
  int N, T, min=1001;
  cin >> N >> T;
  for(int i=0; i<N; i++){
    int c, t;
    cin >> c >> t;
    if(t <= T && c < min){
      min = c;
    }
  }
  if(min == 1001)
    cout << "TLE" << endl;
  else
    cout << min << endl;
  return 0;
}


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

int H,A[MAX + 1];

void maxHeap(int i){
  int l,r,largest;
  l = 2*i;
  r = 2*i +1;
  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;
  if(largest != i){
    swap(A[i],A[largest]);
    maxHeap(largest);
  }
}

int main(){
  cin >> H;
  for(int i = 1;i <= H;i++) cin >> A[i];
  for(int i = H/2;i >= 1;i--) maxHeap(i);
  for(int i = 1; i <= H;i++){
    cout << " " << A[i];
  }
  cout << endl;
  return 0;
}




Measured memory_bytes: 4944
n, m = map(int, input().split())
num = [-1]*n

for _ in range(m):
    s, c = map(int, input().split())
    if num[s-1] == c:
        continue
    elif num[s-1] == -1:
        num[s-1] = c
    else:
        print(-1)
        exit()

if num[0] == 0:
    if n == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()
elif num[0] == -1:
    if n == 1:
        print(0)
        exit()
    else:
        num[0] = 1
for i in range(1, n):
    if num[i] == -1:
        num[i] = 0

print(*num, sep='')

Measured memory_bytes: 3064
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    p = 1
    for _ in range(60):
        n = 0
        for i in range(N):
            if A[i] % 2:
                n += 1
            A[i] //= 2
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 118580
n=int(input())
if n==0:
  print(0)
  exit()
s=""
while n!=0:
  if n % 2 == 1:
    s = "1" + s
    n = (n-1)//2*(-1)
  else:
    s="0"+s
    n=n//2*(-1)
print(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;


int main() {
    int x; cin >> x;
    while(1){
        int f = 0;
        Rep(i, 2, x){
            if(x % i == 0 && (i != 1 && i != x )) f = 1;
        }
        if(f) {
            x++;
            continue;
        }else{
            break;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int n = sc.nextInt();
				int x = sc.nextInt();
				if(n==0&&x==0) break;

				int num = 0;
				for(int i=1;i<=x/3;i++) {
					for(int j = i+1;j<=x/2;j++) {
						for(int k = j+1;k<=n;k++) {
							if((i+j+k)==x)
								num++;
						}
					}
				}
				System.out.println(num);
			}
		}
	}
}


Measured memory_bytes: 27076
#include <stdio.h>

int main() {
    int H[100], W[100];
    int count = 0, i, j, k;

    while (1)
    {
        scanf("%d %d", &H[count], &W[count]);
        if (H[count] == 0 && W[count] == 0) {
            break;
        }
        count++;
    }

    for (i = 0; i < count; i++) {
        for (j = 0; j < H[i]; j++) {
            for (k = 0; k < W[i]; k++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    int A, B;
    cin >> A >> B;
    int plus = A + B;
    int minus = A - B;
    int mul = A * B;
    int ans = max(plus, max(minus, mul));
    
   	cout << ans << endl;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int main(){
	int N,a,b,i,c;
	string s,t;
	for(cin>>N,getline(cin,s);N--;){
		getline(cin,s);
		for(a=1;a<26;a++){
			if(a%2==0||a%13==0)continue;
			for(b=0;b<26;b++){
				t=s;
				for(i=0;i<t.length();i++){
					if(t[i]<'a'||'z'<t[i])continue;
					c=t[i]-'a'+b;
					for(;c%a;)c+=26;
					t[i]=c/a%26+'a';
				}
				if(t.find("this")!=-1||t.find("that")!=-1){cout<<t<<endl;goto n;}
			}
		}	
	n:;}
}

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

int main() {
  int n, a, b;
  while (cin >> n >> a >> b) {
    cout << min(n * a, b) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
    /* check 
        0 -> とくになし
        1 -> dream を読んで、dream + erase(r)かdreamer + ?か判断したい
    */
    int n, i, check;
    string str, tmp, ans;
    cin >> str;
    n = str.length();
    i = 0;
    check = 0;
    while(true){
        if(check == 1){
            if(i + 5 < n && str[i+1] == 'e' && str[i+2] == 'r' && str[i+3] == 'a' && str[i+4] == 's' && str[i+5] == 'e'){
                // token -> "dream"
                check = 0;
                i++;
            }
            else if(i + 2 < n && str[i+1] == 'e' && str[i+2] == 'r'){
                // token -> "dreamer"
                i += 2;
                if(i == n-1){
                    cout << "YES" << endl;
                    break;
                }
                else {
                    i++;
                }
                check = 0;
            }
            else if(i + 1 < n){
                check = 0;
                i++;
            }
            else {
                cout << "NO" << endl;
                break;
            }
        }
        else if(i + 4 < n && str[i] == 'e' && str[i+1] == 'r' && str[i+2] == 'a' && str[i+3] == 's' && str[i+4] == 'e'){
            if (i + 5 < n && str[i+5] == 'r'){ // token -> "eraser"
                i += 5;
                if(i == n-1){
                    cout << "YES" << endl;
                    break;
                }
                else {
                    i++;
                }
            }
            else { // token -> "erase"
                i += 4;
                if(i == n-1){
                    cout << "YES" << endl;
                    break;
                }
                else {
                    i++;
                }
            }
        }
        else if(i + 4 < n && str[i] == 'd' && str[i+1] == 'r' && str[i+2] == 'e' && str[i+3] == 'a' && str[i+4] == 'm'){
            i += 4;
            if(i == n-1){
                cout << "YES" << endl;
                break;
            }
            check = 1;
            //cout << check << endl;
        }
        else {
            cout << "NO" << endl;
            break;
        }
    }
    //cout << str << " " << i << endl;
}


Measured memory_bytes: 512
N = int(input())
S = list(input())
half = int(N / 2)
a = []
b = []

for i in range(half):
  a.append(S[i])
  b.append(S[i + half])
  
if(N % 2 != 0):
  ans = 0
else:
  if(a == b):
    ans = 1
  else:
    ans = 0

if(ans == 1):
  print("Yes")
else:
  print("No")

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,M;
int cnt[31];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) {
		cin>>x;
		FOR(j,x) {
			cin>>y;
			cnt[y]++;
		}
	}
	int ret=0;
	FOR(i,31) if(cnt[i]==N) ret++;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define M 500000
#define SE 1000000000

int LI[M/2+2],RI[M/2+2];
int count;

void merge(int X[],int num,int left,int mid,int right){
  int ml = mid - left;
  int rm = right - mid;
  int i,k,j=0;
    for(i=0;i<ml;i++){
      LI[i] = X[left + i ];
    }
  for( i=0;i<rm;i++){
    RI[i] = X[mid +i];
  }
  LI[ml] = RI[rm] = SE;
  i =0;
  

  for(k = left;k<right;k++){
    count++;
    if(LI[i] <= RI[j]){
      X[k] = LI[i++];
    }
    else{
      X[k]=RI[j++];
    }
  }
}

void mergeSort(int X[],int n,int left, int right){
  if(left+1 < right){
    int mid = (left + right )/2;
    mergeSort(X,n,left,mid);
    mergeSort(X,n,mid,right);
    merge(X,n,left,mid,right);
  }
}

int main(){
  int X[M],num,i;
  count =0;

  cin >> num;
  for(i=0;i<num;i++){
    cin >> X[i];
  }

  mergeSort(X,num,0,num);

  for(i=0;i<num;i++){
    if(i){
      cout<< " ";
    }
      cout << X[i];
    }
    cout << endl;

    cout << count << endl;

    return 0;

  }



Measured memory_bytes: 6972
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)

int n, p, a[200005], pre[200005];
ll lo=1, mid, hi, c;
bool check(ll L){
    p=0; c=0;
    drain(pre);
    fox(l, n*2){
        c+=a[l];
        while(p<=l && c-a[p]>=L){
            c-=a[p];
            p++;
        }
        if (c<L) pre[l]=-(1 << 30);
        else {
            pre[l]=p;
            //cout << pre[l] << ' ';
            if (pre[l]>0 && pre[pre[l]-1]-1>=0 && l-pre[pre[pre[l]-1]-1]+1<=n) return 1;
            continue;
        }
        //cout << pre[l] << ' ';
    }
    return 0;
}
int main(){
    cin >> n;
    fox(l, n){
        cin >> a[l];
        a[l+n]=a[l];
    }
    hi=1LL*n*MN;
    //cout << check(6);
    //return 0;
    while(lo<hi){
        mid=(lo+hi+1)/2;
        //cout << mid << endl;
        if (check(mid)) lo=mid;
        else hi=mid-1;
        //cout << endl;
    }
    cout << lo << endl;
    return 0;
}

Measured memory_bytes: 4676
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int meke_comb(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int fact(int n){
//   int ans;
//   if(n==1 || n == 0) return 1;
//   ans = n*fact(n-1);
//   return ans;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }




int main(){
  int K;
  cin >> K;
  cout << K/2 * (K/2+K%2) << endl;
}



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

using namespace std;

const int MAXN = 100005;

void readAndPreprocess(char s[], int &n, int diff[]) {
    scanf("%s", s);
    n = strlen(s);

    for(int i = 1; i <= n; ++i) {
        if (s[i-1] == 'A')
            diff[i] = diff[i-1] - 1;
        else
            diff[i] = diff[i-1] + 1;
    }
}

int n, m, q, diffS[MAXN], diffT[MAXN];
char s[MAXN], t[MAXN];

int getDiff(int diff[], int l, int r) {
    int res = diff[r] - diff[l-1];
    return (res%3 + 3)%3;
}

int main() {
    readAndPreprocess(s, n, diffS);
    readAndPreprocess(t, m, diffT);

    scanf("%d", &q);
    for(int i = 0; i < q; ++i) {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);

        bool canTransform = (getDiff(diffS, a, b) == getDiff(diffT, c, d));
        puts(canTransform ? "YES" : "NO");
    }

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const db eps=1e-9;
const int M=1e5+5;
vector<int> vt[M];
db f[M];
int n,m;
db dfs(int x,int c)
{
    if(f[x]>eps||x==n)return f[x];
    if(vt[x].size()==0)return f[x]=1e9;
    db mx=0;
    for(int i=0;i<vt[x].size();i++)
    {
        db t=dfs(vt[x][i],c);
        mx=max(mx,t);
        f[x]+=t;
    }
    if(x==c)
    {
        if(vt[x].size()==1)return f[x]=1e9;
        f[x]-=mx;
        f[x]/=(vt[x].size()-1);
        return f[x]=f[x]+1;
    }
    else
    {
        f[x]/=vt[x].size();
        return f[x]=f[x]+1;
    }

}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        vt[x].push_back(y);
    }
    f[n]=0;
    db ans=1e12;
    for(int i=0;i<=n-1;i++)
    {
        db tmp=dfs(1,i);
        for(int j=1;j<=n-1;j++)f[j]=0;
        ans=min(ans,tmp);
    }

    printf("%.10lf\n",ans);
    return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long x = Long.parseLong(sc.next());
        
        long[] d = new long[6209];
        for(int i = 0; i < 6209; i++){
            long l = i;
            d[i] = l*l*l*l*l;
        }
        
        long a = 0;
        long b = 0;
        for(int i = 0; i < 6209; i++){
            int left = -1;
            int right = 6208;
            long c = Math.abs(d[i] - x);
            while(right-left > 1){
                int mid = (left + right) / 2;
                if(d[mid] > c){
                    right = mid;
                }else{
                    left = mid;
                }
            }
            if(d[i] - d[left] == x){
                a = i;
                b = left;
                break;
            }
            if(d[i] + d[left] == x){
                a = i;
                b = -left;
                break;
            }
        }
        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 38816
#!/usr/bin/env python3
#ABC138 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
v.sort()
if n == 2:
    print(sum(v)/2)
    quit()
ans = (v[0]+v[1])/2
for i in range(2,n):
    x = (ans+v[i])/2
    ans = x
print(ans)


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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int A[2], C[2];
	
	cin >> A[0] >> C[0] >> A[1] >> C[1];
	
	sort(A, A+2);
	sort(C, C+2);
	
	if(C[0] - A[1] > 0)
		cout << C[0] - A[1];
	else
		cout << 0;
	
	return 0;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  cout << N*(N-1)/2 << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		sc.close();

		if (Math.abs(x - y) <= 1) {
			System.out.println("Brown");
		} else {
			System.out.println("Alice");
		}
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner stdIn = new Scanner(System.in)) {
			Main m = new Main();
			while (true) {
				int h = stdIn.nextInt();
				int w = stdIn.nextInt();
				if (h > 300 || w > 300) {
					throw new RuntimeException("Error:Out of Range from 0 to 300");
				}
				if (h == 0 && w == 0) {
					break;
				}
				m.setChar('#');
				m.DrawSquare(h, w);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	private Character displayChar;
	/**
	 * Draw square by define character
	 * @param height Square of height
	 * @param width  Square of width
	 */
	protected void DrawSquare(int height, int width) {
		if (height < 0 || width < 0) {
			throw new RuntimeException("Error:Minus Value Input");
		}
		for (int i = 1; i <= height; i++) {
			for (int j = 1; j <= width; j++) {
				System.out.print(this.displayChar);
			}
			System.out.println("");
		}
		System.out.println("");
	}

	/**
	 * Define character to draw square
	 * @param displayChar Set a character
	 */
	protected void setChar(Character displayChar) {
		this.displayChar = displayChar;
	}
}

Measured memory_bytes: 36196
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int L=scn.nextInt();
        int R=scn.nextInt();
        for(int i=0;i<2*(m-1);i++){
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        }    
            
         if(L>R){
            System.out.println(0);
        }else{
            System.out.println(R-L+1);
        }
    }
}


Measured memory_bytes: 62696
#include<bits/stdc++.h>
using namespace std;
string s,st;
int p;
int main()
{
	cin>>s;
	st=s;
	reverse(st.begin(),st.end());
	for (int i=0; i<s.size(); i++)
	{
		if (st[i]=='b') st[i]='d';
		else if (st[i]=='d') st[i]='b';
		else if (st[i]=='p') st[i]='q';
		else st[i]='p';
	}
	if (st==s) cout<<"Yes"<<endl; else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b, ret = 0;
  	cin >> a >> b;
  	if (a < b) swap(a, b);
  	ret += a--;
  	if (a < b) swap(a, b);
  	ret += a--;
  	cout << ret << '\n';
  	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int B = 0;
  string S;
  rep(i, N){
   cin >> S;
   if(S == "Y"){
    B = 1;}
  }
  if(B == 0){
  cout << "Three" <<endl;
  }
  if(B == 1){
  cout << "Four" <<endl;
  }
}

Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ab = [list(map(int, readline().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
cnt = 0
for a, b in ab:
    cnt += a
    if cnt > b:
        print('No')
        break
else:
    print('Yes')


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

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

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

const ll mod = 1e9+7;
ll N,A,B,C,D;
ll dp[1060][1060];
ll cdp[1060][1060];
ll fact[1050];
ll fpow(ll a, ll b){
	ll res = 1, t = a;
	while( b ){
		if( b&1 ) res = (res*t)%mod;
		t = (t*t)%mod;
		b >>= 1;
	}
	return res;
}
ll inv(ll a){
	return fpow(a,mod-2);
}

ll comb(ll n, ll m){
	if( n == m || m == 0 ) return 1;
	ll& res = cdp[n][m];
	if( res != -1 ) return res;
	res = (comb(n-1,m) + comb(n-1,m-1))%mod;
	return res;
}


int main(){
	fact[0] = 1;
	for(ll i=1;i<=1000;i++) fact[i] = (fact[i-1]*i)%mod;
	memset(cdp,-1,sizeof cdp);
	scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D);
	for(int i=0;i<=N;i++) dp[0][i] = 1;

	for(int n=1;n<=N;n++){
		for(int x=A;x<=B;x++){
			dp[n][x] = dp[n][x-1];
			ll cur = n;
			ll tmp = comb(n,x);
			cur -= x;
			for(int y=1;y<=D;y++){
				if( cur < 0 ) break;
				if( y >= C && y <= D ){
					dp[n][x] = (dp[n][x] + ((tmp*inv(fact[y]))%mod)*dp[cur][x-1])%mod;
				}
				tmp = (tmp * comb(cur,x))%mod;
				cur -= x;
			}
		}
	}

	printf("%lld\n",dp[N][B]);
}


Measured memory_bytes: 17280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
struct edg{
	int f,t;
	ll w;
};
struct nod{
	int x,y,no;
};
int n,p,fat[100010];
edg e[200010];
nod a[200010];
int find(int x){
	if(fat[x]==x)	return x;
	return fat[x]=find(fat[x]);
}
void merge(int x,int y){
	fat[find(x)]=find(y);
}
bool cmp(edg a,edg b){
	return a.w<b.w;
}
bool cmp1(nod a,nod b){
	return a.x<b.x;
}
bool cmp2(nod a,nod b){
	return a.y<b.y;
}
edg tmp;
ll ans;
int main(){
	cin>>n;
	rep(i,1,n){
		scanf("%d%d",&a[i].x,&a[i].y);
		a[i].no=i;
	}
	sort(a+1,a+1+n,cmp1);
	rep(i,2,n){
		tmp.f=a[i-1].no;
		tmp.t=a[i].no;
		tmp.w=a[i].x-a[i-1].x;
		e[++p]=tmp;
	}
	sort(a+1,a+1+n,cmp2);
	rep(i,2,n){
		tmp.f=a[i-1].no;
		tmp.t=a[i].no;
		tmp.w=a[i].y-a[i-1].y;
		e[++p]=tmp;
	}
	sort(e+1,e+1+p,cmp);
	for(int i=1;i<=n;i++){
		fat[i]=i;
	}
	for(int i=1;i<=p;i++){
		int x=find(e[i].f),y=find(e[i].t);
		if(x==y){
			continue;
		}
		merge(x,y);
		ans+=e[i].w;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5248
import functools

import os
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def Yesif(cond):
    print('Yes' if cond else 'No')


def YESIF(cond):
    print('YES' if cond else 'NO')


def yesif(cond):
    print('yes' if cond else 'no')


a, b, c = inl()
Yesif(a <= c <= b)


Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

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

	sort(all(a));

	ll res = 1;

	for (ll i = 0; i < n; i++)
	{
		if (a[i] == 0)
		{
			println(0);
			return 0;
		}
	}

	for (ll i = 0; i < n; i++)
	{
		if (a[i] <= (ll)1e18 / res)
		{
			res *= a[i];
		}
		else
		{
			println(-1);
			return 0;
		}
	}

	println(res);
}

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

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

/*********** Constants ***********/
const auto INF = static_cast<ll>(1e15);
const auto MOD = static_cast<ll>(1e9 + 7);

/*********** Variables ***********/
ll N, ANS;
vector<ll> A;

/*********** Functions ***********/
bool init() {
    cin >> N;
    A.resize(N, 0);
    for (auto& a : A) cin >> a;
    return true;
}

void solve() {
    ll flag = true;
    while (flag) {
        flag = false;
        for (ll i = 0; i < N - 1; i++) {
            if (A[i] > A[i + 1]) {
                flag = true;
                swap(A[i], A[i + 1]);
                ANS++;
            }
        }
    }
}

void output() {
    for (ll i = 0; i < N; i++) {
        cout << (i ? " " : "") << A[i];
    }
    cout << endl;
    cout << ANS << endl;
}

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


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

int main() {
    string str;
    int m;

    while(1) {
        cin >> str;
        if(str=="-") break;
      
      	cin >> m;
      
      	string ans;

        for(int i = 0; i < m; i++) {
            int h;
            cin >> h;

            string tmp1, tmp2;
            tmp1 = str.substr(0, h);
            tmp2 = str.substr(h, str.size()-h);
            str = tmp2+tmp1;
        }

        cout << str << endl;
    }
}


Measured memory_bytes: 3160