akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

signed main(){
  int N;cin>>N;
  vector<int> l(N),r(N);
  for(int i=0;i<N;i++)cin>>l[i]>>r[i];
  vector<P> q(N);
  for(int i=0;i<N;i++)q[i]=P(r[i],l[i]);
  //for(int i=0;i<N;i++)swap(q[i].first,q[i].second);
  sort(q.rbegin(),q.rend());
  //for(int i=0;i<N;i++)swap(q[i].first,q[i].second);
  int m=0;
  for(int i=0;i<N;i++)m=max(m,l[i]);
  int R=0;
  for(int i=0;i<N;i++)if(q[i].second==m)R=i;
  map<int,int> lm,rm;
  for(int i=0;i<N;i++){
    if(i==R)continue;
    lm[q[i].second]++;
    rm[q[i].first]++;
  }
  //お互いちっこいのはいらない　左に関しては大丈夫なので、右で決められる　右決めればそれより小さい右は全部受け取れる
  //１体それ以外の時だけは1がでかいそれが必要だから
  //cout<<R<<endl;
  //for(int i=0;i<N;i++)cout<<q[i].second<<" "<<q[i].first<<endl;
  int nowr=q[R].first,nowl=q[R].second;
  int ans=0;
  ans=max(rm.begin()->first-lm.rbegin()->first+1,0)+q[R].first-q[R].second+1;
  for(int i=0;i<N;i++){
    if(i==R)continue;
    //cout<<ans<<endl;
    lm[q[i].second]--;if(lm[q[i].second]==0)lm.erase(q[i].second);
    rm[q[i].first]--;if(rm[q[i].first]==0)rm.erase(q[i].first);
    if(lm.size()==0)continue;
    nowl=max(nowl,q[i].second);
    nowr=min(nowr,q[i].first);
    //cout<<rm.begin()->first<<" "<<lm.rbegin()->first<<" "<<nowr<<" "<<nowl<<endl;
    ans=max(ans,max(rm.begin()->first-lm.rbegin()->first+1,0)+max(nowr-nowl+1,0));
  }
  nowl=q[0].second,nowr=q[0].first;
  map<int,int> ll,rr;
  for(int i=0;i<N;i++){
    ll[l[i]]++;rr[r[i]]++;
  }
  for(int i=0;i<N;i++){
    int A=r[i]-l[i]+1;
    ll[l[i]]--;rr[r[i]]--;
    if(ll[l[i]]==0)ll.erase(l[i]);
    if(rr[r[i]]==0)rr.erase(r[i]);
    int B=max(rr.begin()->first-ll.rbegin()->first+1,0);
    ans=max(ans,A+B);
    ll[l[i]]++;rr[r[i]]++;
  }
  

  cout<<ans<<endl;
}


