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

#define input(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;cin>>n>>m;
    int sum=0;
    if(n<2&&m<2){
        cout<<0<<endl;
        return 0;
    }
    n--;m--;
    while(n>0){
        sum+=n;
        n--;
    }
    while(m>0){
        sum+=m;
        m--;
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.substring(s.length()-1).equals("s")) {
			System.out.println(s+"es");
		} else {
			System.out.println(s+"s");
		}
	}
}


Measured memory_bytes: 38404
#include <iostream>

using namespace std;

int calc(int num, int k) {
  int ans = 0;
  ans += (num / k);
  if (num % k != 0) {
    ans += 1;
  }

  return ans;
}

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

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

  cout << calc(n - 1, k - 1) << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;
typedef pair<string, string> P;
const ll MOD = 1000000007LL;
ll x[200001];
ll sum[200001];
int main() {
	int N;
	ll X;
	cin >> N >> X;
	for (int i = 0; i < N; i++) cin >> x[i];
	reverse(x, x + N);
	sum[0] = x[0];
	for (int i = 1; i < N; i++) sum[i] = sum[i - 1] + x[i];
	ll ans = 0;
	bool init = 1;
	for (int k = 1; k <= N; k++) {
		int x = 0;
		ll t = 0;
		for (int i = 0; i < N; i += k) {
			int l = k*x, r = min(k*(x + 1) - 1, N - 1);
			ll s = sum[r];
			if (l > 0) s -= sum[l - 1];
			if (x == 0) t += 5 * s;
			else t += (2 * (x + 1) + 1)*s;
			x++;
		}
		if (init) ans = t + k*X, init = 0;
		else ans = min(ans, t + k*X);
	}
	cout << ans + N*X << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(x-a>0 && x-b>0 && x-a>x-b) cout<<"B\n";
    else if(x-a>0 && x-b>0 && x-a<x-b) cout<<"A\n";
    else if(x-a<0 && x-b>0 && a-x<x-b) cout<<"A\n";
    else if(x-a<0 && x-b>0 && a-x>x-b) cout<<"B\n";
    else if(x-a<0 && x-b<0 && a-x>b-x) cout<<"B\n";
    else if(x-a<0 && x-b<0 && a-x<b-x) cout<<"A\n";
    else if(x-a>0 && x-b<0 && x-a<b-x) cout<<"A\n";
    else if(x-a>0 && x-b<0 && x-a>b-x) cout<<"B\n";
    return 0;
}


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

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

using namespace std;

int main(int argc, const char* argv[]) {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K & 1) {
		cout << B - A << endl;
	} else {
		cout << A - B << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;




int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) cout << c << endl;
	else if (a == c) cout << b << endl;
	else if (b == c) cout << a << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	A := make([]int, N + 2)
	full := 0
	for i := 1; i < N + 1; i++ {
		fmt.Scanf("%d", &A[i])
		full += abs(A[i - 1] - A[i])
	}
	full += abs(A[N] - A[N + 1])
	for i := 1; i < N + 1; i++ {
		fmt.Printf("%d\n", full - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]))
	}
	return
}

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


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int sum = accumulate(ALL(a),0);
    double mn = 1.0 * sum / (4*m);
    int cnt = 0;
    REP(i,n) if (a[i] >= mn) cnt++;

    ATYN(cnt >= m)

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int N,A,B; cin >>N >> A >> B;
    int P[105];
    rep(i,N) cin >> P[i];
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    rep(i,N){
        if(P[i] <= A) cnt1++;
        else if(A < P[i] && P[i] <= B) cnt2++;
        else cnt3++;
    }
    cout << min(cnt1,min(cnt2,cnt3)) << endl;
    return 0;
}

Measured memory_bytes: 3580
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
 
using namespace std;
  
