akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

char c[1001][1001];
int sx,sy,tx,ty;
int n,m;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
bool canVisit(int i,int j) {
    return(i >= 1 and i <= n and j >= 1 and j <= m and c[i][j] == '.');
}
int main() {
    cin >> n >> m;
    cin >> sx >> sy >> tx >> ty;
    ll vis[n+1][m+1];
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> c[i][j];
            vis[i][j] = 1e18;
        }
    }

    priority_queue<pair<ll,pair<ll,ll>> , vector<pair<ll,pair<ll,ll>>>, greater<pair<ll,pair<ll,ll>> > > pq;
    vis[sx][sy] = 0;
    pq.push({0,{sx,sy}});
    while(!pq.empty()) {
        pair<ll,pair<ll,ll>> k = pq.top();
        pq.pop();
        ll magic = k.first;
        ll cx = k.second.first;
        ll cy = k.second.second;
        if(vis[cx][cy] != magic) continue;
        if(cx == tx and cy == ty) break;
      
        for(int dir = 0; dir < 4; dir++) {
            ll nx = dx[dir] + cx;
            ll ny = dy[dir] + cy;

            if(canVisit(nx,ny)) {
                if(vis[nx][ny] > vis[cx][cy]) {
                    vis[nx][ny] = vis[cx][cy];
                    pq.push({vis[nx][ny],{nx,ny}});
                }
            }
        }

        for(ll i = -2; i <= 2; i++) {
            for(ll j = -2; j <= 2; j++) {

                ll nx = cx + i;
                ll ny = cy + j;

                if(canVisit(nx,ny)) {
                     if(vis[nx][ny] > vis[cx][cy] + 1) {
                         vis[nx][ny] = vis[cx][cy] + 1;
                         pq.push({vis[nx][ny],{nx,ny}});
                     }
                }
            }
        }
    }

    ll ans = -1;
    if(vis[tx][ty] != 1e18) {
        ans = vis[tx][ty];
    }

    cout << ans << endl;

}

Measured memory_bytes: 12504
n = int(input())
s = [input() for _ in range(n)]
d = {}
for w in s:
    if w not in d:
        d[w] = 0
    d[w] += 1
d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
    print(ans)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'

//DP法
template <class T>
inline bool chmin(T &a, T b) //change minimum
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) //change max
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

typedef long long ll; //64bit型
using namespace std;

const long long INF = 1LL << 60; //無限大の値
int N;
int main()
{
    int n;
    cin >> n;

    int F[50];
    F[0] = F[1] = 1;
    for (int  i = 2; i <= n; i++)
    {
        F[i] = F[i - 1] + F[i - 2];
    }

    cout << F[n] << endl;
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
double EPS = 1e-10;
typedef pair<long long, long long> P;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++){
        double a;
        cin >> a;
        A[i] = (a + EPS) * 1e9;
    }
    vector<P> cnt(N);
    for(int i = 0; i < N; i++){
        long long f = 0, n = 0;
        while(A[i] % 5 == 0){
            f++;
            A[i] /= 5;
        }
        while(A[i] % 2 == 0){
            n++;
            A[i] /= 2;
        }
        cnt[i] = P(f, n);
    }
    vector<vector<long long>> dp(24, vector<long long> (50, 0));
    for(int i = 0; i < N; i++){
        P p = cnt[i];
        dp[p.first][p.second]++;
    }
    for(int k = 0; k < 24; k++){
        for(int j = 1; j < 50; j++){
            dp[23 - k][49 - j] += dp[23 - k][50 - j];
        }
    }
    for(int k = 0; k < 50; k++){
        for(int j = 1; j < 24; j++){
            dp[23 - j][49 - k] += dp[24 - j][49 - k];
        }
    }
    long long ans = 0;
    long long cntf = 18, cntn = 18;
    for(int i = 0; i < N; i++){
        P p = cnt[i];
        if(p.first * 2 >= 18 && p.second * 2 >= 18) ans--;
        ans += dp[max(0LL, cntf - p.first)][max(0LL, cntn - p.second)];
    }
    cout << ans / 2 << endl;
}

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

#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define tiiii tuple<int,int,int,int>
#define popcount __builtin_popcountll

const int INF = 1LL<<60;
const int MOD = 1000000007;

template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
string to_string(string s) {return s;}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";}
template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

string bin_string(int x) {
    const int d = 32;
    string result(d, ' ');
    RREP(i, d-1, -1) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}