Measured memory_bytes: 13184
#include <stdio.h>
int main(){
  int A,B,C,K,x;
  scanf("%d %d %d %d",&A,&B,&C,&K);
  if(K<A){x=K;}
  else if(K>A+B){x=A-(K-(A+B));}
  else{x=A;}
  printf("%d",x);
  return 0;
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000 << endl;
	return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;


ll n,m,x[100001],y[100001],ve[100001];
//vector<pair<ll,ll>> v;

// int main()
// {
// 	cin>>n>>m;
// 	for (int i = 0; i < n; ++i)
// 	{
// 		cin>>x[i]>>u[i];
// 		v.push_back(make_pair(x[i]*u[i],i));
// 	}
// 	for (int i = 0; i < m; ++i)
// 	{
// 		cin>>y[i]>>ve[i];
// 		v.push_back(make_pair(y[i]*ve[i],i));
// 	}
// 	sort(v.begin(),v.end());
// 	ll cnt=0;
// 	for (int i = 0; i < v.size()-1; ++i)
// 	{
// 		while(v[i]==v[i+1] && i<v.size()-1)
// 		{
// 			i++;
// 			continue;
// 		}
// 		cnt++;
// 	}
// 	if(v[v.size()-2]!=v[v.size()-1])
// 		cnt++;
// 	cout<<cnt<<endl;
// }
// int gcd(int a,int b)
// {
// 	if(b==0)
// 		return a;
// 	else
// 		return gcd(b,b%a);
// }
// int main()
// {
// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
// 		cin>>m>>n;
// 		if(__gcd(m,n)==1)
// 			cout<<"NO"<<endl;
// 		else
// 			cout<<"YES"<<endl;
// 	}
// 	return 0;
// }
// int main()
// {
// 	ll t,a;
// 	cin>>t;
// 	vector<ll>v;
// 	string s,prev;
// 	ll ans[100001],fin=0,pre[100001],d;
// 	//std::vector<ll>::iterator upper1, upper2; 
// 	while(t--)
// 	{
// 		memset(pre,0,sizeof(pre));
// 		memset(ans,0,sizeof(ans));
// 		fin=0;
// 		cin>>n>>d;
// 		cin>>s;
// 		pre[0]=1;
// 		prev=s;
// 		for (int i = 1; i < n; ++i)
// 		{
// 			cin>>s;
// 			if(s!=prev)
// 				pre[i]=pre[i-1]+1;
// 			else
// 				pre[i]=pre[i-1];
// 			prev=s;
// 		}
// 		for (int i = 0; i < n; ++i)
// 		{
// 			if(i-d+1<0)
// 				ans[i]=pre[i]-pre[0];
// 			else
// 				ans[i]=pre[i]-pre[i-d+1];
// 			cout<<ans[i]<<endl;
// 			fin=max(fin,ans[i]);
// 		}
// 		cout<<fin+1<<endl;
// 	}
// }

ll dp[100011][3];
vector<ll> adj[100011];
ll solve(ll v, ll c, ll p)
{
	if(dp[v][c]!=-1)
		return dp[v][c];
	ll tot=1;
	for (int i = 0; i < adj[v].size(); ++i)
	{
		ll u=adj[v][i];
		if(u==p)
			continue;
		if(c==0)
			tot=(tot*(solve(u,0,v)+solve(u,1,v)%mod))%mod;
		else
			tot=(tot*solve(u,0,v))%mod;
	}
	return dp[v][c]=tot;
}

int main()
{
	ll n,u,v;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for (int i = 1; i < n ; ++i)
	{
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	ll ans=(solve(1,0,-1)+solve(1,1,-1))%mod;
	cout<<ans<<endl;
}



Measured memory_bytes: 17792
//解説AC
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef long long ll;

int main(){
ll N,Q; cin >> N >> Q;
  
  vector<pair<ll,pair<ll,ll>>>v;
  //挿入を-1,クエリを0,削除を1とする
  for(ll i = 0; i < N; i++){
    ll s,t,x; cin >> s >> t >> x;
    v.push_back(make_pair(s-x,make_pair(-1,x)));
    v.push_back(make_pair(t-x,make_pair(0,x)));
  }
  
  for(ll j = 0; j < Q; j++){
    ll d; cin >> d;
    v.push_back(make_pair(d,make_pair(1,j)));} 
  
  sort(v.begin(),v.end());
  
  multiset<ll> se;
  vector<ll> answer(Q);
  
  sort(v.begin(),v.end());
  
  for(auto ne : v){ 
    ll p = ne.first;
    ll q = ne.second.first;
    ll r = ne.second.second;
    
    if( q == -1){//挿入
      se.insert(r);}
    else if( q == 0){//削除
      se.erase(se.lower_bound(r));}
    else{// クエリ　seがすでに空だったら-1をres[r]に入れないといけない
       if( se.empty()){
         answer[r] = -1;}
      else{
        answer[r] = *(se.begin());}
  }
  }
  
  for(ll k = 0; k < Q; k++){
    cout << answer[k] << endl;}
    
    return 0;}
  


Measured memory_bytes: 27620
#include<stdio.h>
#define EPS 1e-8
int main(){
	int l[10];
	int v1,v2;
	int i;
	while(~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
						&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2)){
		int sum=0;
		double t;
		for(i=0;i<10;i++){
			sum+=l[i];
		}
		t = (double)sum/(v1+v2);
		sum=0;
		for(i=0;i<10;i++){
			sum+=l[i];
			if(t*v1-sum<EPS){
				printf("%d\n",i+1);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  string s1;
  istringstream ss1;
  int p1;

  //string >> int
  cin >> s1;

  for(int i = 0; i < s1.length(); i++){
    if(s1[i] == '1'){
      s1[i] = '9';
    }else if(s1[i] == '9'){
      s1[i] = '1';
    }
  }

  // ss1 = istringstream(s1);
  // ss1 >> p1;

  cout  << s1 << endl;
}


Measured memory_bytes: 256
#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 <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	int X,Y,A,B,C;
	
	priority_queue<int, vector<int>, greater<int>> eat;
	cin>>X>>Y>>A>>B>>C;
	vector<int>red(A),green(B),trans(C);
	rep(i,A)cin>>red[i];
	rep(i,B)cin>>green[i];
	rep(i,C)cin>>trans[i];
	sort(all(red),greater<int>());
	sort(all(green),greater<int>());
	sort(all(trans),greater<int>());
	rep(i,X){
		eat.push(red[i]);
	}
	rep(i,Y){
		eat.push(green[i]);
	}
	rep(i,C){
		if(eat.top()<trans[i]){
			eat.pop();
			eat.push(trans[i]);
		}else{
			break;
		}
	}
	ll maxutility=0;
	while(eat.size()){
		maxutility+=eat.top();
		eat.pop();
	}
	cout<<maxutility<<endl;
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 2552
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

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

#define F first
#define S second
#define ii pair<int,int>

typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl pi = acos(-1);
const ll inf = 1LL<<60;
const dbl eps = 1e-9;
const ll mod = 1e9+7;

/** /////////// ** Code ** /////////// **/

const int N=5050;
int p[N];
ll a[N];

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1 ; i<=n ; i++)
        scanf("%d",&p[i]);

    for(int i=1 ; i<=n ; i++)
        scanf("%lld",&a[i]);

    ll ans=-inf;

    for(int i=1 ; i<=n ; i++){
        ll mx=a[i];
        ll sum=0;
        int j=i;
        int sz=0;

        do{
            sum+=a[j];
            sz++;
            j=p[j];
        }while(j != i);

        ll rep=k/sz;
        ll m=k%sz;

        if(rep){
            rep--;
            m+=sz;
        }

        if(rep)
            mx=max(mx, sum*rep);

        ll sum1=0;
        while(m--){
            sum1+=a[j];
            mx=max(mx, sum*rep+sum1);
            mx=max(mx, sum1);
            j=p[j];
        }

        ans=max(ans, mx);

    }
    printf("%lld\n",ans);
}


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

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;

  vector<P> A(N);
  vector<int> B(N);


  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    A.at(i) = P(a, i);
  }

  sort(A.begin(), A.end());

  int p = A.at(N/2-1).first;
  int q = A.at(N/2).first;

  for(int i=0;i<N;i++){
    if(i < N/2){
      B.at(A.at(i).second) = q;
    }else{
      B.at(A.at(i).second) = p;
    }
  }

  for(int i=0;i<N;i++){
    cout << B.at(i) << endl;
  }
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 2e5 + 5;

int n, k, a[N];

const ll mo = 23333333333333333;

ll mul(ll x, ll y) {
	ll z = (long double) x * y / mo;
	z = x * y - z * mo;
	if(z < 0) z += mo; else if(z >= mo) z -= mo;
	return z;
}

const ll w = 19260817;

ll aw[N];

ll p[N], q[N];

int t[N * 4]; ll h[N * 4];
#define i0 i + i
#define i1 i + i + 1
int pl, pr, px;
void upd(int i) {
	h[i] = (h[i0] + mul(h[i1], aw[t[i0]])) % mo;
	t[i] = t[i0] + t[i1];
}
void add(int i, int x, int y) {
	if(x == y) {
		t[i] += px;
		h[i] = !t[i] ? 0 : x;
		return;
	}
	int m = x + y >> 1;
	if(pl <= m) add(i0, x, m); else add(i1, m + 1, y);
	upd(i);
}

map<ll, int> bz;

int main() {
	scanf("%d %d", &n, &k);
	fo(i, 1, n) scanf("%d", &a[i]);
	aw[0] = 1; fo(i, 1, n) aw[i] = mul(aw[i - 1], w);
	fo(i, 1, n) p[i] = (p[i - 1] + mul(aw[i], a[i])) % mo;
	fd(i, n, 1) q[i] = (q[i + 1] + mul(aw[i], a[i])) % mo;
	fo(i, 1, k - 1) {
		px = 1; pl = pr = a[i];
		add(1, 0, n);
	}
	fo(i, 1, n - k + 1) {
		if(i != 1) pl = pr = a[i - 1], px = -1, add(1, 0, n);
		pl = pr = a[i + k - 1]; px = 1; add(1, 0, n);
		ll ha = p[i - 1] + q[i + k];
		ha = (ha + mul(aw[i], h[1])) % mo;
		bz[ha] = 1;
	}
	pp("%d", bz.size());
}


Measured memory_bytes: 27520
n,q=map(int,input().split())
ab=[[int(i) for i in input().split()] for j in range(n-1)]
px=[[int(i) for i in input().split()] for j in range(q)]

graph=[[] for i in range(n+1)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
    
value=[0]*(n+1)

for p,x in px:
    value[p]+=x
    
q=[(0,1)]
while q:
    parent,child = q.pop()
    value[child]+=value[parent]
    for i in graph[child]:
        if i==parent:
            continue
        q.append((child,i))
ans=' '.join(map(str,value[1:]))
print(ans)
    

Measured memory_bytes: 124236
#include <stdio.h>
#define MAX 100
void insertionSort(int *,int);
void printData(int *,int);
int main(void){
	int i,n;
	int a[MAX];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	printData(a,n);
	insertionSort(a,n);

	return 0;
}
void insertionSort(int *a,int n){
	int i,j,v;
	
	for(i=1;i<n;i++){
		v=a[i];
		j=i-1;
		while(j>=0){
			if(v<a[j]){
				a[j+1]=a[j];
				j--;
			}
			else{
				break;
			}
		}
        a[j+1]=v;
		printData(a,n);
	}
}

void printData(int *a,int n){
	int i;
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if(i<n-1){
			printf(" ");
		}
	}
	printf("\n");
}

Measured memory_bytes: 1780
n, m = map(int, input().split())
source_list = []
for i in range(m):
    instr = input()
    source_list_mini = []
    source_list_mini.append(instr.split(" ")[0])
    source_list_mini.append(instr.split(" ")[1])
    source_list.append(source_list_mini)

finish_dic = {}
pena_count_dic = {}
for source in source_list:
    pena_count_dic[source[0]] = 0
    finish_dic[source[0]] = False

for source in source_list:
    if source[1] == "AC":
        finish_dic[source[0]] = True
    else:
        if finish_dic[source[0]] == False:
            pena_count_dic[source[0]] += 1
        
ans_count = 0
for flag in finish_dic.values():
    if flag == True:
        ans_count += 1

pena_count = 0
for pro_num, pena in pena_count_dic.items():
    if finish_dic[pro_num] == True:
        pena_count += pena
     
print(ans_count, pena_count)


Measured memory_bytes: 41632
import java.util.Scanner;

 class Main {

    static class Elem{
        int val;
        int index;

        public Elem(int val, int index) {
            this.val = val;
            this.index = index;
        }
    }

    public static void heapify(Elem[] heap, int index, int n){
        int left=index*2+1;
        int right = index*2+2;

        int max=index;
        if(left < n && heap[left].val >= heap[max].val){
            max=left;
        }
        if(right<n && heap[right].val >= heap[max].val){
            max=right;
        }
        if(max!=index){
            Elem temp = heap[index];
            heap[index]=heap[max];
            heap[max]=temp;
            heapify(heap, max, n);
        }

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++)
            a[i]=in.nextInt();

        Elem[] heap =new Elem[n];

        for(int i=0;i<n;i++){
            heap[i]=new Elem(a[i],i);
        }

        for(int i=n/2;i>=0;i--){
            heapify(heap, i,n);
        }
//        for(int i=0;i<n;i++){
//            System.out.println(heap[i].val + " " + heap[i].index);
//        }

        int[] ans = new int[n];
        for(int i=0;i<n;i++){
            if(heap[0].index!=i){
                ans[i]=heap[0].val;
            }
            else{
                if(n>=3){
                    ans[i]=Math.max(heap[1].val, heap[2].val);
                }
                else
                    if(n==2){
                    ans[i]=heap[1].val;
                    }
            }
        }
        for(int i=0;i<n;i++){
            System.out.println(ans[i]);
        }

    }
}


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