int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> a(N);
    for (int i=0; i<M; ++i)
    {
        int k;
        cin >> k;
        for (int j=0; j<k; ++j)
        {
            int s;
            cin >> s;
            --s;
            a[s] |= 1<<i; //各スイッチにつながっている電球を保持
        }
    }

    int p=0;
    for (int i=0; i<M; ++i)
    {
        int tmp;
        cin >> tmp;
        p |= (tmp << i); 
    }

    int ans = 0;
    for(int s=0; s<(1<<N); ++s)
    {
        int t=0;
        for(int i=0; i<N; ++i)
        {
            if(1 & (s>>i))
            {
                t ^= a[i];
            }
        }
        if(t==p) ++ans;
    }

    cout << ans << endl;
    //std::cout << "Hello, Wandbox!" << std::endl;
}
 
// GCC reference:
//   https://gcc.gnu.org/
 
// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/
 
// Boost libraries references:
//   https://www.boost.org/doc/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
# define rep(i,n) for(int i=0;i<n;i++)
void solve(){
    int n;
    cin>>n;
    lli a[n];
    
    lli mod =1e9+7;
    lli b[n];
    rep(i,n){
        cin>>a[i];
    }
    b[0]=a[0];
    for(int i=1;i<n;i++){
        b[i] = (a[i]+b[i-1])%mod;
    }
    lli ans = 0;
    for(int i=0;i<n;i++){

            lli x =b[n-1]-b[i];
            if(x<0)
                x+=mod;
            ans+=(a[i]*x);
            ans%=mod;
        
    }
    cout<<ans<<endl;
    


}
int main()
{
    int t;
    //cin>>t;
    
    t=1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 6660
#include<bits/stdc++.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<queue>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define pb push_back
using namespace std;
typedef pair<int, int>pii;

map<string,int> C;

int main(){
	string A[105],B[105];
	int N,M;
	cin >> N;
	rep(i,N) cin >>A[i];
	cin >> M;
	rep(i,M) cin >>B[i];
	rep(i,N) C[A[i]]++;
	rep(i,M) C[B[i]]--;
	int a=-1;
	rep(i,N) a=max(a,C[A[i]]);
	rep(i,M) a=max(a,C[B[i]]);
	if(a<0) cout << "0"<<endl;
	else cout << a <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

signed main(){
	fast;
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int dp[n]={0};
	for(int i=1;i<n;i++){
		dp[i] = 1e10;
		for(int j=1;j<=k;j++){
			if(i-j>=0){
				dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
			}
		}
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
fun main(args: Array<String>) {
    var s = readLine()!!
    val n = s.length
    var list = mutableListOf<String>()
    for (i in 0 until n) {
        // 1文字ずつ取り出す
        val subString = s.substring(i, i + 1)
        // 文字が小文字だとtrue, 大文字だとfalseになる条件↓
        if (subString > subString.toUpperCase()) {
            list.add(subString.toUpperCase())
        } else {
            list.add(subString.toLowerCase())
        }
    }
    println(list.joinToString(""))
}


Measured memory_bytes: 28996
n,k,q = map(int,input().split())
A = [int(input()) for _ in range(q)]
#print(n,A)
p = [k-q]*n
for i in range(q):
  p[A[i]-1] += 1 

for num in p:
  if num <= 0:
    print("No")
  else:
    print("Yes")

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,C;
ll x[100005];
ll v[100005];
ll vsum[100005];
ll doko1[100005];
ll doko2[100005];
ll cal[100005];
ll ans;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>C;

rep(i,N) cin>>x[i]>>v[i];

vsum[0]=v[0];
rep1(i,N){
	vsum[i]=vsum[i-1]+v[i];
}

doko1[0]=max((ll)0,v[0]-2*x[0]);
rep1(i,N){
	doko1[i]=max(doko1[i-1],vsum[i]-2*x[i]);
}
doko2[N-1]=max((ll)0,v[N-1]-2*(C-x[N-1]));
rep1(i,N){
	ll j=N-1-i;
	doko2[j]=max(doko2[j+1],vsum[N-1]-vsum[j-1]-2*(C-x[j]));
}

rep(i,N){
	ll cmp1;
	if(i-1>=0) cmp1=vsum[N-1]-vsum[i-1]-(C-x[i]);
	else cmp1=vsum[N-1]-(C-x[i]);
	if(i-1>=0) cmp1+=doko1[i-1];
	ll cmp2=vsum[i]-x[i];
	if(i+1<=N-1) cmp2+=doko2[i+1];
	cal[i]=max(cmp1,cmp2);
}

rep(i,N){
	ans=max(ans,cal[i]);
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 4992
#include <cstdio>

using namespace std;

int main() 
{
    int n;
    scanf("%d", &n);

    bool a[n];
    bool ans[n];

    for (int i = 0; i < n; ++i) {
       int j;
       scanf("%d", &j);
       a[i] = (j == 1);
       ans[i] = a[i];
    } 

    for (int i = n; i > 0; --i) {
        bool total = false;

        for (int j = 1; i * j - 1 < n; ++j) {
            total ^= ans[i * j - 1];
        }

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

    int total = 0;

    for (int i = 0; i < n; ++i) {
        if (ans[i]) total++;
    }
    
    printf("%d\n", total);

    for (int i = 0; i < n; ++i) {
        if (ans[i]) printf("%d ", i + 1);
    }

    return 0;
}

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

using namespace std;

int main() {
	int mountain[10];
	int m_max[3];
	int MAX;
	int count = 0;
	int n;

	for(int i = 0; i < 10; i++) {
		cin >> mountain[i];
	}

	MAX = mountain[0];

	while(count != 3){

		for(int i = 0; i < 10; i++) {
			if(MAX < mountain[i]) {
				MAX = mountain[i];
				n = i;
			}
		}

		m_max[count] = MAX;
		count++;
		mountain[n] = 0;
		MAX = 0;

	}

	for(int i = 0; i < 3; i++) {
		cout << m_max[i] << endl;
	}

}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>
#include <map>

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


int main(){
    map<ll,ll> mp;
    ll N,K,a,b;
    cin>>N>>K;
    for(ll i=0;i<N;i++){
        cin>>a>>b;
        mp[a]+=b;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        a=itr->first;
        K-=itr->second;
        if(K<=0){
            break;
        }
    }
    cout<<a<<endl;
    return 0;
}


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

// Nを入力したあとでN個の要素をもつ配列を入力する
vector<int> input(int N) {
  vector<int> vec(N);
  rep (i, N) {
    cin >> vec.at(i);
  }
  return vec;
}

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

  vector<int> H;
  H = input(N);

  sort(H.begin(), H.end()); 
  reverse(H.begin(), H.end());

  long long int at = 0;

  if(K<N){  
    for(int i=K; i<N; i++){ // K体までは必殺なので無視
      at += H.at(i);
    }
  }
  
  cout << at << endl;

}


Measured memory_bytes: 1024
n=int(input())
hl=list(map(int,input().split()))

total=1

for i in range(1,n):
  flag=True
  #print(i)
  for j in range(i):
    #print(j)
    dif=hl[i]-hl[j]
    #print(dif)
    if dif<0:
      flag=False
      break
  if flag:
    total+=1
print(total)

Measured memory_bytes: 3060
from math import *

def lcm(a,b):
    return a*b//gcd(a,b)

def lcm2(array):
    temp = 1
    for a in array:
        temp = lcm(temp, a)
    return temp

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x:x//2, A))

b = []
for a in A:
    cnt = 0
    while a:
        if not a%2:
            cnt += 1
            a = a // 2
        else:
            break
    b.append(cnt)

if b.count(cnt) != N:
    print(0)
    exit()

res = lcm2(A)

print((M//res-1)//2+1)

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

int main()
{
  while(1){
    int n, w;
    cin >> n >> w;
    if(n == 0 && w == 0) break;
    vector<double> v(11);
    fill(v.begin(), v.end(), 0.0);
    double m = 0.0;
    int mi;
    for(int i = 0; i < n; i++){
      double x;
      cin >> x;
      if(m < x){
        m = x;
        mi = x/w;
      }
      v[x/w]++;
    }
    double me = *max_element(v.begin(), v.end());
    for(int i = 0; i <= mi; i++)
      v[i] *= mi - i;
    double ans = 0;
    for(int i = 0; i <= mi; i++)
      ans += v[i];
    ans = ans / (double)mi / me + 0.01;
    printf("%.6lf\n", ans);
  }
}

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

int main() {
    int N;
    cin >> N;
    bool flag = false;
    int a;
    for(int i=0; i<N; ++i) {
        cin >> a;
        if(a % 2 == 1) flag = true;
    }
    if(flag) cout << "first" << endl;
    else cout << "second" << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
using namespace std;

typedef long long ll;

void factorize(vector<ll> &p,vector<ll> &cnt,ll x) {
    p.clear(); cnt.clear();
    if(x == 1 || x == 0) {
        p.push_back(1);
        cnt.push_back(1);
        return;
    }

    int pp = 2;
    while(true) {
        if(x <= 1) break;
        if(x % pp == 0) {
            p.push_back(pp);
            cnt.push_back(0);
            while(x%pp == 0) {
                cnt[cnt.size()-1]++;
                x /= pp;
            }
        }
        pp++;
    }
    return;
}

int main() {
    int base;
    string a;
    while(cin>>base>>a) {
        if(base == 0 && a == "0") break;
        unsigned long long m = 0;
        for(int i=0; i<a.length(); ++i) {
            m *= base;
            if(a[i] <= '9') m += a[i] - '0';
            else m += a[i] - 'A' + 10;
        }

        // cout<<base<<" "<<m<<endl;
        vector<ll> p,cnt;
        factorize(p,cnt,base);
        // for(int i=0; i<p.size(); ++i) cout<<p[i]<<" : "<<cnt[i]<<endl;

        vector<ll> pp(p.size(), 0);
        for(int i=0; i<p.size(); ++i) {
            ll n = p[i];
            while(n <= m) {
                pp[i] += m/n;
                n *= p[i];
            }
        }

        ll ans = 1ll<<62;
        for(int i=0; i<p.size(); ++i) {
            // cout<<p[i]<<" "<<pp[i]/cnt[i]<<endl;
            ans = min(ans, pp[i]/cnt[i]);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 936
#include <iostream>
#include <queue>

using namespace std;
static const int N=100;
static const int INFTY =(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    for (int i=0;i<n;i++)d[i]=INFTY;
    d[s]=0;
    int u;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(int v=0;v<n;v++){
            if(M[u][v]==0)continue;
            if(d[v]!=INFTY)continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<((d[i]==INFTY)?(-1):d[i])<<endl;
    }
}

int main(){
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    bfs(0);
    
    return 0;
    
}


Measured memory_bytes: 3132
import sys
 
N, W = map(int, input().split())
 
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
 
dp = [[0]*(N+1) for i in range(W+1)]
for i in range(1, W+1):
        for j in range(1, N+1):
                if i - WV[j-1][0]>=0:
                        dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = dp[i][j-1]
 
print(dp[W][N])

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

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

const long long MOD = 1000000007;

int main(){
  ll n,k;
  ll ans=0;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  rep(i,n-k){
      ans += h.at(i);
  }
  cout << ans << endl;

}


Measured memory_bytes: 1024
#include<stdio.h>

using namespace std;
typedef long long ll;

const int N=55;
ll a[N];
int n;

bool check(){
    for(int i=1;i<=n;i++){
        if(a[i]>=n) return 1;
    }
    return 0;
}

ll cnt[N];
void solve(){

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

    ll ans=0;
    while(check()){
        ll tot=0;
        for(int i=1;i<=n;i++){
            cnt[i]=a[i]/n,tot+=cnt[i];
            a[i]%=n;
        }
        ans+=tot;
        for(int i=1;i<=n;i++){
            a[i]+=tot-cnt[i];
        }
    }
    printf("%lld\n",ans);
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 3e5+10;
char s[maxn];
int y[maxn],x[maxn],c[maxn],sa[maxn],rk[maxn],height[maxn],wt[30];
int n,m;
void get_SA() {
    for (int i=1; i<=n; ++i) ++c[x[i]=s[i]];
//c数组是桶
//x[i]是第i个元素的第一关键字
    for (int i=2; i<=m; ++i) c[i]+=c[i-1];
//做c的前缀和，我们就可以得出每个关键字最多是在第几名
    for (int i=n; i>=1; --i) sa[c[x[i]]--]=i;
    for (int k=1; k<=n; k<<=1) {
        int num=0;
        for (int i=n-k+1; i<=n; ++i) y[++num]=i;
//y[i]表示第二关键字排名为i的数，第一关键字的位置
//第n-k+1到第n位是没有第二关键字的 所以排名在最前面
        for (int i=1; i<=n; ++i) if (sa[i]>k) y[++num]=sa[i]-k;
//排名为i的数 在数组中是否在第k位以后
//如果满足(sa[i]>k) 那么它可以作为别人的第二关键字，就把它的第一关键字的位置添加进y就行了
//所以i枚举的是第二关键字的排名，第二关键字靠前的先入队
        for (int i=1; i<=m; ++i) c[i]=0;
//初始化c桶
        for (int i=1; i<=n; ++i) ++c[x[i]];
//因为上一次循环已经算出了这次的第一关键字 所以直接加就行了
        for (int i=2; i<=m; ++i) c[i]+=c[i-1]; //第一关键字排名为1~i的数有多少个
        for (int i=n; i>=1; --i) sa[c[x[y[i]]]--]=y[i],y[i]=0;
//因为y的顺序是按照第二关键字的顺序来排的
//第二关键字靠后的，在同一个第一关键字桶中排名越靠后
//基数排序
        swap(x,y);
//这里不用想太多，因为要生成新的x时要用到旧的，就把旧的复制下来，没别的意思
        x[sa[1]]=1;
        num=1;
        for (int i=2; i<=n; ++i)
            x[sa[i]]=(y[sa[i]]==y[sa[i-1]] && y[sa[i]+k]==y[sa[i-1]+k]) ? num : ++num;
        if (num==n) break;
        m=num;
    }
    return ;
}

void get_height() {
    int k=0;
    for (int i=1; i<=n; ++i) rk[sa[i]]=i;
    for (int i=1; i<=n; ++i) {
        if (rk[i]==1) continue;//第一名height为0
        if (k) --k;//h[i]>=h[i-1]-1;
        int j=sa[rk[i]-1];
        while (j+k<=n && i+k<=n && s[i+k]==s[j+k]) ++k;
        height[rk[i]]=k;//h[i]=height[rk[i]];
    }
    return ;
}
bool check(int x){
    int maxx,minn=maxn;
    for(int i=1;i<=n;i++){
        if(height[i]<x)maxx=minn=sa[i];
        else{
            maxx=max(maxx,sa[i]);
            minn=min(minn,sa[i]);
            if(maxx-minn>=x)
                return true;
        }
    }
    return false;
}

int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    m=122;
    //scanf("%d",&n);
    //cout<<n<<"\n";
    get_SA();
    get_height();
    int l=0,r=n/2,ans;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid))ans=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 5248
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define MAX 100005
#define MOD 1000000007
#define INF 1e9
#define vi vector<int>
#define vl vector<ll> 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<'\n';}
vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)){ v.emplace_back(x);} return move(v); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...); }
//int bit[MAX], p[MAX];
//void upd(int i, int v=1) {while(i < MAX){bit[i] += v; i += i&-i;}}
//int read(int i) {int s=0; while(i > 0){s += bit[i]; i -= i&-i;} return s;}
//int fs(int i) {while(i != p[i]){p[i]=p[p[i]]; i=p[i];} return i;}
//ll modexp(ll a, ll b, ll c=MOD) { ll res=1;while(b){res=b&1?(res*a)%c:res; a=(a*a)%c; b>>=1;} return res; }
// auto f = [](int a, int b) -> int { return a+b; };
 
int a[101];
int get(int n) {
	for(int i=n;i>0;--i) {
		if(a[i] == i) return i;
	}
	return -1;
}
void fix(int ind, int n) {
	for(int i=ind;i<n;++i) {
		a[i] = a[i+1];
	}
}

int main() {
 	int n,i,m;
 	cin>>n;
 	for(i=1;i<=n;++i) {
 		cin>>a[i];
 	}

 	vector<int> vt;
 	bool good = true;
 	m = n;
 	while(m) {
 		int ind = get(m);
 		if(ind == -1) {
 			good = false;
 			break;
 		}
 		fix(ind,m);
 	// 	cout<<"ind="<<ind<<" : ";
 	// 	for(int i=1;i<m;++i) cout<<a[i]<<",";
		// cout<<endl;
 		vt.pb(ind);
 		m--;
 	}
 	if(not good) cout<<-1<<endl;
 	else {
 		reverse(vt.begin(), vt.end());
 		for(auto x : vt) {
 			cout<<x<<endl;
 		}
 	}
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    ll a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    ll ans = 0;
    for (i = 0; i < n - 1; i++) {
        ans += a[(i + 1) / 2];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5216
package main

import "fmt"

func main() {
	var S, T, U string
	var A, B int
	fmt.Scanf("%s %s", &S, &T)
	fmt.Scanf("%d %d", &A, &B)
	fmt.Scanf("%s", &U)
	if S == U {
		A--
	} else {
		B--
	}
	fmt.Printf("%d %d", A, B)


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    string s;
    cin >> s;
    ll i, j, n = s.size();
    vll ans(n, 0);
    for(i = 0; i < n; )
    {
        j = i;
        while(j < n)
        {
            if(s[j] != 'R')
                break;
            j++;
        }
        // this is a two pointers approach, remember it
        ll nr = (j - i);
        if(nr % 2 == 0)
        {
            // number of Rs even
            ans[j] = 1 + nr / 2;
            ans[j - 1] = 1 + (nr - 1) - nr / 2; 
        }
        else
        {
            ans[j] = 1 + (nr - 1) - nr / 2;
            ans[j - 1] = 1 + nr / 2;
        }
        ll k = j;
        while(k < n)
        {
            if(s[k] != 'L')
                break;
            k++;
        }
        ll nl = (k - j);
        if(nl % 2 != 0)
        {
            // number of Ls odd
            ans[j] += nl / 2;
            ans[j - 1] += (nl - 1) - nl / 2; 
        }
        else
        {
            ans[j] += nl - 1 - nl / 2;
            ans[j - 1] += nl / 2;
        }
        i = k;
    }
    for(auto x : ans)
        cout << x << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 1488
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N;
  cin >> N;
  int64_t answer = divisor(N - 1).size() - 1L;
  for (auto div : divisor(N)) {
    if (div == 1) continue;
    int64_t N0 = N;
    while (N0 % div == 0) {
      N0 /= div;
    }
    if (N0 % div == 1) ++answer;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {

    static final int max = 200000;
    public static void main(String[]args){
        int R[] = new int[max];
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i<n; i++)
        {
            R[i]= scanner.nextInt();
        }

        int maxv = -2000000000; //设置一个足够小的值
        int minv = R[0];

        for (int i = 1; i<n; i++){
            maxv = Math.max(maxv,R[i]-minv);
            minv = Math.min(minv,R[i]);
        }
        System.out.println(maxv);
    }
}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s; --t;
    vector<vpii> ga(n), gb(n);
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u; --v;
        ga[u].emplace_back(v, a);
        ga[v].emplace_back(u, a);
        gb[u].emplace_back(v, b);
        gb[v].emplace_back(u, b);
    }
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> qa, qb;
    vll dista(n, INF), distb(n, INF);
    qa.emplace(0, s);
    dista[s] = 0;
    while (!qa.empty()) {
        int pos = qa.top().second; qa.pop();
        for (auto tos : ga[pos]) {
            int to = tos.first, cost = tos.second;
            if (dista[to] > dista[pos]+cost) {
                qa.emplace(dista[pos]+cost, to);
                dista[to] = dista[pos] + cost;
            }
        }
    }
    qb.emplace(0, t);
    distb[t] = 0;
    while (!qb.empty()) {
        int pos = qb.top().second; qb.pop();
        for (auto tos : gb[pos]) {
            int to = tos.first, cost = tos.second;
            if (distb[to] > distb[pos]+cost) {
                qb.emplace(distb[pos]+cost, to);
                distb[to] = distb[pos] + cost;
            }
        }
    }
    vll mns(n+1, INF);
    repr(i, n) mns[i] = min(mns[i+1], dista[i]+distb[i]);
    rep(i, n) cout << (ll)(1e15) - mns[i] << endl;
    return 0;
}


Measured memory_bytes: 17396
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

int main()
{
    int N[4];
    REP(i, 4) cin >> N[i];

    sort(N, N+4);
    bool yes = true;
    if (N[0] != 1) yes = false;
    if (N[1] != 4) yes = false;
    if (N[2] != 7) yes = false;
    if (N[3] != 9) yes = false;

    cout << (yes ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main( void )
{
  int x, t, n;
  int i = 0;

  scanf( "%d %d %d", &n, &x, &t );

  while( 1 ) {
    n = n - x;
    i++;
    if( n <= 0 )
      break;
  }

  printf( "%d\n", i * t );
    
  
  return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>

int main(void)
{
	int i;
	int no;
	i = 1;
	
	//printf("??£?????´??°?????\????????????????????? :");
	//scanf("%d", &no);
	
	while(1){
		scanf("%d", &no);
		i++;
		if(no == 0){
			break;
		}
		printf("Case %d: %d\n", i - 1, no);
	}
	
	
	return 0;
}

Measured memory_bytes: 600
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)

Measured memory_bytes: 94232
def main():
    n, k = map(int, input().split())
    aa = list(map(int, input().split()))
    m = aa.index(1) + 1
    i = 0
    c = 0
    while i < m:
        if i == 0:
            i += k
        else:
            i += (k - 1)
        c += 1
    r = max(n - i, 0)
    c += r // (k - 1) + int(r % (k - 1) != 0)
    print(c)


if __name__ == '__main__':
    main()


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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

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

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }


  int main(){
    string S;
    cin >> S;
    int N = S.length() + 1;
    vector<int>A(N, 0);

    REP(i, N - 1){
      if(S[i] == '<') A[i + 1] = max(A[i] + 1, A[i + 1]);
    }
    for(int i = N - 1; i >= 0; i--){
      if(S[i] == '>') A[i] = max(A[i + 1] + 1, A[i]);
    }
    ll ans = 0;
    REP(i, N) ans += A.at(i);

    print(ans);

  }

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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] w = new int[N];
		int[] v = new int[N];
		for (int i = 0; i < N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		long[] dp = new long[100001];
		Arrays.fill(dp, W + 1);
		dp[0] = 0;
		for (int i = 0; i < N; i++) {
			for (int j = dp.length - 1 - v[i]; j >= 0; j--) {
				if (dp[j] + w[i] < dp[j + v[i]]) {
					dp[j + v[i]] = dp[j] + w[i];
				}
			}
		}
		for (int i = dp.length - 1; ; i--) {
			if (dp[i] <= W) {
				System.out.println(i);
				break;
			}
		}
	}

}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

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

  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
};


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int N, W;
int w[100], v[100];
int dp[101][100001];   // DP????????????

// i ????????\???????????????????????????????????? j ??\??????????????????????????¶
int rec(int i, int j) {
	// ?????§?????????????????¨?????????????????°???????????????????????¨
	if (dp[i][j] >= 0) return dp[i][j];

	int res;
	// ????????????????????£???????????¨???0
	if (i == N) res = 0;
	// ??????????????????????????????????????????????°?????????¨???
	// ?¬??????????????§??????????????????????????????????
	else if (j < w[i]) res = rec(i + 1, j);
	// ?????????????????\????????´?????¨??\???????????´?????????????????????
	else res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);

	return dp[i][j] = res;
}

int main() {
	cin >> N >> W;
	rep(i, N) cin >> v[i] >> w[i];
	mset(dp, -1);

	int ans = rec(0, W);

	// rep(i, N + 1) {
	// 	rep(j, N + 2) {
	// 		if (dp[i][j] < 0) cout << dp[i][j] << " ";
	// 		else cout << " " << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

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

Measured memory_bytes: 40624
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N = int(input())
ans = 10
for i in range(1,round(math.sqrt(N))+1):
    if N % i == 0:
        f = max(i,N//i)
        f = len(str(f))
        ans = min(f,ans)
    else:
        pass
print(ans)


Measured memory_bytes: 5460
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
int main() {
	ll min_c[26] = {};
	rep(i, 0, 26) {
		min_c[i] = 1 << 21;
	}

	ll n; cin >> n;
	rep(i, 0, n) {
		string s; cin >> s;

		ll c[26] = {};
		rep(j, 0, s.size()) {
			c[s[j] - 'a']++;
		}

		rep(j, 0, 26) {
			min_c[j] = min(c[j], min_c[j]);
		}
	}

	rep(i, 0, 26) {
		rep(j, 0, min_c[i]) {
			cout << (char)(i + 'a');
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;
int a[101010];
int main(){
    int n;
    cin>>n;
    int m=100000;
    rep(i,n){
        int x;
        cin>>x;
        a[x-1]++;
    }
    int ans1=0,ans2=0;
    rep(i,m){
        if(a[i]%2)++ans1;
        else if(a[i]>=2)++ans2;
    }   
    if(ans2%2)--ans1;
    cout<<ans1+ans2<<endl;
   return 0;
}

Measured memory_bytes: 640
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
300IQ as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         //solve
         sort(arr);
         int res = 0;
         int[] freq = new int[1000001];
         for(int x: arr)   freq[x]++;
         boolean[] seen = new boolean[1000001];
         for(int x: arr)
            if(!seen[x])
            {
               if(freq[x] == 1)
                  res++;
               for(int k=x; k <= 1000000; k += x)
                  seen[k] = true;
            }
         System.out.println(res);
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }

Measured memory_bytes: 55092
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
}
bool prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    int x=0;
    int y=0;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='S'){
            y=max(y,x);
            x=0;
        }
        else x++;
    }
    cout<<max(x,y);
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();
    int old = 0;

    for (int i = 0; i < N; ++i) {
        int x = in.read<int>();
        if (old <= x) {
            old = x;
        } else if (old <= x + 1) {
            old = x + 1;
        } else {
            out << "No";
            return 0;
        }
    }

    out << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,h,w,a,b,ans=0;
	cin>>n>>h>>w;
	rep(i,n){
		cin>>a>>b;
		if(a>=h&&b>=w)ans++;
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 384
import heapq

VEr = input().split()
#隣接リスト
V,E,r = int(VEr[0]), int(VEr[1]), int(VEr[2])
List = [[] for i_ in range(V)]
heap = []
result = [float("inf")] * V
for i in range(E):
    s,t,d = map(int,input().split())
    List[s].append([t, d])

result[r] = 0
heapq.heappush(heap, [0,r])
while len(heap) != 0:
    #temp[コスト,]
    temp = heapq.heappop(heap)
    cost = temp[0]
    basyo =temp[1]
    if(cost > result[basyo]):
        continue
    else:
        for i in List[basyo]:
            if(result[i[0]] > result[basyo] + i[1]): 
                result[i[0]] = result[basyo] + i[1]
                heapq.heappush(heap, [result[i[0]] , i[0]])

for i in result:
    if(i == float("inf")):
        print("INF")
    else:
        print(i)


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


void solve(long long N, std::string S, std::string T){
    REP(i, N){
        cout << S.at(i) << T.at(i);
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(N, S, T);
    return 0;
}


Measured memory_bytes: 256