akhauriyash/Code-Regression huggingface dataset:
using System;

public class Program
{
    private int N;
    private long K;
    private int[] A;
    private int[] F;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextLong();
        A = sc.IntArray();
        Array.Sort(A);
        F = sc.IntArray();
        Array.Sort(F, (a, b) => -a.CompareTo(b));
        long ok = 999999999999999;
        long ng = -1;

        while (ok - ng > 1)
        {
            long med = (ok + ng) / 2;

            if (Check(med))
                ok = med;
            else
                ng = med;
        }

        Console.WriteLine(ok);
    }

    private bool Check(long l)
    {
        long cnt = 0;
        for (int i = 0; i < N; i++)
        {
            long req = l / F[i];

            cnt += Math.Max(0, A[i] - req);
            if (cnt > K)
                return false;
        }

        return true;
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 47456
import itertools
N, M, X = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
li = []
for i in range(N+1):
    for j in itertools.combinations(range(N), i):
        sm = [0] * (M+1)
        for k in j:
            for l in range(M+1):
                sm[l] += a[k][l]
        if all(y >= X for y in sm[1:M+1]):
            li.append(sm[0])
if li == []:
    print(-1)
else:
    print(min(li))

Measured memory_bytes: 9276
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	long long int t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	if (((a1 - b1) * t1 + (a2 - b2) * t2) == 0) {
		cout << "infinity" << endl;
	}
	else if ((a1 - b1) > 0 && ((a1 - b1) * t1 + (a2 - b2) * t2) > 0) {
		cout << 0 << endl;
	}
	else if ((a1 - b1) < 0 && ((a1 - b1) * t1 + (a2 - b2) * t2) < 0) {
		cout << 0 << endl;
	}
	else {
		// cout << "not infinity" << endl;
		long long int d1 = (a1 - b1) * t1;
		long long int d2 = (a1 - b1) * t1 + (a2 - b2) * t2;
		// cout << d1 << endl << d2 << endl;
		cout << abs(d1) / abs(d2) * 2 + (d1 % d2 == 0 ? 0 : 1) << endl;
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
 
int main(){
    fast 
    int n;cin>>n;
    ll sum=0;
    unordered_map<int,int>cnt;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        sum+=x;
        cnt[x]++;
    }
    int q;cin>>q;
    while(q--){
        int a,b;cin>>a>>b;
        cnt[b]+=cnt[a];
        sum+=(b-a)*cnt[a];
        cnt[a]=0;
        cout<<sum<<endl;
    }
    
    
    return 0;
}

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

template <class T>
inline void read(T &res)
{
	char ch;
	while (ch = getchar(), !isdigit(ch));
	res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
}

using std::vector;
typedef long long ll;
const int N = 1e5 + 5;
const int mod = 998244353;

vector<int> e[N];
int am, bm, cm, n, m, bas;
int sg[N], vis[N], ans[N], b[N], c[N], ex[N];

template <class T>
inline void CkMax(T &x, T y) {x < y ? x = y : 0;}

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

inline void solve()
{
	for (int i = 1; i <= n; ++i)
		e[i].clear();
	read(m);
	for (int i = 1, u, v; i <= m; ++i)
	{
		read(u); read(v);
		if (u > v)
			std::swap(u, v);
		e[u].push_back(v);
	}
	bm = 0;
	for (int i = n; i >= 1; --i)
	{
		sg[i] = 0;
		for (int j = 0, jm = e[i].size(); j < jm; ++j)
			vis[sg[e[i][j]]] = i;
		while (vis[sg[i]] == i)
			++sg[i];
		add(b[sg[i]], ex[i]);
		CkMax(bm, sg[i]);
	}
	cm = 0;
	for (int i = 0; i <= am; ++i)
	if (ans[i])
		for (int j = 0; j <= bm; ++j)
		if (b[j])
		{
			c[i ^ j] = (1ll * ans[i] * b[j] + c[i ^ j]) % mod;
			CkMax(cm, i ^ j);
		}
	for (int i = 0; i <= am; ++i)
		ans[i] = 0;
	for (int i = 0; i <= bm; ++i)
		b[i] = 0;
	am = cm;
	for (int i = 0; i <= cm; ++i)
		ans[i] = c[i], c[i] = 0;
	for (int i = 0; i <= m; ++i)
		vis[i] = 0; 
}

int main()
{
	read(n);
	bas = (ll)(1e18) % mod;
	ex[0] = 1;
	for (int i = 1; i <= n; ++i)
		ex[i] = 1ll * ex[i - 1] * bas % mod;
	
	am = 0;
	ans[0] = 1;
	solve();
	solve();
	solve();
	printf("%d\n", ans[0]); 
}

Measured memory_bytes: 6400
double p[333][333][333];
n;c[4];j,k;
main(i,a){
	for(;~scanf("%d",&a);)!n?n=a:c[a]++;
	for(;i>n?i=0,++j>n?j=0,k++<n:1:1;i++)p[i][j][k]=(i*p[i?i-1:i][j][k]+j*p[i+1][j?j-1:j][k]+k*p[i][j+1][k?k-1:k]+n)/(i+j+k);
	printf("%.9f",p[c[1]][c[2]][c[3]]);
}

Measured memory_bytes: 262144
/*
ID: dorijan1
TASK: tu napisi ime zadatka molim te molim te ali samo ako si na usaco training
LANG: C++11
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
const int MOD=1000000007;
const int MOD2=998244353;
const int BASE=29;
const ll LLINF=1ll<<60;
const char en='\n';

void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}

ll raand()
{
   return rand()*RAND_MAX+rand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

ll mult(ll a,ll b)
{
	return (a*b)%MOD;
}

ll pot(ll n,ll k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

ll divide(ll a,ll b)
{
	return mult(a,pot(b,MOD-2));
}

ll sub(ll a,ll b)
{
	return (a-b+MOD)%MOD;
}

ll add(ll a,ll b)
{
	return (a+b)%MOD;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

pair<int,int> has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (auto a: x)
	{
		h1*=BASE;
		h1+=a-'a';
		h1%=MOD;
		h2*=BASE;
		h2+=a-'a';
		h2%=MOD2;
	}
	return {h1,h2};
}

const int N=300010;
int n;
ll zs[N],sol;
int a;

int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>a;
		zs[i]=a-(i+1);
	}
	sort(zs,zs+n);
	int b=zs[n/2];
	for (int i=0;i<n;++i) sol+=abs(zs[i]-b);
	cout<<sol;
}





Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final long n = Long.parseLong(in.nextLine());
        System.out.println(numToTitle(n));
    }

    public static String numToTitle(long n) {
        final StringBuilder sb = new StringBuilder();
        while (n > 0) {
            n--;
            sb.append((char) ('a' + n % 26));
            n /= 26;
        }
        return sb.reverse().toString();
    }
}


Measured memory_bytes: 35820
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		
		String text = sc.next();
		for(int i = 0; i<n; i++) {
			if(i == k-1) {
				System.out.print(Character.toLowerCase(text.charAt(i)));
			} else {
				System.out.print(text.charAt(i));
			}
		}
//		long n= sc.nextLong();
	}
}

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

using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    ll sum = 0;
    unordered_map<int, int> cntMap;
    for (int i = 0; i < N; ++i) {
        cntMap[A[i]]++;
    }
    for (const auto& p : cntMap) {
        int cnt = p.second;
        sum += (ll)((cnt - 1LL) * cnt) / 2;
    }
    for (int item : A) {
        cout << sum - (cntMap[item] - 1) << endl;
    }
}


Measured memory_bytes: 8392
#include <iostream>
#define MAX_N 100000

using namespace std;

typedef long long ll;

int n;
int a[MAX_N];


void solve() {
     ll tmp1 = 0, tmp2 = 0; 
     ll sum = 0;
     for(int i = 0; i < n; i++) {
        sum += a[i];
        if(i % 2 ==  0) {
            if(sum <= 0) {
                tmp1 += -sum + 1;
                sum = 1;
            }
        }else {
            if(sum >= 0) {
                tmp1 += sum + 1;
                sum = -1;
            }
        }
    }

    sum = 0;
    for(int i = 0; i < n; i++) {
        sum += a[i];
        if(i % 2 ==  1) {
            if(sum <= 0) {
                tmp2 += -sum + 1;
                sum = 1;
            }
        }else {
            if(sum >= 0) {
                tmp2 += sum + 1;
                sum = - 1;
            }
        }
    }
    ll ans = min(tmp1, tmp2);
    
    cout << ans << endl;
}

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

Measured memory_bytes: 640
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    string S;
    cin>>S;
    int N=S.size();
    auto dp=make_vec<ll>(N+1,13);

    REP(i,13){
        dp[0][i]=0;
    }
    dp[0][0]=1;

    REP(i,N){
        if(S[i]=='?'){
            REP(j,10){
                REP(k,13){
                    dp[i+1][(10*k+j)%13]+=dp[i][k];
                }
            }
        }else{
            int j=S[i]-'0';
            REP(k,13){
                dp[i+1][(10*k+j)%13]+=dp[i][k];
            }
        }
        REP(j,13){
            dp[i+1][j]%=MOD;
        }
    }
    cout<<dp[N][5]<<endl;

}

Measured memory_bytes: 13696
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  cin>>N;
  bool ok = true;
  int cnt = 0;
  REP(i, N){
    char c; int t;
    cin>>c>>t;
    if(c == '('){
      cnt += t;
    }else{
      cnt -= t;
    }
    if(cnt < 0) ok = false;
  }
  if(ok && cnt == 0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <string.h>
#define maxn 4010
#define LL long long
LL sum;
char s[maxn];
int r[maxn],g[maxn],b[maxn],n;
void count(char a,char b,char c,int *p){//abc
	int i,j,k;
	for(i=1;i<=n;i++)
		for(k=i+1;k<=n;k++)
			if(s[i]==a&&s[k]==c){
				if((i+k)%2==0){
					j=(i+k)/2;
					if(s[j]==b)sum+=p[k-1]-p[i]-1;
					else sum+=p[k-1]-p[i];
				}else sum+=p[k-1]-p[i];
			}
}
int main(){
	int i;
	scanf("%d%s",&n,s+1);
	for(i=1;i<=n;i++){
		r[i]=r[i-1],g[i]=g[i-1],b[i]=b[i-1];
		if(s[i]=='R')r[i]+=1;
		else if(s[i]=='G')g[i]+=1;
		else if(s[i]=='B')b[i]+=1;
	}
	count('R','G','B',g);
	count('B','G','R',g);
	count('R','B','G',b);
	count('G','B','R',b);
	count('B','R','G',r);
	count('G','R','B',r);
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 1784
/*
AOJ #2806
title:Weight Range
@kankichi573
2016/11/15
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct A_st {
  int no;
  int wt;
} A[1000],A1[1000];
int M,N,min_val[1000],max_val[1000];
int gcd_mn,no_seq;

int gcd_(int m,int n)
{
  int r;
  
  if(m < n)
    gcd_(n,m);
  if((r=(m % n))==0)
    return(n);
  else
    return (gcd_(n,r));
}

int compA( const void * a , const void * b ) {

  if( ((struct A_st * )a)->wt > ((struct A_st * )b)->wt)
    return -1;

  else
    if( ((struct A_st * )a)->wt == ((struct A_st * )b)->wt)
    return 0;
  
  return 1;
}

void dump(struct A_st A[])
{
  int i;
  
  for(i=0;i<N;i++)
    printf("%d :%d\n",A[i].wt,A[i].no);

}

void dump2()
{
  int i;

  for(i=0;i<N;i++)
    printf("%d|",max_val[i]);
  printf("\n");

  for(i=0;i<N;i++)
    printf("%d|",min_val[i]);
  printf("\n");

}

int solve()
{
  int i,j,j1,p_,w_,c,ret;
  ret=0;
  for(i=c=0;i<N;i++)
    {
      p_ = A1[i].no;
      w_ = A1[i].wt;
      for(j=p_-M+1;j<=p_;j++)
	{
	  j1 =(j + N) % N;
	  if((j1 % gcd_mn)==0 && max_val[j1]==-1)
	    {
	      max_val[j1]=w_;
	      c++;
	      ret += w_;		
	    }
	}
      if(c >= no_seq)
	break;
    }
  
  for(i=N-1,c=0;i>=0;i--)
    {
      p_ = A1[i].no;
      w_ = A1[i].wt;
      for(j=p_-M+1;j<=p_;j++)
	{
	  j1 =(j + N) % N;
	  if((j1 % gcd_mn)==0 && min_val[j1]==-1)
	    {
	      min_val[j1]=w_;
	      c++;
	      ret -= w_;		
	    }
	}
      if(c >= no_seq)
	break;
    }
  //dump2();
  return(ret);

}



int main()
{
  int i,ret;

  memset(min_val,-1,sizeof(min_val));
  memset(max_val,-1,sizeof(max_val));
  
  scanf("%d %d",&N,&M);
  gcd_mn = gcd_(N,M);
  no_seq = N/gcd_mn;

  for(i=0;i<N;i++)
    {
      scanf("%d",&A[i].wt);
      A[i].no = i;
    }
  memcpy(A1,A,sizeof(A));
  qsort(A1,N,sizeof(struct A_st),compA);

  // dump(A1);
  ret=solve();
  printf("%d\n",ret);
  
    return(0);
}

Measured memory_bytes: 676
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n, m;
    cin >> n >> m;
    int mx = (n + 1) / 2;
    if (m <= mx) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最小公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最大公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[300000];
    REP(i,n)cin >> a[i+1];
    bool x[300000] = {false};
    vector<ll> v;
    FORR(i,n+1,1){
      int sum=0;
      for(int j=i;j<=n;j+=i)if(x[j])sum++;
      if(a[i]!=sum%2){
        x[i]=true;
        v.push_back(i);
      }
    }
    cout << v.size() << endl;
    REP(i,v.size())cout << v[i] << " ";
    cout << endl;
}

Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main()
{
	long long a,b,c,k;
	cin>>a>>b>>c>>k;
	long long ans;
	if(k>a)
	  {
	  	  ans=a;
	  	  k-=a;
	  }
	else
	  {
	  	  ans=k;
	  	  k=0;
	  }  
	if(k>b)
	  k-=b;
	else k=0;
	if(k>0)
	  {
	  	  ans-=k;
	  }    
	cout<<ans<<endl;  
}


Measured memory_bytes: 3624
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**18] * n
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
    
print(dp[-1])

Measured memory_bytes: 84692
n, m = list(map(int, input().split()))
# [[preficture, year, num]...]
towns = [list(map(int, input().split())) + [i] for i in range(m)]
sort_towns = sorted(towns, key = lambda x : (x[0], x[1]))

prev_pref = 1
town_no = 1
for i in range(len(sort_towns)):
    pref = sort_towns[i][0]
    town = sort_towns[i][1]
    if not prev_pref == pref:
        town_no = 1
        prev_pref = pref
        sort_towns[i].append(town_no)
    sort_towns[i].append(town_no)
    town_no += 1
sort_towns = sorted(sort_towns, key=lambda x : x[2])
for i in range(len(sort_towns)):
    print(str(sort_towns[i][0]).zfill(6) + str(sort_towns[i][3]).zfill(6))





Measured memory_bytes: 37504
#include<bits/stdc++.h>
using namespace std;
int H,W;
int main(){
  cin>>H>>W;
  vector<char> a(H*W);
  for(int i=0;i<H*W;i++)cin>>a[i];
  for(int i=0;i<W+2;i++)cout<<'#';
  cout<<endl;
  for(int i=0;i<H;i++){
    cout<<'#';
    for(int j=0;j<W;j++)cout<<a[i*W+j];
    cout<<'#'<<endl;
  }
  for(int i=0;i<W+2;i++)cout<<'#';
  cout<<endl;
}

Measured memory_bytes: 256
<?php
trait Count {
    function count($array, $minimum) {
        $summary = array_count_values(array_map(function ($x) use ($minimum) { return ($x >= $minimum) * 1; }, $array));
        return $summary[1] ?? 0;
    }
}

class solve {
    use Count;
}

fscanf(STDIN, "%d %d", $N, $K);
$h = explode(" ", trim(fgets(STDIN)));
$x = new solve();
echo $x->count($h, $K);


Measured memory_bytes: 14836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define jaldi_chal  ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c,i) for(auto i=(c).begin(); i != (c).end(); i++)
#define REP(i,k) for( ll i=0;i<k;i++)
#define REW(i,a,b) for(ll i=a;i<=b;i++)
#define MOD 1000000007
#define F first
#define dbg(x)  cout<<#x<<" " <<x<<endl;
#define S second
#define inf 1e10
#define endl "\n"
#define setbit(n) __builtin_popcount(n)
#define all(x) x.begin() , x.end()
#define clr(x) memset(x,0,sizeof(x))
ll power(ll a, ll b);

double dp[3001][3001];

double p[3001];

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	jaldi_chal
	ll t = 1, i;
	// cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;


		REW(i, 1,  n) cin >> p[i];


		dp[1][0] = (1 - p[1]);

		dp[1][1] = p[1];

		REW(i, 2, n)
		{
			for (ll j = 0; j < 3000; j++)
			{
				// tail
				dp[i][j] += (1 - p[i]) * (dp[i - 1][j]);

				if (j > 0)
				{
					dp[i][j] += (p[i]) * (dp[i - 1][j - 1]);
				}
			}
		}

		double ans = 0;

		for (ll i = n / 2 + 1; i <= n; i++)
		{
			ans += dp[n][i];
		}


		cout << setprecision(9) << fixed;

		cout << ans << endl;















	}


	return 0;
}


ll power(ll a, ll b) {
	ll res = 1;
	while (b)
	{
		if (b % 2) b-- , res = res * a;
		else b = b / 2 , a *= a;
	}
	return res;
}

Measured memory_bytes: 74020
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int a;
  cin>>a;
  cout<<(a+1)/2<<endl;
 

  return 0;
}

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

typedef long long ll;
typedef vector <int> vi;
typedef pair< int ,int > pii;
typedef istringstream iss;
typedef ostringstream oss;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ln length()
#define rep(i,n) for(int i=0;i<n;i++)
#define fu(i,a,n) for(int i=a;i<=n;i++)
#define fd(i,n,a) for(int i=n;i>=a;i--)
#define all(a)  a.begin(),a.end() 
#define ESP (1e-9)
#define gi(n) scanf("%d",&n)
#define gl(n) cin >> n
#define pi(n) printf("%d",n)
#define pl(n) cout << n
#define ps printf(" ")
#define pn printf("\n")
#define dg(n,s); printf("%s %d",s,n)
#define imax numeric_limits<int>::max()
#define imin numeric_limits<int>::min()
#define lmax numeric_limits<ll>::max()
#define lmin numeric_limits<ll>::min()
 int a , b , c ,d , e, f  ; 
 bool vis[3100] , vis1[3100] ; 
int main () {
//	freopen ( "inp.in" , "r" , stdin ) ; 
//	freopen ("out.out" , "w" , stdout ) ; 
	 cin >> a >> b >> c >>  d >> e >> f ;
	  a = a * 100 ;
	 b = b * 100 ; 
	 vis[c] = vis[d] = 1 ; 
	 vis1[a] = vis1[b] = 1 ; 
	 vis[0] = vis1[0] = 1 ; 
	 for ( int i = 1 ; i <= f ; i++){
	 	 if ( ( i - c > 0 && vis [ i - c ] ) ||  ( i - d > 0 && vis [ i - d ] ) )    vis[i] = 1 ; 
	 	 if ( ( i - a > 0 && vis1[ i - a]) ||  ( i - b > 0 && vis1 [ i - b] )  )   vis1[i] = 1 ; 
	 }
	  int mx =  ( f * e ) / ( e + 100 ) ; 
	 int w , s ;  
	 double opt = - 1.0  ; 
	 for ( int i = mx ; i >= 0 ; i-- ){
	 	if ( !vis[i] )   continue ; 
	 	 // sugar = i ; 
	 	 // water <= f - i  && ceil ( i / w )  <= e 
	 	 for ( int j = f - i ; j >= 1; j-- ) {
	 	 	   if (  !vis1[j] )   continue ;
			   if ( ceil ( 1.0 * i ) / j >  1.0* e / 100  )   continue ; 
	 	 	 
			   
			   	    double val = 100.0 * i / ( i + j ) ; 
			   	    if ( val > opt )  {
			   	    	   w  = j ,  s = i ;
							  opt = val ;  
			   	    	  // cout << w << " " << s <<" " << opt << " " << val << endl;
					   } 
			   	   
		  }
	 }
	 cout << w + s <<" " << s ; 
	// cout << mx << endl; 
	/* if ( c > d )   swap ( c , d ) ;
	 int mx1 = mx ; 
	 mx1 = mx1 % d ; 
	 mx1 = mx1 % c ; 
	 mx = mx - mx1 ; 
	 //cout << mx1 << endl;
	 int req =  ( mx * 100)  / e ;
	 int req1 = req ;
	 if ( a > b ) swap ( a,  b ) ; 
	 req1 = req1 %  b ;
	 req1 = req1 % a ; 
	 req = req - req1 ; 
	 cout << req + mx << " " << mx ;    */ 
	 return 0; 
}

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