using namespace std;

typedef long long ll;

const int N = 17;
const ll INF = 1e16 + 69;
const int M = (1 << 15) + 5;

int n;
ll x[N], y[N], p[N], f[N][M], cost[M];

ll get (vector <pair <ll, ll>> vec) {
  if (vec.empty()) return 0;
  sort(vec.begin(), vec.end());
  ll tot = 0, cur = 0, pt = -1;
  for (auto it : vec) tot += it.second;
  for (auto it : vec) {
    cur += it.second;
    if (cur + cur >= tot) {
      pt = it.first;
      break;
    }
  }
  ll ret = 0;
  for (auto it : vec) ret += it.second * abs(pt - it.first);
  return ret;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> p[i];
  }
  for (int mask = 0; mask < 1 << n; ++mask) {
    vector <pair <ll, ll>> one, two;
    for (int i = 0; i < n; ++i) if (mask & 1 << i) {
      one.emplace_back(x[i], p[i]);
      two.emplace_back(y[i], p[i]);
    }
    cost[mask] = min(get(one), get(two));
  }
  for (int mask = 0; mask < 1 << n; ++mask) {
    for (int i = 0; i < n; ++i) if (mask & 1 << i) {
      f[0][mask] += p[i] * min(abs(x[i]), abs(y[i]));
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int mask = 1; mask < 1 << n; ++mask) {
      f[i][mask] = INF;
      for (int sub = mask; sub; sub = (sub - 1) & mask) {
        f[i][mask] = min(f[i][mask], cost[sub] + f[i - 1][mask ^ sub]);
      }
    }
  }
  for (int i = 0; i <= n; ++i) cout << f[i][(1 << n) - 1] << '\n';
  return 0;
}



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