int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n;
    string s, t;
    cin >> n >> s >> t;
    REP(i, 0, n) {
        cout << s[i] << t[i];
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (LL i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<LL> VI;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 400040	;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = 1000LL * 1000 * 1000 + 7;

int n,m;
char arr[1007][1007];
LL dpT[1007][1007];
LL dp(int n1, int m1)
{
	if(n1==n || m1==m)
		return 0;
	if(dpT[n1][m1]!=-1)
		return dpT[n1][m1];
	LL ans=0;
	if(arr[n1+1][m1]!='#')
		ans+=dp(n1+1,m1);
	if(arr[n1][m1+1]!='#')
		ans+=dp(n1,m1+1);
	return dpT[n1][m1]=ans%mod;
}



int main()
{
	//freopen("input.tXXt", "r", stdin);
	ios_base::sync_with_stdio(0);
	FILL(dpT,-1);
	cin >> n >> m;
	dpT[n-1][m-1]=1;
	FOR(i,0,n)
		FOR(j,0,m)
			cin >> arr[i][j];
	cout<<dp(0,0);


	return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=200010;
int N,a[maxn],f[maxn][21],g[maxn][21],lg[maxn],ans[maxn],cnt;
struct seg{
	int L,R,vl,vr;
	seg(int L=0,int R=0,int vl=0,int vr=0){
		this->L=L;
		this->R=R;
		this->vl=vl;
		this->vr=vr;
	}
	bool friend operator<(const seg&A,const seg&B){
		if(a[A.vl]!=a[B.vl])
			return a[A.vl]<a[B.vl];
		return a[A.vr]<a[B.vr];
	}
	void print(){
		printf("%d %d %d %d\n",L,R,vl,vr);
	}
};
int rmq(int L,int R){
	if((L&1)!=(R&1))
		R--;
	int j=lg[R-L+1];
	int u=f[L][j],v=g[R][j];
	if(a[u]<a[v])
		return u;
	return v;
}
seg make_seg(int L,int R){
	int u=rmq(L,R),v;
	v=rmq(u+1,R);
	//printf("in:%d %d %d %d\n",L,R,u,v);
	return seg(L,R,u,v);
}
set<seg>s;
set<seg>::iterator it;
int main(){
	for(int i=1;i<maxn;i++)
		lg[i]=(int)log2(1.0*i);
	//freopen("in","r",stdin);
	N=read();
	for(int i=1;i<=N;i++)
		a[i]=read();
	for(int i=1;i<=N;i++){
		f[i][0]=g[i][0]=i;
		if(i+2-1<=N)
			f[i][1]=i;
		if(i-2+1>=1)
			g[i][1]=i;
	}
	for(int j=2;j<=20;j++)
		for(int i=1;i<=N;i++){
			if(i+(1<<j)-1<=N){
				f[i][j]=f[i][j-1];
				if(a[ f[i][j] ]>a[ f[i+(1<<j-1)][j-1] ])
					f[i][j]=f[i+(1<<j-1)][j-1];
			}
			if(i-(1<<j)+1>=1){
				g[i][j]=g[i][j-1];
				if(a[ g[i][j] ]>a[ g[i-(1<<j-1)][j-1] ])
					g[i][j]=g[i-(1<<j-1)][j-1];
			}
		}
	s.clear();
	s.insert(make_seg(1,N));
	while(!s.empty()){
		it=s.begin();
		seg tmp=*it;
		//tmp.print();
		s.erase(it);
		ans[++cnt]=a[tmp.vl],ans[++cnt]=a[tmp.vr];
		if(tmp.L<tmp.vl-1)
			s.insert(make_seg(tmp.L,tmp.vl-1));
		if(tmp.vl+1<tmp.vr-1)
			s.insert(make_seg(tmp.vl+1,tmp.vr-1));
		if(tmp.vr+1<tmp.R)
			s.insert(make_seg(tmp.vr+1,tmp.R));
	}
	for(int i=1;i<cnt;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[cnt]);
	return 0;
}


Measured memory_bytes: 39168
#include<bits/stdc++.h>
using namespace std;
int main(){
    while (true)
    {
        int N,X;scanf("%d%d",&N,&X);
        if(N+X==0)break;
        int count=0;
        for (int i = 1; i <= N-2; i++)
        {
            for (int j = i+1; j <= N-1; j++)
            {
                for (int k = j+1; k <= N; k++)
                {
                    if(i+j+k==X)count++;
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define ll  long long  
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
 
        ll n,i,j,k;
        cin>>n;
        ll lmt= (ll)(1e18);
        ll a[n],flg=0;
  		long double ans =1;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]==0){
              flg=1;
            }
        }
        if(flg==1){ 
          cout<<"0" << endl;
          return 0;
        }
        else 
        {
            for(i=0;i<n;i++)
            {
                if((a[i]*ans)>lmt)
                {
                    flg=1;
                    cout<<"-1" << endl;
                    return 0;
                }
                ans*=a[i];
            }
           cout << (ll)ans << endl;
        }
    return 0;
}

Measured memory_bytes: 4392
#include<stdio.h>
#include<math.h>
int main(void){
    double x1,y1,x2,y2,t=0;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    if(x1>x2){
        t+=pow(x1-x2,2.0);
    }else{
        t+=pow(x2-x1,2.0);
    }
    if(y1>y2){
        t+=pow(y1-y2,2.0);
    }else{
        t+=pow(y2-y1,2.0);
    }
    printf("%f\n",pow(t,0.5));
    return 0;
}


Measured memory_bytes: 2052
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>V(N);
	vector<int>C(N);

	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int j = 0; j < N; j++) {
		cin >> C[j];
	}

	for (int k = 0; k < N; k++) {
		if (V[k] - C[k] > 0) {
			ans += V[k] - C[k];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int panel[3];
  for(int i=0; i<3; i++){
    scanf("%d",&panel[i]);
  }
  
  int maxArrayNum = max(panel[0],panel[1],panel[2]); 
  int m=0;
  for(int i=0; i<3; i++){
    if(i == maxArrayNum){
      m += 10 * panel[i];
    }else{
      m += panel[i];
    }
  }
  printf("%d",m);
}

int max(int a,int b,int c){
  int num = a;
  int maxArrayNum = 0;
  
  if(num < b){
    num = b;
    maxArrayNum = 1;
  }
  if(num < c){
    num = c;
    maxArrayNum = 2;
  }
  return maxArrayNum;
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n';
typedef long long ll;
const ll INF = 1e17 + 1;
const ll MAX = 2147483647;
const ll MOD = 1000003;

using namespace std;

ll min(ll x, ll y, ll z)
{
    return min(min(x, y), z);
}
ll max(ll x, ll y, ll z)
{
    return max(max(x, y), z);
}

ll min(ll x, ll y, ll z, ll o)
{
    return min(min(x, y, z), o);
}

ll _power(ll b, ll p)
{
    ll res = 1;
    while (p)
    {
        if (p % 2)
            res = (res * b) % MOD;
        b = (b * b) % MOD;
        p /= 2;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy\n";
    else if (s == "Cloudy")
        cout << "Rainy\n";
    else if (s == "Rainy")
        cout << "Sunny\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <thread>///////////////////

#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;

//int N, Y;
int mode = 0;

//tuple<int, int, int> calc(int A, int B, int C) {}



int main() {
	ll N, A, B;
	ll ans;
	cin >> N >> A >> B;
	ans = (N / (A + B))*A;
	if (N % (A + B) > A)ans += A;
	else ans += N % (A + B);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>

using namespace std;

template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int CountBit(int i){
	int ret = 0;
	while(i > 0){
		if(i&1){
			ret++;
		}
		i = i >> 1;
	}
	return ret;
}

int main(void){
	int n, k;
	
	while(cin >> n){
		cin >> k;
		if((n|k) == 0) break;
		vector<int> cards;
		vector<int> candidates;
		int tmp;
		int ret = 0;
		string tmpstr;
		map<string, bool> m;
		for(int i=0;i<n;i++){
			cin >> tmp;
			cards.push_back(tmp);
		}
		for(int i=0;i < (1 << n); i++){
			if(CountBit(i) == k){
				//add candidates
				for(int j=0;j<n;j++){
					if(i & (1 << j)){
						candidates.push_back(cards[j]);
					}
				}
				//sort them
				sort(candidates.begin(), candidates.end());
				/*
				//begin region test print
				for(int j=0;j<candidates.size();j++) cout << candidates[j] << "  ";
				cout << endl;
				//end region test print
				*/
				do{
					tmpstr = "";
					for(int j=0;j<k;j++){
						tmpstr += toString(candidates[j]);
					}
					m[tmpstr] = true;
				}while(next_permutation(candidates.begin(), candidates.end()));
				
				candidates.clear();
			}
		}
		
		map<string,bool>::iterator it = m.begin();
		for(;it!=m.end();++it){
			if((*it).second == true) ret++;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
struct Vector {
	double x, y;
	Vector(double x = 0, double y = 0) : x(x), y(y) {}
	Vector operator + (Vector &p) { return Vector(x + p.x, y + p.y); }
	Vector operator - (Vector &p) { return Vector(x - p.x, y - p.y); }
	Vector operator * (Vector &p) { return Vector(x * p.x, y * p.y); }
	Vector operator / (Vector &p) { return Vector(x / p.x, y / p.y); }
	void insert(double a, double b) { x = a; y = b; }
	double norm() { return x * x + y * y; }
	double abs() { return sqrt(norm()); }
	bool operator < (const Vector &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator == (const Vector &p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};
struct Segment {
	Vector p1, p2;
	void insert(Vector a1, Vector a2) { p1 = a1; p2 = a2; }
};
inline double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
inline double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
inline bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); }
inline bool isOrthogonal(Vector a1, Vector a2, Vector b1, Vector b2) {
	return isOrthogonal(a1 - a2, b1 - b2);
}
inline bool isOrthogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
inline bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); }
inline bool isParallel(Vector a1, Vector a2, Vector b1, Vector b2) {
	return isParallel(a1 - a2, b1 - b2);
}
inline bool isParallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
int main() {
	int n; cin >> n;
	int x, y;
	Vector v[4];
	Segment s[2];
	rep(i, 0, n) {
		rep(j, 0, 4) {
			cin >> x >> y;
			v[j].insert(x, y);
		}
		s[0].insert(v[0], v[1]); s[1].insert(v[2], v[3]);
		if(isParallel(s[0], s[1])) P(2);
		else if(isOrthogonal(s[0], s[1])) P(1);
		else P(0);
	}
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>

using namespace std;

int c[26];
const long long MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    
    for (int i = 0; i < n; i++) {
        c[s[i] - 'a']++;
    }
    long long ans = 1;
    for (int i = 0; i < 26; i++) {
        ans *= (c[i] + 1LL);
        ans %= MOD;
    }
    cout << ans - 1 << '\n';

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{
  char A[16], B[16], C[16];
  int ae, be;
  
  scanf("%s %s %s", A, B, C);
  
  for(ae = 0; A[ae+1] != '\0'; ae++) ;
  for(be = 0; B[be+1] != '\0'; be++) ;
  
  if(A[ae] == B[0] && B[be] == C[0]) printf("YES\n");
  else printf("NO\n");
  
  return 0;
}


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

using namespace std;

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

int N, R, L;
int score[100000], ans[100000];

set<pair<int, int> > s;

int main(){
	
	scanf("%d%d%d", &N, &R, &L);
	
	rep(i, N) s.insert(mp(0, i));
	
	int prev = 0;
	
	rep(i, R){
		int d, t, x;
		
		scanf("%d%d%d", &d, &t, &x);
		d--;
		
		ans[s.begin()->second] += t - prev;
		
		s.erase(mp(-score[d], d));
		score[d] += x;
		s.insert(mp(-score[d], d));
		
		prev = t;
	}
	ans[s.begin()->second] += L - prev;
	
	int mx = -(int)1.2e9, mxi = 0;
	
	rep(i, N) if(mx < ans[i]) mx = ans[i], mxi = i;
	
	cout << mxi + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 6676
def count_path(graph, node, visited):
    if node in visited: return 0
    if len(visited)==len(graph)-1: return 1
    visited.add(node)
    res=0
    for i in range(len(graph)):
        if graph[node][i]:
            res+=count_path(graph, i, visited)
    visited.remove(node)
    return res

def main():
    n, m=[int(w) for w in input().split()]
    graph=[[False for i in range(n)] for j in range(n)]
    for i in range(m):
        a, b=[int(w) for w in input().split()]
        a-=1
        b-=1
        graph[a][b]=True
        graph[b][a]=True

    res=count_path(graph, 0, set())
    print(res)

if __name__=="__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>

unsigned search(const std::string &S)
{
  char c = S[0];
  unsigned t = 0;
  for(unsigned i=1; i<S.size(); ++i)
  {
    if(S[i] != c)
    {
      ++t;
      c = S[i];
    }
  }
  return t;
}

int main()
{
  std::string S;
  std::cin >> S;
  
  std::cout << search(S) << std::endl;
  
  return 0;
}

Measured memory_bytes: 512
def count_nums(v):
    counter = {}
    for x in v:
        if x not in counter:
            counter[x] = 0
        counter[x] += 1
    retval = list(counter.items())
    retval.sort(lambda a: -a[1])
    # i : index
    # retval[i][0] : number
    # retval[i][1] : count
    # retval is sorted by count
    return retval


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v1 = v[::2]
    v2 = v[1::2]

    cv1 = count_nums(v1)
    cv2 = count_nums(v2)

    if cv1[0][0] != cv2[0][0]:
        print(n - (cv1[0][1] + cv2[0][1]))
    elif len(cv1) == 1 and len(cv2) == 1:
        print(len(v2))
    elif len(cv1) == 1:
        print(len(v2) - cv2[1][1])
    elif len(cv2) == 1:
        print(len(v1) - cv1[1][1])
    else:
        print(n - max(cv1[0][1]+cv2[1][1], cv1[1][1]+cv2[0][1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65156
#include <iostream>
#include<string.h>
using namespace std;


int main(){
  int n;
  int b, f, r, v;
  int room[12][10] = {{0}};

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    if(b == 1){
      room[f-1][r-1] += v;
    }
    if(b == 2){
      room[f+2][r-1] += v;
    }
    if(b == 3){
      room[f+5][r-1] += v;
    }
    if(b == 4){
      room[f+8][r-1] += v;
    }
  }

  for(int i = 0; i < 12; i++){
    for(int j = 0; j < 10; j++){
      cout << " " << room[i][j];
    }
    cout << endl;
    if(i == 2 || i == 5 || i == 8){
      cout << "####################" << endl;

    }
  }

}



Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main(void){
    int n,n1,n2,n3;
    cin >> n;
    n1=n%100%10;
    n2=n/10%10;
    n3=n/100;

    if(n1==1){
        n1=9;
    }else{
        n1=1;
    }
    if(n2==1){
        n2=9;
    }else{
        n2=1;
    }
    if(n3==1){
        n3=9;
    }else{
        n3=1;
    }
    cout <<n3<<n2<<n1<<endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll modpow(ll a,ll n,ll m){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N,AX,BX,AM = 0,BM = 0;
    cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N){
        cin >> A[i];
        if(AM < A[i]){
            AX = i;AM = A[i];
        }
    }
    rep(i,N){
        cin >> B[i];
    }
    rrep(i,N){
        if(BM < B[i]){
            BM = B[i];BX = i;
        }
    }
    if(AM != BM || BX < AX){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    if(AX < BX){
        ans *= modpow(AM,BX-AX-1,MOD);
    }
  	ans %= MOD;
    vector<pair<ll,ll>> C,D;
    C.emplace_back(1,1);
    D.emplace_back(1,1);
    RFOR(i,1,AX+1){
        if(A[i] == A[i-1])C.back().first++;
        else C.emplace_back(1,A[i-1]);
    }
    FOR(i,BX,N-1){
        if(B[i] == B[i+1]) D.back().first++;
        else D.emplace_back(1,B[i+1]);
    }
    rep(i,C.size()){
        ans *= modpow(C[i].second,C[i].first-1,MOD);
        ans %= MOD;
    }
    rep(i,D.size()){
        ans *= modpow(D[i].second,D[i].first-1,MOD);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4084
S = input()

n = len(S)

def dfs(i,f):
    if i == n-1:
        return sum(list(map(int, f.split("+"))))

    return dfs(i+1, f+S[i+1]) + dfs(i+1, f+"+"+S[i+1])
print(dfs(0, S[0]))

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define F first
#define S second
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<ll, null_type, less<ll>, rb_tree_tag, 
tree_order_statistics_node_update> 
new_data_set; 

const ll N=100005;

int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
  
    // ll t;
    // cin>>t;
    // while(t--)
    {
        ll i,j,k,n,m,ans=0,cnt=0,sum=0;  
        cin>>n>>m;
        ll a[m],b[m];
        ll cntt[n+1]={},vis[n+1]={};
        memset(cntt,1,sizeof(cntt));
        for(i=0;i<m;i++){
            cin>>a[i]>>b[i];
        }  
        for(i=1;i<=n;i++){
            cntt[i]=1;
        }
        vis[1]++;
        for(i=0;i<m;i++){
            if(vis[a[i]]){
                vis[b[i]]++;
                cntt[a[i]]--;
                cntt[b[i]]++;
                // cout<<cntt[a[i]]<<" "<<cntt[b[i]]<<'\n';
                if(cntt[a[i]]==0){
                    vis[a[i]]=0;
                }
            }
            else{
                cntt[a[i]]--;
                cntt[b[i]]++;   
            }
        }
        for(i=1;i<=n;i++){
            if(vis[i]&&cntt[i]){
                ans++;
            }
        }
        cout<<ans;
    }
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
#define ll long long int
using namespace std;
int main(void) {
  ll n, m;
  ll nf=1, mf=1;
  ll z=pow(10, 9)+7;
  cin>>n>>m;
  for(int i=1; i<=n; i++) {
    nf*=i%z;
    nf=nf%z;
  }
  for(int i=1; i<=m; i++) {
    mf*=i%z;
    mf=mf%z;
  }
  if(abs(n-m)>=2) {
    cout<<0<<endl;
    return 0;
  } else if(n==m) {
    cout<<(nf*mf*2)%z<<endl;
  } else {
    cout<<(nf*mf)%z<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    char p1[5],p2[5],b,h;
    while(1){
        b=0;
        h=0;
        scanf("%s %s",p1,p2);;
        if(p1[0] - '0' == 0 && p2[0] - '0' == 0){
            break;
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(p1[i] - '0' ==  p2[j] - '0' && i == j){
                    h++;
                }
                else if(p1[i] - '0' == p2[j] - '0'){
                    b++;
                }
            }
        }
        printf("%d %d\n",h,b);
    }
}

Measured memory_bytes: 1136
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double tmp = n - (n/2);
		if(n == 1){
			System.out.println("1");
		}else if(n % 2 == 0){
			System.out.println("0.5");
		}else {
			double ans = tmp/n;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int A[n + 1];
	int B[m + 1];
	for(int i = 0; i < n; i++)
		cin >> A[i];
	for(int i = 0; i < m; i++)
		cin >> B[i];
	sort(A, A + n);
	sort(B, B + m);
	for(int i = x + 1; i <= y; i++)
	{
			if(A[n - 1] < i && B[0] >= i)
			{
				//cout << A[n -1] << " " << B[0] << endl;
				//cout << i << endl;
				cout << "No War" << endl;
				return 0;
			}
	}
	cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
#include<math.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    int n; ll W; cin >> n >> W;
    ll w[n+1],v[n+1];
    for(int i=0;i<n;i++) cin >> w[i] >> v[i];
    ll dp[n+1][100100]={ };
    
    for(int i=0;i<n;i++){
        for(int sum=0;sum<=W;sum++){
            
            if(sum-w[i]>=0) chmax(dp[i+1][sum],dp[i][sum-w[i]]+v[i]);

            chmax(dp[i+1][sum],dp[i][sum]);
        }
    }
    cout << dp[n][W];
    return 0;
}

Measured memory_bytes: 79232
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()

def descrease_dist(dv, dt):
    return dv * (dt - dv / 2) + dv * dv / 4


def main():
    N = int(input())
    T = list(map(int, input().split()))
    T = list(accumulate(T))
    V = list(map(int, input().split()))
    """
    ヒストグラムに対して傾き１の山を内包させる問題だと捉える。
    まず山の凸凹は0.5秒おきに変化するので、各点でのvの値を観察する。
    そして次がポイントだが、各vの値は
        V[t] = min(V[t - 0.5] + 0.5, V[t])
    に更新することでヒストグラムに対して値が増える側が傾き１の斜め線になり、
    さらに
        V[t] = min(V[t + 0.5], V[t])
    の更新をかけると値が減る側も傾き１の斜め線にな利、これが答え。

    「右側と左側からそれぞれ更新」が肝でした。
    """
    velocity = [100] * (T[-1] * 2 + 1)
    velocity[0] = 0
    velocity[-1] = 0
    pre_t = 0
    for i, t in enumerate(T):
        for j in range(pre_t * 2, t * 2 + 1):
            velocity[j] = min(V[i], velocity[j])
        pre_t = t

    for t in range(1, T[-1] * 2 + 1):
        velocity[t] = min(velocity[t], velocity[t - 1] + 0.5)
    for t in range(T[-1] * 2 - 1, -1, -1):
        velocity[t] = min(velocity[t], velocity[t + 1] + 0.5)


    dist = 0
    pre_v = 0
    for t in range(1, T[-1] * 2 + 1):
        dist += (velocity[t] + velocity[t - 1])
    print(dist / 4)

if __name__ == "__main__":
    main()


Measured memory_bytes: 73596
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
const int N=100;
int a[N],n;
int main()
{
    IO;
    cin>>n;

    for(int i=1;i<=n;i++) cin>>a[i];
    ll res=1000;
    for(int i=1;i<=n;i++)
    {
        int j=i;
        while(j<=n&&a[j+1]>=a[j]) j++;
        if(j>i) res=res/a[i]*a[j]+res%a[i];
        i=j;
    }
    cout<<res<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	const ll MOD = 998244353;
	int N;
	cin >> N;
	vector<ll> a(N);
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		sum += a[i];
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, 0));
	dp[0][0] = 1;
	auto dp2 = dp;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j + a[i] <= sum; ++j) {
			(dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
			(dp[i + 1][j] += dp[i][j] * 2) %= MOD;

			(dp2[i + 1][j + a[i]] += dp2[i][j]) %= MOD;
			(dp2[i + 1][j] += dp2[i][j]) %= MOD;
		}
	}
				
	ll res = 1; 
	for (int i = 1; i <= N; ++i) { (res *= 3) %= MOD; }

	ll rm = 0;
	for (int i = sum / 2 + 1; i <= sum; ++i) {
		(rm += (dp[N][i] * 3)) %= MOD;
	}
	if (sum % 2 == 0) {
		(rm += (dp[N][sum / 2] - dp2[N][sum / 2] * 2) * 3) %= MOD;
		(rm += (dp2[N][sum / 2] * 3)) %= MOD;
	}

	res = (res - rm + MOD) % MOD;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 423104
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int mod = 1e9 + 7;
const int maxn = 21;
int n;
int G[maxn][maxn];
int dp[maxn][1<<maxn];


int dfs(const int i, const int j)
{
    if (i == n)
        return 1;
    int& ans = dp[i][j];
    if (-1 == ans) {
        ans = 0;
        FOR(d,0,n) {
            if ((j & (1<<d)) == 0 && G[i][d] == 1) {
                ans += dfs(i+1, j | (1<<d));
                ans %= mod;
                
            }
        }
    }
    dp[i][j] = ans;
    return ans;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    
    while (cin >> n) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,n) FOR (j,0,n)
            cin >> G[i][j];
        cout << dfs(0,0) << endl;
    }
    return 0;
}



Measured memory_bytes: 172288
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
int main() {
    ll x;cin >>x;
    ll tmp = 100;
    ll ans=0;
    while(1){
        tmp+=tmp/100;
        ans++;
        if(tmp>=x){
            break;
        }
    }
    cout <<ans<<endl;
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if (A1 + A2 + A3 < 22) {
    cout << "win" << endl;
  }
  else {
    cout << "bust" << endl;
  }

}


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

ll gcd(ll a,ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll c,d;
ll f(ll x){
  ll lcm=c*d/gcd(c,d);
  return x/c + x/d - x/lcm;
}


int main() {
  ll a,b;
  cin>>b>>a>>c>>d;
//  cout<< f(a)<<f(b-1) <<endl;
  cout<< a-f(a)-(b-1)+f(b-1) <<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

template<class T>
struct BIT {
    int N;
    vector<T> data;
    BIT(int N) {
        data = vector<T>(N + 1);
        this->N = N;
    }

    void add_at(int idx, T val) {
        for (int i = idx + 1; i <= N; i += (i & (-i))) {
            data[i] += val;
        }
    }

    T sum_to(int idx) {
        T res = 0;
        for (int i = idx + 1; i > 0; i -= (i & (-i))) {
            res += data[i];
        }
        return res;
    }

    T sum_in(int l, int r) { // [l, r]
        return sum_to(r) - sum_to(l - 1);
    }
};

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

    int N, Q; 
    cin >> N >> Q;

    vector<int> C(N, -1);
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }

    vector<vector<tuple<int, int, int>>> queries(N);
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        queries[r].push_back(tuple<int, int, int>(l, r, i));
    }

    auto bit = BIT<int>(N);
    auto V = *max_element(C.begin(), C.end());
    auto last = vector<int>(V + 1, -1);
    auto ans = vector<int>(Q, -1);

    for (int i = 0; i < N; i++) {
        if (last[C[i]] != -1) {
            bit.add_at(last[C[i]], -1);
        }

        bit.add_at(i, +1);
        last[C[i]] = i;

        for (auto& [l, r, idx] : queries[i]) {
            ans[idx] = bit.sum_in(l, r);
        }
    }

    for (auto x: ans) {
        cout << x << endl;
    }

    return 0;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N;
    int Q;
    cin >> N;
    cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}


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

#define int long long

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], signed n) {
    string result = "{";
    for (int i=0; i<n; ++i) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

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

    int n, a, b; cin >> n >> a >> b;
    int x[n], d[n-1]; for (int i=0; i<n; ++i) cin >> x[i];
    for (int i=1; i<n; ++i) d[i-1] = a*(x[i]-x[i-1]);
    int res = 0;
    for (int i=0; i<n-1; ++i) res += min(d[i], b);
    cout << res;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string.h>
using namespace std;
char c[200001];
int cc[200001];
int main(){
	cin>>c;
	//cout<<strlen(c)<<endl;
	int length=strlen(c);
		for(int i=0;i<length;i++){
			if(!cc[i]&&c[i]=='S'){
				for(int y=i+1;y<length;y++){
					if(!cc[y]&&c[y]!='T'){
						break;
					}else if(!cc[y]&&c[i]=='S'&&c[y]=='T'){//cout<<i<<' '<<y<<endl;
							cc[i]=1;cc[y]=1;
							
							
							for(int n=1,m=1;n<=i&&y+m<length;){
								while(n<=i&&cc[i-n]){if(cc[i-n])n++;
								}
								while(y+m<length&&cc[y+m])if(cc[y+m])m++;
								if(!cc[i-n]&&!cc[y+m]&&c[i-n]=='S'&&c[y+m]=='T'){//cout<<"s"<<i-n<<' '<<y+m<<endl;
									cc[i-n]=1;cc[y+m]=1;
								}else{//i=y+n;
									break;
								}
							}
							break;
					}
				}
			}
		}
	int ans=0;
	for(int i=0;i<length;i++){
		//cout<<cc[i]<<endl;
		if(!cc[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 1280
#include <stdio.h>

int main(void) {
	int N;
	while(scanf("%d",&N)==1 && N>0) {
		int i;
		char buf[16];
		int ibuf;
		int min=-2000000000,max=2000000000;
		int previsx=0;
		int prev=0;
		int noneflag=0;
		for(i=0;i<N;i++) {
			scanf("%s",buf);
			ibuf=0;
			if(buf[0]=='x') {
				if(previsx) {
					noneflag=1;
				} else {
					if(i>0) {
						if(i%2==0) {
							if(prev-1<max)max=prev-1;
						} else {
							if(prev+1>min)min=prev+1;
						}
					}
				}
				previsx=1;
			} else {
				sscanf(buf,"%d",&ibuf);
				if(i>0) {
					if(i%2==0) {
						if(previsx) {
							if(ibuf+1>min)min=ibuf+1;
						} else {
							if(prev<=ibuf)noneflag=1;
						}
					} else {
						if(previsx) {
							if(ibuf-1<max)max=ibuf-1;
						} else {
							if(prev>=ibuf)noneflag=1;
						}
					}
				}
				previsx=0;
			}
			prev=ibuf;
		}
		if(noneflag || min>max) {
			puts("none");
		} else if(min==max) {
			printf("%d\n",min);
		} else {
			puts("ambiguous");
		}
	}
	return 0;
}

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

int main() {
  string S,S1,S2,ans="Yes";
  cin >> S;
  bool flag=1;
  int N=S.size(),n=(N-1)/2;
  rep(i,N/2){
    if(S[i]!=S[N-1-i]){
      flag=0; 
    }
  }
  if(flag){
  S1=S.substr(0,n);
  S2=S.substr(n+1,n);
  rep(i,n/2){
    if(S1[i]!=S1[n-1-i]){
      flag=0; 
    }
    if(S2[i]!=S2[n-1-i]){
      flag=0; 
    }
  }
  }

  
  if(!flag) ans="No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] S = sc.next().toCharArray();
        char[] T = sc.next().toCharArray();

        Arrays.sort(S);
        Arrays.sort(T);

        int c1 = 0;
        int c2 = 0;

        int count = 1;
        char tmp = S[0];
        for (int i = 1; i < S.length; i++) {
            if (tmp == S[i]) {
                count++;
                c1 += count * 2;
            } else {
                count = 1;
                c1 += count;
            }
            tmp = S[i];
        }

        count = 1;
        tmp = T[0];
        for (int i = 1; i < T.length; i++) {
            if (tmp == T[i]) {
                count++;
                c2 += count * 2;
            } else {
                count = 1;
                c2 += count;
            }
            tmp = T[i];
        }

        if (c1 == c2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

int n;
int cnt = 0;
int arr[10001][10001] = {};
int ret[10001] = {};
priority_queue<int> pq;
void dfs(int node, int value)
{
    if (cnt > n)
        return;

    ret[node] = value;
    cnt++;
    for (int i = 1; i <= n; i++)
    {
        if (arr[node][i] == 1)
        {
            arr[node][i] = 0;
            arr[i][node] = 0;
            int tmp = pq.top();
            pq.pop();
            dfs(i, tmp);
        }
    }
}

signed main()
{
    int a[10001], b[10001], c[10001];
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> a[i] >> b[i];
        arr[a[i]][b[i]] = 1;
        arr[b[i]][a[i]] = 1;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        pq.push(c[i]);
    }

    sort(c, c + n, greater<int>());
    int sum = 0;
    for (int i = 1; i < n; i++)
        sum += c[i];

    pq.pop();
    dfs(1, c[0]);
    cout << sum << endl;
    for (int i = 1; i <= n; i++)
        cout << ret[i] << " ";
    cout << endl;
}

Measured memory_bytes: 779776
#include<iostream>
using namespace std;
int n,l,s; 
int main()
{
	cin>>n>>l;
	s=(l+l+n-1)*n/2;
	if(l>0)cout<<s-l;
	else if(l+n-1<0)cout<<s-(l+n-1);
	else cout<<s;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(unsigned int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string s,t;
    cin>>s>>t;
    lli m=s.size()+1;
    lli n=t.size()+1;
    vector<vector<lli>> dp(m,vector<lli>(n));
    rep(i,m-1){
        rep(j,n-1){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }
            else{
                dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            }
        }
    }
    string ans;
    lli i=s.size(),j=t.size();
    while(i>0&&j>0){
        if(dp[i][j]==dp[i-1][j]) i-=1;
        else if(dp[i][j]==dp[i][j-1]) j-=1;
        else{
            ans=s[i-1]+ans;
            i--;
            j--;
        }
    }
    out(ans);
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int submit[30] = {};
    rep(i, 28) {
        int n; cin >> n;
        n--;
        submit[n]++;
    }
    rep(i, 30) {
        if(submit[i] == 0) cout << i+1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 3164