akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int N,M;
    cin>>N>>M;
    
    int ans[51] = {};
    for(int i=0; i<M; i++){
        int a,b;
        cin>>a>>b;
        ans[a]++;
        ans[b]++;
    }
    for(int i=1; i<= N; i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main(){
  ll a,b,c,d;  // std indput [a,b], [c,d]
  cin >> a >> b >> c >> d;
  vector <ll> v;
  v.pb(a*c);
  v.pb(b*c);
  v.pb(b*d);
  v.pb(d*a);
  cout<<*(max_element(v.begin(),v.end()));
  return 0;
}


Measured memory_bytes: 3624
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    a=LI()
    cnt=0
    for i in range(N):
        if i%2==0 and a[i]%2==1:
            cnt+=1
            
    print(cnt)

main()


Measured memory_bytes: 61756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
int main(){
    ll n,ans=0;cin>>n;
    vi a(n),b(n);
    rep(i,n)cin>>a[i];
    priority_queue<P> p;
    rep(i,n){
        cin>>b[i];
        if(b[i]<a[i]){
            cout<<-1<<endl;
            return 0;
        }
        if(b[i]==a[i])continue;
        p.push(P(b[i],i));
    }
    while(!p.empty()){
        auto d=p.top();p.pop();
        ll i=d.second;
        ll x=b[i],y=b[(n+i-1)%n]+b[(i+1)%n];
        if(x%y>=a[i]){
            if(x/y==0){
                cout<<-1<<endl;
                return 0;
            }
            ans+=x/y;
            b[i]=x%y;
        }
        if(x%y>a[i])p.push(P(b[i],i));
        if(x%y<a[i]){
            if((x-a[i])/y==0){
                cout<<-1<<endl;
                return 0;
            }
            ans+=(x-a[i])/y;
            b[i]=a[i]+(x-a[i])%y;
            if(b[i]!=a[i])p.push(P(b[i],i));
        }
    }
    cout<<ans<<endl;
}

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

#define ll long long int 
#define afor(i,a,b) for(ll i = a; i < b; i++)
#define tc() ll t; cin>>t; while(t--)

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
   	string s;
  	cin >> s;
  	if(s[2]==s[3] && s[4]==s[5])
      cout << "Yes\n";
  	else
      cout << "No\n";
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S;
    cin>>S;
    if(S=="abc"||S=="acb"||S=="bac"||S=="bca"||S=="cab"||S=="cba")cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(N)]
cnt=0
for i in range(N):
    affine=0
    for j in range(M):
         affine+=A[i][j]*B[j]
    if affine+C>0:
        cnt+=1
print(cnt)
    

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

const int mod = 1e9 + 7;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(N + 1, vector<int>(N * N * 2 + 1)));
    dp[0][0][N * N] = 1;
    for(int i = 0;i < N;i++){
        for(int j = 0;j <= i;j++){
            for(int l = 0;l <= N * N * 2;l++) if(dp[i][j][l]) {
                if (0 <= l - i * 2) (dp[i + 1][j + 1][l - i * 2] += dp[i][j][l]) %= mod;
                (dp[i + 1][j][l] += 1LL * dp[i][j][l] * 2 * j % mod) %= mod;
                (dp[i + 1][j][l] += dp[i][j][l]) %= mod;
                if (0 <= j - 1 && l + i * 2 <= N * N * 2) (dp[i + 1][j - 1][l + i * 2] += 1LL * dp[i][j][l] * j % mod * j % mod) %= mod;
            }
        }
    }
    cout << dp[N][0][N * N + K] << endl;
    return 0;
}


Measured memory_bytes: 52224
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int n,i,j,sum,ans,www,w[21],s[21];
char name[21][21];

