akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;

// vector vから要素elmのインデックスを取得
int find_index(vector<char> v, char elm){
	vector<char>::iterator it = find(v.begin(), v.end(), elm);
	int index;
	if (it != v.end()){
		index = distance(v.begin(), it);
	}
	else{
		index = -1;
	}
	return index;
}

int main(){
	string S;
	cin >> S;
	if (S == "zyxwvutsrqponmlkjihgfedcba"){
		cout << "-1" << endl;
		return 0;
	}
	else if (S.length() == 26){
		vector<char> vc;
		int pos = 25;
		char th;
		while (1){
			vc.push_back(S[pos]);
			pos--;
			if (S[pos + 1] > S[pos]){
				vc.push_back(S[pos]);
				th = S[pos];
				break;
			}
		}
		S = S.substr(0, pos);
		sort(vc.begin(), vc.end());
		char ne;
		for (auto ch : vc){
			if (ch > th){
				ne = ch;
				break;
			}
		}
		S += ne;
		cout << S << endl;
		return 0;
	}
	else{
		vector<int> v(26, 1);
		for (int i = 0; i < S.length(); i++){
			char c = S[i];
			int ci = c - 'a';
			v[ci] = 0;
		}
		char next;
		for (int i = 0; i < 26;i++){
			if (v[i]){
				next = 'a' + i;
				break;
			}
		}
		S = S + next;
		cout << S << endl;
		return 0;
	}

}


Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N = int(input())
    W = []
    for i in range(N):
        W.append(input())

    f = True
    d = {}
    pv = ''
    for i in range(N):
        v = W[i]
        if v in d:
            f = False
            break
        if 0 < i and pv[-1] != v[0]:
            f = False
            break
        d[v] = pv = v

    print('Yes' if f else 'No')


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  long long N,M,L[100003],R[100003],X,Y,Z;
  cin >> N >> M;
  for(int i=1;i<=M;i++){
    cin >> L[i]>>R[i];
    if(i==1){
      X=L[1];
      Y=R[1];
    }else{
    X = max({X,L[i]});
    Y = min({Y,R[i]});
  }
}
Z = Y - X + 1;
if(0<=Z){
cout << Z <<endl;
}else{
  cout << 0 << endl;
}
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main ()
{
  int N, T, c[100], t[100], mawa, rep1, rep2, resultc;
  scanf ("%d %d", &N, &T);
  
  for (mawa=0; mawa==99; mawa++)
  {
    c[mawa]=1001;
    t[mawa]=1001;
  }
  
  
  for (rep1=0; rep1<=N-1; rep1++)
  {
    scanf ("%d %d", &c[rep1], &t[rep1]);
  }
  
  resultc = 1001;
  
  for (rep2=0; rep2<=N-1; rep2++)
  {
    if (t[rep2]<=T && resultc > c[rep2])
    {
      resultc = c[rep2];
    }
  }
  
  if (resultc == 1001)
  {
    printf("TLE");
  }
  
  else
  {
    printf("%d", resultc);
  }
  return 0;
}


Measured memory_bytes: 128
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 100 + 20 ;
string s ;
int n , k , cnt , ans  ;

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

	cin >> s ;
	cin >> k ;

	n = _sz(s) ;

	bool fl = 1 ;
	for (int i = 0 ; i < n ; i ++) fl &= (s[i] == s[0]) ;

	if (fl) {
		cout << n * k / 2 << '\n' ;
		return 0 ;
	}

	cnt = 1 ;
	for (int i = 1 ; i < n ; i ++) {
		if (s[i] == s[i - 1]) cnt ++ ;
		else {
			ans += k * (cnt / 2) ;
			cnt = 1 ;
		}
	}
	ans += k * (cnt / 2) ;

	if (s[n - 1] == s[0]) {
		int p = 0 ;
		for (int i = 0 ; i < n; i ++) {
			if (s[i] == s[0]) p ++ ;
			else break ;
		}

		ans -= (k - 1) * (p / 2) ;
	
		int q = 0 ;

		for (int i = n - 1 ; i >= 0 ; i --) {
			if (s[i] == s[n - 1]) q ++ ;
			else break ;
		}

		ans -= (k - 1) * (q / 2) ;

		ans += (k - 1) * ((p + q) / 2) ; 
	}

	cout << ans << '\n' ;

}


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