int main() {
	int n, q; cin >> n >> q;
	fenwick_tree<int64_t> ft(n);
	for(int i = 0; i < n; ++i) {
		int a; cin >> a;
		ft.add(i, a);
	}
	while(q--) {
		int t; cin >> t;
		if(t == 0) {
			int p, x; cin >> p >> x;
			ft.add(p, x);
		} else {
			int l, r; cin >> l >> r;
			cout << ft.sum(l, r) << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 8200
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }

fn is_prime(n: usize) -> bool {
    if n <= 1 {
        return false;
    }
    for i in 2..n {
        if n % i == 0 {
            return false;
        }
        if i * i > n {
            return true;
        }
    }
    true
}

fn main() {
    input! {
        x: usize
    }

    let mut ans = x;
    loop {
        if is_prime(ans) {
            break;
        }
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <climits>
using namespace std;

int main(){
	int n; cin >> n;
	int s = INT_MAX;
	int ans = INT_MIN;
	for (int i = 0; i < n; i++) {
		int r; cin >> r;
		ans = max(ans, r - s);
		s = min(s, r);
	}
	cout << ans << endl;
	return 0;
}




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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

char a[5];

int main(){
  scanf("%s",a);
  if(a[0]==a[2]) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
#include<iostream>

using ll = long long;

int main(){
    int m;
    std::cin >> m;
    ll digit=0,total=0;
    for(int i=0 ; i<m ;i++){
        ll d,c;
        std::cin >> d >> c;
        digit += c;
        total += d*c;
    }
    ll moveup = (total-1)/9;
    std::cout << digit+moveup-1 << "\n";
}


Measured memory_bytes: 3592
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

// Modpow
int64_t modpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
  if (a == 0) return 0;
  int64_t res = 1;
  for (a %= mod; b; a = a * a % mod, b >>= 1)
    if (b & 1) res = res * a % mod;
  return res;
}

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

  int64_t N, K;
  cin >> N >> K;

  int64_t res = 0;
  vector<int64_t> dp(K+1,0);
  for (int64_t i = K; i > 0; i--) {
    int64_t m = K / i;
    int64_t num_i_all = modpow(m, N, MOD);
    for (int64_t j = i * 2; j <= K; j += i) {
      num_i_all = (num_i_all - dp[j]) % MOD;
      if (num_i_all < 0) num_i_all += MOD;
    }
    dp[i] = num_i_all;
    int64_t update = (i * num_i_all) % MOD;
    res += update;
    res %= MOD;
  }

  cout << res << endl;

  return 0;
}


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

int main() {
  int N, Q;
  long long K;
  cin >> N >> K >> Q;
  int A[Q];
  for (int i = 0; i < Q; i++) cin >> A[i];
  map<int, int> point;
  for (int i = 0; i < Q; i++) point[A[i]] += 1;

  for (int i = 1; i <= N; i++) {
    if (K - (Q - point[i]) > 0) {
      cout << "Yes";
    } else {
      cout << "No";
    }
    cout << endl;
  }
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	int m = (h2*60+m2) - (h1*60+m1);
	cout << m - k << endl;
}



Measured memory_bytes: 3636
#include<cstdio>
#define mod (1000000007)
typedef long long ll;
ll x[110000],y[110000];
int main()
{
	ll n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	for(int i=1;i<=m;i++) scanf("%lld",&y[i]);
	ll s1=0,s2=0;
	for (int i=1;i<=n;i++) s1=((2*i-n-1)*x[i]+s1)%mod;
	for (int i=1;i<=m;i++) s2=((2*i-m-1)*y[i]+s2)%mod;
	printf("%lld\n",s1*s2%mod);
	return 0;
}

Measured memory_bytes: 1792
public class Main {

  private static void solve() {
    int x = ni();
    int y = ni();

    if (x * 2 <= y && y <= x * 4 && y % 2 == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main(){
  int n,mx=0,mx2=0,cnt;cin>>n;
  vector<int> a(n,0);
  REP(i,n){
    cin>>a.at(i);
    if(a.at(i)>mx){
      mx2=mx;
      mx=a.at(i);
      cnt=1;
    }else if(a.at(i)==mx){
      cnt++;
    }else if(mx2<a.at(i)&&a.at(i)<mx){
      mx2=a.at(i);
    }
  }
  
  if(cnt>1) REP(i,n) cout<<mx<<endl;
  else REP(i,n){
    if(a.at(i)==mx) cout<<mx2<<endl;
    else cout<<mx<<endl;
  }
}

Measured memory_bytes: 2432
N, M = map(int, input().split())
egdes = [list(map(int, input().split())) for _ in range(M)]

INF = 10 ** 13
dist = [INF] * (N + 1)
dist[1] = 0
for _ in range(N - 1):
    for a, b, c in egdes:
        dist[b] = min(dist[b], dist[a] - c)
ans = dist[N]
for a, b, c in egdes:
    dist[b] = min(dist[b], dist[a] - c)
print(-ans if ans == dist[N] else 'inf')


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

using ll = long long;

using str = string;
using ss = stringstream;

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

    int n,k;cin>>n>>k;
    int r,s,p;cin>>r>>s>>p;
    str t;cin>>t;

    map<char,ll> m;
    m['r']=p;
    m['s']=r;
    m['p']=s;
    m['b']=0;

    ll ans=0;

    for(int i=0;i<k;i++)for(int j=i+k;j<n;j+=k)if(t[j]==t[j-k])t[j]='b';

    for(int i=0;i<n;i++)ans+=m[t[i]];

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

int main () {
	string s;
	cin >> s;
	For (i, 0, s.size() - 1) if (s[i] == 'A' && s[i + 1] == 'C')
			return printf ("Yes"), 0;
	puts("No");
    return 0;
}


Measured memory_bytes: 256
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
#define int long long
using namespace std;

const ll N = 1e6 + 100, OO = 1e10 + 10, M = 1e9 + 7, lg = 22;
typedef pair <int, int> pii;

int32_t main() {
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	int t = 1;
	for(int i = 1; i < n; i++) {
		if(s[i] != s[i - 1])
			t++;
	}
	if(t == 1) {
		cout << n - 1 << endl;
		return 0;
	}
	if(t == 2) {
		cout << n - 1 << endl;
		return 0;
	}
	int m = n - t;
	if(t % 2 == 0) {
		int z = t / 2;
		if(k >= z) {
			cout << n - 1 << endl;
			return 0;
		}
		else {
			cout << m + 2 * k << endl;
			return 0;
		}
	}
	else {
		int z = t / 2;
		if(k >= z) {
			cout << n - 1 << endl;
			return 0;
		}
		else {
			cout << m + 2 * k << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 512
N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
mod = 10**9+7
cnt = 0
for ind,a in enumerate(A):
    cnt_l = 0
    cnt_r = 0
    for ind2,b in enumerate(A):
        if(ind==ind2):
            continue
        if(ind<ind2):
            if(a>b):
                cnt_r += 1
        if(ind>ind2):
            if(a>b):
                cnt_l += 1
    cnt += cnt_r*(K*(K+1)//2)
    cnt += cnt_l*((K-1)*K//2)
    cnt %= mod
print(cnt)


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

using namespace std;

int main()
{
	int N, P;
	cin >> N >> P;
	vector < int >A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	int oddCount = 0, evenCount = 0;

	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) {
			evenCount++;
		} else {
			oddCount++;
		}
	}

	if (oddCount == 0) {
		if (P == 0) {
			cout << fixed << setprecision(0) << pow(2, N) << endl;
		} else {
			cout << 0 << endl;
		}
		return 0;
	}

	cout << fixed << setprecision(0) << pow(2, N - 1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
int main(){
        int N;
        std::cin >> N;
        std::vector<int> a_arr(N);
        std::vector<std::vector<std::tuple<int,int>>> xij_arr(N);
        for(int i = 0; i < N; i++){
                std::cin >> a_arr[i];
                for(int j = 0; j < a_arr[i]; j++){
                        int k,x;
                        std::cin >> k >> x;
                        k--;
                        xij_arr[i].emplace_back(k,x);
                }
        }
        int nc_max = 0;
        for(int i = 0; i < (1<<N); i++){
                bool valid_flag = true;
                int nc = 0;
                for(int j = 0; j < N; j++){
                        if(((1<<j)&i) == 0) continue;
                        nc += 1;
                        for(auto&& it: xij_arr[j]){
                                int k,x;
                                std::tie(k,x) = it;
                                if(((i>>k)&1) != x){
                                        valid_flag = false;
                                        break;
                                }
                        }
                }
                if(valid_flag){
                        nc_max = std::max(nc_max, nc);
                }
        }
        std::cout << nc_max << std::endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
    ll N,M;
    cin >>N>>M;
    ll MS=0;
    //while(MS*MS<M){MS++;}
    MS++;
    //ll soin[MS];
    //ll kari[MS];
    //FOR(i,0,MS-1){
    //    soin[MS]=0;
    //}

    //FOR(i,0,MS){
    //    if(M%i==0){
    //        M=M/i;
    //        soin[i]++;
    //    }
    //}

    ll max;
    max=M/N;

    RFOR(i,max,1){
        if(M%i==0){cout<<i<<endl;return 0;}
    }

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  string S;
  cin >> N >> S;
  int res = 1;
  char head = S[0];
  for (auto s : S) {
    if (head != s) {
      res++;
      head = s;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(){

    int N; cin >> N;
    int A[N+1];

    int cnt = 0;
    for(int i=1; i<=N; i++){
        cin >> A[i];        
    }

    int temp;
    for(int i=1; i<=N; i++){
        if(A[i] == i){
            temp = A[i];
            A[i] = A[i+1];
            A[i+1] = temp;
            cnt++;
        }

    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
n, k = map(int, input().split())
A = [0] * n

# print(A)

for i in range(k):
    di = int(input())
    Ai = list(map(int, input().split()))

    for j in range(di):
        A[Ai[j] - 1] += 1

# print(A)

ans = 0
for i in range(n):
    if A[i] == 0:
        ans += 1

print(ans)


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

#define mod 1000000007

int n,k,ans;

int qpow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=(long long)res*a%mod;
		a=(long long)a*a%mod;
		b>>=1;
	}
	return res;
}

int main()
{
	scanf("%d%d",&n,&k);
	set<int> v;
	unordered_map<int,int> s;
	for(int i=1;i*i<=n;++i)
		if(n%i==0)
		{
			v.insert(i);
			if(i*i!=n)v.insert(n/i);
		}
	for(auto x : v)
	{
		int res=qpow(k,(x+1)/2);
		for(int i=1;i*i<=x;++i)
			if(x%i==0)
			{
				res-=s[i];
				if(res<0)res+=mod;
				if(i*i!=x)
				{
					res-=s[x/i];
					if(res<0)res+=mod;
				}
			}
		s[x]=res;
		ans+=(long long)res*(x%2?x:x/2)%mod;
		if(ans>=mod)ans-=mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(19);

  int n; string s;
  cin >> n >> s;
  int ans = 0, cnt = 0;
  int f[26] = {0};
  for(int pos = 0; pos < n; pos++){
    for(int i = 0; i <= pos; i++){
      for(int j = pos + 1; j < n; j++){
        if(s[i] == s[j]){
          f[s[i] - 'a']++;
          break;
        }        
      }        
    }
    for(int i = 0; i < 26; i++){
      if(f[i]) cnt++;
    }
    ans = max(ans, cnt);
    cnt = 0;
    for(int i = 0; i < 26; i++) f[i] = 0;
  }
  cout << ans << "\n";


  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  cioacc();
  string s,t;
  cin >> s >> t;
  ll ssz = (ll)s.size(),tsz = (ll)t.size();
  vector<vector<string>> dp(ssz+1,vector<string>(tsz+1));
  vector<string> last(tsz+1);
  REP(i,ssz){
    vector<string> now(tsz+1);
    REP(j,tsz){
      if(s[i]==t[j]) {
        now[j+1] = last[j] + s[i];
        continue;
      }
      now[j+1] = (now[j].size()>=last[j+1].size()?now[j]:last[j+1]);
    }
    last = move(now);
  }
  cout << last[tsz] << endl;
}


Measured memory_bytes: 87280
s = input()
N = len(s)
pc = 0
gc = 0
wp = 0
lp = 0
for i in range(N):
  if s[i] == "g":
    if pc+1 <= gc:
      pc += 1
      wp += 1
    else:
      gc += 1  
  if s[i] == "p":  
    if pc+1 <= gc:
      pc += 1
    else:
      gc += 1  
      lp += 1
print(wp-lp)      

Measured memory_bytes: 3316
package main

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

var (
	S string
)

func main() {
	readVariables()
	if S[0] == S[1] && S[1] == S[2] {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

func readVariables() {
	S = nextStr()
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


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

using namespace std;

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

  string s; cin>>s;
  int ans = 1;
  char c = s[0];
  bool use = false;
  bool skip = false;
  for (int i = 1; i < s.size(); i++) {
    if (not use and not skip and s[i] == c) {
      skip = true;
    } else {
      if (use)
        use = false;
      if (skip)
        use = true;
      skip = false;
      ans++;
    }
    c = s[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 720
package main

import (
	"fmt"
)

func main() {
	var A, B, C, D int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&C)
	fmt.Scan(&D)

	bus, train := A, C
	if A > B {
		bus = B
	}
	if C > D {
		train = D
	}

	fmt.Println(bus + train)
}

Measured memory_bytes: 512
#include <stdio.h>

#define   N   300000
#define  MID  500000
#define INFTY 2000000000

void mergeSort(int*,int,int);
void merge(int*,int,int,int);

long long count=0;

int main(){

  int i;
  int n;
  int A[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
  scanf("%d",&A[i]);
  }
  
  mergeSort(A,0,n);
  
  printf("%lld\n",count);

 return 0;
}

void mergeSort(int *A,int left,int right){
  int mid;
  
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

void merge(int *A,int left,int mid,int right){

  int i;
  int j;
  int k;
  int n1 = mid - left;
  int n2 = right - mid;
  int L[MID];
  int R[MID];
  
  for(i=0;i<n1;i++){
    L[i] = A[left+i];
  }
  
  for(j=0;j<n2;j++){
    R[j] = A[mid+j];
  }
    L[n1] = INFTY;
    R[n2] = INFTY;
    
    i = 0;
    j = 0;
    
  for(k=left;k<right;k++){
    if(L[i] <= R[j]){
      A[k]=L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
      if(L[i] !=  INFTY) count += n1 - i;
    }
  }
}

Measured memory_bytes: 3824
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String str = sc.next();

		int result = 0;

		int l = 0;
		int r = n - 1;

		while (true) {

			// 最も左にある 'W' を探す
			while (true) {
				if (str.length() == l) {
					break;
				}
				if (str.charAt(l) == 'W') {
					break;
				}
				l++;
			}

			// 最も右にある 'R' を探す
			while (true) {
				if (r == -1) {
					break;
				}
				if (str.charAt(r) == 'R') {
					break;
				}
				r--;
			}

			//System.out.println("swap! " + " " + l + " " + r);

			// 次へ
			if (l > r) {
				break;
			}
			result++;
			l++;
			r--;
		}

		System.out.println(result);

	}
}


Measured memory_bytes: 40324