int main(){
	while(scanf("%d",&n)*n){
		sum=0;
		for(i=0;i<n;i++){
			scanf("%s %d %d",name[i],&w[i],&s[i]);
			sum+=w[i];
		}
		for(i=0;i<n;i++){
			www=0;
			for(j=0;j<n;j++){if(sum-w[j]<=s[j] && w[j]>www){ans=j;www=w[j];}}
			printf("%s\n",name[ans]);
			s[ans]=-99999999;
			sum-=w[ans];
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    int ans = min(N*A, B);
    cout << ans << endl;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,p,N,v;
  int *A;

  scanf("%d",&N);
  A=(int *)malloc(N*sizeof(int));
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N;i++){
    if(i!=N-1){
      printf("%d ",A[i]);
    }
    else if(i==N-1){
      printf("%d",A[i]);
    }
  }
  printf("\n");
  
  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;  
    for(p=0;p<N;p++){
      if(p!=N-1){
	printf("%d ",A[p]);
      }
      else if(p==N-1){
	printf("%d",A[p]);
      }
    }
    printf("\n"); 
  }
  free(A);
  return 0;
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int a, b, q,_;
vector<int> s,t;
int x[100001];
signed main() {
    cin >> a >> b >> q;
    for (int i=0;i<a;i++) {cin >> _; s.push_back(_);}
    for (int i=0;i<b;i++) {cin >> _; t.push_back(_);}
    for (int i=0;i<q;i++) cin >> x[i];
    for (int i=0;i<3;i++) {
        s.push_back(INF);s.push_back(-INF);
        t.push_back(INF);t.push_back(-INF);
    }
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());

    int sh[4], te[4];
    for (int i=0;i<q;i++) {
        auto s_i = lower_bound(s.begin(), s.end(), x[i]);
        auto t_i = lower_bound(t.begin(),t.end(),x[i]);
        sh[0] = *s_i;
        te[0] = *t_i;
        sh[1] = *(s_i+1);
        te[1] = *(t_i+1);
        sh[2] = *(s_i-1);
        te[2] = *(t_i-1);
        sh[3] = *(s_i-2);
        te[3] = *(t_i-2);

        int ans = INF * 100;
        int d = INF * 100;
        for (int j=0;j<4;j++) {
            for (int k=0;k<4;k++) {
                d = abs(x[i]-sh[j]) + abs(sh[j]-te[k]);
                ans = min(ans,d);
                d = abs(x[i]-te[k]) + abs(sh[j]-te[k]);
                ans = min(ans,d);
            }
        }
        cout << ans << endl;
    }
}

// 挟まる区間を求める問題
// 2分探索で右側で(xより大きい)一番近い寺と神社を求める
// これはlog(n)
// その一個前が右側で一番近い寺と神社
// さらに左右に１つずつ広げた8通りが考える場合
// 方向*方向*(s or i) = 2^3

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
ll dp[20100];
ll inf  = 1e9+7;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll h,n; cin >> h >> n;
    vector<pair<ll,ll>> magic(n);
    rep(i,0,n) cin >> magic[i].first >> magic[i].second;
    rep(i,1,20100)dp[i] = inf;
    dp[0]=0;
    rep(i,0,h){
        rep(j,0,n){
            dp[i+magic[j].first] = min(dp[i+magic[j].first],dp[i]+magic[j].second);
        }
    }
    ll ans = inf;
    rep(i,h,20100){
        ans = min(ans,dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long long max(long long a,long long b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}
int main()
{
    long long n,x;
    scanf("%lld %lld",&n,&x);
    long long counter=0;
    long long len1,len2,val;
    counter+=n;
    len1=n-max(x,n-x);
    len2=max(x,n-x);
    while(1)
    {if(len2%len1== 0)
    {counter +=(len2/len1)*2*len1 - len1;
    break;}
    else
    {counter+=(len2/len1)*2*len1;
    val=len1;
    len1=len2-(len2/len1)*len1;
    len2=val;}}
    printf("%lld\n",counter);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int N = sc.nextInt();   
        while(N-->0){
            String s = sc.next();
            String t = sc.next();
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(s.length()-i-1);
                switch(c){
                case 'J':
                    t=J(t);
                    break;
                case 'C':
                    t=C(t);
                    break;
                case 'E':
                    t=E(t);
                    break;
                case 'A':
                    t=A(t);
                    break;
                    
                case 'P':
                    t=P(t);
                    break;
                case 'M':
                    t=M(t);
                    break;
                }
            }
            System.out.println(t);
        }
    }

    private static String M(String t) {
        char[] s = t.toCharArray();
        for (int i = 0; i < s.length; i++) {
            if(Character.isDigit(s[i])){
                s[i]++;
                if(s[i]=='9'+1){
                    s[i]='0';
                }
            }
        }
        return new String(s);
    }

    private static String P(String t) {
        char[] s = t.toCharArray();
        for (int i = 0; i < s.length; i++) {
            if(Character.isDigit(s[i])){
                s[i]--;
                if(s[i]=='0'-1){
                    s[i]='9';
                }
            }
        }
        return new String(s);
    }

    private static String A(String t) {
        return new StringBuffer(t).reverse().toString();
    }

    private static String E(String t) {
        if(t.length()%2==0){
            return t.substring(t.length()/2)+t.substring(0,t.length()/2);
        }
        return t.substring(t.length()/2+1)+t.charAt(t.length()/2)+t.substring(0,t.length()/2);
    }

    private static String C(String t) {
        char[] s = new char[t.length()];
        for (int i = 1; i < t.length(); i++) {
            s[i-1]=t.charAt(i);
        }
        s[s.length-1]=t.charAt(0);
        return new String(s);
    }

    private static String J(String t) {
        char[] s = new char[t.length()];
        for (int i = 0; i < t.length()-1; i++) {
            s[i+1]=t.charAt(i);
        }
        s[0]=t.charAt(t.length()-1);
        return new String(s);
    }

}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ll smallest2(ll a){
	ll rtn=1;
	while(rtn<=a) rtn*=2;
	return rtn;
}