int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<long long,long long>> g;
    vector<pair<long long,long long>> point;
    int a,b;
    for(int i=0; i<N;i++){
        cin >> a >> b;
        g.push_back(make_pair(a,b));
    }
    for(int i=0; i<M;i++){
        cin >> a >> b;
        point.push_back(make_pair(a,b));
    }

    for (int i=0;i<N;i++){
        vector<pair<long long, int>> dis;
        for (int j=0;j<M;j++){
            long long d = abs((g[i].first - point[j].first)) + abs((g[i].second - point[j].second));
            dis.push_back(make_pair(d, j+1));
        }
        sort(dis.begin(), dis.end());
        cout << dis[0].second << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;



int main(void) {
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    ll i, j, k;
    vector<ll> a(X), b(Y), c(Z);
    
    for(i=0; i<X; i++) cin >> a[i];
    for(i=0; i<Y; i++) cin >> b[i];
    for(i=0; i<Z; i++) cin >> c[i];
    
    vector<ll> ab;
    for(i=0; i<X; i++)
        for(j=0; j<Y; j++)
            ab.pb(a[i]+b[j]);
    sort(ab.rbegin(), ab.rend());
    
    vector<ll> ans;
    for(i=0; i<min(K, X*Y); i++)
        for(j=0; j<Z; j++)
            ans.pb(ab[i]+c[j]);
    sort(ans.rbegin(), ans.rend());
    
    for(i=0; i<K; i++) pt(ans[i]);
    
}







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

using namespace std;

int main(){

  int n;

  cin >> n;

  vector<double> h(n);
  vector<int> num(6);
  
  for(int i=0;i<n;++i){
	cin >> h[i];

	if(h[i] < 165.0)
	  num[0]++;
	else if(h[i] >= 165.0 && h[i] < 170.0)
	  num[1]++;
	else if(h[i] >= 170.0 && h[i] < 175.0)
	  num[2]++;
	else if(h[i] >= 175.0 && h[i] < 180.0)
	  num[3]++;
	else if(h[i] >= 180.0 && h[i] < 185.0)
	  num[4]++;
	else if(h[i] >= 185.0)
	  num[5]++;
	
  }
	
  for(int i=0;i<=5;++i){
	cout << i+1 << ":";

	for(int j=0;j<num[i];++j)
	  cout << "*";

	cout << endl;
	
  }
  
}
  


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define int long long
#define print(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = (1LL << 30);
const ll MOD = 1000000007;

//=============================================================
//=============================================================

/*
 */



int N,K,L,M,A,B;
void solve()
{
    int ans = INF;

    ans = B;
    ans = min(N*A,ans);
    cout<<ans<<endl;
}
signed main()
{
    cin>>N>>A>>B;
    solve();
    return 0;
}

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

using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define pb			    push_back

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;
    cout << fixed << setprecision(12) << (double) n * n * n / 27;

    return 0;
}


Measured memory_bytes: 256
<>;$str = <>; chomp $str;
@chars = split //, $str;

@counts = ();

for my $index (1..$#chars) {
    my $pre = substr $str, 0, $index;
    my $suf = substr $str, $index;

    my $count=0;
    my @pre_chars = split //, $pre;

    my %hoge;
    @hoge{@pre_chars} = ();
    @pre_chars = keys %hoge;
    for my $pre_char (@pre_chars) {
        $count++ if (index $suf, $pre_char)+1;
    }

    push @counts, $count;
}

@counts = sort { $b <=> $a } @counts;
print shift @counts;