int main() {
  int N;
  int P=0, W=0, G=0, Y=0;
  cin >> N;

  while(N){
    string type;
    cin >> type;
    
    if (type == "P")
      P++;
    else if(type == "W")
      W++;
    else if(type == "G")
      G++;
    else if(type == "Y")
      Y++;
      
    N--;
  }
  if(P&&W&&G&&Y)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i, j, N, A[101], swap=0, n;

  scanf("%d", &N);
  for(i=0;i<N;i++){
    scanf("%d", &A[i]);
  }

  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
	n = A[j];
	A[j] = A[j-1];
	A[j-1] = n;
	swap++;
      }
    }
  }

  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", swap);

  return 0;
}

Measured memory_bytes: 604
(print (let* ((n (read))
		(vec (make-array (1+ n) :initial-element nil)))
	   (setf (svref vec 1) 1)
	   (do ((i 2 (1+ i)))
	       ((> i n))
	     (do ((j (* i i) (* i j)))
		 ((> j n))
	       (setf (svref vec j) j)))
	   (find-if #'numberp vec :from-end t)))

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

int main(){
    

    int W, H;

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

        for(int h=0; h<H; h++){
            for(int w=0; w<W; w++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2060
#include<iostream>

using namespace std;

int main(){
	int a, b, a_nums[3000], b_nums[3000];
	for (int i = 0; i < 10000; i++){
		cin >> a >> b;
		if (a == 0 && b == 0){
			break;
		}
		if (a > b){
			cout << b << " " << a << endl;
		}
		if (b >= a){
			cout << a << " " << b << endl;
		}
	}
}


Measured memory_bytes: 3012
#include <iostream>
#include  <stdio.h>
#include  <algorithm>
#include  <math.h>
#include  <vector>
#include  <string>
#include  <sstream>
#include  <numeric>
#include  <set>
#include <map>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long

using namespace std;

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

	int n = 0, m = 0; 
	while (cin >> n >> m && n != 0 && m != 0)
	{
		vector<int> a(n, 0), b(m, 0);
		vector<int> at(n, 0), bt(m, 0);
		rep(i, n) { cin >> a[i]; }
		rep(i, m) { cin >> b[i]; }
		int ans_a = 5690823, ans_b = 5690823;
		rep(i, n) rep(j, m)
		{
			int tmp = 0, tmp2 = 0;
			tmp = accumulate(all(a), 0) - a[i] + b[j];
			tmp2 = accumulate(all(b), 0) - b[j] + a[i];
			if (tmp == tmp2)
			{
				ans_a = min(a[i], ans_a); ans_b = min(b[j], ans_b);
			}
		}
		if (ans_a == 5690823 && ans_b == 5690823) { printf("-1\n");}
		else { printf("%d %d\n", ans_a, ans_b); }
	}
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;

string S;
int N;
void input(){
  cin>>S;
  N=sz(S);
}

vi cr, cl;
int ans[MAX];
void solve(){
  bool nowr=true;
  int ct=1;
  rep1(i,N-1){
    if(nowr){
      if(S[i]=='R'){
        ct++;
      }
      else {
        cr.pb(ct);
        ct=1;
        nowr=false;
      }
    }
    else{
      if(S[i]=='L'){
        ct++;
      }
      else{
        cl.pb(ct);
        ct=1;
        nowr=true;
      }
    }
  }
  cl.pb(ct);

  int tmp=-1;
  rep(i,sz(cr)){
    int br=tmp+cr[i];
    int ntmp=tmp+cr[i]+cl[i];
    int cto, cte;
    if((cr[i]+cl[i])%2==0){
      cto=(cr[i]+cl[i])/2;
      cte=(cr[i]+cl[i])/2;
    }
    else if((tmp+1)%2==1){
      cto=(cr[i]+cl[i])/2+1;
      cte=(cr[i]+cl[i])/2;
    }
    else{
      cto=(cr[i]+cl[i])/2;
      cte=(cr[i]+cl[i])/2+1;
    }
    tmp=ntmp;

    if(br%2==0){
      ans[br]=cte;
      ans[br+1]=cto;
    }
    else{
      ans[br]=cto;
      ans[br+1]=cte;
    }
  }

}

void output(){
  rep(i,N)cout<<ans[i]<<" ";
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 1532
N = int(input())
five = 0
i = 0
if N % 2 == 1:
    print(0)
else:
    while True:
        i += 1
        if 2 * (5 ** i) > N:
            break
        else:
            five += N // (2 * (5**i))
if N %2 != 1:
    print(five)

Measured memory_bytes: 2940
using System;

namespace abc159_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] mn = Console.ReadLine().Split(" ");
            int n = int.Parse(mn[0]);
            int m = int.Parse(mn[1]);

            int sum = 0;
            if(n > 1)
            {
                sum += n * (n - 1) / 2;
            }

            if(m > 1)
            {
                sum += m * (m - 1) / 2;
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 27252
/*  ex6_2
    kosaq       */

#include <stdio.h>
#include <string.h>
#define SIZE 101//十分な要素数

int main(void){
    char string_s[SIZE];//入力に使う文字列を定義
    int number_total;//全文字数を定義

    scanf("%s", string_s);//文字列を入力

    number_total = strlen(string_s);//全文字数は入力された文字列の長さに等しい

    printf("%c%d%c\n", string_s[0], number_total - 2, string_s[number_total - 1]);
    //string_s[0]は先頭の文字を出力、number_total - 2は間の文字数を出力、string_s[number - 1]は最後の文字を出力
    return 0;
}

Measured memory_bytes: 128
#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>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

ll dp[101][100005];
vector<ll>w,v;
int n,W;

ll rec(int i,int j){
  if(dp[i][j]>=0)return dp[i][j];
  ll res;
  if(i==n)res=0;
  else if(j<w[i])res=rec(i+1,j);
  else res=max(rec(i+1,j),rec(i+1,j-w[i])+v[i]);
  return dp[i][j]=res;
}
 
 
int main(){
    cin>>n>>W;
    w.resize(n);v.resize(n);
    memset(dp,-1,sizeof(dp));
    rep(i,n)cin>>w[i]>>v[i];
    cout<<rec(0,W)<<endl;
    return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int main(){
int N,M;
cin>>N>>M;
vector<int>oks(N+1,true);
for(int i=0;i<M;++i){
int a;cin>>a;
oks[a]=false;
}
vector<long long int>dp(N+1);
dp[0]=1;
for(int now=0;now<N;++now){
for(int next=now+1;next<=min(N,now+2);++next){
if(oks[next]){
dp[next]+=dp[now];
dp[next]%=mod;
}
}
}
cout<<dp[N]<<endl;
return 0;
}

Measured memory_bytes: 1408
N, M = gets.split.map(&:to_i)
S, C = [], []
M.times do |i|
  S[i], C[i] = gets.split.map(&:to_i)
end

result = Array.new N 

M.times do |i|
  s = S[i] - 1
  c = C[i]

  if result[s] && result[s] != c 
    puts -1
    exit
  end
  result[s] = c
end

str = ""
result.each_with_index do |r, i|
  if r 
    str += r.to_s
  else
    if i == 0 && result.length > 1
      str += "1"
    else
      str += "0"
    end
  end
end

if str[0] == "0" && str.length > 1
  puts -1
else
  puts str
end

Measured memory_bytes: 1788
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (line)
  (let ((size (length (remove-duplicates line))))
    (if (oddp size)
        size
        (1- size))))

(princ (main (read-times (read))))


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

int main(){
  vector<int> a(4);
  string b;
  cin >> b;
  a[0] = b[0] - '0';
  a[1] = b[1] - '0';
  a[2] = b[2] - '0';
  a[3] = b[3] - '0';
  int n = 4;
  for (int bit; bit < (1 << n); ++bit){
    vector<char> A{'-', '-', '-'};
    rep(i, n){
      if (bit & (1 << i)) {
        A[i] = '+';
      }
    }
    int sum = a[0];
    rep(i, 3){
      if (A[i] == '-') sum -= a[i+1];
      if (A[i] == '+') sum += a[i+1];
    }
    
    if (sum == 7){
      rep(i, 3){
        cout << a[i] << A[i];
      }
      cout << a[3] << "=7" << endl;
      break;
    }
  }
}

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

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int MAX = 12;
	boolean[][] map = new boolean[MAX+2][MAX+2];
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;sc.hasNext();) {
			for(boolean[] a: map) fill(a, false);
			for(int i=1;i<=MAX;i++) {
				String str = sc.next();
				for(int j=1;j<=MAX;j++) map[i][j] = str.charAt(j-1) == '1';
			}
			int cnt = 0;
			for(int i=1;i<=MAX;i++) for(int j=1;j<=MAX;j++) if(map[i][j]) {
				cnt++; dfs(j, i);
			}
			System.out.println(cnt);
		}
	}
	int[] dx = {-1,0,1,0}, dy = {0,-1,0,1};
	void dfs(int x, int y) {
		map[y][x] = false;
		for(int i=0;i<4;i++) if(map[y+dy[i]][x+dx[i]]) dfs(x+dx[i], y+dy[i]);
	}

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

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

Measured memory_bytes: 17160
count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = sli[len(sli) - 1]
pair_b = 0
current_max = 0

i = sli[len(sli) - 1]

diff = 10**9
for j in range(0, len(sli) - 1):
    h = pair_a / 2
    if abs(h - sli[j]) < diff:
        diff = abs(h - sli[j])
        pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))


Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int MOD = 1e9 + 7;
int Path(vector< vector< char > >  &grid,int h,int w)
{
     vector< vector< int > > DP(h+1,vector< int > (w+1,0));
     DP[1][0] = 1;
     for(int i=1;i<h+1;i++){
          for(int j=1;j<w+1;j++){
               if(grid[i-1][j-1] == '.'){
                    DP[i][j] = (DP[i-1][j]%MOD + DP[i][j-1]%MOD)%MOD;
               }
               //cout << DP[i][j] << ' ';
          }
          //cout << endl;
     }
     return DP[h][w];
}
int main()
{
     //freopen("in.txt","r",stdin);
    int h,w;
    cin >> h >> w;
    vector< vector< char > >  grid(h,vector< char >(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> grid[i][j];
        }
    }
    int path = Path(grid,h,w);
     cout << path << endl;
}


Measured memory_bytes: 5248
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
nums=[0]*(10**5)
for q in a:
  nums[q-1]+=1
# N(10**5)
  
q=int(input())
bc=[]
# N(10**5)
for _ in range(q):
  b,c=map(int,input().split())
  b-=1
  c-=1
  bc.append((b,c))
  
# N(10**5)
for b,c in bc:
  ans-=(b+1)*nums[b]
  ans+=(c+1)*nums[b]
  print(ans)
  nums[c]+=nums[b]
  nums[b]=0


Measured memory_bytes: 89072
import java.util.Scanner;
import java.util.Stack;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("[\\s]+");
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            double[] x = new double[4];
            double[] y = new double[4];
            for (int j = 0; j < 4; j++) {
                x[j] = sc.nextDouble();
                y[j] = sc.nextDouble();
            }
            boolean b = Math.abs((x[1] - x[0]) * (y[3] - y[2]) - (x[3] - x[2]) * (y[1] - y[0])) < 1e-10;
            System.out.println(b ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 30560
#include<bits/stdc++.h>
using namespace std;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}int n,a[1000000],x,d;
int main(){
	n=read();for (int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+1+n);d=n;while (a[d]!=a[d-1]&&d>0)d--;
	x=a[d-1];d-=2;while (a[d]!=a[d-1]&&d>0)d--;if (d==0)puts("0");else cout<<1ll*a[d]*x<<endl;
}


Measured memory_bytes: 640
N = int(input())
Hlist = list(map(int, input().split()))
ans = 0
c = 0
now = Hlist[0]
for next_step in Hlist[1:]:
    if next_step <= now:
        c += 1
    else:
        ans = max(ans, c)
        c = 0
    now = next_step
ans = max(ans, c)

print(ans)


Measured memory_bytes: 14252
using System;

class C
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

		int r = 0, m = n + 1;
		for (int i = 0; i < n; i++)
			if (p[i] <= (m = Math.Min(m, p[i]))) r++;
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 31068
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

const int MOD=1000000007;
int n;
int X,Y,Z;
int encode(const deque<int> &a) {
    int ret=0;
    FORE(x,a) {
        ret<<=x;
        ret|=1<<(x-1);
    }
    return ret;
}
deque<int> decode(int x) {
    deque<int> ret;
    int cnt=0;
    REP(i,18) {
        if((x>>i)&1) {
            ret.push_front(cnt+1);
            cnt=0;
        } else {
            cnt++;
        }
    }
    return ret;
}
int dp[41][1<<18];
int rec(int i,int sum) {
    if(dp[i][sum]!=INF) return dp[i][sum];

    deque<int> a=decode(sum);
    int s=0;
    int state=0;
    REP(x,SZ(a)) {
        s+=a[x];
        if(state==0 && s==X) state++;
        if(state==1 && s==X+Y) state++;
        if(state==2 && s==X+Y+Z) state++;
    }
    if(state==3) return dp[i][sum]=0;
    if(i==n) return dp[i][sum]=1;

    int bit=encode(a);
    int ret=0;
    REPF(x,1,11) {
        int next=bit;
        next<<=x;
        next|=1<<(x-1);
        int t=s+x;
        int len=32-__builtin_clz(next);
        while(len>X+Y+Z) {
            next^=1<<(len-1);
            len=32-__builtin_clz(next);
        }
        ret+=rec(i+1,next);
        ret%=MOD;
    }
    return dp[i][sum]=ret;
}
signed main() {
    REP(i,41) REP(j,1<<18) dp[i][j]=INF;

    cin>>n>>X>>Y>>Z;
    int ans=1;
    REP(i,n) (ans*=10)%=MOD;
    cout<<(ans+MOD-rec(0,0))%MOD<<endl;
    return 0;
}



Measured memory_bytes: 84352
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll h,w,n,x=0,y=0;
  bool prev=true;
  cin >> h >> w >> n;
  ll a[n];
  ll grid[h][w];
  P v;
  v.first = v.second = 0;
  queue<P> que;
  for(int i=0;i<n;i++){
    cin >> a[i];
    que.push(P(i+1,a[i]));
  }
  for(int i=0;i<h*w;i++){
    if(v.second==0){
      v = que.front();
      que.pop();
    }
    v.second--;
    grid[y][x] = v.first;
    if((x==w-1 || x == 0)&&!prev){
      y++;
      prev = true;
    }else{
      if(y%2==0) x++;
      else x--;
      prev = false;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << grid[i][j]<<" ";
    }
    cout << endl;
  }
}


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

int main(){
    while(1){
        string s;
        getline(cin, s);
        if(s == "0") return 0;

        int n = s.size();
        int sum = 0;
        int cnt1 = 0;
        for(int i=0; i<n; i++){
            string t = "";
            while(i < n && '0' <= s[i] && s[i] <= '9'){
                t += s[i];
                i++;
            }
            int num = stoi(t);
            if(10 <= num) sum += 10;
            else if(1 < num) sum += num;
            else{
                cnt1++;
                sum++;
            }
        }

        vector<int> v;
        v.emplace_back(sum);

        for(int i=1; i<=cnt1; i++){
            sum += 10;
            v.emplace_back(sum);
        }

        sort(v.begin(), v.end(), greater<int>());

        bool valid = false;
        for(auto i : v){
            if(21 >= i){
                cout << i << endl;
                valid = true;
                break;
            }
        }

        if(!valid){
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3132
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

template <typename T>
bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    rep(count_num,n){
        string x,y;
        cin>>x>>y;
        int s=x.size(),t=y.size();
        vector<vector<int>> dp(s+1,vector<int>(t+1,-1));
        dp[0][0]=0;
        rep(i,s+1)rep(j,t+1){
            if(i+j==0) continue;
            if(i>0) chmax(dp[i][j],dp[i-1][j]);
            if(j>0) chmax(dp[i][j],dp[i][j-1]);
            if(i*j>0 && x[i-1]==y[j-1]) chmax(dp[i][j],dp[i-1][j-1]+1);
        }
        cout<<dp[s][t]<<'\n';
    }
}


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

int main() {
    std::string S, T;
    std::cin >> S >> T;

    if (S == T.substr(0, T.size() - 1)) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl; 
    }

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int n, k;
	int hash[105];
	memset(hash, 0, sizeof(hash));
	cin >> n >> k;
	
	for (int i = 1; i <= k; i++){
		int d;
		cin >> d;
		for (int j = 1; j <= d; j++){
			int x;
			cin >> x;
			hash[x] = 1;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++){
		cnt += hash[i];
	}
	cout << n - cnt << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll ans=0;
  string S;
  cin >> S;
  ll G=0,P=0;
  rep(i,S.size()){
    if(S[i]=='g'){
      if(G>P){
        P++;
        ans++;
      }
      else{
        G++;
      }
    }
    else{
      if(G>P){
        P++;
      }
      else{
        G++;
        ans--;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 

int main(){
  ll n;cin>>n;
  vector<string>p(n);
  rep(i,n)
  {
    cin>>p.at(i);
  }
  sort(p.begin(),p.end());
  ll cnt=1;
  ll k=1;
  for(int i=1;i<n;i++)
  {
    if(p.at(i)==p.at(i-1))
    {
      k++;
    }
    else
    {
      cnt=max(cnt,k);
      k=1;
    }
    if(i==n-1)
    {
      cnt=max(cnt,k);
    }
  }
  k=1;
    for(int i=1;i<n;i++)
  {
      if(cnt==1 && i==1)
        cout<<p.at(0)<<endl;
      if(p.at(i)==p.at(i-1))
    {
      k++;
    }
      else
    {
      k=1;
    }
      if(k==cnt)
    {
      cout<<p.at(i)<<endl;
    }
    }
}
  
    
    
  


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e5+5;
const long long inf=0x3f3f3f3f;
long long n;
long long a[maxn],ans;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin>>n;
    for(long long i=1;i<=n;i++)
    	cin>>a[i];
    sort(a+1,a+n+1);
    for(long long i=1;i<=n;i++)
    {
    	for(long long j=i+1;j<=n;j++)
    	{
    		for(long long k=j+1;k<=n;k++)
    		{
    			if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k])
    				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0; i<H; i++){
    cin >> S.at(i);
  }
  vector<vector<int>> U(H,vector<int>(W,0)),D(H,vector<int>(W,0)),
                      L(H,vector<int>(W,0)),R(H,vector<int>(W,0)),
                      P(H,vector<int>(W,0));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(i==0&&S.at(i).at(j)!='#'){
        U.at(i).at(j)=1;
      }
      else if(S.at(i).at(j)!='#'){
        U.at(i).at(j)=U.at(i-1).at(j)+1;
      }
      if(j==0&&S.at(i).at(j)!='#'){
        L.at(i).at(j)=1;
      }
      else if(S.at(i).at(j)!='#'){
        L.at(i).at(j)=L.at(i).at(j-1)+1;
      }
    }
  }
  for(int i=H-1; i>=0; i--){
    for(int j=W-1; j>=0; j--){
      if(i==H-1&&S.at(i).at(j)!='#'){
        D.at(i).at(j)=1;
      }
      else if(S.at(i).at(j)!='#'){
        D.at(i).at(j)=D.at(i+1).at(j)+1;
      }
      if(j==W-1&&S.at(i).at(j)!='#'){
        R.at(i).at(j)=1;
      }
      else if(S.at(i).at(j)!='#'){
        R.at(i).at(j)=R.at(i).at(j+1)+1;
      }
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      P.at(i).at(j)=U.at(i).at(j)+D.at(i).at(j)+L.at(i).at(j)+R.at(i).at(j)-3;
    }
  }
  vector<int> a(H);
  for(int i=0; i<H; i++){
    sort(P.at(i).begin(),P.at(i).end());
    a.at(i)=P.at(i).at(W-1);
  }
  sort(a.begin(),a.end());
  cout << a.at(H-1) << endl;
}

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

const long mod=1e9+7;

long mpow(long x, long n)
{
    long res=1;
    for(; n>0; n>>=1) {
        if (n%2) res=res*x%mod;
        x=x*x%mod;
    }
    return res;
}

long mfac(long x)
{
    long res=1;
    while (x>0) res=res*x--%mod;
    return res;
}

long inv(long x)
{
    return mpow(x, mod-2);
}

int main()
{
    int x, y; cin>>x>>y;
    int a=min(x, y), b=max(x, y), c=0;
    for(; 2*a>b; ++c) --a, ++b;

    if (2*a!=b) {
        cout<<0<<endl;
    }
    else {
        cout<<mfac(a)*inv(mfac(c))%mod*inv(mfac(a-c))%mod<<endl;
    }
}


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

typedef double db;
const int maxn = 3010;
int n; db a[maxn], f[2][maxn];

int main() {
	scanf("%d", &n);
	int sel = 1; f[0][0] = 1;
	for (int i = 1; i <= n; i++, sel ^= 1) {
		scanf("%lf", a + i);
		f[sel][0] = f[sel ^ 1][0] * (1 - a[i]);
		for (int j = 1; j <= i; j++) {
			f[sel][j] = f[sel ^ 1][j - 1] * a[i] + f[sel ^ 1][j] * (1 - a[i]);
		}
	}
	db ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += f[sel ^ 1][i];
	}
	printf("%.15f", ans);
	return 0;
}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

    map<string, ll> mp;

    while(Q--){
        ll a;
        string key;
        cin >> a >> key;

        if(a==0){
            //insert
            ll x; cin >> x;
            mp[key] = x;
        }
        else{
            //get
            p(mp[key]);
        }
    }

    return 0;
}


Measured memory_bytes: 27744
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const int INF = 1 << 29;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M;
  while (cin >> N >> M) {
    vector<int> a(M), m(M, 0);
    for (int i = 0; i < M; i++) {
      int sz;
      cin >> a[i] >> sz;
      for (int j = 0; j < sz; j++) {
        int x;
        cin >> x;
        m[i] |= 1 << (x - 1);
      }
    }
    vector<int> dp(1 << N, INF);
    dp[0] = 0;
    for (int i = 0; i < M; i++) {
      for (int j = (1 << N) - 1; j >= 0; j--) {
        chmin(dp[j | m[i]], dp[j] + a[i]);
      }
    }
    int res = dp.back();
    if (res >= INF) res = -1;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
static const int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;

void dfs(int u){
    V[u] = true;
    for(int i=0; i<G[u].size(); i++){
        int v = G[u][i];
        if(!V[v]) dfs(v);
    }
    out.push_front(u);
}

int main(){
    int s, t, M;
    
    cin >> N >> M;
    
    for(int i=0; i<N; i++) V[i] = false;
    
    for(int i=0; i<M; i++){
        cin >> s >> t;
        G[s].push_back(t);
    }
    
    for(int i=0; i<N; i++){
        if(!V[i]) dfs(i);
    }
    
    for(list<int>::iterator it = out.begin(); it != out.end(); it++){
        cout << *it << endl;
    }
    
    return 0;
}



Measured memory_bytes: 6088
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int sum = 0;
  int tmp = n;
  while(tmp > 0){
    sum += tmp % 10;
    tmp = tmp / 10;
  }
  if(n % sum == 0){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 128