int main(){
	int n;
	cin >> n;
	map<ll, int> cnt;
	for(int i=0; i<n; i++){
		ll a;
		cin >> a;
		cnt[a]++;
	}

	int ans=0;
	for(map<ll, int>::reverse_iterator it=cnt.rbegin(); ; it++){
		if(&it==0) continue;
		if(it==cnt.rend()) break;
		ll s=it->first, t=smallest2(s)-s;

		if(s==t){
			ll p=cnt[s]/2;
			ans+=p;
			cnt[s]-=p;
		}else{
			ll p=min(cnt[s], cnt[t]);
			ans+=p;
			cnt[s]-=p;
			cnt[t]-=p;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 85504
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 200000;
ull sum[MAXN + 5];
int main() {
	int N; ull X;
	cin >> N >> X;
	for(int i=1;i<=N;i++) {
		cin >> sum[i];
		sum[i] += sum[i-1];
	}
	ull ans = X*N + sum[N]*5;
	for(int i=1;i<N;i++) {
		ull res = X*i;
		if( 2*i >= N )
			res = res + sum[N]*5;
		else {
			ull coef = 7;
			int lst = N - 2*i;
			res = res + (sum[N]-sum[N-2*i])*5;
			while( lst >= i ) {
				res = res + (sum[lst]-sum[lst-i])*coef;
				lst -= i; coef += 2;
			}
			res = res + sum[lst]*coef;
		}
		if( res < ans ) ans = res;
	}
	cout << ans + X*N;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,A,B,N;
vvi a;
vi DX,DY;

void f(ll d){
	DX.clear();
	DY.clear();
	ll I=d;
	for(ll i=0;i<=d;i++){
		while(I>0&&(I-1)*(I-1)+i*i>=d) I--;
		if(I*I+i*i==d){
			DX.push_back(i);DY.push_back(I);
			DX.push_back(i);DY.push_back(-I);
			DX.push_back(-i);DY.push_back(I);
			DX.push_back(-i);DY.push_back(-I);
		}
	}
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(!a[i][j]){
		queue<P> q;
		q.push({i,j});
		a[i][j]=1;
		while(!q.empty()){
			P p=q.front();q.pop();
			int x=p.first,y=p.second;
			for(int k=0;k<(int)DX.size();k++){
				int X=x+DX[k],Y=y+DY[k];
				if(X>=0&&X<N&&Y>=0&&Y<N&&!a[X][Y]){
					a[X][Y]=-a[x][y];
					q.push({X,Y});
				}
			}
		}
	}
	int t=0;
	for(auto i:a) for(auto j:i) if(abs(j)==1) t+=j;
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(abs(a[i][j])==1){
		if(t>=0^a[i][j]<0) a[i][j]=0;
		else a[i][j]=2;
	}
}

int main(){
	cin>>n>>A>>B;
	N=2*n;
	a=vvi(N,vi(N));
	f(A);f(B);
	int t=n*n;
	for(int i=0;i<N&&t;i++) for(int j=0;j<N&&t;j++) if(!a[i][j]){
		cout<<i<<' '<<j<<endl;
		t--;
	}
}

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

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int l[q], r[q];
    for(int i = 0; i < q; i++){
        cin >> l[i] >> r[i];
    }
    int num[n];
    num[0] = 0;
    for(int i = 1; i < n; i++){
        if (s[i-1] == 'A' && s[i] == 'C') {
            num[i] = num[i-1] + 1;
        }else{
            num[i] = num[i-1];
        }
        
        
    }
    for(int i = 0; i < q; i++){
        cout << num[r[i]-1] - num[l[i]-1] << '\n';
    }
    
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<vector>
#include<string>

using namespace std;

int main(){
	string s;
	long long k;
	cin >> s >> k;
	long long  kn = k;
	bool flag = false;
	for (long long i = 0; i < s.size(); ++i){
		if (s[i] != 'a'){
			if ((26 - (s[i] - 'a')) <= k){
				k = k - (26 - (s[i] - 'a'));
				s[i] = 'a';
			}
		}
	}

	//最後の一文字
	if (k>0){
		if (s[s.size() - 1] == 'a'){
			k = k % 26;
			s[s.size() - 1] = 'a' + k;
		}
		else if ((k <= (26 - (s[s.size() - 1] - 'a')))){
			s[s.size() - 1] = s[s.size() - 1] + k;
			k = 0;
		}
		
		else{
			exit(-1);
		}
	}
	

	cout << s << endl;

	return 0;
}


// a  100 とかのパターン

Measured memory_bytes: 512
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
#define MASK 0x0003FFFF
//#define Hsize ((1<<18)-1)
#define Hsize 100009
#define MAXN 210001 
ll sumZ=0; //sum from the beginning
int Ai; //This is Ai in the problem, we use it only once so array is not necessary.
int N; //N in the problem

struct T
{
    ll number,times;
    int next;
}hashBucket[MAXN];
int top=0;
int hashIndex[Hsize];


//x->hash(x)
inline int hashFunc(ll x)
{
    if (x<0) x=-x;
    return (x%100007);
    return (x&MASK);
}

//add the current sumZ to the hash table
void addToHash(ll sumZ)
{
    int index, HsumZ, beginP;
    HsumZ = hashFunc(sumZ);
    for (beginP=index=hashIndex[HsumZ]; index>0; index=hashBucket[index].next)
        if (hashBucket[index].number == sumZ) // there is already that number in the hashbucket
        {
            hashBucket[index].times+=1;
            return;
        } 
    top++;
    hashIndex[HsumZ]=top;
    hashBucket[top].number = sumZ;
    hashBucket[top].times = 1;
    hashBucket[top].next = beginP;
}

void init()
{
//    memset(hashBucket,-1,sizeof(hashBucket));
    scanf("%d",&N);
    addToHash(0);
    for (int i=0; i<N; ++i)
    {
        scanf("%d",&Ai);
        sumZ=sumZ+Ai;
        addToHash(sumZ);
    }
}

void work()
{
    ll answer=0;
    for (int i=1; i<=top; ++i)
        answer=answer+(((hashBucket[i].times)*(hashBucket[i].times-1))>>1) ;
    cout<<answer<<endl;
}
    
int main()
{
    init();
    work();
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <limits>

using namespace std;

int main()
{
    int N;
    int64_t a[200'000];

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

        a[i] -= i + 1;
    }

    sort(a, a + N, [](int64_t l, int64_t r) {
        return l > r;
    });

    int64_t med = a[N / 2];
    int64_t result = accumulate(a, a + N, (int64_t)0, [&](int64_t acc, int64_t r) {
        return acc + abs(r - med);
    });

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1792
a,b,c=map(int,input().split())
k=int(input())

ans=0
for x in range(k+1):
  bb=b*(2**x)
  for y in range(k-x+1):
    cc=c*(2**y)
    if a<bb<cc:
      ans+=1
      
if ans>0:
  print('Yes')
else:
  print('No')

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    string s; cin >> s; int n = s.size();
    int m = -1, l = -1;
    rep(i, n){
        if(m < 0 && s[i] == 'A') m = i;
    }
    repr(i, n){
        if(l < 0 && s[i] == 'Z') l = i;
    }
    out(l - m + 1);
}

Measured memory_bytes: 640
import java.util.Scanner;

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

		String result = "Yes";

		for(int i = 0; i < N; i++) {
			W[i] = sc.next();
		}

		for(int i = 0; i < N-1; i++) {
			if(W[i].charAt(W[i].length() -1) != W[i+1].charAt(0)) {
				result = "No";
				break;
			}
			for(int j = i+1; j < N; j++) {
				if(W[i].equals(W[j])) {
					result = "No";
					break;
				}
			}
			if("No".contentEquals(result)) {
				break;
			}
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 23764
///*/////////////////////////////*///
/// IN THE NAME OF ALMIGHTY ALLAH ///
///*/////////////////////////////*///

///*////////////////////*///
/// Author : SAIFULLAH29 ///
///*////////////////////*///

///*//////////////////////////////////////////*///
/// "When you want something, all the universe ///
///  conspires in helping you to achieve it."  ///
///              - Paulo Coelho, The Alchemist ///
///*//////////////////////////////////////////*///

#include <bits/stdc++.h>

#define SS           " "
#define endl         "\n"
#define EPS          1e-9
#define gcd          __gcd
#define pb           push_back
#define pi           acos(-1.0)
#define Ars          greater<int>()
#define vi           vector<int>
#define vvi          vector<vector<int> >
#define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define wow          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long              ll;
typedef double                 dbl;
typedef unsigned long long     ull;

void solve()
{
    ll a, b, c, d, x, y;
    cin>>a>>b>>c>>d;
    x = max(a*c, b*c);
    y = max(a*d, b*d);
    cout<<max(x, y)<<endl;
}

int main()
{
    wow

    int t=1;
    //cin>>t;

    while(t--)
        solve();

    return 0;
}

///*////////////////////////////////////////////*///
/// "There is only one thing that makes a dream  ///
/// impossible to achieve: the fear of failure." ///
///                - Paulo Coelho, The Alchemist ///
///*////////////////////////////////////////////*///


Measured memory_bytes: 3644
<?php 
    fscanf(STDIN, '%d', $x);

    $thousand = floor($x / 500);
    $amount_of_thousand = $x - ($thousand * 500);
    $thousand_happy = $thousand * 1000;

    $five = floor($amount_of_thousand / 5);
    $five_happy = 5 * $five;
    
    echo $thousand_happy + $five_happy;

Measured memory_bytes: 4604
#include <stdio.h>

int main(void){
	int i,j,k,n,m,l;
	int A[100][100];
	int B[100][100];
	long int C[100][100]={0};
	scanf("%d %d %d",&n,&m,&l);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(j=0;j<m;j++){
		for(k=0;k<l;k++){
		scanf("%d",&B[j][k]);
		}
	}

	for(i=0;i<n;i++){
		for(k=0;k<l;k++){
			for(j=0;j<m;j++){
				C[i][k]+=A[i][j]*B[j][k];
			}
			if(k==(l-1)){
				printf("%ld\n",C[i][k]);
			}else{
				printf("%ld ",C[i][k]);
			}
		}
	}

	return 0;
}

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

using namespace std;

#define pb push_back

const int maxn = 7e2 + 10;
int n, m, col[maxn], a[maxn], t, mn, mx, ans;
bitset <maxn> edge[maxn], mark;
bitset <maxn << 1> dp[maxn];
vector <int> adj[maxn];
queue <int> bfs;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		edge[i].set();
		edge[i][i] = false;
	}
	for (int i = 0, v, u; i < m; ++i) {
		cin >> v >> u;
		edge[--v][--u] = false;
		edge[u][v] = false;
	}
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			if (edge[i][j])
				adj[i].pb(j);
	memset(col, -1, sizeof(col));
	for (int i = 0; i < n; ++i)
		if (!mark[i]) {
			int cnt = 0;
			col[i] = 0;
			bfs.push(i);
			mark[i] = true;
			while (!bfs.empty()) {
				int v = bfs.front();
				bfs.pop();
				if (col[v])
					cnt++;
				else
					cnt--;
				for (auto u: adj[v])
					if (mark[u]) {
						if (col[v] == col[u])
							return cout << "-1\n", 0;
					}
					else {
						col[u] = col[v] ^ 1;
						bfs.push(u);
						mark[u] = true;
					}
			}
			a[t++] = abs(cnt);
		}
	dp[0][maxn] = true;
	for (int i = 0; i < t; ++i)
		dp[i + 1] = (dp[i] << a[i]) | (dp[i] >> a[i]);
	for (int i = maxn; ; ++i)
		if (dp[t][i]) {
			i -= maxn;
			mn = (n - i) / 2;
			mx = mn + i;
			break;
		}
	ans = (mn * (mn - 1) + mx * (mx - 1)) / 2;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
 
int face[7][7][4] = {
{{0},{0},{0},{0},{0},{0},{0}},
{{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
{{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
{{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
{{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
{{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
{{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int assign[7];
 
int main()
{
    int q, i, t, f;
 
    for (i = 1; i <= 6; i++) scanf("%d", assign+i);
    scanf("%d", &q);
    while (q--) {
        scanf("%d%d", &t, &f);
        for (i = 1; i <= 6; i++) {
            if (assign[i] == t) t = i;
            if (assign[i] == f) f = i;
        }
        printf("%d\n", assign[face[t][f][3]]);
    }
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	int ans = 1;
	int res = 1;
	int now = a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<=now)
		{
			now=a[i];
			ans++;
		}
		else
		{
			now = a[i];
			res=max(res,ans);
			ans = 1;
		}
	}
	printf("%d\n",max(ans,res)-1);
}

Measured memory_bytes: 640
// atcoder/abc066/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  while (cin >> s) {
    string t;
    int mx = 0;
    each (c, s) {
      t += c;
      if (t.size() % 2 || s.size() == t.size()) continue;
      bool f = true;
      for (int i = 0; i < t.size() / 2; ++i) {
        f = f && (t[i] == t[i + t.size() / 2]);
      }
      if (f) mx = t.size();
    }
    cout << mx << endl;
  }

  return 0;
}


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

int N;
string S;

int main() {
    cin >> N >> S;
    map<pair<string, string>, int> mp;
    for (int i = 0; i < (1 << N); i++) {
        string a = "", b = "";
        for (int j = 0; j < N; j++) {
            if (1 << j & i) {
                a += S[j];
            } else {
                b += S[j];
            }
        }
        mp[make_pair(a, b)] += 1;
    }
    long long ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        string a = "", b = "";
        for (int j = 0; j < N; j++) {
            if (1 << j & i) {
                a += S[2 * N - 1 - j];
            } else {
                b += S[2 * N - 1 - j];
            }
        }
        ans += mp[make_pair(a, b)];
    }
    cout << ans << endl;
}

Measured memory_bytes: 91904
n, m = map(int, input().split())

if n < 1 or m < 2:
    print(0)
    quit()

if n <= m:
    if 2*n == m:
        print(n)
    elif 2*n < m:
        print(n + (m-2*n)//4)
    elif 2*n > m:
        print(m//2)
else:
    print(m//2)


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

using namespace std;
using int64 = long long;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int64> p(a), q(b), r(c);
    for (int i=0; i<a; i++) cin >> p[i];
    for (int i=0; i<b; i++) cin >> q[i];
    for (int i=0; i<c; i++) cin >> r[i];

    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    sort(r.begin(), r.end());

    int xx = x;
    int yy = y;
    while (c > 0 && ((xx > 0 && r[c-1] > p[a-xx]) || (yy > 0 && r[c-1] > q[b-yy]))) {
        if (yy <= 0 || p[a-xx] < q[b-yy]) {
            p[a-xx] = r[c-1];
            xx--;
        }
        else {
            q[b-yy] = r[c-1];
            yy--;
        }
        c--;
    }

    int64 ans = 0;
    for (int i=1; i<=x; i++)
        ans += p[a-i];
    for (int i=1; i<=y; i++)
        ans += q[b-i];
    cout << ans << endl;
}


Measured memory_bytes: 2560
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func dfs(s string) int {
	ans := 0
	sl := len(s)

	mod := 2019
	s = Reverse(s)

	sum := 0
	cnt := make(map[int]int)

	cnt[0] = 0
	x := 1

	for i := 0; i < sl; i++ {
		cnt[sum]++
		a, _ := strconv.Atoi(string(s[i]))
		sum += (a * x)
		sum = sum % mod
		ans += cnt[sum]
		x = x * 10 % mod
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 1000000000000000)

	ss := nextString()

	fmt.Println(dfs(ss))
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        char[] ans = new char[s.length];
        if (isCorrect('S', 'S', ans, s)) {
            System.out.println(String.valueOf(ans));
            return;
        }
        if (isCorrect('S', 'W', ans, s)) {
            System.out.println(String.valueOf(ans));
            return;
        }
        if (isCorrect('W', 'S', ans, s)) {
            System.out.println(String.valueOf(ans));
            return;
        }
        if (isCorrect('W', 'W', ans, s)) {
            System.out.println(String.valueOf(ans));
            return;
        }
        System.out.println(-1);
    }

    private static boolean isCorrect(char c1, char c2, char[] ans, char[] s) {
        ans[0] = c1;
        ans[1] = c2;
        boolean isOK = false;
        for (int i = 1; i < s.length; i++) {
            int idx = i + 1;
            if (i == s.length - 1) {
                idx = 0;
            }
            if (ans[i] == 'S') {
                if (s[i] == 'o' && ans[i - 1] == 'S') {
                    ans[idx] = 'S';
                } else if (s[i] == 'o' && ans[i - 1] == 'W') {
                    ans[idx] = 'W';
                } else if (s[i] == 'x' && ans[i - 1] == 'S') {
                    ans[idx] = 'W';
                } else if (s[i] == 'x' && ans[i - 1] == 'W') {
                    ans[idx] = 'S';
                }
            } else if (ans[i] == 'W') {
                if (s[i] == 'o' && ans[i - 1] == 'S') {
                    ans[idx] = 'W';
                } else if (s[i] == 'o' && ans[i - 1] == 'W') {
                    ans[idx] = 'S';
                } else if (s[i] == 'x' && ans[i - 1] == 'S') {
                    ans[idx] = 'S';
                } else if (s[i] == 'x' && ans[i - 1] == 'W') {
                    ans[idx] = 'W';
                }
            }
            if (idx == 0) {
                if (ans[0] == 'S') {
                    if (s[0] == 'o' && ans[i] == ans[1] && ans[0] == c1) {
                        isOK = true;
                    } else {
                        isOK = (s[0] == 'x' && ans[i] != ans[1] && ans[0] == c1);
                    }
                } else if (ans[0] == 'W') {
                    if (s[0] == 'o' && ans[i] != ans[1] && ans[0] == c1) {
                        isOK = true;
                    } else {
                        isOK = (s[0] == 'x' && ans[i] == ans[1] && ans[0] == c1);
                    }
                }
            }
        }
        return isOK;
    }
}

Measured memory_bytes: 28128
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int main()
{
    fio;
   int a1[4];
   loop(i,0,3)
   {
       cin>>a1[i];
   }
   sort(a1,a1+3);
   if(a1[0]==5 && a1[1]==5 && a1[2]==7)
    cout<<"YES\n";
   else
    cout<<"NO\n";
    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(void){
	long N,A[200000],buka[200000],i,ans;
	cin >> N;
	myfor(i,N)buka[i] = 0;
	myfor(i,N-1){
		cin >> A[i];
		buka[A[i]-1]++;
	}
	myfor(i,N)cout << buka[i] << endl;
	return 0;
}


Measured memory_bytes: 6708
mod=998244353
n,m,k=map(int,input().split())
fcl=[1]*(n+1)
for i in range(1,n+1):
  fcl[i]=(fcl[i-1]*i)%mod
def comb(x,y,p):
  return ((fcl[x]*pow(fcl[y],p-2,p))%p*pow(fcl[x-y],p-2,p))%p
ans=0
for i in range(k+1):
  ans+=m*pow(m-1,n-1-i,mod)*comb(n-1,i,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 72916
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)


int main() {
    LL N;cin >> N;
    vector<string> s(N);
    rep(i,N)cin >> s[i];

    map<string,LL> m;
    rep(i,N){
        sort(all(s[i]));
        m[s[i]]++;
    }
    LL ans = 0;
    for(auto t : m){
        if(t.S > 1){
            ans += (t.S*(t.S-1)/2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    string S;
    cin >> S;
    int a = stoi(S.substr(0, 2));
    int b = stoi(S.substr(2, 2));
    if(1 <= a && 1 <= b && a <= 12 && b <= 12){
        cout << "AMBIGUOUS" << endl;
        return 0;
    }
    if(1 <= a && a <= 12){
        cout << "MMYY" << endl;
        return 0;
    }
    if(1 <= b && b <= 12){
        cout << "YYMM" << endl;
        return 0;
    }
    cout << "NA" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main(){

    static double ASpeed = 0.5;
    static double BSpeed = 6.0;

    double  A, B, H, M;
    cin >> A >> B >> H >> M;

    double angle = (BSpeed - ASpeed) * (60 * H + M);

    double length = sqrt(A * A + B * B - 2 * A * B * cos(2 * M_PI * angle / 360));

    cout << fixed << setprecision(20) << length << endl;
}

Measured memory_bytes: 4228
// Aizu Vol-28 2800: Mod!Mod!
// 2017.8.8

#include <stdio.h>

int main()
{
	int n;
	int i, a, b, c[3];

	scanf("%d", &n);
	c[0] = c[1] = c[2] = 0;
	for (i = 0; i < n; i++) scanf("%d", &a), c[a % 3]++;
	if (!c[1] && !c[2]) a = 1;
	else {
		a = c[0]; n -= c[0];
		if (n <= 3) a += n;
		else {
			b = c[1] - c[2]; 
			if      (b ==  0) a += 2 * c[1];
			else if (b ==  1) a += 2 * c[2] + 1;
			else if (b ==  2) a += 2 * c[2] + 2;
			else if (b >   2) a += 2 * c[2] + 3;
			else if (b == -1) a += 2 * c[1] + 1;
			else if (b == -2) a += 2 * c[1] + 2;
			else if (b <  -2) a += 2 * c[1] + 3;
		}
	}
	printf("%d\n", a);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		solve(N);
	}
	public static void solve(int N) {
		for (int i = -120; i <120 ; i++) {
			for (int j = -120; j < 120; j++) {
				long ans = i*i*i*i*i - j*j*j*j*j;
				if (ans == N) {
					System.out.println(i +" " + j);
					return;
				}
			}
		}
		return;
	}
}

Measured memory_bytes: 38404
#include <bits/stdc++.h>
#define SE second
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define LL long long
#define LI long int
#define LLI long long int
#define REP(i,a,b) for(long long i=a;i<b;i++)
#define PER(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl

using namespace std;
template< unsigned mod >
struct RollingHash {
    vector< unsigned > hashed, power;

    inline unsigned mul(unsigned a, unsigned b) const {
        unsigned long long x = (unsigned long long) a * b;
        unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
        asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
        return m;
    }

    RollingHash(const string &s, unsigned base = 10007) {
        int sz = (int) s.size();
        hashed.assign(sz + 1, 0);
        power.assign(sz + 1, 0);
        power[0] = 1;
        for(int i = 0; i < sz; i++) {
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i];
            if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
        }
    }

    unsigned get(int l, int r) const {
        unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
        if(ret >= mod) ret -= mod;
        return ret;
    }

    unsigned connect(unsigned h1, int h2, int h2len) const {
        unsigned ret = mul(h1, power[h2len]) + h2;
        if(ret >= mod) ret -= mod;
        return ret;
    }

    int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
        int len = min(r1 - l1, r2 - l2);
        int low = -1, high = len + 1;
        while(high - low > 1) {
            int mid = (low + high) / 2;
            if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
            else high = mid;
        }
        return (low);
    }
};
//using RH = RollingHash< 1000000007 >;

int main() {
    string T, P;

    cin >> T;
    cin >> P;
    RollingHash< 1000000007 > rh(T), rh2(P);
    for(int i = 0; i + P.size() <= T.size(); i++) {
        if(rh.get(i, i + P.size()) == rh2.get(0, P.size())) {
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[100],maxi=0,b[100],f=0,pos=0,k,i;
	for(i=0;i<3;i++)
	{
	   scanf("%d",&a[i]);  
	   b[a[i]]++;
	}
	scanf("%d",&k);
	for(i=0;i<3;i++)
	{
	     if(b[a[i]]==2)
	     {
	     	f=1;
		 }
	}
	if(!f)
	{
	 	maxi=max(max(a[0],a[1]),a[2]);
	 	for(i=0;i<3;i++)
		{
	     	if(a[i]==maxi)
	     	{	
	     		pos=i;
		 	}
		}
		for(i=0;i<k;i++)
		{
			a[pos]*=2;
		}
		if(pos==0)
		    printf("%d",a[pos]+a[1]+a[2]);
		else if(pos==1)
		    printf("%d",a[0]+a[pos]+a[2]); 
		else if(pos==2)
		    printf("%d",a[0]+a[1]+a[pos]);	   
	}  
	else
	{
		maxi=max(max(a[0],a[1]),a[2]);
	 	for(i=0;i<3;i++)
		{
	     	if(a[i]==maxi)
	     	{	
	     		pos=i;
		 	}
		}
		for(i=0;i<k;i++)
		{
			a[pos]*=2;
		}
		if(pos==0)
		    printf("%d",a[pos]+a[1]+a[2]);
		else if(pos==1)
		    printf("%d",a[0]+a[pos]+a[2]); 
		else if(pos==2)
		    printf("%d",a[0]+a[1]+a[pos]);	
	}
	return 0;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
   ll n;
   cin>>n;
  if(n>=400 && n<=599)
  {
    cout<<8<<"\n";
  }
  else if(n>=600 && n<=799)
  {
    cout<<7<<"\n";
  }
  else if(n>=800 && n<=999)
  {
    cout<<6<<"\n";
  }
  else if(n>=1000 && n<=1199)
  {
    cout<<5<<"\n";
  }
  else if(n>=1200 && n<=1399)
  {
    cout<<4<<"\n";
  }
  else if(n>=1400 && n<=1599)
  {
    cout<<3<<"\n";
  }
  else if(n>=1600 && n<=1799)
  {
    cout<<2<<"\n";
  }
  else if(n>=1800 && n<=1999)
  {
    cout<<1<<"\n";
  }
}

Measured memory_bytes: 3632
//#include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef int64_t ll;

#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+6;

ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

// using namespace __gnu_pbds;
// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set

int32_t main()
{
IOS

    int n,m;
    cin>>n>>m;
    map<int,int> m1;
    int ans=0,ans1=0;;
    bool done[n+1];
    memset(done,0,sizeof(done));
    for(int i=1;i<=m;++i)
    {
         int p;
        cin>>p;
        string s;
        cin>>s;
       
        if(s=="AC")
        {
            if(done[p])
                continue;
            ans1++;
            ans+=m1[p];
            done[p]=1;
        }
        else
        {
            if(done[p])
                continue;
            m1[p]++;
        }
    }
    cout<<ans1<<" "<<ans<<endl;
    
}       

Measured memory_bytes: 6656
#include <stdio.h>
int saisho(int a,int b){

  int yaku=1,i,blank;

  if(a > b){

    blank=a;
    a=b;
    b=blank;

  }

  for(i = a; i >= 2; i--){

    if(a%i == 0 && b%i == 0){

      a /= i;
      b /= i;
      yaku *= i;

    }

  }

  return a*b*yaku;

}
      

int main(){

  int a[1000000],b,n,m,result=0,i,j,k,blank;
  
  scanf("%d %d",&n,&m);

  b=saisho(n,m);
  
  //printf("%d\n",b);

  for(i = 0; i < n; i++) scanf("%d",&a[i]);

  for(i = 0; i < b; i++) a[i]=a[i%n];

  for(i = 0; i < b; i += m){

    for(j = 0; j < m-1; j++){

      for(k = 0; k < m-1; k++){

        if(a[i+k] < a[i+k+1]){

          blank=a[i+k];
          a[i+k]=a[i+k+1];
          a[i+k+1]=blank;

        }

      }

    }

    result += a[i]-a[i+m-1];

  }

  printf("%d\n",result);

  return 0;

}

Measured memory_bytes: 4472
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


/*
 * ????????????????????\??????????£??????\???????????????
 * ????????§??????max??????????§?????????¨??????????£?????????????????????????????????£???????????????????????\??§??¨?????????????????????
 */
#define ELEMENT_NUM 10000

typedef struct UF{
    int parent;
}UF;

UF uf[ELEMENT_NUM + 1];


void initialize(int num){
    int i ;
    
    for (i=1; i <= num; i++) {
        uf[i].parent = i;
    }
}

int find(int a){

    if (a == uf[a].parent) {
        return a;
    }
    
    return uf[a].parent = find(uf[a].parent);
}

int isSame(int a, int b){
    
    if (find(a) == find(b)) {
        return 1;
    }
    else{
        return 0;
    }
}

void unite(int a, int b){
   a = find(a);
   b = find(b);
    
    if (a == b) {
        return;
    }
    
    uf[b].parent = a;
    
}


int main( ){
    
    int i, n, q, op, a, b;
    
    scanf("%d", &n);
    
    initialize(n);
    
    scanf("%d", &q);
    
    for (i=1; i<=q; i++){
        scanf("%d %d %d", &op, &a, &b);
        
        if (op == 0) {
            unite(a, b);
        }
        else{
            printf("%d\n", isSame(a, b));
        }
    }
    
    return 0;
}

Measured memory_bytes: 636
def prime?(n)
  (2..(n**(0.5)).to_i).each do |i|
    return false if n % i == 0
  end
  return n > 1
end
Q=gets.to_i
max = 10**5 + 10
a = Array.new(max, 0)

max.times do |i|
  a[i] = 1 if prime?(i) && prime?((i+1)/2)
end
s = Array.new(max+1, 0)
max.times do |i|
  s[i+1] = s[i] + a[i]
end
ans = []
Q.times do
  l, r = gets.split.map(&:to_i)
  r += 1
  ans << s[r] - s[l]
end

puts ans



Measured memory_bytes: 4732