Measured memory_bytes: 640
const main = (input) => {
  input = input.split(' ');
  const A = input[0];
  const B = input[1];
  const C = input[2];
  
  const resultA = A.slice(-1);
  const resultB = B.slice(0,1);
  const resultb = B.slice(-1);
  const resultC = C.slice(0,1);
  
  if (resultA==resultB && resultb==resultC) {
    console.log('YES');
  }else{
    console.log('NO');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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


const int N = 1005;
bool visited[N][N];
char a[N][N];
int dirx[8] = {0, 0, 1, -1, 1};
int diry[8] = {1, -1, 0, 0, 1};
int n, m;

int ifingrid(int x, int y){
    if(x < 0 or x >= n or y < 0 or y >= m){
        return false;
    } else {
        return true;
    }
}

int main(){
    cin>>n>>m;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            cin>>a[i][j];
            visited[i][j] = false;
        }
    }
    queue<pair<pair<int, int>,int> > q;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            if(a[i][j] == '#'){
                q.push(make_pair(make_pair(i,j),0));
                visited[i][j] = true;
            }
        }
    }
    int res = 0;
    while(!q.empty()){
        int x = q.front().first.first;
        int y = q.front().first.second;
        int dist = q.front().second;
        res = max(res, dist);
        q.pop();
        for(int i = 0;i<4;i++){
            int sx = x + dirx[i];
            int sy = y + diry[i];
            if(ifingrid(sx, sy)){
                if(!visited[sx][sy]){
                    q.push(make_pair(make_pair(sx, sy), dist+1));
                    visited[sx][sy] = true;
                }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 14352
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
  int n;
  cin >> n;
  vector< vector <long long int> > v(n);
  for (int i = 0; i < n; i++) {
    long long int tmp1;
    long long int tmp2;
    cin >> tmp1 >> tmp2;
    v[i].push_back(tmp1);
    v[i].push_back(tmp2);
  }

  sort(v.rbegin(), v.rend(), [](auto& x, auto& y) {return x[1] < y[1];});

  long long int tlimit = v[0][1];
  long long int count = 0;
  for (int i = 0; i < n; i++) {
    while (tlimit > 0) {
      if (v[i][1] >= tlimit) {
        tlimit -= v[i][0];
        count++;
        break;
      } else {
        tlimit--;
      }
    }
  }
  if (tlimit >= 0 && count == n) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  vec d(n);
  for(ll i=0;i<n;i++)cin >> d[i];
  sort(d.begin(),d.end());
  d.erase(unique(d.begin(),d.end()),d.end());
  
  cout << d.size() << endl;

}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+4;
int n,K,a[N];
ll ans;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
inline void smax(int &x,int y) {
	x=x<y?y:x;
}
inline void smin(int &x,int y) {
	x=x>y?y:x;
}
int main() {
//	freopen("in.txt","r",stdin);
	n=read(),K=read();
	for (register int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+n+1);
	for (int i=1;i<=n-K;++i) ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

struct edge{
	int to;
	double cost;
};
typedef pair<double, int> pr;

#define MAX 1002
#define INF DBL_MAX

int n;
vector<edge> g[MAX];
double d[MAX];

void dijkstra(int s){
	priority_queue<pr, vector<pr>, greater<pr>> que;
	fill(d, d+n, INF);
	d[s]=0.0;
	que.push(pr(0.0, s));

	while(!que.empty()){
		pr p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first) continue;
		for(int i=0; i<g[v].size(); i++){
			edge e=g[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(pr(d[e.to], e.to));
			}
		}
	}
	return;
}

int main(){
	ll xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	cin >> n;
	n+=2;
	tuple<ll, ll, ll> pt[n];
	pt[0]=make_tuple(xs, ys, 0);
	pt[1]=make_tuple(xt, yt, 0);
	for(int i=2; i<n; i++){
		ll x, y, r;
		cin >> x >> y >> r;
		pt[i]=make_tuple(x, y, r);
	}

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			ll x[2], y[2], r[2];
			x[0]=get<0>(pt[i]), y[0]=get<1>(pt[i]), r[0]=get<2>(pt[i]);
			x[1]=get<0>(pt[j]), y[1]=get<1>(pt[j]), r[1]=get<2>(pt[j]);
			double cost=max(0.0, sqrt(pow(x[0]-x[1], 2)+pow(y[0]-y[1], 2))-r[0]-r[1]);
			g[i].push_back(edge{j, cost});
		}
	}
	dijkstra(0);
	printf("%.9f\n", d[1]);
	return 0;
}

Measured memory_bytes: 21488
//https://atcoder.jp/contests/abc106/tasks/abc106_d
//D - AtCoder Express 2
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-3.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,M,Q; cin>>N>>M>>Q;
    struct Data{
        ll s,e;
        bool query=false;
        ll query_id=-1;
    };    
    vector<Data> total; //query,data両方いれて終端でsortする
    total.reserve(M+Q);
    REP(i,M){
        ll l,r; cin>>l>>r;
        Data d;
        d.s=l;
        d.e=r;
        total.push_back(d);
    }
    //query
    REP(i,Q){
        ll p,q; cin>>p>>q;
        Data d;
        d.s=p;
        d.e=q;
        d.query=true;
        d.query_id=i;
        total.push_back(d);
    }
    sort(total.begin(),total.end(),[](const auto& a,const auto& b){
        if (a.e==b.e) return a.query_id<b.query_id; //queryを後ろにする
        return a.e<b.e;
    }); //終端でsort
    vector<ll> cnttbl(N+1);
    vector<ll> ans(Q);
    for(auto& d:total){
        if(d.query){
            FOR(p,d.s,d.e+1){
                ans.at(d.query_id) += cnttbl.at(p);
            }
        }else{
            cnttbl.at(d.s)++;
        }
    }
    for(const auto& a:ans){
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A,*B;
	
	int C[MAX+1];
	int n,i,j;
	scanf("%d",&n);
	
	A=malloc(sizeof(short)*n+1);
	B=malloc(sizeof(short)*n+1);
	for(i==0;i<=VMAX;i++) C[i]=0;
	
	for(i=0;i<n;i++) C[i]=0;
	
	for(i=0;i<n;++i){
		scanf("%hu",&A[i+1]);
		C[A[i+1]]++;
	}
	
	for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];
	
	for(j=1;j<=n;j++){
		B[C[A[j]]]=A[j];
		C[A[j]]--;
	}
	
	for(i=1;i<=n;i++){
		if(i>1) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	
	return 0;
} 


