akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//clock_t t=clock();
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    #define sz 202002
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t)
    {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    char sr[1<<21],z[20];int C=-1,Z=0;
    inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
    inline void print(register int x)
    {
        if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
        while(z[++Z]=x%10+48,x/=10);
        while(sr[++C]=z[Z],--Z);sr[++C]='\n';
    }
//    void file()
//    {
//        #ifndef ONLINE_JUDGE
//        freopen("a.in","r",stdin);
//        #endif
//    }
//    inline void chktime()
//    {
//        #ifndef ONLINE_JUDGE
//        cout<<(clock()-t)/1000.0<<'\n';
//        #endif
//    }
//    #ifdef mod
//    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
//    ll inv(ll x){return ksm(x,mod-2);}
//    #else
//    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
//    #endif
//  inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
ll D;
ll a[sz];

struct hh{int u,v;ll w;inline const bool operator < (const hh &y) const {return w<y.w;}}edge[sz*30];
int ecnt;
int fa[sz];
int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}

void link(int x,int y){edge[++ecnt]=(hh){x,y,D*(y-x)+a[x]+a[y]};}
int solve(int l,int r,int opt)
{
	if (l==r) return l;
	int mid=(l+r)>>1;
	int L=solve(l,mid,-1),R=solve(mid+1,r,1);
	rep(i,l,mid) link(i,R);
	rep(i,mid+1,r) link(L,i);
	ll mn=1e18;int ret;
	rep(i,l,r) if (chkmin(mn,D*opt*i+a[i])) ret=i;
	return ret;
}
ll solve()
{
	rep(i,1,n) fa[i]=i;
	sort(edge+1,edge+ecnt+1);
	ll ret=0;
	rep(i,1,ecnt)
	{
		int u=getfa(edge[i].u),v=getfa(edge[i].v);
		if (u!=v) ret+=edge[i].w,fa[u]=v;
	}
	return ret;
}

int main()
{
//    file();
	read(n,D);
	rep(i,1,n) read(a[i]);
	solve(1,n,0);
	cout<<solve();
	return 0;
}

Measured memory_bytes: 62080
#include <iostream>
using namespace std;
int main(){
   int x,y;
   cin>>x>>y;
   while(x!=0||y!=0){
  if(x>y){
       cout<<y<<" "<<x<<endl;
      
   }else if(y>=x){
       cout<<x<<" "<<y<<endl;
   } cin>>x>>y;
       
   }
    return 0;
}



Measured memory_bytes: 2988
from math import gcd
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

a, b, c, d = map(int, input().split())
a -= 1
tmp1 = b - (b//c + b//d - b//(lcm(c, d)))
tmp2 = a - (a//c + a//d - a//(lcm(c, d)))

print(tmp1-tmp2)

Measured memory_bytes: 61604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
template <class T>
void print(vector<T> x){ for(auto it=x.begin();it!=x.end();++it){cout<<*it<<" ";} cout<<endl;}
template <class T>
void print(T x){cout << x << '\n';}

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n=1, Abel SUM_UNITY=0) {
        init(n, SUM_UNITY);
    }

    void init(int n=1, Abel SUM_UNITY=0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for(int i=0;i<n;++i)par[i]=i, rank[i]=0, diff_weight[i]=SUM_UNITY;
    }

    int root(int x) {
        if(par[x] == x){
            return x;
        }else{
            int r=root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x]=r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x=root(x); y=root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w=-w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y]=x;
        diff_weight[y]=w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

const string YES="Yes";
const string NO="No";

void solve(long long N,
           long long M,
           std::vector<long long> L,
           std::vector<long long> R,
           std::vector<long long> D){
    UnionFind<int> uf(N);
    REP(i, M){
        uf.merge(L[i]-1, R[i]-1, D[i]);
        if(uf.issame(L[i]-1, R[i]-1)){
            int diff=uf.diff(L[i]-1, R[i]-1);
            if(diff!=D[i]){
                cout<<NO<<endl;
                return;
            }
        }else{
            uf.merge(L[i]-1, R[i]-1,D[i]);
        }
    }

    print(YES);
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> L(M);
    std::vector<long long> R(M);
    std::vector<long long> D(M);
    for(int i=0 ; i < M ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
        scanf("%lld",&D[i]);
    }
    solve(N, M, std::move(L), std::move(R), std::move(D));
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

double temp(int t, int h) {
    double s = t-h*0.006;
    return s;
}

int main() {
    int n,t,c,T;
    cin >> n >> t;
    vector<pair<int,int>> C;
    rep(i,n) {
        cin >> c >> T;
        if (T <= t) {
            C.pb(make_pair(T,c));
        }
    }
    if (C.size() == 0) {
        cout << "TLE" << "\n";
        return 0;
    }
    sort(all(C));
    int res = INF;
    rep(i,C.size()) {
        res = min(C[i].second, res);
    }
    cout << res << "\n";

}


Measured memory_bytes: 256
import scala.io.StdIn
import scala.math.min

object Main {

  def main(args: Array[String]): Unit = {

    val s: List[Int] = StdIn.readLine().toList.map(_.asDigit)
    val cnt: Tuple2[Int, Int] = s.foldLeft((0, 0))((acc, c) =>
      if (c == 0) {
        (acc._1 + 1, acc._2)
      } else {
        (acc._1, acc._2 + 1)
      })
    val ans = min(cnt._1, cnt._2) * 2
    println(ans)

  }

}


Measured memory_bytes: 39916
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> s;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];


	cout << s[0] << s[1] << s[2] << endl;
	return 0;
}


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

