akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int a[3];
    int i;
    int b;
    
    for( i=0; i<3; i++)cin >> a[i];
    if (a[0] > a[1]){b = a[1];a[1] = a[0];a[0] = b;}
    if (a[0] > a[2]){b = a[2];a[2] = a[0];a[0] = b;}
    if (a[1] > a[2]){b = a[2];a[2] = a[1];a[1] = b;}
    for( i=0; i<3; i++){
        if(i < 2){
            cout << a[i] << ' ';
        } else {
            cout << a[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3096
#include <cstdio>

int main()
{
	int N, h[100], count=0;
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%d", &h[i]);
	}
	for(int i=0; i<N-1; i++){
		if(h[i]>h[i+1]){
			count += h[i]-h[i+1];
		}
	}
	count += h[N-1];
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main () {
  int a;
  int b;
  scanf ("%d %d", &a,&b);
  if (a > b) {
    printf ("a > b\n");
  }else if (a < b){
    printf ("a < b\n");
  }else{
    printf ("a == b\n");
  }

  return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int antennaAmounts = 5;
		int[] antennas = new int[antennaAmounts];
		
		for(int i = 0 ; i < antennaAmounts ; i++) {
			antennas[i] = sc.nextInt();
		}
		int inputK = sc.nextInt();
		sc.close();
		
		if(antennas[antennaAmounts-1] - antennas[0] <= inputK) {
			System.out.println("Yay!");
		}else {
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 21716
k = int(input())
tens = 10
exist = False
count = 1

if k % 2 == 0:
  exist = False
elif k % 5 == 0:
  exist = False
else:
  if k % 7 == 0:
    L = 9 * k / 7
  else:
    L = 9 * k
  for i in range(9000000):
    if tens % L == 1:
      exist = True
      break
    tens = tens % L * 10 % L
    count += 1
    

if exist:
  print(count)
else:
  print(-1)

Measured memory_bytes: 64416
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}

ll N;
vl A;
ll Q;
vl B;
vl C;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    A = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    cin >> Q;
    B = vl(Q);
    C = vl(Q);
    for(int i = 0; i < Q; ++i){
        cin >> B[i];
        cin >> C[i];
    }
    solve();
}

// 入力は全て整数
// 1 <= N, Q, A_{i}, B_{i}, C_{i} <= 10^{5}
// B_{i} != C_{i}

#ifndef TEMPLATE_USED
#include "../template/template.hpp"
#endif

struct BinaryIndexedTree {
    int sz;
    vector<ll> data;

    BinaryIndexedTree(int sz):sz(sz){
        data.assign(sz,0);
    }

    void add(int x,ll val){
        while(x<sz)data[x]+=val,x|=x+1;
    }

    ll sum(int to){
        to=min(to,sz-1);
        ll ret=0;
        while(to>=0)ret+=data[to],to=(to&(to+1))-1;
        return ret;
    }

    ll sum(int from,int to){
        if(from>to)return 0;
        return sum(to)-sum(from-1);
    }
};

// ll N, vl A, ll Q, vl B, vl C
// Q 個の整数 S_{i} を以下の形式で標準出力に出力せよ。
// S_{i} は 32 ビット整数に収まらない可能性があることに注意せよ。
void solve(){
    BinaryIndexedTree bit(100010);
    rep(i,N){
        bit.add(A[i],A[i]);
    }
    rep(i,Q){
        ll cnt=(bit.sum(B[i],B[i]))/B[i];
        bit.add(B[i],-B[i]*cnt);
        bit.add(C[i],C[i]*cnt);
        cout<<bit.sum(100000)<<endl;
    }
}


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

int main() {
	int s,s1,s2,s3;
	cin >> s;
	s3 = s % 10;
	s2 = s / 10 % 10;
	s1 = s / 100;
	cout << s1+s2+s3 << endl;
}


Measured memory_bytes: 3580
#include <stdio.h>

int main(){
	
	//長方形の幅, 高さ, 円の中心の位置(x, y), 円の半径
	int w, h, x, y, r;
	
	int result = 1;
	
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	
	
	if(x - r < 0 || x + r > w){
		
		result = 0;
		
	}
	
	if(y - r < 0 || y + r > h){
		
		result = 0;
		
	}
	
	if(result == 1){
		
		printf("Yes\n");
		
	}
	else{
		
		printf("No\n");
		
	}
	
	return 0;
	
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  Graph k(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    k[a].push_back(b);
    k[b].push_back(a);
  }
  vector<int> c(n);
  rep(i,n)cin >> c[i];
  sort(c.begin(),c.end());
  int ans[n];
  rep(i,n)ans[i]=-1;
  int cnt=n-1;
  queue<int> q;
  q.push(0);
  while(q.size()!=0){
    int y=q.front();
    //cout << y << endl;
    q.pop();
    ans[y]=c.at(cnt);
    //cout << y << " " << cnt << " " << ans[y] << endl;
    cnt--;
    for(int o: k[y]){
      if(ans[o]>=0)continue;
      q.push(o);
    }
  }
  int an=0;
  rep(i,n-1)an+=c[i];
  cout << an << endl;
  rep(i,n-1)cout << ans[i] << " ";
  cout << ans[n-1] << endl;
}

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

ll comb(ll N_, ll C_) {
	const int NUM_=2400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:comb(P_+Q_-1,Q_);}

ll modpow(ll a, ll n) {
	ll r=1;a%=mo;
	while(n){
      r=r*((n%2)?a:1)%mo;
      a=a*a%mo;
      n>>=1;
    }
	return r;
}


int main() {
  int K;
  string S;
  int N;
  
  cin>>K>>S;
  N=S.size();
	
  ll ret=0;
  for(int i=0;i<=K;i++){
    ret+=modpow(26,i)*modpow(25,K-i)%mo*hcomb(N,K-i)%mo;
  }
  
  cout<<ret%mo<<endl;
  return 0;
}


Measured memory_bytes: 60732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define db long double
#define mp make_pair
#define X first
#define Y second
#define vi vector<int>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<(a).size();++i)
#define gc getchar
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const int N=8,M=305;
int n,C,l[N],p[N];db ans,f[M][M][35];
int main()
{
	n=rd();C=rd();
	rep(i,1,n)l[i]=rd(),p[i]=i;
	sort(l+1,l+n+1);
	do
	{
		memset(f,0,sizeof(f));
		f[0][l[n]*n][0]=1;int nn=1<<(n-1);
		rep0(i,1,n*C)rep(j,i,n*C)rep0(S,0,nn)
		{
			f[i][j][S]+=f[i-1][j][S];int x=i%n;
			if(!x||(S>>(x-1)&1))continue;
			f[i][min(n*C,max(j,i+l[p[x]]*n))][S|(1<<x-1)]+=f[i-1][j][S];
		}
		ans+=f[n*C-1][n*C][nn-1];
	}while(next_permutation(p+1,p+n));
	rep0(i,1,n)ans/=i*C;
	printf("%.15lf\n",(double)ans);return 0;
}


Measured memory_bytes: 54608
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a,b;
	cin>>n>>a>>b;
	if(n*a<b)
		cout<<n*a<<endl;
	else
		cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int n = fetch<int>();
	int k = fetch<int>();
	auto S = fetch<string>();
	vector<int> a;

	for(int i = 0; i < n;) {
		int j = i;

		while(j + 1 < n && S[j + 1] == S[i]) {
			++j;
		}

		a.push_back(S[i] == 'R' ? 0 : 1);
		i = j + 1;
	}

	DBG(a);
	int answ = n - 1;

	for(int i = 1; i < len(a); ++i) {
		if(a[i] != a[i - 1] && k > 0) {
			a[i] ^= 1;
			--k;
		}

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

	DBG(a);
	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

using namespace std;

int main() {
    int D;
    cin >> D;
    if (D == 25) cout << "Christmas" << endl;
    else if (D == 24) cout << "Christmas Eve" << endl;
    else if (D == 23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
    
}

Measured memory_bytes: 256
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var r = o.getValue(0);
    return r * r;
}

Measured memory_bytes: 21064
input_lines = str(input())
input_lines2 = str(input())

n = int(input_lines)
aAry = input_lines2.split(' ')
aAry = map(int,aAry)
aAry = sorted(aAry)
#print(aAry)

answer1 = 0
for i in range(n):
    answer1 += int(aAry[(-i-1)*2])
'''
answer2 = 0
for i in range(n):
    answer2 += int(aAry[-i-3])

if answer1 >= answer2:
    answer = answer1
else:
    answer = answer2
'''
print(answer1)

Measured memory_bytes: 39516
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,i;
  int64_t ans0=0,ans1=0,t=0;
  cin>>m;
  vector<int64_t> x(m);
  for(i=0;i<m;i++) cin>>x.at(i);
  for(i=0;i<m;i++){
    t+=x.at(i);
    if(i%2==0&&t<=0){
      ans0+=abs(t)+1;
      t=1;
    }
    else if(i%2==1&&t>=0){
      ans0+=abs(t)+1;
      t=-1;
    }
  }
  t=0;
  for(i=0;i<m;i++){
    t+=x.at(i);
    if(i%2==0&&t>=0){
      ans1+=abs(t)+1;
      t=-1;
    }
    else if(i%2==1&&t<=0){
      ans1+=abs(t)+1;
      t=1;
    }
  }
  cout<<min(ans0,ans1)<<endl;
}

Measured memory_bytes: 4016
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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


int main() {
    string S,T;
    cin >> S >> T;
    ll sizeS = S.size();

    ll ans =0;
    rep(i,sizeS){
        if(S[i] != T[i]){
            ans++;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 3848
import scala.io.StdIn

object Main {
  def main(args:Array[String]) {
    val input = StdIn.readLine()
    val x = input.toInt
    println(pow(x, 3))
  }
  def pow(x:Int, y:Int) = {
    val list = List.fill(y)(x)
    list.reduceLeft{(x1, x2)=>x1*x2}
  }
}

Measured memory_bytes: 43832
#include <stdio.h>

int main (void)

{

int a,b,c,d;

scanf("%d %d %d",&a,&b,&c);

if(a>b){

d=a;

a=b;

b=d;

}

if(a>c){

d=a;

a=c;

c=d;

}

if(b>c){

d=b;

b=c;

c=d;

}

printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int a[100000];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = INF;
	for (int b = 0; b < 2; b++) {
		bool plus = b;
		ll cost = 0;
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];
			if (plus) {
				if (sum <= 0) cost += 1 - sum, sum = 1;
			}
			else {
				if (sum >= 0) cost += sum + 1, sum = -1;
			}
			plus ^= 1;
		}
		ans = min(ans, cost);
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

int main(){
int n;cin>>n;
string a;
cin>>a;

int flag=0;
int ans=0;
int i=0;
int j=n-1;

while(i<j){


  if((a[i]=='W')&&(a[j]=='R')){
      a[i]='R';
      a[j]='W';
        ans++;
            //cout<<a[i];
        
        
  }else if(a[i]=='R')j+=1;
  else if(a[j]=='W')i-=1;
i++;
j--;
}
cout<<ans<<endl;

return 0;

 }


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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}

int  N, Q;
string s;
char t[200010];
char d[200010];

bool checkleft(int i) {
  rep(j,Q) {
    if (t[j]==s[i]) {
      if (d[j]=='L') --i;
      else ++i;
    }
    if (i<0) return true;
    if (i>=N) return false;
  }
  return false;
}
bool checkright(int i) {
  rep(j,Q) {
    if (t[j]==s[i]) {
      if (d[j]=='L') --i;
      else ++i;
    }
    if (i<0) return false;
    if (i>=N) return true;
  }
  return false;
}

int main(){
  cin >> N >> Q;
  cin >> s;
  rep(i,Q) cin >> t[i] >> d[i];

  int LL, RR;

  int l,r;
  l = 0;
  r = N-1;
  while (l+1<r){
    int c = (l+r)/2;
    if (checkleft(c)) l=c;
    else r=c;
  }
  if (!checkleft(l)) LL= l-1;
  else if (checkleft(r)) LL = r;
  else LL = l;

  l = 0;
  r = N-1;
  while (l+1<r){
    int c = (l+r)/2;
    if (checkright(c)) r=c;
    else l=c;
  }
  if (!checkright(r)) RR= r+1;
  else if (checkright(l)) RR = l;
  else RR = r;

  if (RR<=LL) RR = LL+1;
  int ans = RR-LL-1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vll a(N);
    for(ll i=0;i<N;i++){
        cin>>a[i];
        a[i]--;
    }
    
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(a[i]>i && a[a[i]]==i)ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  vector<vector<int> > edge(N);
  int a, b;
  for(int i=0;i<M;++i) {
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int ans = 0;
  queue<int> que;
  int state;
  bool can;
  for(int i=0;i<N;++i) {
    for(int j=0;j<edge[i].size();++j) {
      if(i>edge[i][j]) continue;
      map<int, int> amap;
      que.push(0);
      while(!que.empty()) {
        state = que.front();que.pop();
        if(amap[state]>0) continue;
        amap[state]++;
        for(int k=0;k<edge[state].size();++k) {
          if((state==i && edge[state][k]==edge[i][j]) || (state==edge[i][j] && edge[state][k]==i)) continue;
          if(amap[edge[state][k]]>0) continue;
          que.push(edge[state][k]);
        }
      }
      can = true;
      for(int i=0;i<N;++i) {
        if(amap[i]==0) can = false;
      }
      if(!can) ans++;
    }
  }
  cout<<ans<<endl;
}



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


using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e3 + 5;
bool isPrime[MAXN];
void sevie() {
    memset(isPrime, 1, sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for (ll i = 2; i * i <= MAXN; i++) {
        if (isPrime[i]) {
            for (ll j = i * 2; j <= MAXN; j += i) {
                isPrime[j] = 0;

            }
        }
    }
}
ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (!(b & 1)) {
        return fastPow(x * x, b / 2);
    } else
        return x * fastPow(x * x, (b - 1) / 2);
}
//__builtin_popcount ();
bool isPrim(int n) {
    if (n == 1 || n == 0)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}


int main() {
    FAST
ll n,k;
    cin>>n>>k;
    n%=k;
    if(abs(n-k)<n)
        cout<<abs(n-k)<<endl;
    else
        cout<<n<<endl;
    return 0;
}


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

int main()
{
  long double a,b,x;cin>>a>>b>>x;
  if (a*a*b/2.0 <= x)
  cout << fixed << setprecision(10) << atanl(2.0/a* (b- x/a/a)) * 180 / acos(-1) << endl;
  else
  cout << fixed << setprecision(10) << (acos(-1)/2 - atanl(2*x/a/b/b))* 180 / acos(-1) << endl;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int d;
  cin >> d;
  while (d--) {
    int p, x;
    cin >> p >> x;
    --p;
    cout << sum - a[p] + x << '\n';
  }
  return 0;
}

Measured memory_bytes: 3632
N = int(input())
S = str(N)
if(len(S) == 1): print(S); exit(0)
if(len(S) == 2): print(max(N // 10 + N % 10, N // 10 - 1 + 9)); exit(0)
for i in range(1, len(S)):
    if(int(S[i]) != 9):
        print(int(S[0]) - 1 + (len(S) - 1) * 9)
        exit(0)
print(int(S[0]) + (len(S) - 1) * 9)

Measured memory_bytes: 3064
S = input()
T = 'abcdefghijklmnopqrstuvwxyz'
if S == T[::-1]:
  print(-1)
  exit()
if len(S) != 26:
  for i in T:
    if i not in S:
      print(S+i)
      exit()
k = 25
while S[k-1] > S[k]:
  k -= 1
X = S[k-1]
Y = list(S[k-1:])
Y.sort()
print(S[:k-1] + Y[Y.index(X) + 1])

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
int n,i,j,a[100010],s,x,lg,maxi;
double val;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    val=((double)a[1]+a[2])/2;
    for(i=3;i<=n;i++)
        val=(val+a[i])/2;
    cout<<fixed<<setprecision(5)<<val;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    for (auto& p : mp) {
        if (p.second % 2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

int main() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<long long> a(x), b(y), c(z);
	for (int i = 0; i < x; i++)
		cin >> a[i];
	for (int i = 0; i < y; i++)
		cin >> b[i];
	for (int i = 0; i < z; i++)
		cin >> c[i];
	sort(a.begin(), a.end(), greater<>());
	sort(b.begin(), b.end(), greater<>());
	sort(c.begin(), c.end(), greater<>());
	priority_queue<pair<long long, pair<int, pair<int, int>>>> pq;
	set<pair<int, pair<int, int>>> st;
	pq.push(make_pair(a[0] + b[0] + c[0], make_pair(0, make_pair(0, 0))));
	st.insert(make_pair(0, make_pair(0, 0)));
	for (int i = 0; i < k; i++) {
		auto tp = pq.top();
		pq.pop();
		cout << tp.first << endl;
		int d = tp.second.first, e = tp.second.second.first, f = tp.second.second.second;
		if (d + 1 < x && st.find(make_pair(d + 1, make_pair(e, f))) == st.end()) {
			pq.push(make_pair(a[d + 1] + b[e] + c[f], make_pair(d + 1, make_pair(e, f))));
			st.insert(make_pair(d + 1, make_pair(e, f)));
		}
		if (e + 1 < y && st.find(make_pair(d, make_pair(e + 1, f))) == st.end()) {
			pq.push(make_pair(a[d] + b[e + 1] + c[f], make_pair(d, make_pair(e + 1, f))));
			st.insert(make_pair(d, make_pair(e + 1, f)));
		}
		if (f + 1 < z && st.find(make_pair(d, make_pair(e, f + 1))) == st.end()) {
			pq.push(make_pair(a[d] + b[e] + c[f + 1], make_pair(d, make_pair(e, f + 1))));
			st.insert(make_pair(d, make_pair(e, f + 1)));
		}
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int a=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){a++;}
  }
  cout<<a<<endl;
  
}

Measured memory_bytes: 256
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int k;
	string n;
	cin  >> k >> n;

	if(n.length() <= k){
		cout << n << endl;
	}
	else{
		n.erase(k);
		cout << n  << "..." << endl;
	}


	return 0;
}


Measured memory_bytes: 3044
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

ll dp[301][301][301];

int main() {
	int N, M; cin >> N >> M;
	dp[1][0][0] = 1;
	rep(m, M)
		for (int i = 1; i <= N; i++)
			for (int j = 0; i + j <= N; j++) {
				ll x = dp[i][j][m];
				int k = N - i - j;
				dp[i + j][0][m + 1] = (dp[i + j][0][m + 1] + x * i) % MOD;
				dp[i][j + 1][m + 1] = (dp[i][j + 1][m + 1] + x * k) % MOD;
				dp[i][j][m + 1] = (dp[i][j][m + 1] + x * j) % MOD;
			}
	cout << dp[N][0][M] << endl;
}


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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

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

const int N = 100100;

vector< int > g[N], ord;
int n, c[N], ans[N], deg[N];
ll ANS;
bool was[N];
set< pii > st;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i < n; i++){
		int v, u;
		scanf("%d%d", &v, &u);
		g[v].pb(u);
		g[u].pb(v);
		deg[v]++;
		deg[u]++;
	}
	for(int i = 1; i <= n; i++)
		scanf("%d", &c[i]);
	for(int i = 1; i <= n; i++)
		st.insert({deg[i], i});
	
	while(!st.empty()){
		int v = st.begin() -> s;
		ord.pb(v);
		was[v] = 1;
		st.erase(st.begin());
		for(auto to : g[v]){
			if(was[to])
				continue;            
			st.erase({deg[to], to});
			deg[to]--;
			st.insert({deg[to], to});
		}
	}	
	sort(c + 1, c + 1 + n);
	for(int i = 1; i <= n; i++)
		ans[ord[i - 1]] = c[i];
	for(int v = 1; v <= n; v++)
		for(auto to : g[v])
			ANS += min(ans[v], ans[to]);
	printf("%lld\n", ANS / 2);
	for(int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
int n,k,r,s,p,i,z=0;
char t[100001];
int main(){
    scanf("%d%d%d%d%d%s",&n,&k,&r,&s,&p,t);
    for(i=0;i<n;i++){
        if(i<k||t[i]!=t[i-k]){
            if(t[i]=='r')z+=p;
            else if(t[i]=='s')z+=r;
            else if(t[i]=='p')z+=s;
        }
        else if(t[i]==t[i-k])t[i]='n';
    }
    printf("%d",z);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

typedef pair<double, pair<int, int>> D;
int dp[200010][30];
const int inf = 1000000009;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, t;
	cin >> n >> t;
	vector<int> a(n), b(n);
	vector<D> p(n);
	rep(i, n) {
		cin >> p[i].second.first >> p[i].second.second;
		double d = (double)p[i].second.first / (double)(p[i].second.second + 1);
		p[i].first = d;
	}
	sort(all(p)); reverse(all(p));
	rep(i, n) {
		a[i] = p[i].second.first;
		b[i] = p[i].second.second;
	}
	int f = n;
	rep(i, n + 1) for (int j = 1; j < 30; j++) dp[i][j] = inf;
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) {
			f = i;
			break;
		}
		for (int j = 1; j < 30; j++) {
			chmin(dp[i + 1][j], dp[i][j]);
			if ((dp[i][j - 1] + 1) * (a[i] + 1) + b[i] <= inf) chmin(dp[i + 1][j], (dp[i][j - 1] + 1) * (a[i] + 1) + b[i]);
		}
	}
	int ans = 0;
	rep(i, 30) {
		int d = dp[f][i];
		int cnt = i;
		int idx = n - 1;
		while (d <= t && idx >= 0 && a[idx] == 0) {
			chmax(ans, cnt);
			d += b[idx] + 1;
			cnt++; idx--;
		}
		if (d <= t) chmax(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 56576
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
typedef long long int ll;
 
int main()
{
    fast;
    ll x;
    cin >> x;
    ll div = x / 500;
    ll ans = 0;
    ans = div * 1000 + ((x % 500) / 5) * 5;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 8
#define FREE 1;
#define NOT_FREE -1

int C[N]={0};
int R[N]={0};
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)
	printf("Q");
      else
	printf(".");
    }
    printf("\n");
  }
  //printf("\n");
}

int putQueen(int i){
  int j;
  //  printf("%d\n",i);
  if(i == N){
    printBoard();
    return 1;
  }

  if(C[i]==1){
    //    printf("set 2\n");
    //printBoard();
    if(putQueen(i+1))return 1;
    //printf("check\n");
    return;
  }

  for(j =0;j<N;j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      //printf("next column\n");
      continue;
    }
    
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    //printf("set 1\n");
    //printBoard();

    //    printf("next row\n");
    if(putQueen(i+1))return 1;

    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
  return 0;
}

int main(){
  int k,a,b,i;
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&a,&b);
    C[a] = 1;
    R[b] = 1;
    row[a] = b;
    col[b] = dpos[a+b] = dneg[a-b+N-1] = NOT_FREE;
  }
  //printf("start\n");
  putQueen(0);

  return 0;
  
}



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

int main(){
	string s; int k; cin>>s>>k;
	set<string> c;
	rep(i, s.size())
		rep(j, k) c.insert(s.substr(i, j+1));
	for(auto x:c)
		if(--k == 0){ cout<< x <<"\n"; break; }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define PI pair<int,int>
#define F first
#define S second
#define all(x) x.begin(),x.end()
using namespace std;
int n;
map<string,int> mp;
int main(){
    cin >> n;
    for(int i=0 ; i<n ; ++i){
        string s;
        cin >> s;
        sort(all(s));
        mp[s]++;
    }
    ll ans = 0;
    for(auto el : mp){
        ans += 1ll* el.S*(el.S-1)/2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,sum=0;
    cin>>n;
    vector<long long>a(n+1),b(n);
    for(int i=0; i<=n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        cin>>b[i];
    for(int i=0; i<n; i++)
    {
        if(a[i]>=b[i])
            sum+=b[i];
        else if((a[i]+a[i+1])>=b[i])
        {
           sum+=b[i];
           a[i+1]-=b[i]-a[i];
        }
        else
        {
            sum+=(a[i]+a[i+1]);
            a[i+1]=0;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 4844
# -*- coding: utf-8 -*-

def check_group(n):
    if n == 2:
        return 3
    elif n in (4, 6, 9, 11):
        return 2
    else:
        return 1

x,y = map(int, raw_input().split())
xgroup, ygroup = (check_group(x), check_group(y))
if xgroup == ygroup:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 2568
def main():
    string = input()[:-1]
    while True:
        if len(string) % 2 == 0 and string[:len(string) // 2] == string[len(string) // 2:]:
            print(len(string))
            break
        else:
            string = string[:-1]


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
//#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
//#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long


using namespace std;
typedef pair<int, int>P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


const int MAX = 500010;
const int MOD = 1000000007;
const ll INF = 10e17;

int A[50][50];
signed main() {
	map<int, int>mp;
	int N, M; cin >> N >> M;
	REP(i, N) {
		int k; cin >> k;
		REP(j, k) {
			int a; cin >> a;
			mp[a]++;
		}
	}
	int ans = 0;
	for (auto x : mp) {
		if (x.second == N)ans++;
	}
	print(ans);
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	map<int, vector<int>> adj;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<int> v(n+1, -1);
	queue<int> q;
	q.push(1);
	while (!q.empty()) {
		auto u = q.front(); 
		q.pop();

		for (auto w : adj[u]) if (v[w] == -1) {
			q.push(w);
			v[w] = u;			
		}
	}
	for (int i = 2; i <= n; i++) if (v[i] == -1) {
		cout << "No\n";
		return 0;
	}

	cout << "Yes\n";
	for (int i = 2; i <= n; i++)
		cout << v[i] << "\n";
	return 0;
}

Measured memory_bytes: 15904
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

const int N_MAX = 1000*100;

int count32bit(unsigned int v) {
	unsigned int count = (v & 0x55555555) + ((v >> 1) & 0x55555555);
	count = (count & 0x33333333) + ((count >> 2) & 0x33333333);
	count = (count & 0x0f0f0f0f) + ((count >> 4) & 0x0f0f0f0f);
	count = (count & 0x00ff00ff) + ((count >> 8) & 0x00ff00ff);
	return (count & 0x0000ffff) + ((count >> 16) & 0x0000ffff);
}

int main() {
	int N, C;
	scanf("%d %d", &N, &C);
	unsigned int time[(N_MAX+1)*2];
	SET_ZERO(time);
	for (int i = 0; i < N; i++) {
		int s, t, c;
		scanf("%d %d %d", &s, &t, &c);
		time[s*2-1] |= 1 << (c-1);
		time[t*2] |= 1 << (c-1);
	}

	int max = 0;
	unsigned int state = 0;
	for (int i = 0; i < (N_MAX+1)*2; i++) {
		state = state ^ time[i];
		chmax(max, count32bit(state));
	}
	printf("%d\n", max);
	return 0;
}


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

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

    vector<long long> nums(100000, 0);
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        nums.at(a - 1) += b;
    }

    int counter = 0;
    while (K > 0)
    {
        K -= nums.at(counter);
        counter++;
    }

    cout << counter << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int n;
	int a[10000],b[10000];
	
	while(cin>>n && n!=0){
		int point_a=0;
		int point_b=0;

		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i];
			if(a[i] > b[i]){
				point_a+=(a[i] + b[i]);
			}else if(a[i] == b[i]){
				point_a+=a[i];
				point_b+=b[i];
			}else{
				point_b+=(a[i] + b[i]);
			}
		}
		cout<<point_a<<" "<<point_b<<endl;
	}
	return 0;
}

Measured memory_bytes: 3156
from functools import partial
from itertools import islice, product


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    n, m, *xyz = map(int, s.split())
    ans = 0
    for sign_x, sign_y, sign_z in product([1, -1], repeat=3):
        ordered = sorted([x * sign_x + y * sign_y + z * sign_z for x, y, z in chunked(xyz, 3)],
                         reverse=True)
        ans = max(ans, sum(ordered[:m]))
    return ans


if __name__ == "__main__":
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 4172
#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>;

int main() {
  ll n,ans=0;
  cin >>n;
  vector<int> a(n);
  rep(i,n){
    cin>> a[i];
  }
  sort(a.begin(),a.end());
  rep(i,n){
    for(int j=i+1;j<n;j++){
        int lb = lower_bound(a.begin(),a.end(),a[i]+a[j])-a.begin();
        ans += max(lb-(j+1),0);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

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

Measured memory_bytes: 596
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    T=list(map(int,input().split()))
    s=sum(T)
    m=int(input())
    PX=[tuple(map(int,input().split())) for _ in range(m)]
    for i in range(m):
        p,x=PX[i]
        p-=1
        print(s-T[p]+x)
resolve()

Measured memory_bytes: 38384
def main():
    n = input()
    A = []
    for i in xrange(n):
        A.append(map(int,raw_input().split()))

    c,d = bfs(n,A)

    for i in xrange(n):
        if c[i] == -1:
            print i+1, -1
        else:
            print i+1, d[i]

def bfs(n,A):
    color = [-1]*n
    d = [-1]*n
    Q = []
    d[0] = 0
    Q.append(0)
    while(True):
        if len(Q)==0:
            break
        u = Q.pop(0)
        for i in A[u][2:]:
            if color[i-1] == -1:
                color[i-1] = 0
                d[i-1] = d[u]+1
                Q.append(i-1)
        color[u] = 1
    return color, d    

if __name__ == '__main__':
    main()

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

int main(){
    long long q,w,e,r,t,y,u; cin>>q>>w>>e>>r>>t>>y>>u;
    long long ans=0;
    for(long long g3=0;g3<=1;++g3){
        if(q<g3 || r<g3 || t<g3)break;
        ans=max(ans,g3*3+((q-g3)^((q-g3)&1))+((r-g3)^((r-g3)&1))+((t-g3)^((t-g3)&1))+w);
    }
    cout<<ans<<endl;
}


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

int main(){
  string S;
  string T;
  cin >> S >> T;
  int s = S.size();
  int t = T.size();
  for(int i=s-t; i>=0; i--){
    bool flag = true;
    for(int j=0; j<t; j++){
      if(S[i+j]=='?' || S[i+j]==T[j]) continue;
      flag = false; break;
    }
    if(flag){
      for(int j=0; j<t; j++){
        S[i+j]=T[j];
      }
      for(int j=0; j<s; j++){
        if(S[j]=='?') S[j]='a';
      }
      cout << S << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define br cout<<"\n"
using namespace std;
int dr[]={-1,1,0,0};
int dc[]={0,0,-1,1};
ll mod=1000000007;
ll po(ll x,ll n){
    ll res = 1;
    while(n>0){
        if(n%2==1)
            res = ((res)*(x));
        x = (x*x);
        n = n/2;
    }
    return res;
}
ll ceil(ll x,ll y)
{
    if(x%y==0)
        return x/y;
    else
        return(x/y)+1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,weight;
    cin>>n>>weight;
    ll wt[n],val[n];
    rep(i,0,n) cin>>wt[i]>>val[i];
    ll knapsack[n+1][weight+1];
    for(ll i=0;i<=n;i++)
        knapsack[i][0]=0;
    for(ll j=0;j<=weight;j++)
        knapsack[0][j]=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=weight;j++)
        {
            if(j<wt[i-1])
            {
                knapsack[i][j]=knapsack[i-1][j];
            }
            else
            {
                knapsack[i][j]=max(knapsack[i-1][j],knapsack[i-1][j-wt[i-1]]+val[i-1]);
            }
        }
    }
    cout<<knapsack[n][weight];
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A;
  cin >> A;
  char a, b, c;
  a = A.at(0);
  b = A.at(1);
  c = A.at(2);
  int ans;
  if(!(a == b)) {
    ans++;
  }
  if(!(c == b)) {
    ans++;
  }
  if(!(a == c)) {
    ans++;
  }
  if(ans == 3) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
	int n,m,sum=0;
	cin >> n >> m;
	vector<int> pos(m);
	for(int i=0;i<m;++i){cin >> pos[i];}
	sort(pos.begin(),pos.end());
	--m;
	for(int i=0;i<m;++i){pos[i] = abs(pos[i] - pos[i + 1]);}
	sort(pos.begin(),pos.end()-1,[](int i,int j){return i > j;});
	for(int i=n-1;i<m;++i){sum += pos[i];}
	cout << sum << endl;
}

Measured memory_bytes: 640
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()
	A := readInt()
	x := make([]int, N)
	xsum := 0
	for i := range x {
		x[i] = readInt()
		xsum += x[i]
	}
	dp := make([][][]int64, N+1)
	for i := range dp {
		dp[i] = make([][]int64, N+1)
		for j := range dp[i] {
			dp[i][j] = make([]int64, xsum+1)
		}
	}

	dp[0][0][0] = 1
	for i := 0; i <= N; i++ {
		dp[i][0][0] = 1
	}
	for i := 1; i <= N; i++ {
		v := x[i-1]
		for j := 1; j <= i; j++ {
			for k := 0; k <= xsum; k++ {
				dp[i][j][k] += dp[i-1][j][k]
				if v <= k {
					dp[i][j][k] += dp[i-1][j-1][k-v]
				}
			}
		}
	}
	var ans int64
	for i := 1; i <= N && i*A <= xsum; i++ {
		ans += dp[N][i][i*A]
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 33408