Measured memory_bytes: 17408
// 2020-08-23 18:22:05
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  ll tn = 1, an = 1;
  rep(i, n) {
    ll t, a;
    cin >> t >> a;
    ll tn1 = tn, tn2 = tn, an1 = an, an2 = an;
    if(tn1 % t) tn1 += t - tn1 % t;
    an1 = tn1 / t * a;
    if(an2 % a) an2 += a - an2 % a;
    tn2 = an2 / a * t;
    if(tn1 < tn || an1 < an || tn1 * a != an1 * t) {
      tn = tn2;
      an = an2;
    }
    else if(tn2 < tn || an2 < an || tn2 * a != an2 * t) {
      tn = tn1;
      an = an1;
    }
    else if(tn1 + an1 < tn2 + an2) {
      tn = tn1;
      an = an1;
    }
    else {
      tn = tn2;
      an = an2;
    }
  }
  cout << tn + an << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, x, y, ans = 0;
  char c;
  scanf("%lld%lld", &n, &k);
  ll w[k][k], b[k][k];
  for(i = 0; i < k; ++i) for(j = 0; j < k; ++j) w[i][j] = 0, b[i][j] = 0;
  for(i = 0; i < n; i++) {
    bool s = false;
    scanf("%lld %lld %c", &x, &y, &c);
    if(c == 'B') s = true;
    x %= 2 * k;
    y %= 2 * k;
    if(x >= k) s = !s, x -= k;
    if(y >= k) s = !s, y -= k;
    if(s) b[y][x]++;
    else w[y][x]++;
  }
  for(i = 0; i < k; ++i) {
    for(j = 0; j < k; ++j) {
      if(i) b[i][j] += b[i - 1][j], w[i][j] += w[i - 1][j];
      if(j) b[i][j] += b[i][j - 1], w[i][j] += w[i][j - 1];
      if(i && j) b[i][j] -= b[i - 1][j - 1], w[i][j] -= w[i - 1][j - 1];
    }
  }
  for(i = 0; i <= k; ++i) {
    for(j = 0; j <= k; ++j) {
      int num = 0;
      if(i && j) {
        num = 2 * b[i - 1][j - 1] + w[k - 1][j - 1] + w[i - 1][k - 1] - 2 * w[i - 1][j - 1] + b[k - 1][k - 1] - b[i - 1][k - 1] - b[k - 1][j - 1];
      } else if(i) {
        num = w[i - 1][k - 1] + b[k - 1][k - 1] - b[i - 1][k - 1];
      } else if(j) {
        num = w[k - 1][j - 1] + b[k - 1][k - 1] - b[k - 1][j - 1];
      } else {
        num = b[k - 1][k - 1];
      }
      if(num > ans) ans = num;
    }
  }