int prime(long x){
	int key=1;
	long i;
	
	for(i=3; i<=sqrt(x); i+=2){
		if(x%i==0){
			key=0;
			break;
		}
	}

	return key;
}

int main(void){
	long n;
	while(scanf(" %ld", &n) != EOF){
		long a=n, b=n;
		if(n%2==0) {
			--a;
			++b;
		}else{
			a-=2;
			b+=2;
		}
		 
		if(n==3) {
			a=2;
			b=5;
		}
		else{
			while(prime(a) != 1) a-=2;
			while(prime(b) != 1) b+=2;
		}
		
		printf("%ld %ld\n", a, b);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main(){
IOS;
int n,i,j;
cin>>n;
ld a[n];
for(i=0;i<n;i++){
    cin>>a[i];
}
ld dp[n+1][n+1];
for(i=0;i<=n;i++){
    dp[0][i]=1;
}
dp[1][0]=1-a[0];
dp[1][1]=a[0];
for(i=1;i<=n;i++){
    for(j=0;j<=i;j++){
        if(j>n)
        continue;
        if(j==0)
            dp[i][j]=dp[i-1][j]*(1-a[i-1]);
        else if(j==i){
            dp[i][j]=dp[i-1][j-1]*a[i-1];
        }
        else{
            dp[i][j]=dp[i-1][j-1]*(a[i-1])+dp[i-1][j]*(1-a[i-1]);
        }
    }
}
ld sum=0;
for(j=(n+1)/2;j<=n;j++){
    sum=sum+dp[n][j];
}
cout<<setprecision(11)<<sum<<endl;
}


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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

typedef long long int ll;

void solve(){
	string str, beg, en;
	cin >> str;
	int Q;
	cin >> Q;
	
	list<char> ans;
	for(int i = 0; i < str.size(); i++) ans.pb(str[i]);
	
	bool rev = false;
	while(Q--){
		int t;
		cin >> t;
		if(t == 1){
			rev = !rev;
		}
		else{
			int f; char c;
			cin >> f >> c;
			if(rev == false){
				if(f == 1) ans.push_front(c);
				else ans.pb(c);
			}
			else{
				if(f == 1) ans.pb(c);
				else ans.push_front(c);
			}
		}
	}
	
	string answer;
	for(auto it = ans.begin(); it !=ans.end(); it++){
		answer.pb(*it);
	}
	if(rev) reverse(all(answer));
	cout << answer << endl;
	
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 10452
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int dx[] = {-1, 1,  0, 0};
int dy[] = { 0, 0, -1, 1};
int density[10][10];

bool WithinRange(int y, int x) {
  if (y < 0) return false;
  if (y >= 10) return false;
  if (x < 0) return false;
  if (x >= 10) return false;
  return true;
}

int main() {
  while (1) {
    int x, y, t;
    if (scanf("%d,%d,%d", &x, &y, &t) != 3) break;
    if (t == 1) {
      density[y][x]++;
      for (int i=0; i<4; i++) {
        int newy = y+dy[i];
        int newx = x+dx[i];
        if (WithinRange(newy, newx)) density[newy][newx]++;
      }
    } else if (t == 2) {
      for (int i=-1; i<=1; i++) {
        for (int j=-1; j<=1; j++) {
          int newy = y+i;
          int newx = x+j;
          if (WithinRange(newy, newx)) density[newy][newx]++;
        }
      }
    } else if (t == 3) {
      for (int i=-2; i<=2; i++) {
        for (int j=-2; j<=2; j++) {
          if (abs(i)+abs(j) > 2) continue;

          int newy = y+i;
          int newx = x+j;
          if (WithinRange(newy, newx)) density[newy][newx]++;
        }
      }
    }
  }

  int ans = 0;
  int mans = 0;
  for (int i=0; i<10; i++) { 
    for (int j=0; j<10; j++) {
      if (density[i][j] == 0) ans++;
      mans = max(density[i][j], mans);
    }
  }
  printf("%d\n", ans);
  printf("%d\n", mans);
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;

int main()
{
	scanf("%d",&N);
	vector<ll> A(N),B(N);
	FOR(i,0,N){
		scanf("%lld%lld",&A [i],&B [i]);
	}

	ll sum = 0;
	for(int i = N - 1;i >= 0;i--){
		A [i] += sum;
		if(A [i] % B [i]){
			sum += B [i] - (A [i] % B [i]);
			A [i] += B [i] - (A [i] % B [i]);
		}
	}

	printf("%lld\n",sum);

	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define maxn 120
using namespace std ;

int a[maxn] , n ;
double s ;

int main () {
	cin >> n ;
	for(int i = 1 ; i <= n ; i ++) {
		double x ;
		cin >> x ;
		x = 1/x ;
		s += x ;
	}
	cout << 1/s <<endl ;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n,m,s,t=0;
  double total=0;
  
  scanf("%d %d",&n, &m);
  
  int a[n];
  
  for(s=0;s<n;s++){
    scanf("%d",&a[s]);
    total+=a[s];
  }
  
  for(s=0;s<n;s++){
    if(a[s]>=total/(4*m)){
      t++;
    }
  }
  
  if(t>=m)
    puts("Yes");
  else
    puts("No");
  
  return 0;
}


Measured memory_bytes: 1640
N, M, D = map(int, input().split())
input_list = [["."]*M]*N
for i in range(N):
    input_list[i] = list(input())

# 連続した領域の長さの集合
area_list = []
    
# 横方向
for i in range(N):
    if M < D:
        break
        
    tmp_count = 0
    for j in range(M):
        if input_list[i][j] == ".":
            tmp_count += 1
        else:
            if tmp_count >= D:
                area_list.append(tmp_count)
            tmp_count = 0
    
    if tmp_count >= D:
        area_list.append(tmp_count)

# 縦方向
for j in range(M):
    if N < D:
        break
        
    tmp_count = 0
    for i in range(N):
        if input_list[i][j] == ".":
            tmp_count += 1
        else:
            if tmp_count >= D:
                area_list.append(tmp_count)
            tmp_count = 0
    
    if tmp_count >= D:
        area_list.append(tmp_count)

sa_list = [D-1]*len(area_list)
add_list = [x - y for (x, y) in zip(area_list, sa_list)]
print(sum(add_list))


Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    string s, t; cin >> s >> t;
    int ans = INT_MAX;
    for(int i = 0; i <= s.size() - t.size(); i++) {
        int k = 0;
        int cnt = 0;
        for(int j = i; j < i + t.size(); j++) {
            if(s[j] != t[k]) cnt++;
            k++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
int n,pos;
double t,a,h[1005],minn=2e9;
template<typename I>inline I abss(I x){return x>0 ? x : -x;}
int main()
{
	//freopen("Palace.in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%lf%lf",&n,&t,&a);
	for(int i=1;i<=n;i++) 
	{
		scanf("%lf",&h[i]);
		if(abss(a-(t-0.006*h[i]))<minn) pos=i, minn=abss(a-(t-0.006*h[i]));
	}
	printf("%d\n",pos);
	//fclose(stdin); fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastio;
    int a, b, c;
    cin >> a >> b >> c;
    if (c <= a + b)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,M;
  cin>>N>>M;
  ll total=0;
  vector<ll> A(N);
  
  for(ll i=0;i<N;i++) {
    cin>>A[i];
    total+=A[i];
  }
  ll count=0;
  for(ll  i=0;i<N;i++){
if(A[i]*4*M>=total) {
count++;
}
    
  }
  if(count>=M) {
cout<<"Yes"<<endl;
  }
  else {
cout<<"No"<<endl;
  }
}

  

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
typedef struct {
    int x; 
    int y;
    int c;
}D;
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};
struct Edge
{
  int a, b, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};
struct Kruskal
{
  int n;  // 頂点数
  vector<Edge> es;  // 辺集合
    Kruskal(int n) {
        this->n = n;
    }
  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  void addEdge(int a, int b, int c) {
      Edge e;
      e.a = a; e.b = b; e.cost = c;
      this->es.push_back(e);
  }
  int calc() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;

    rep(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.a, e.b)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};
int main() {
    int N; cin >> N;
    vector<P> x(N), y(N);
    //x<pos,num>
    rep(i, N) {
        cin >> x[i].first >> y[i].first;
        x[i].second = y[i].second = i;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    vector<D> cand;
    rep(i, x.size()-1) {
        D d = {x[i].second, x[i+1].second, abs(x[i].first-x[i+1].first)};
        cand.push_back(d);
    }
    rep(i, y.size()-1) {
        D d = {y[i].second, y[i+1].second, abs(y[i].first-y[i+1].first)};
        cand.push_back(d);
    }
    Kruskal g(N);
    rep(i, cand.size()) {
        g.addEdge(cand[i].x, cand[i].y, cand[i].c);
    }
    cout << g.calc();
}


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

using namespace std;


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define vi                                        vector<int> 
#define vpii                                      vector< pii >

#define all(v)                                    v.begin(),v.end()
#define sZ(re)                                    (int)re.size()
#define mset(a,f)                                 memset(a,f,sizeof(a))
#define M                                         1000000007
#define Think_Twice_Code_Once                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)


bool J27 = 1;
#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(!J27)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7;
const long long INF = LLONG_MAX;
const int inf = INT_MAX;

int n, Q;
int arr[N+2];

void solve()
{
      cin >> n;
      lop(i,0,n) cin >> arr[i];

      vi vec(3, 0);

      int ans = 1;
      lop(i,0,n)
      {	
      	int val = 0, f = 0;
      	lop(j,0,3)
      	{
      		if( vec[j] == arr[i] )
      		{
      			if(!f) vec[j]++, f = 1;
      			val++;
      		}
      	}
      	ans *= val;
      	ans %= M;
      }

      cout << ans << endl;

}


int32_t main()
{

      J27 = 1;
      Think_Twice_Code_Once;
//      INP(); 
      int t = 1;
      //cin >> t;
      while(t--) solve();


}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 1024
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
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);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;


signed main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    vector< tuple<int, int, int> > elems;
    for(int i=0; i<N; i++) {
        cin >> A[i] >> B[i];
        elems.emplace_back(A[i] + B[i], -A[i], B[i]);
    }

    sort(elems.rbegin(), elems.rend());
    int ans = 0;
    for(int i=0; i<N; i++) {
        int sum, a, b; tie(sum, a, b) = elems[i];
        // fprintf(stderr, "%lld, %lld, %lld\n", sum, -a, b);
        if(i % 2 == 0) ans += -get<1>(elems[i]);
        else ans -= get<2>(elems[i]);
    }
    cout << ans << endl;
    return 0;
}


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



int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++){
        cin >> s.at(i);
       // cout << s.at(i) << endl;
    }
    
    sort (s.begin(), s.end());
    //for (int i = 0; i < n; i++) cout << s.at(i) << endl;
    vector<int> count(n);
    int check = 0;
    
    for (int i = 0; i < n; i++){
        if (i == 0){
            count.at(check) = 1;
        }else{
            if (s.at(i - 1) == s.at(i)){
                count.at(check)++;
            }else{
                check++;
                count.at(check)++;
            }
        }
    }
    
    int ans = 0;
    int countMax = 0;
    for (int i = 0; i < count.size(); i++){
        countMax = max(countMax, count.at(i));
    }
    
    for (int i = 0; i < count.size(); i ++){
        if (count.at(i) == countMax){
            cout << s.at(ans) << endl;
            ans += count.at(i);
        }else{
            ans += count.at(i);
        }
    }
    
}

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

int main(){
    long double a, b, c;
    cin >> a >> b >> c;

    long double eps = 1e-14;

    if ( sqrt(a) + sqrt(b) + eps < sqrt(c)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import collections

s = str(input())
t = str(input())
f = s + t
c = collections.Counter(f)
red = False
if len(c) == 1:
    if len(s) < len(t):
        red = True

for i in s:
    for k in t:
        if i < k:
            red = True
            break
if red:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
fun main(args: Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    val x = (1..n).map { readLine()!!.split(" ").map { it.toDouble() } }
    (0..n-1).map { i ->
        (i+1..n-1).count { j ->
            val m = Math.sqrt((0..d-1).sumByDouble { Math.pow(x[i][it]-x[j][it], 2.0) })
            m == Math.floor(m)
        }
    }.sum().let { println(it) }
}

Measured memory_bytes: 37748
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;

int main(){
  char s[81];
  int n=0;
  while(cin>>s){
    int p=1;
    for(int i=strlen(s)-1;i>=0;--i){
      if(isdigit(s[i])){
	n+=(s[i]-'0')*p;
	p*=10;
      }
      else p=1;
    }
  }
  cout<<n<<endl;
  return 0;
}

Measured memory_bytes: 1140
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    unsigned long long int x, y;
    int t, a;
    unsigned long long int p, q;
    scanf("%lld %lld", &x, &y);
    for (i = 1; i < n; i++)
    {
        scanf("%d %d", &t, &a);
        if (x%t > 0)
            x += t - (x%t);
        if (y%a > 0)
            y += a - (y%a);
        p = x / t;
        q = y / a;
        if (p < q)
            p = q;
        x = p * t;
        y = p * a;
    }
    printf("%lld\n", x + y);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int A; cin >> A;
    int a = A / 1000;
    int b = (A % 1000) / 100;
    int c = (A % 100) / 10;
    int d = A % 10;

    for (int bit = 0; bit < (1 << 3); ++bit) {
        int sum = a;
        char op1,op2,op3;
        rep(i,3){
            if (bit & (1 << i)) {
                if(i == 0){
                    sum += b;
                    op1 = '+';
                }
                if(i == 1){
                    sum += c;
                    op2 = '+';
                }
                if(i == 2){
                    sum += d;
                    op3 = '+';
                }
            }else{
                 if(i == 0){
                    sum -= b;
                    op1 = '-';
                }
                if(i == 1){
                    sum -= c;
                    op2 = '-';
                }
                if(i == 2){
                    sum -= d;
                    op3 = '-';
                }
            }
        }
        if(sum == 7){
            cout << a << op1 << b << op2 << c << op3 << d << '=' << 7 << endl;
            return 0;
        }else{
            sum = a;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int N,K;
    cin >> N >> K;
    char c;
    int cnt = 0;
    while( cin >> c ){
      cnt++;
      if(cnt==K){
        c = c + 0x20;
      }
      cout << c;
      if(cnt==N){
        break;
      }
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int n=s.length();
    for(int i=1; ; i++){
        s.erase(n-1,1); n--;
        if(n%2!=0)continue;
        if(s.substr(0,n/2)==s.substr(n/2,n)){
            cout<<s.length()<<endl; return 0;
        }
    }   
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }


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

	int N, A, B; cin >> N >> A >> B;
	vector<int>v(N);
	rep(i, 0, N)cin >> v[i];
	sort(all(v), greater<int>());
	double maxave(0.0);
	rep(i, 0, A)maxave += v[i];
	maxave /= A;

	int nCr[51][51];
	rep(i, 0, N + 1)rep(j, 0, i + 1) {
		if (j == 0 || j == i)nCr[i][j] = 1;
		else nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
	}

	int ans(0);
	if (v[0] == v[A - 1]) {
		int cnt = count(all(v), v[0]);
		rep(i, A, B + 1)ans += nCr[cnt][i];
	}
	else {
		int r(0);
		rep(i, 0, A)r += v[i] == v[A - 1];
		int n = count(v.begin(), v.end(), v[A - 1]);
		ans = nCr[n][r];
	}

	cout << fixed << setprecision(8) << maxave << endl << ans << endl;











	//vector<vector<map<int, int>>>dp(N + 1, vector<map<int, int>>(N + 1));

	//function<int(int, int, int)> dfs = [&](int n, int k, int s) {
	//	//dump(n, k, s);
	//	if (dp[n][k].count(s))return dp[n][k][s];

	//	if (n == N) {
	//		if (A <= k&&k <= B) {
	//			//dump(maxave - 1.0*s / k);
	//			//dump(abs(maxave - 1.0*s / k));
	//			//dump(1.0*s / k, maxave, (abs(maxave - 1.0*s / 1.0*k)));
	//			return dp[n][k][s] = (abs(maxave - 1.0*s / k) <= EPS);
	//		}
	//		else return dp[n][k][s] = 0;
	//	}
	//	int ret(0);
	//	ret += dfs(n + 1, k, s);

	//	ret += dfs(n + 1, k + 1, s + v[n]);

	//	return dp[n][k][s] = ret;
	//};

	//cout <<fixed<<setprecision(8)<< maxave << endl << dfs(0, 0, 0) << endl;












	//vector<vector<int>>dp(N + 1, vector<int>(N + 1, -INF));
	//dp[0][0] = 0;
	//rep(i, 0, N)rep(j, 0, i + 1) {
	//	chmax(dp[i + 1][j], dp[i][j]);
	//	chmax(dp[i + 1][j + 1], dp[i][j] + v[i + 1]);
	//}

	//map<double, int>m;
	//double mxx(-INF);
	//for (int i = A; i <= B; i++) {
	//	rep(j, 0, N + 1) {
	//		if (dp[j][i] != -INF) {
	//			m[(double)dp[j][i] / (double)i]++;
	//			chmax(mxx, (double)dp[j][i] / (double)i);
	//		}
	//	}
	//}
	//dump(m);
	//auto aaa = m.find(mxx);
	//cout <<fixed<<setprecision(8)<< aaa->first << endl << aaa->second << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> a(N), b(N), c(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    vec<vec<ll>> dp(4,vec<ll>(N+1,-1e9));
    dp[0][0] = 0;
    rep(i,N)rep(p,4){
        if(p!=1) dp[1][i+1] = max(dp[1][i+1],dp[p][i]+a[i]);
        if(p!=2) dp[2][i+1] = max(dp[2][i+1],dp[p][i]+b[i]);
        if(p!=3) dp[3][i+1] = max(dp[3][i+1],dp[p][i]+c[i]);
    }
    cout << max({dp[1][N],dp[2][N],dp[3][N]}) << '\n';
}


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

int main()
{
	int book,algo, goal;
	cin >> book >> algo >> goal;
	int money[book];
	int p[book][algo];
	rep(i, book)
	{
		cin >> money[i];
		rep(j,algo)
			cin >> p[i][j];
	}
	long ans = LONG_MAX;
	long cnt;
	for (int s = 0; s < (1<<book); s++)
	{
		vector<long> x(algo);
		long sum = 0;
		for (int i = 0; i < book; i++)
		{
			cnt = 0;
			if (s>>i&1)
			{
				sum += money[i];
				rep(j, algo)
				{
					x[j] += p[i][j];
					if (x[j] >= goal)
						cnt++;
				}
			}
			if (cnt == algo)
				ans = min(ans, sum);
		}
	}
	if (ans == LONG_MAX)
		cout << -1 << endl;
	else
		cout << ans << endl;
	return (0);
}


Measured memory_bytes: 3596
n=int(input())
hoge=list(map(int,input().split()))
i=0
ans=0
while 1:
  if(hoge[i]%2==0):
    ans+=1
    hoge[i]=hoge[i]/2
  else:
    if(i==n-1):
      print(ans)
      break
    else:
      i+=1


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

left = 0
right = 0

for i in range(N):
    if right == 0 and S[i] == ')':
        left += 1
    elif S[i] == '(':
        right += 1
    elif right > 0 and S[i] == ")":
        right -= 1
        
print("("*left + S + ")"*right)

Measured memory_bytes: 38384
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N+1):
    for g in range(N+1):
        num_box, amari = divmod(N-R*r-G*g, B)
        if num_box >= 0 and amari == 0:
            ans += 1
print(ans)

Measured memory_bytes: 67992
#include <stdio.h>

int main(void){
	int N;
	int red[100][3],blue[100][2];
	int i,j;
	
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d%d",&red[i][0],&red[i][1]);
	}
	for(i=0;i<N;i++){
		scanf("%d%d",&blue[i][0],&blue[i][1]);
	}
	for(i=0;i<N;i++){
		red[i][2]=0;
	}

	for(i=N-1;i>0;i--){
		for(j=0;j<i;j++){
			if(red[j][0]>red[j+1][0]){
				int x,y;
				x=red[j][0];
				y=red[j][1];
				red[j][0]=red[j+1][0];
				red[j][1]=red[j+1][1];
				red[j+1][0]=x;
				red[j+1][1]=y;
			}
		}
	}
	for(i=N-1;i>0;i--){
		for(j=0;j<i;j++){
			if(blue[j][0]>blue[j+1][0]){
				int x,y;
				x=blue[j][0];
				y=blue[j][1];
				blue[j][0]=blue[j+1][0];
				blue[j][1]=blue[j+1][1];
				blue[j+1][0]=x;
				blue[j+1][1]=y;
			}
		}
	}
	
	int memo[100][3];
	int list;
	int k;
	int tmp,pair;
	int count=0;
	for(i=0;i<N;i++){	//i:index of blue
		list=0;
		for(j=0;j<N;j++){// j:index of red
			if(red[j][2]==0){
				if(red[j][0]<blue[i][0] && red[j][1]<blue[i][1]){
					memo[list][0]=red[j][0];
					memo[list][1]=red[j][1];
					memo[list][2]=j;		//red no index
					list++;
				}
			}
		}
		
		if(list!=0){
			tmp=-1;
			for(k=0;k<list;k++){
				if(tmp<memo[k][1]){
					tmp=memo[k][1];
					pair=memo[k][2];
				}
			}
			red[pair][2]=1;		//1->paired		0->not pair
		}
	}
	
	
	for(i=0;i<N;i++){
		if(red[i][2]==1){
			count++;
		}
	}
	
	printf("%d",count);
	
	return 0;}

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

#define MAXN (200010)

int n, k, nowA;
char str[MAXN];
std::deque<int> dq;

int main(){
	scanf("%d%d%s", &n, &k, str);
	for(int i = 0; i < n; ++ i){
		dq.push_back(str[i] - 'A');
	}
	for(int i = 1; i <= (n << 1) && i <= k; ++ i){
		if(dq.front() == nowA){
			dq.pop_front();
			dq.push_front(nowA ^ 1);
		}
		else{
			dq.pop_front();
			nowA ^= 1;
			dq.push_back(nowA);
		}
	}
	if(k > (n << 1) && (n & 1) && ((k - (n << 1)) & 1)){
		if(dq.front() == nowA){
			dq.pop_front();
			dq.push_front(nowA ^ 1);
		}
		else{
			dq.pop_front();
			nowA ^= 1;
			dq.push_back(nowA);
		}
	}
	for(int v : dq){
	    putchar(v == nowA ? 'A' : 'B');
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long int

#define vi vector<int>
#define vll vector<long long int>
#define endl "\n"
#define enter cout << "\n" ;
#define For(x) for( int i=0; i<x; i++)
#define sortV(x) sort(x.begin(), x.end())
#define sortVr(x) sort(x.rbegin(), x.rend() )
#define sortA(x) sort(x, x+(sizeof(x)/sizeof(x[0])))
#define sortAr(x) sort(x, x+(sizeof(x)/sizeof(x[0])), greater<long long int> ())
#define asige(x) (sizeof(x)/sizeof(x[0]))
#define vsige(x) x.size()
#define pb push_back
#define ff first
#define ss second
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yess cout << "Yes" << endl
#define noo cout << "No" << endl


using namespace std;


void prntV(vector<long long int> v)
{
    cout << endl << endl << "vector size: " << v.size() << "  \nthe vector: " ;

    for(int i=0; i<v.size(); i++)
    {
        cout << v[i] << " ";
    }


    cout << endl << endl;
}

void prntA(ll a[])
{
    cout << endl << endl<< "size of the array: " << asige(a) << "\nthe array is: " ;

    for(ll i=0; i<asige(a); i++)
    {
        cout << a[i] << " ";
    }

    cout << endl << endl;
}


void solve()
{
    string s;
    cin >> s;
    if(s[0]>95) cout << "a";
    else cout << "A";


    return;
}





int main()
{
    //IOS;
    int tc=1;
    //cin >> tc;
    while(tc--)
    {
        solve();
        cout << endl;
        //solve1();
        //cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	string s;
	cin>>s;
	stack<char>ans;
	int n=s.size();
	rep(i,n){
		if(s[i]=='S'){
			ans.push(s[i]);
		}else if(ans.size()==0) {
			ans.push(s[i]);
		}
		else if(ans.top()=='S'){
			ans.pop();
		}else{
			ans.push(s[i]);
		}
	}
	cout<<ans.size()<<endl;
}

Measured memory_bytes: 644
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A.sort(reverse=True)
    n = max(A)
    med = n/2
    r = INF
    d = INF
    for a in A[1:]:
        if abs(a-med)<d:
            r = a
            d = abs(a-med)
    print(n,r)



if __name__ == '__main__':
    main()


Measured memory_bytes: 19152
a1, b1 = map(x->parse(Int, x), split(readline()))
a2, b2 = map(x->parse(Int, x), split(readline()))
a3, b3 = map(x->parse(Int, x), split(readline()))

x = zeros(Int, 4)
x[a1] += 1
x[a2] += 1
x[a3] += 1
x[b1] += 1
x[b2] += 1
x[b3] += 1

if maximum(x) == 3
    print("NO")
else
    print("YES")
end

Measured memory_bytes: 164328
#include <stdio.h>

struct stone{
	long id;
	long long num;
};

void quick(struct stone a[],long left,long right);

int main(){
	long n;
	long i,j;
	long long buf,sum,max;
	
	scanf("%ld",&n);
	struct stone a[n];
	long long s[n];
	
	for(i=0;i<n;i++){
		scanf("%lld",&buf);
		a[i].num = buf;
		a[i].id = i;
		s[i] = 0;
	}
	
	for(i=0,sum=0;i<n;i++){
		sum += a[i].num;
	}
	
	quick(a,0,n-1);
	
	long min = a[n-1].id;
	
	for(i=n-1;i>=0;i--){
		long long d;
		long tmp = a[i].id;
		
		if(i>0)	d = a[i].num - a[i-1].num;
		else d = a[i].num;
		
		if(min > tmp) min = tmp;
		
		a[i].num -= d;
		s[min] += (n-i)*d;
	}
		
	for(i=0;i<n;i++){
		printf("%lld\n",s[i]);
	}
	
	return 0;
}

void quick(struct stone a[],long left,long right){
	long i,j,p;
	long long pivot;
	
	i = left;
	j = right;
	
	pivot = a[(left+right)/2].num;
	p = a[(left+right)/2].id;
	
	while(1){
		while(a[i].num < pivot || (a[i].num==pivot && a[i].id < p)) i++;
		while(pivot < a[j].num || (a[j].num==pivot && p < a[j].id)) j--;
		if(i>=j) break;
		
		struct stone tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
		
		i++;
		j--;
	}
	
	if(left < i-1) quick(a,left,i-1);
	if(j+1 < right) quick(a,j+1,right);
}

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

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

using namespace std;

int main(void){
int n,z;
int h = -1;
int ans = 0;

cin >> n;
rep(i,n){
  cin >> z;
  if(h <= z){
    ans++;
    h = max(z, h);
  }
  }
cout << ans << endl;



return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>

#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    long double eps = 1.0E-14;
    if(sqrtl(a)+sqrtl(b) + eps< sqrtl(c)){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;
    //cout << sqrt(a) << endl;
    //cout << sqrt(b) << endl;
    //cout << sqrt(c) << endl;
    return 0;
}





Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int p[101];
int main(){
	int x,n,ans=1000,anss;
	cin>>x>>n;
	for(int i=0;i<n;i++)
	    cin>>p[i];
	for(int i=-1;i<=105;i++){
		bool f=true;
		for(int j=0;j<n;j++){
			if(i==p[j]){
				f=false;
				break;
			}
		}
		if(f&&abs(x-i)<ans){
			ans=abs(x-i);
			anss=i;
		}
	}
	cout<<anss;
	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    
    int x1;
    if(a>b){
        
        x1 = a;a--;
    }
    else{
        
        x1 = b;b--;
    }

    int x2;
    if(a>b){
        
        x2 = a;a--; 
    }
    else{
        
        x2 = b;b--;
    }
    int x;
    x = x1+x2;

    cout << x <<"\n";
}


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

int main(){
    int n, m;

    while(scanf("%d%d",&n,&m)==2){
        vector<pair<int, int> > v[n+1];

        for(int i=0; i<m; i++){
            int c, y;
            scanf("%d %d",&c,&y);

            v[c].push_back(make_pair(y,i));
        }

        pair<int, int>ans[m+1];

        for(int i=1; i<=n; i++){
            sort(v[i].begin(), v[i].end());

            for(int j=0; j<v[i].size(); j++){
                ans[v[i][j].second] = make_pair(i, j+1);
            }
        }

        for(int i=0; i<m; i++)
            printf("%06d%06d\n",ans[i].first, ans[i].second);
    }

    return 0;
}



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

int main() {
  int A, B;
  cin >> A >> B;
  if(A == B) cout << 0;
  else if((A + B) % 2 == 0)
    cout << (A + B) / 2;
  else
    cout << "IMPOSSIBLE";
}

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

int main()
{
int i;
int counter[26] = {0};
while (1) {
int c = getchar();
if (c == EOF) break;
c = tolower(c);
int num = c - 'a';  // 文字 ch の番号
if (0 <= num && num < 26) {
counter[num]++;
}
}
for (i = 0; i < 26; i++) {
printf("%c : %d\n", i +'a', counter[i]);
}
return 0;
}

Measured memory_bytes: 524
/*Author : Yuvraj Singh
 * Patience is Power
 * 
 * */
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
#define ar array
ll power(ll x,ll y) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return ((temp%mod)*(temp%mod))%mod; 
    else
        return ((x%mod)*(temp%mod)*(temp%mod))%mod; 
}

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}


bool cmp(pair<int,int>a,pair<int,int>b){
	return a.second<b.second;
}




void solve(){
	string s;
	cin>>s;
	int n=s.size();
	if(s[n-1]=='s')
		cout<<(s+"es");
	else
		cout<<(s+"s");

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	//int t; cin>>t;
	//while(t--)
		solve();
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
int main(void)
{
	int a,b,n;
	int i,j;
	int x,y;
	int suu[17][17];
	int kouji[17][17];
	
	scanf("%d %d",&a,&b);
	while(a!=0 || b!=0){
		for(i=1;i<=a;i++){
			for(j=1;j<=b;j++){
				kouji[i][j]=0;
			}
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&x,&y);
			kouji[x][y]=1;
		}
		for(i=1;i<=a;i++){
			for(j=1;j<=b;j++){
				if(i==1 && j==1){
					suu[i][j]=1;
				}
				else {
					if(kouji[i][j]==1){
						suu[i][j]=0;
					}
					else {
						if(i==1){
							suu[i][j]=suu[i][j-1];
						}
						else if(j==1){
							suu[i][j]=suu[i-1][j];
						}
						else {
							suu[i][j]=suu[i-1][j]+suu[i][j-1];
						}
					}
				}
			}
		}
		printf("%d\n",suu[a][b]);
		scanf("%d %d",&a,&b);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for(ll i=n-1;i>=a;i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fastread cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
#define online_judge

const ll MOD=1e9+7;

ll pow(ll n, ll e){
  if(e==0)
    return 1;
  else if(e==1)
    return n;
  else if(e%2==0)
    return pow(n,e/2)*pow(n,e/2);
  else
    return pow(n,e/2)*pow(n,e/2)*n;
}

bool prime(ll n){
  ll ct=0;
  rep(i,2,sqrt(n)+1){
    if(n%i==0)
      return false;
  }
  return true;
}

void solve(){
  fastread;
  ll n,m,temp,mi,q,ma=0,t;
  string s;
  getline(cin,s);
  int a[3];
  rep(i,0,3)
    a[i]=(s[i]=='R')?1:0;
  rep(i,1,3)
    if(a[i])
      a[i]+=a[i-1];
  cout << max(a[0], max(a[1], a[2]));
}

int main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
  #endif
  clock_t start, end;
  start = clock();
  solve();
  end=clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
    cerr << "Time taken by program is : " << fixed  
         << time_taken << setprecision(5); 
    cerr << " sec " << endl;
  return 0;
}

Measured memory_bytes: 3784