for(i = 0; i <= k; ++i) {
    for(j = 0; j <= k; ++j) {
      int num = 0;
      if(i && j) {
        num = 2 * w[i - 1][j - 1] + b[k - 1][j - 1] + b[i - 1][k - 1] - 2 * b[i - 1][j - 1] + w[k - 1][k - 1] - w[i - 1][k - 1] - w[k - 1][j - 1];
      } else if(i) {
        num = b[i - 1][k - 1] + w[k - 1][k - 1] - w[i - 1][k - 1];
      } else if(j) {
        num = b[k - 1][j - 1] + w[k - 1][k - 1] - w[k - 1][j - 1];
      } else {
        num = w[k - 1][k - 1];
      }
      if(num > ans) ans = num;
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 15744
//Solution By SlavicG
#include <bits/stdc++.h>
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long

int32_t  main()
{
	int n;
	cin >> n;
	map<string,int> m;
	for(int i = 0;i<n;i++)
	{
		string s;
		cin >> s;
		sort(all(s));
		m[s]++;
	}
	int ans = 0;
	for(auto x : m)
	{
		int k = x.second;
		ans += (k  *(k-1)) / 2;
 	}
	cout << ans << endl;
}

Measured memory_bytes: 11416
//

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

bool data[1005] = {false};
void cal(){
  data[1] = true;
  for(int i = 2; i < 1005; i++){
    for(int k = 2; ; k++){
      int work = pow(i, k);
      if(work > 1005) break;
      data[work] = true;
    }
  }
}

int main(){
  int x;
  cin >> x;
  cal();

  int max = 0;
  for(int i = 0; i < 1005; i++){
    if(data[i]) max = i;
    if(i >= x) break;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int N = 1e6+5;
const double eps = 1e-8;

map<int,int> vis;
int n,now;
bool check = true;
int main(){
  // freopen("input.txt","r",stdin);
  cin>>n;
  for(int i = 1;i <= n;i++){
    cin>>now;
    if(!vis[now]) vis[now] = 1;
    else check = false;
  }
  if(check) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 9600
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    ll n,k;cin>>n>>k;
    cout<<min(n-n/k*k,-(n-n/k*k-k))<<endl;
}

Measured memory_bytes: 256
n = int(input())
count = 0
ans = 0

line = [input().split() for i in range(n)]

for j in line:
    if j[0] == j[1]:
        count += 1
        if count >= 3:
            ans += 1
        else:
            continue
    else:
        count = 0
if ans == 0:
    print('No')
else:
    print('Yes')

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<char> t(Q), d(Q);
    REP(i, Q) cin >> t[i] >> d[i];

    int ans_left, ans_right;

    // 左にギリギリ落ちないものを二分探索
    int left = 0, right = N; // 左に全部落ちる場合に備えて N から
    while(left < right){
        int mid = (left+right)/2;
        int pos = mid;
        REP(i, Q){
            if(t[i] == s[pos]){
                if(d[i] == 'L') --pos;
                if(d[i] == 'R') ++pos;
                if(pos < 0){
                    left = mid+1;
                    break;
                }
                if(pos >= N) break;
            }
        }
        if(pos >= 0) right = mid;
        // cout << "left: " <<  left << " " << right << endl;
    }
    ans_left = left;

    left = -1, right = N-1; // 右に全部落ちる場合に備えて -1 から
    // 右にギリギリ落ちないものを二分探索
    while(left < right){
        int mid = (left+right+1)/2;
        int pos = mid;
        REP(i, Q){
            if(t[i] == s[pos]){
                if(d[i] == 'L') --pos;
                if(d[i] == 'R') ++pos;
                if(pos < 0) break;
                if(pos >= N){
                    right = mid-1;
                    break;
                }
            }
        }
        if(pos < N) left = mid;
        // cout << "right: " << left << " " << right << endl;
    }
    ans_right = right;

    cout << ans_right-ans_left+1 << endl;


    return 0;
}

Measured memory_bytes: 1024
sd=input()
t=input()

n=len(sd)
m=len(t)
s=[]

for i in range(n-m,-1,-1):
    t_kamo=sd[i:i+m]
    for j in range(m+1):
        if j==m:
            print((sd[:i]+t+sd[i+m:]).replace("?","a"))
            exit()
        if t_kamo[j]=="?":
            continue
        elif t_kamo[j]!=t[j]:
            break
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = long long;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve(){
    int x[3];
    ll count = 0;

    rep(i, 3){
        cin >> x[i];
    }

    while(true){
        if(x[0] == x[1] && x[1] == x[2] && x[2] == x[0]){
            break;
        }
        sort(x, x+3);
        if(x[2] - x[1] == 1){   //最大と中間の差が1
            x[1] += 1;
            x[0] += 1; 
        }else if(x[2] - x[1] == 2){
            x[1] += 2;
        }else{
            x[0] += 2;
        }
        count++;
    }
    cout << count << endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ruikei = 0;
		for(int d=a;d<=b;d++) {
			if(c%d==0) {
				ruikei++;
			}
		}
		System.out.println(ruikei);
	}
}

Measured memory_bytes: 26244
c1x, c1y, c1r = map(int, input().split())
c2x, c2y, c2r = map(int, input().split())
dx, dy = c2x - c1x, c2y - c1y
s2 = dx ** 2 + dy ** 2
a = (s2 + c1r ** 2 - c2r ** 2) / 2
df = (s2 * c1r ** 2 - a ** 2) ** 0.5
ix1, ix2 = (a * dx + dy * df) / s2, (a * dx - dy * df) / s2
iy1, iy2 = (a * dy - dx * df) / s2, (a * dy + dx * df) / s2
if (ix1, iy1) > (ix2, iy2):
    ix1, ix2 = ix2, ix1
    iy1, iy2 = iy2, iy1
print(ix1 + c1x, iy1 + c1y, ix2 + c1x, iy2 + c1y)

Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
using pos = tuple<ll, int, int>;

int main() {
  int H, W;
  cin >> H >> W;
  int sx, sy, gx, gy;
  cin >> sy >> sx >> gy >> gx;
  sy--;
  sx--;
  gy--;
  gx--;
  pos start = make_tuple(0, sy, sx);

  vector<vector<char>> S(H, vector<char>(W));
  vector<vector<ll>> dis(H, vector<ll>(W, INF));
  for (auto &l : S) {
    for (auto &i : l) {
      cin >> i;
    }
  }
  priority_queue<pos, vector<pos>, greater<pos>> que;
  que.push(start);
  while (!que.empty()) {
    auto from = que.top();
    que.pop();
    auto [d, y, x] = from;
    if (dis[y][x] <= d) continue;
    dis[y][x] = d;

    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= W || ny < 0 || ny >= H || dis[ny][nx] <= d ||
          S[ny][nx] == '#')
        continue;
      que.push(make_tuple(d, ny, nx));
    }

    for (int nx = x - 2; nx < x - 2 + 5; nx++) {
      for (int ny = y - 2; ny < y - 2 + 5; ny++) {
        if (nx < 0 || nx >= W || ny < 0 || ny >= H || dis[ny][nx] <= d + 1 ||
            S[ny][nx] == '#')
          continue;
        que.push(make_tuple(d + 1, ny, nx));
      }
    }
  }
  if (dis[gy][gx] == INF)
    cout << -1 << endl;
  else
    cout << dis[gy][gx] << endl;
}


Measured memory_bytes: 14096
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			
			if (h == 0 && w == 0)
				break;
			
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++)
					System.out.print("#");
				System.out.println();
			}
			System.out.println();
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 35448
n, q = map(int, input().split())
S = input().strip()
*LR, = (map(int, input().split()) for _ in range(q))

A = [0] * n
for i in range(1, n):
    A[i] = A[i-1] + (S[i-1:i+1] == 'AC')
for l, r in LR:
    print(A[r-1]-A[l-1])

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const int mod = 1000000007;

int main() {
    int X;
    cin >> X;
    if (X >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

int dp[22][(1 << 22)];
int graph[22][22];
const int MOD = 1e9 + 7;

int main()
{
    turbo

    int n; cin >> n;

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            cin >> graph[i][j];

    dp[0][0] = 1;

    for(int i = 1; i < (1 << n); i++)
    {
        for(int j = 0; j < n; j++)
            if(((i >> j) | 1) == (i >> j) && graph[__builtin_popcount(i)][j + 1])
                (dp[__builtin_popcount(i)][i] += dp[__builtin_popcount(i) - 1][(i ^ (1 << j))]) %= MOD;
    }

    return cout << dp[n][(1 << n) - 1], 0;
}

Measured memory_bytes: 178432
#include<iostream>
#include<string>
#include<algorithm>
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;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int K, X, max, min;
  scanf("%d%d", &K, &X);
  max = X + K - 1;
  min = X - K + 1;
  for (int i = min; i < max + 1; i++)
  {
    if (min < i)
    {
      printf(" ");
    }
    printf("%d", i);
  }
  printf("\n");
}


Measured memory_bytes: 128
S = input()
ans = 0
l = []

def calc(S, i, stack):
    if i == len(S):
        l.append(stack) 
    elif i == 0:
        calc(S, 1, str(S[0]))
    else:
        # わけない
        calc(S, i + 1, stack + str(S[i]))

        # わけない(スタック)
        calc(S, i + 1, stack + '+' + str(S[i]))


calc(S, 0, '')

for equation in l:
    ans += eval(equation)

print(ans)

Measured memory_bytes: 38512
use std::io::BufRead;
use std::cmp::Ordering;

fn main() {
  let stdin = std::io::stdin();
  let mut buf = String::new();
  stdin.read_line(&mut buf).unwrap();
  let n = buf.trim().parse::<usize>().unwrap();

  let score = stdin.lock().lines().take(n).fold((0, 0), |acc, line| {
    let line = line.unwrap();
    let mut ite = line.split_whitespace();
    let w1 = ite.next().unwrap();
    let w2 = ite.next().unwrap();

    match w1.cmp(w2) {
      Ordering::Less    => (acc.0, acc.1 + 3),
      Ordering::Equal   => (acc.0 + 1, acc.1 + 1),
      Ordering::Greater => (acc.0 + 3, acc.1)
    }
  });

  println!("{} {}", score.0, score.1);
}


Measured memory_bytes: 5036
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    ll k = (X + D - 1) / D;
    ll res;
    if (k > K) {
        res = X - D * K;
    } else {
        res = X - D * k;
        if ((k - K) % 2) {
            res += D;
        }
    }
    res = abs(res);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second

using namespace std;
int n , m , i , j , ans , viz[55] , x[55] , y[55];
vector< int > a[55];

void dfs(int x)
{
    viz[x]=1;
    for(int i = 0; i < a[x].size() ;i++)
	    if( !viz[a[x][i]] )
		    dfs(a[x][i]);
}

int main()
{

    cin >> n >> m;
    for(i = 1 ; i <= m ; i++)
	    cin >> x[ i ] >> y[ i ];
    for(i = 1 ; i <= m ; i++)
    {
        for(j = 1 ; j <= n ; j++) viz[ j ]=0;
        for(j = 1 ; j <= n ; j++) a[ j ].clear();
        for(j = 1 ; j <= m ; j++) if(j != i)a[ x [ j ] ].pb( y [ j ] ),a[ y [ j ] ].pb(x [ j ] );
        dfs(1);
        for(j = 1 ; j <= n ; j++)
         if( !viz[j] )
         {
             ans ++ ;
             break ;
         }
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
#define PER(i,n) for(int i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  vii c(3,vi(3));
  rep(i,3)rep(j,3) cin >> c[i][j];
  rep(cnt,c[0][0]+1) {
    vi a(3,-1), b(3,-1);
    a[0] = cnt;
    b[0] = c[0][0] - cnt;
    rep(i,3)rep(j,3) {
      if(a[i] == -1) a[i] = c[i][j] - b[j];
      else if(b[j] == -1) b[j] = c[i][j] - a[i];
      else {
        if(a[i] + b[j] != c[i][j]) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

// GCC __gcd(long long A, long long B)

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

bool solve() {
  ll a = -1, b = 1;
  char S[300];

  scanf("%s", S);

  if (S[0] == '#') return false;

  int N = strlen(S);
  reverse(S, S+N);

  int i = 0;

  a = (S[i] == 't') * 90;
  b = 1;

  if (S[i] == 'h') i += 5;
  else i += 4;

  while (S[i]) {
    b *= 2;
    a *= 2;
    if (S[i] == 'h') {
      a -= 90;
      i += 5;
    } else {
      a += 90;
      i += 4;
    }
  }

  ll g = gcd(a, b);
  a /= g;
  b /= g;

  if (b == 1) {
    printf("%lld\n", a);
  } else {
    printf("%lld/%lld\n", a, b);
  }

  return true;
}

int main(){

  while(solve());
  return 0;
}



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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int cnt = 0;
  int cur = 1;
  for (int i = 0; i < n; i++) {
    int elem;
    cin >> elem;
    if (elem == cur) cur++, cnt++;
  }
  int need = n - cnt;
  if (need <= n - 1) cout << need << '\n';
  else cout << -1 << '\n';
  return (0);
}


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

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

	ll N,Q;
	cin >> N >> Q;
	vector<pair<ll,ll>> x(N);
	vector<ll> s(N),t(N);
	for(int i=0;i<N;++i){
		cin >> s[i] >> t[i] >> x[i].first;
		x[i].second = i;
		s[i] -= x[i].first;
		t[i] -= x[i].first;
	}
	sort(x.begin(),x.end());
	set<ll> d;
	map<ll,ll> ma;
	for(int i=0;i<Q;++i){
		ll di;
		cin >> di;
		ma[di] = i;
		d.insert(di);
	}
	vector<ll> ans(Q,-1);
	for(int i=0;i<N;++i){
		ll xi = x[i].first;
		ll si = s[x[i].second];
		ll ti = t[x[i].second];
		vector<ll> del;
		auto l = d.lower_bound(si);
		auto r = d.lower_bound(ti);
		while(l!=r){
			ans[ma[*l]] = xi;
			del.push_back(*l);
			l++;
		}
		for(auto er:del) d.erase(er);
	}
	for(auto a:ans){
		cout << a << endl;
	}
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  set<string> s;
  int n; cin >> n;
  for (int i = 0; i < n; ++i){
    string c; cin >> c;
    s.insert(c);
  }
  cout << (int)s.size();
}



Measured memory_bytes: 19260
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
struct SegmentTree {
    int N;
    vector<Int> A;
    SegmentTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        A.resize(2 * N);
    }
    void add(int idx, Int val) {
        idx += N;
        A[idx] += val;
        idx >>= 1;
        while (idx > 0) {
            A[idx] = A[2*idx+0] + A[2*idx+1];
            idx >>= 1;
        }
    }
    Int sum(int L, int R) {
        L += N, R += N;
        Int ans = 0;
        while (L < R) {
            if (L & 1) ans += A[L++];
            if (R & 1) ans += A[--R];
            L >>= 1, R >>= 1;
        }
        return ans;
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> C(N); for (auto &c : C) cin >> c, c--;
    SegmentTree st(N);
    vector<int> nxt(N);
    {
        vector<int> last(N, -1);
        for (int i = N - 1; i >= 0; i--) {
            nxt[i] = last[C[i]];
            last[C[i]] = i;
        }
        for (int i = 0; i < N; i++) {
            if (last[i] != -1) {
                st.add(last[i], 1);
            }
        }
    }
    vector<tuple<int, int, int>> queries;
    vector<int> ans(Q);
    for (int i = 0; i < Q; i++) {
        int l, r; cin >> l >> r; l--;
        queries.emplace_back(l, r, i);
    }
    sort(begin(queries), end(queries));
    int left = 0;
    for (auto [l, r, i] : queries) {
        while (left < l) {
            st.add(left, -1);
            if (nxt[left] != -1) st.add(nxt[left], +1);
            left++;
        }
        ans[i] = st.sum(0, r);
    }
    for (auto a : ans) cout << a << '\n';
    return 0;
}

Measured memory_bytes: 26700
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        cout<<"safe"<<endl;
    }
    else{
        cout<<"unsafe"<<endl;
    }
  

}



Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#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 VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
int range_check(int val, int min, int max) {
	if (val < min) {
		return -1;
	}
	if (val > max) {
		return -1;
	}
	return val;
}
class wi{
public:
	int work;
	int f;
	string str;
};
int main() {
	string str;
	cin >> str;
	if (str.size() % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	for(int i=0;i<str.size();i+=2){
		if (str[i] != 'h' || str[i + 1] != 'i') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  for(int i = 1; i <= 1450; i++) {
    int ta = i*8/100;
    int tb = i*10/100;
    if(ta == a && tb == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl;
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl;
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl;
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl;
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl;
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl;
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


int w,h;
vector<string> mp;

vector<vector<int> > bfs(char start){
  int dx[] = {1,-1,0,0};
  int dy[] = {0,0,1,-1};
  
  queue<P> Q;
  vector<vector<int> > D(h,vector<int> (w,INF));
 
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(mp[i][j] == start) Q.push(P(i,j)), D[i][j] = 0;

  while(!Q.empty()){
    P t = Q.front();Q.pop();
    int y, x; tie(y, x) = t;
    for(int i=0;i<4;i++){
      int ny = y + dy[i];
      int nx = x + dx[i];
      if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if(mp[ny][nx] == '#' || mp[ny][nx] == '*') continue;
      if(D[ny][nx] != INF) continue;
      D[ny][nx] = D[y][x] + 1;
      Q.push(P(ny, nx));
    }  
  }
  return D;
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  cin>>w>>h;
  mp.resize(h);
  cin>>mp;

  P S, T;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(mp[i][j] == 's') S = P(i,j), mp[i][j] = '.';
      if(mp[i][j] == 'g') T = P(i,j);
    }

  auto DB = bfs('*');
  auto DT = bfs('g');
  
  vector<P> A;
  double dot = 0;
  int sum = 0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(mp[i][j] != '.') continue;
      if(DB[i][j] == INF && DT[i][j] == INF) continue;
      if(DT[i][j] == INF) {sum += DB[i][j]; continue;}
      dot++;
      if(DB[i][j] == INF) {sum += DT[i][j]; continue;}
      A.push_back(P(DB[i][j], DT[i][j]));
    }
  
  for(auto p:A) sum += p.second;

  sort(A.begin(),A.end(),[&](auto a,auto b){return a.first - a.second < b.first - b.second;});
  
  
  int sy = S.first, sx = S.second;
  auto calc=[&](double x){return DB[sy][sx] + x;};
  
  double ans = calc(sum/dot);
  Min(ans, (double)DT[sy][sx]);
  for(int i=0;i<(int)A.size() - 1;i++){
    sum += A[i].first - A[i].second;
    double x = sum / (dot - i - 1);
    Min(ans, calc(x));
  }
  
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 11152
#include <bits/stdc++.h>
#define llint long long int
#define ldouble long double

//setprecision()<<

using namespace std;

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    bool jg=false;
    if(A<C){
        if(C<B){
            jg=true;
        }
    }
    if(A>C){
        if(C>B){
            jg=true;
        }
    }

    if(jg==true){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
return 0;
}

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

#define rep(i,a,b)                for(ll i=a;i<b;i++)
#define repr(i,n)                for(ll i=n-1;i>=0;i--)
#define ll long long int
#define ld long double
#define llu long long unsigned
#define vll std::vector<ll>
#define mll std::map<ll, ll>
#define sll std::set<ll>
#define msll std::multiset<ll>
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define srt(x) sort(all(x))
#define rsrt(x) sort(allr(x))
#define mp make_pair
#define pb push_back
#define mod 1000000007

/*
                    ** author **
                ** Parth Lathiya **
    ** https://www.cse.iitb.ac.in/~parthiitb/ **
*/

int main()
{

ios::sync_with_stdio(false);


//  --------------------------------------------------------------------------------------
ll h,w;
cin>>h>>w;
char a[h][w];

rep(i,0,h)
rep(j,0,w)
	cin>>a[i][j];


// cout<<h<<w;
rep(i,0,h+2)
{
	rep(j,0,w+2)
	{
		if(i==0 || j==0 || i==h+1 || j==w+1)
			cout<<"#";
		else
			cout<<a[i-1][j-1];
	}
	cout<<endl;
}

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

return 0;
}


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


int main()
{
	char m;
	int n,N, a[4][13] = {};
	cin >> N;
	for (int I = 0;I < N;I++) {
		cin >> m >> n;
		if (m == 'S')
			a[0][n-1] = 1;
		else if (m == 'H')
			a[1][n-1] = 1;
		else if (m == 'C')
			a[2][n-1] = 1;
		else if (m == 'D')
			a[3][n-1] = 1;
	}
	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 13;j++) {
			if (a[i][j]==0) {
				if (i == 0)
					cout << 'S' << " " << j+1 << endl;
				else if (i == 1)
					cout << 'H' << " " << j +1<< endl;
				else if (i == 2)
					cout << 'C' << " " << j +1<< endl;
				else
					cout << 'D' << " " << j +1<< endl;
			}
		}
	}


    return 0;
}


Measured memory_bytes: 3100