akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  string S; cin>>S;
  ll q; cin>>q;
  rep(_,q){
    ll k; cin>>k;
    vector<ll> DMC(3);
    ll cnt=0;
    ll ans=0;
    queue<char> Q;
    foreach(s,S){
      // push
      if(s=='D'){
        DMC[0]++;
      }else if(s=='M'){
        DMC[1]++;
        cnt+=DMC[0];
      }else if(s=='C'){
        DMC[2]++;
        ans+=cnt;
      }
      Q.push(s);

      // pop
      if(Q.size()<k) continue;
      char t=Q.front(); Q.pop();
      if(t=='D'){
        DMC[0]--;
        cnt-=DMC[1];
      }else if(t=='M'){
        DMC[1]--;
      }else if(t=='C'){
        DMC[2]--;
      }
    }
    cout<<ans<<"\n";
  }
}

Measured memory_bytes: 2332
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 109, Mod = 1e9 + 7;
int n, m, q, A[N], dp[N][N], D[N][N];
string S[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)
        cin >> S[i], S[i] = '.' + S[i];
    memset(dp, 63, sizeof(dp));
    dp[0][0] = dp[0][1] = dp[1][0] = 0;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
            if (1)
            {
                dp[i][j] = Mod;
                if (i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (S[i][j] == '#'));
                if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + (S[i][j] == '#'));
                if (S[i][j] == '.')
                    continue;
                memset(D, -1, sizeof(D));
                queue < pair < int , int > > qu;
                qu.push({i, j});
                D[i][j] = 1;
                while (qu.size())
                {
                    int a = qu.front().first;
                    int b = qu.front().second;
                    qu.pop();
                    dp[i][j] = min(dp[i][j], min(dp[a - 1][b], dp[a][b - 1]) + 1);
                    if (a > 1 && S[a - 1][b] == '#' && D[a - 1][b] == -1)
                        qu.push({a - 1, b}), D[a - 1][b] = 1;
                    if (b > 1 && S[a][b - 1] == '#' && D[a][b - 1] == -1)
                        qu.push({a, b - 1}), D[a][b - 1] = 1;
                }
            }
    printf("%d\n", dp[n][m]);
    return 0;
}

Measured memory_bytes: 384
S = input()
K = int(input())

import random
import string


def count(string):
    total = 0
    i = 1
    while i < len(string):
        if string[i-1] == string[i]:
            total += 1
            i += 1
        i += 1
    return total

if S == len(S) * S[0]:
    res = (K * len(S)) // 2      
elif S[0] == S[-1]:
    new = S.strip(S[0])
    start = len(S) - len(S.lstrip(S[0]))
    end = len(S) - len(S.rstrip(S[0]))
    res = start // 2 + end // 2 + K * count(new) + (K - 1) * ((start + end) // 2)
else:
    res = K * count(S)

print(res)


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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



int main(void)
{
  ll n, m, x;
  cin >> n >> m >> x;
  vector<ll> a(m);
  REP(i, m) cin >> a[i];

  ll s = 0, b = 0;
  REP(i, m) {
    if(a[i] > x) {
      b ++;
    } else {
      s ++;
    }
  }
  ll ans ;
  if(b > s) {
    ans = s;
  } else {
    ans = b;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    agc019a()
}

fun agc019a() {
    val (q, h, s, d) = readLine()!!.split(' ').map { it.toLong() }
    val n = readLine()!!.toLong()

    val bottle1 = Math.min(Math.min(q * 4, h * 2), s)
    val bottle2 = d

    if (n == 1L) return println(bottle1)

    val answer = if (bottle1 * 2 <= bottle2) {
        bottle1 * n
    } else {
        (n / 2 * bottle2) + (if (n % 2 == 0L) 0 else bottle1)
    }

    println(answer)
}


Measured memory_bytes: 38304
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N=2e5+2;
vector<int> lis[N];
pair<int,int> coor[N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,m,num,ans,lef;
	cin>>n>>m>>num;
	lef=0;
	ans=n;
	for(i=1;i<=num;i++){
		cin>>j>>k;
		j-=k;
		if(j>=0){
			lis[k].push_back(j);
		}
	}
	for(i=1;i<=m;i++){
		sort(lis[i].begin(),lis[i].end());
		j=0;
		while(j<lis[i].size()&&lef>=lis[i][j]){
			if(lef==lis[i][j]){
				lef++;
			}
			j++;
		}
		if(j<lis[i].size()){
			ans=min(ans,i-1+lis[i][j]);
		}
	}
	cout<<ans;
}

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

int main()
{
    int n, m, l;
    cin>>n>>m>>l;
    int A[101][101], B[101][101];
    long C[101][101]={0};

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>A[i][j];
        }
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<l;j++)
        {
            cin>>B[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<l;j++)
        {
            for(int k=0;k<m;k++)
            {
                C[i][j] += A[i][k]*B[k][j];
            }
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<l;j++)
        {
            cout<<C[i][j];
            if(j<l-1)cout<<' ';
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=200020;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,k,a[maxn];
ll ans;
int main(){
	n=read();k=read();
	FOR(i,1,n) a[i]=read();
	sort(a+1,a+n+1);
	FOR(i,1,n-k) ans+=a[i];
	printf("%lld\n",ans); 
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

type freq struct {
	s string
	count int64
}


func solve(n int64, ss []string) []string {
	freqs := make([]freq, 0)
	previous := ""
	for _, s := range ss {
		if s == previous {
			freqs[len(freqs) - 1].count += 1
			continue
		}

		var f freq
		f.s = s
		f.count = 1
		freqs = append(freqs, f)
		previous = s
	}

	ret := make([]string, 0)
	l := int64(0)
	for _, f := range freqs {
		if f.count < l {
			continue
		}
		if f.count > l {
			ret = make([]string, 0)
		}
		l = f.count
		ret = append(ret, f.s)
	}

	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()
	ss := nextStrings(n)
	sort.Strings(ss)
	res := solve(n, ss)
	for _, r := range res {
		fmt.Fprintln(out, r)
	}
}

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

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=305,mod=998244353;
int n,k,m,a[N],sum[N];
int dp[N][N][N];
//dp[i][j][h] 第i个坑，用了j个1，移动了k次的方案数
char s[N];
int main()
{
    scanf("%s%d",s+1,&k);
    for(int i=1;s[i];i++) m+=s[i]=='1';
    int t=0;
    for(int i=1;s[i];i++)
        if(s[i]=='0') a[++n]=t,t=0;
    else t++;
    a[++n]=t;
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    k=min(k,m);
    dp[0][0][0]=1;
    for(int i=0;i<n;i++)
        for(int j=sum[i];j<=sum[n];j++)
            for(int h=0;h<=k;h++)
        {
            if(!dp[i][j][h]) continue;
            for(int f=max(j,sum[i+1]);f<=sum[n];f++)
                if(f>=sum[i+1]&&h+f-j-a[i+1]<=k)
            {
                if(i+1==n&&f-j>a[i+1]) break;
                int cost=f-j<=a[i+1]?0:f-j-a[i+1];
                dp[i+1][f][h+cost]=(dp[i+1][f][h+cost]+dp[i][j][h])%mod;
            }
        }
    ll ans=0;
    for(int i=0;i<=k;i++) ans=(ans+dp[n][m][i])%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 17872
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int prime(int n)
{
	if(n<2) return 0;
	if(n==2) return 1;
	if(n%2==0) return 0;
	int i;
	for(i=3; i<=sqrt(n); i=i+2){
		if(n%i==0) return 0;
	}
	return 1;
}
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	while(!prime(n)){
		n++;
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[101];
int main()
{
	int n;
	scanf("%s",s+1);
	int l=strlen(s+1);
	cout<<s[1]<<l-2<<s[l]<<endl;
	return 0; 
}

Measured memory_bytes: 256
n = int(input())
a = list(int(input()) for _ in range(n))

max_a = max(a)

cnt = 0

for b in a:
  if b == max_a:
    cnt += 1
    
if cnt >= 2:
  for _ in range(n):
    print(max_a)
    
elif cnt == 1:
  for i in range(n):
    if a[i] != max_a:
      print(max_a)
    else:
      b = sorted(set(a))
      print(b[-2])
  

Measured memory_bytes: 22852
#include <iostream>
#include <vector>
using namespace std;
vector<long long> nums(60);
long long memo[60];
long long rec(int layer, long long index) {
  if (layer == 0) return 1;
  if (index == nums[layer] && memo[layer]) {
    return memo[layer];
  }
  long long num = nums[layer - 1];
  long long ret = 0;
  if (index <= 1) return 0;
  if (index <= num + 1) {
    return 0 + rec(layer - 1, index - 1);
  }
  if (index == num + 2) {
    return 0 + (memo[layer - 1] = rec(layer - 1, num)) + 1;
  }
  return 0 + (memo[layer - 1] = rec(layer - 1, num)) + 1 + rec(layer - 1, min(index - num - 2, num));
}
int main() {
  nums[0] = 1;
  for (int i = 0; i <= 49; i++) {
    nums[i + 1] = nums[i] * 2 + 3;
  }
  int n;
  long long x;
  cin >> n >> x;
  cout << rec(n, x) << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n,k;
vector<lli> a;
bool c(lli ex){
    lli t = k;
    lli tar = n;
    for(;;){
        tar = lower_bound(a.begin(),a.begin()+tar,t) - a.begin();
        tar--;
        if(tar == ex) tar--;
        if(tar < 0) break;
        t -= a[tar];
    }
    return t <= a[ex];
}
int main(){
    cin >> n >> k;
    a = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    lli l = 0,h = n,m;
    while(l < h){
        m = (h + l) / 2;
        if(c(m)) h = m;
        else l = m+1;
    }
    cout << h << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  int n,m;
  vector<pair<long,int>> v;
  cin>>n>>m;
  v.resize(n);
  for(int i=0;i<n;i++){
    cin>>v[i].first>>v[i].second;
  }
  sort(v.begin(),v.end());
  long val=0;
  long sum=0;
  vector<int> h;
  h.resize(n);
  for(int i=0;i<n;i++){
    bool br=((m-sum)>v[i].second);
    val+=br?(v[i].first*v[i].second):(v[i].first*(m-sum));
    h[i]=br?v[i].second:(m-sum);
    sum+=h[i];
    if(!br)break;
  }
  cout<<val<<endl;
  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int N; cin >> N;
    vector<ll> A;
    REP(i,N)
    {
        int temp; cin >> temp;
        A.push_back(temp);
    }

    int count = 0;
    bool is_odd = true;
    while (is_odd)
    {
        for (int i = 0; i < N; i++)
        {
            if (A[i]%2 != 0)
            {
                is_odd = false;
            }
        }
        if (!is_odd)
            break;
        
        for (int i = 0; i < N; i++)
        {
            A[i] = A[i]/2;
        }
        count++;
    }
    cout << count << endl;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

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

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> e[n];
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  
  int s[n];
  rep(i,n) s[i] = -1;
  s[0] = 0;
  queue<int> q;
  q.push(0);
  while(! q.empty()) {
    int i = q.front();
    q.pop();
    for(int j : e[i]) {
      if(s[j] == -1) {
        s[j] = i;
        q.push(j);
      }
    }
  }
  
  cout << "Yes" << endl;
  rep(i,n-1) cout << s[i+1]+1 << endl;
  return 0;
}

Measured memory_bytes: 10028
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var amax = -999999999; var amaxi = -1;
        var amin = 999999999; var amini = -1;
        for (int i = 0; i < n; i++)
        {
            if (a[i] > amax) { amax = a[i]; amaxi = i + 1; }
            if (a[i] < amin) { amin = a[i]; amini = i + 1; }
        }
        if (amax <= 0) { Console.WriteLine(n - 1); putAllM(n); }
        else if (amin >= 0) { Console.WriteLine(n - 1); putAllP(n); }
        else
        {
            if (amax >= -amin) { Console.WriteLine(2 * n - 1); plusAll(amaxi, n); putAllP(n); }
            else { Console.WriteLine(2 * n - 1); plusAll(amini, n); putAllM(n); }
        }
    }
    public static void plusAll(int a, int n)
    {
        for (int i = 1; i <= n; i++)
            Console.WriteLine("{0} {1}", a, i);
    }
    public static void putAllP(int n)
    {
        for (int i = 1; i <= n - 1; i++)
            Console.WriteLine("{0} {1}", i, i + 1);
    }
    public static void putAllM(int n)
    {
        for (int i = n; i >= 2; i--)
            Console.WriteLine("{0} {1}", i, i - 1);
    }
}


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

#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

inline int getsum(const vvi& sums,int t,int b,int l,int r)
{
	if(t>=b || l>=r) return 0;
	return sums[b][r]-sums[t][r]-sums[b][l]+sums[t][l];
}

inline int rsum(const vvi& sums,int i,int l,int r)
{
	return getsum(sums,i,i+1,l,r);
}

inline int csum(const vvi& sums,int t,int b,int j)
{
	return getsum(sums,t,b,j,j+1);
}

inline void chmax(int& a,int b)
{
	a=max(a,b);
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vs grid(h);
		rep(i,h) cin>>grid[i];

		int ci=-1,cj=-1;
		rep(i,h) rep(j,w) if(grid[i][j]=='E') ci=i,cj=j;

		vvi sums(h+1,vi(w+1));
		rep(i,h) rep(j,w)
			sums[i+1][j+1]=(grid[i][j]=='o')+sums[i+1][j]+sums[i][j+1]-sums[i][j];

		int T=h-1-ci,B=ci,L=w-1-cj,R=cj;

		int dp[T+1][B+1][L+1][R+1]={};
		rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1){
			if(t!=T && ci+t+1<h-b)
				chmax(dp[t+1][b][l][r],dp[t][b][l][r]+rsum(sums,ci+(t+1),max(cj-r,l),min(cj+l+1,w-r)));
			if(b!=B && t<=ci-(b+1))
				chmax(dp[t][b+1][l][r],dp[t][b][l][r]+rsum(sums,ci-(b+1),max(cj-r,l),min(cj+l+1,w-r)));
			if(l!=L && cj+l+1<w-r)
				chmax(dp[t][b][l+1][r],dp[t][b][l][r]+csum(sums,max(ci-b,t),min(ci+t+1,h-b),cj+(l+1)));
			if(r!=R && l<=cj-(r+1))
				chmax(dp[t][b][l][r+1],dp[t][b][l][r]+csum(sums,max(ci-b,t),min(ci+t+1,h-b),cj-(r+1)));
		}

		int res=0;
		rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1) chmax(res,dp[t][b][l][r]);
		cout<<res<<endl;
	}
}


Measured memory_bytes: 25728
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
#define double long double
typedef long long ll;
typedef unsigned long long ull;

template<typename T>
void __read(T &a) { cin >> a; }

template<typename T, typename ... Args>
void __read(T &a, Args &... args) {
    cin >> a;
    __read(args...);
}

#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T>
void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
template<class T>
static auto __super_speed__ = (ios_base::sync_with_stdio(0), cin.tie(
        0)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
//endregion

int gcd(int a, int b){
    while(b != 0){
        a %= b;
        swap(a, b);
    }
    return a;
}

int lcm(int a, int b){
    return a * b / gcd(a, b);
}

int32_t main() {
    make(int, n, m);
    makev(a, n);
    int L = 1;
    for(int i = 0; L < M9 && i < n; ++i){
        L = lcm(L, a[i]);
    }
    if (L > M9){
        cout << 0;
        return 0;
    }
    bool ok = true;
    for(int i = 0; ok && i < n; ++i){
        ok = (L / a[i]) % 2 == 1;
    }
    if (!ok){
        cout << 0;
        return 0;
    }
    int z = 2*m / L;
    cout << (z + 1) / 2;
    return 0;
}

Measured memory_bytes: 1024
package main

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

/*　入力方法
１、簡単に書く
fmt.Scan
2,たくさん読む()
bufio.Scanner
(テキストを1行ずつ読み込む。fileからscannerを生成し、scan()が末尾に達してfalseを返すまで読み込む。Text()を呼ぶことで文字列として取り出すことができる)
3,長い行を読む
bufio.ReadLine
4, スペース区切りのデータを読み込む
sc.Split(bufio.ScanWords)
#########バッファの最大読み込みの数を変更するには
sc.Buffer(buf,MaxBuf)#MAXBUFのところにサイズをしていする
*/

/* 書き込み
１、接頭辞F（前）
書き込み先を指定できる
2,接頭辞S(前)
出力ではなくフォーマットした結果を文字列で返す
3,接頭辞 f（後ろ）
フォーマット（文字列型など）を指定することができる
４、接頭辞 ln（後ろ）
オペランドの間に半角スペースが入り、文字列の最後に開業が追加

・interface{}型
どのような型がくるかわからないときに演算はできないが全ての型を受ける
new(T)
任意の型

*/
/*
フォーマット文字列
%c 1文字を出力　　　%d　　整数を10進む
%s 文字列を出力

指定子	対応する型	説明	使用例
%c	char	１文字を出力する
%s	char *	文字列を出力する
%d	int, short	整数を10進で出力する
%u	unsigned int, unsigned short	符号なし整数を10進で出力する
%o	int, short,unsigned int, unsigned short	整数を8進で出力する
%x	int, short,unsigned int, unsigned short	整数を16進で出力する
%f	float	実数を出力する
%e	float	実数を指数表示で出力する
%g	float	実数を最適な形式で出力する
%ld	long	倍精度整数を10進で出力する
%lu	unsigned long	符号なし倍精度整数を10進で出力する
%lo	long, unsigned long	倍精度整数を8進で出力する
%lx	long, unsigned long	倍精度整数を16進で出力する
%lf	double	倍精度実数を出力する
*/
/*
strconvパッケージ→　文字列と基本データ型の双方向変換を実装
func Atob(str string)(value bool,err os.Error)
文字列で表されている論理値を返す。それ以外のときはエラー

func Atof(s string)(f float,err os.Error)
floatのサイズによってAtof32またはAtof64を呼ぶ

func Atoi(s string(i int,error os.Error))
戻り値がint型を返す

*/
/*
string と[]byteの違いについて
*/
const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

/*strings.Splitで入力したものを分ける*/
func Scanner() []string {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}
	slice := strings.Split(s, " ")
	return slice

}

/* ---------------IO-------------------*/
func next() string {
	sc.Scan()
	return sc.Text()

}

/*型変換*/
func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		/*panic関数　　強制的にエラーを発生させるもの*/
		panic(err)
	}
	return i

}

/* 整数型に型変換したものを配列に格納する*/
func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

/*"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""*/
func main() {
	var n int
	fmt.Scan(&n)

	var s, t []byte
	fmt.Scan(&s, &t)

	for i := 0; i < n; i++ {
		fmt.Print(string([]byte{s[i]}))
		fmt.Print(string([]byte{t[i]}))
	}
	fmt.Println()

}


Measured memory_bytes: 1836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n;cin>>n;
  //caricurate
  if(n==100000){cout<<90909<<endl;return 0;}
  if(n>=10000){
    cout<<(909+n-9999)<<endl;
  }else if(n>=1000){
    cout<<909<<endl;
  }else if(n>=100){
    cout<<(9+n-99)<<endl;
  }else if(n>=10){
    cout<<9<<endl;
  }else{
   cout<<n<<endl; 
  }
  //output
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll gcd(ll a, ll b){//計算量はO(log(max(a,b))
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};



int main(){
  int N, K;
  cin >> N >> K;
  if(K > (N-1) * (N-2) / 2){
    cout << -1 << endl;
    return 0;
  }
  cout << N - 1 + (N-1) * (N-2) / 2 - K << endl;
  rep(i, N-1){
    cout << 1 << " " << i + 2 << endl;
  }

  ll s = 2, t = 3;
  rep(i, (N-1) * (N-2) / 2 - K){
    if(t > N){
      s++;
      t = s + 1;
    }
    cout << s << " " << t << endl;
    t++;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> a[100020];
int n, x, y, z;
int w[100020];
int c[16];
int f[65537];
int g[65537];
int ans, mask;
int dfs(int x, int y) {
	int re = w[x];
	for (int i: a[x]) {
		if (i != y) {
			re ^= dfs(i, x);
		}
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%d", &x, &y, &z);
		a[x].push_back(y);
		a[y].push_back(x);
		w[x] ^= z;
		w[y] ^= z;
	}
	for (int i = 0; i < n; i++) {
		c[w[i]]++;
	}
	for (int i = 1; i < 16; i++) {
		ans += c[i] / 2;
		c[i] %= 2;
		mask |= c[i] << i;
	}
	for (int i = 1; i < 1 << 16; i++) {
		int v = 0, c = 0;
		for (int j = 0; j < 16; j++) {
			if (i >> j & 1) {
				v ^= j;
				c++;
			}
		}
		if (v == 0) {
			f[i] = c - 1;
		} else {
			f[i] = -1;
		}
		for (int j = i; ; j = (j - 1) & i) {
			if (f[j] >= 0 && f[i ^ j] >= 0) {
				f[i] = min(f[i], f[j] + f[i ^ j]);
			}
			if (j == 0) {
				break;
			}
		}
	}
	printf("%d\n", ans + f[mask]);
//	dfs(0, -1);
	return 0;
}

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

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

    int m;
    cin >> m;
    vector<string> b(m);
    for (int i = 0; i < m; i++)
        cin >> b[i];

    vector<string> moji;
    vector<int> mojic;
    for (int i = 0; i < n; i++) {
        if (!(any_of(moji.begin(), moji.end(), [&](string x) { return x == a[i]; }))) {
            moji.push_back(a[i]);
            mojic.push_back(count(a.begin(), a.end(), a[i]));
        }
    }
    for (int i = 0; i < moji.size(); i++) {
        mojic[i] -= count(b.begin(), b.end(), moji[i]);
    }

    int answer = *max_element(mojic.begin(), mojic.end());
    if (answer > 0) {
        cout << answer << endl;
    } else {
        cout << 0 << endl;
    }
}

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

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

  vector<pair<int, int>> r(n);
  for (int i = 0; i < n; i++) cin >> r[i].first >> r[i].second;

  int mr = 1001;

  for (int i = 0; i < n; i++) {
    if (r[i].second <= t && r[i].first <= mr) {
      mr = r[i].first;
    }
  }

  if (mr == 1001)
    cout << "TLE" << endl;
  else
    cout << mr << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int max(int a, int b, int c) {
		return Math.max(Math.max(a, b),c);
	}
	static int min(int a, int b, int c) {
		return Math.min(Math.min(a, b),c);
	}
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			System.out.println(min(a,b,c) + " " + max(a,b,c));
			
		}
	}
}


Measured memory_bytes: 26272
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		boolean atnd[] = new boolean[30];
		for(int i=0;i<28;i++) {
			atnd[sc.nextInt()-1] = true;
		}
		for(int i=0;i<30;i++) if(!atnd[i]){
			System.out.println(i+1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    string s;
    cin>>n;
    cin>>s;
    vi w(n+1);
    vi b(n+1);
    REP(i,n){
        if(s[i]=='#'){
            b[i+1] = b[i]+1;
            w[i+1] = w[i];
        }else{
            b[i+1] = b[i];
            w[i+1] = w[i]+1;
        }
    }

    int ans=IINF;
    REP(i,n+1){
        ans = min(ans,b[i]+(w[n]-w[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
long myPow(long x, long n, long m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
int main(){
   long long n, i, ans=1, cnt[100101]={0}, max=-1;
   cin >> n;
   for(i=0;i<n;i++){
       long long tmp;
       cin >> tmp;
       if(i==0 && tmp!=0) ans=0;
       if(tmp>max) max=tmp;
       cnt[tmp]++;
   }
   if(ans==0){
       cout << ans <<endl;
       return 0;
   }
   else if(cnt[0]>=2) ans=0;
   else{
       for(i=2;i<=max;i++){
        ans=ans*myPow(cnt[i-1], cnt[i], 998244353);
        ans=ans%998244353;
       }
   }
   cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 1024
a,b,c,x,y = map(int,input().split())
res = 9999999999999
for i in range(0, 200002, 2):
    na = x - i//2
    nb = y - i//2
    na = 0 if na < 0 else na
    nb = 0 if nb < 0 else nb
    res = min(res, c * i + a*na + b*nb)
print(res)

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int i,n,m,j;
int a[4];
 
int main(){
	//gets(textA);
	//gets(textB);
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	cout<<(a[2]-a[1])+(a[3]-a[2])<<endl;
	return 0;	
}


Measured memory_bytes: 256
K = input()
# A = input()
# B = input()

# a = int(A)
# b = int(B)
k = int(K)

a,b=map(int,input().split())

for i in range(a,b+1):
	if i % k == 0:
		print('OK')
		break
	else:
		if i == b:
			print('NG')


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

int a, b;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> a >> b;
    for (int i=1; i<=2000; ++i) {
        int x=8*i/100, y=10*i/100;
        if (x==a && y==b) {
            cout << i;
            return 0;
        }
    }

    cout << -1;

    return 0;
}


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

int n, x, ans[1<<20];

int main() {
    cin >> n >> x;
    if (x == 1 || x == n+n-1) {
        cout << "No";
        return 0;
    } else cout << "Yes\n";
    if (n == 2) { cout << "1\n2\n3"; return 0; }
    if (x == 2) ans[n-1] = x, ans[n-2] = x+1, ans[n] = x-1, ans[n+1] = x+2;
    else ans[n-1] = x, ans[n-2] = x-1, ans[n] = x+1, ans[n+1] = x-2;
    
    for (int i = 0, k = 1; i < n+n-1; i++) {
        if (k == ans[n+1] || k == ans[n]) k += 4;
        if (ans[i]) i += 3;
        else ans[i] = k++;
    }
    for (int i = 0; i < n+n-1; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if( a[i] % 2 == 0 ){
			if( a[i] % 3 != 0 && a[i] % 5 != 0 ){
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    for(string line; cin >> line && line != "0";)
	{
		int a = count(line.begin() + 1, line.end(), 'A');
		int b = line.size() - a - 1;

		(a > b ? a : b) += 1;
		
		cout << a << " " << b << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

i64 n,m,L;
int k[2020];
i64 s[101010];
i64 sum[101010];
i64 dp[2020][2020];
i64 get_sum(int l,int r){
    return sum[k[r]] - sum[k[l] - 1];
}

i64 dfs(int l,int r){
    if(dp[l][r] != -1) return dp[l][r];
    
    //its end?
    if(min(l,r) == 0){
        return dp[l][r] = get_sum(min(l,r),max(l,r)) / L;
    }
    
    int next = min(l,r) - 1;

    //left
    dp[l][r] = dfs(next,r) + get_sum(next ,l) / L;
    dp[l][r] = min(dp[l][r] , dfs(l,next) + get_sum(next , r) / L);

    return dp[l][r];
}

int main(){
    cin >> n >> m >> L;
    for(int i = 0;i < n;i++){
        cin >> k[i];
    }
    for(int i = 1;i <= m;i++){
        cin >> s[i];
        sum[i] = sum[i - 1] + s[i];
    }

    sort(k , k + n);

    memset(dp,-1,sizeof(dp));

    cout << dfs(n - 1,n - 2) + get_sum(n - 2,n - 1) / L << endl;
}





Measured memory_bytes: 36700
import collections
import sys
sys.setrecursionlimit(10000000)

N,M = map(int,input().split())
A = [list(map(int, input().split())) for i in range(M)]
visit = set()
G = collections.defaultdict(set)
for idx,(f,to) in enumerate(A):
    G[f].add(to)

cache = {}
    
def dfs(start):
    if start in cache:
        return cache[start]
    ma = 0
    for i in G[start]:
        if i not in visit:
            visit.add(i)
            ma = max(ma,dfs(i))
            visit.remove(i)
    cache[start] = ma + 1 
    return ma + 1

ma = 0 
for f,to in A:
    visit.add(f)
    ma = max(ma,dfs(f))
    visit.remove(f)
print(ma - 1)
        
        

Measured memory_bytes: 121388
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

const mod = 10^^9+7;
alias mint = FactorRing!mod;

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  a.sort();
  foreach (i; 0..n) {
    if (n%2 == 0 && a[i] != i/2*2+1 ||
        n%2 == 1 && a[i] != (i+1)/2*2) {
      writeln(0);
      return;
    }
  }

  writeln(mint(2).repeatedSquare(n/2));
}

pure T repeatedSquare(alias pred = "a * b", T, U)(T a, U n)
{
  return repeatedSquare!(pred, T, U)(a, n, T(1));
}

pure T repeatedSquare(alias pred = "a * b", T, U)(T a, U n, T init)
{
  import std.functional;
  alias predFun = binaryFun!pred;

  if (n == 0) return init;

  auto r = init;
  while (n > 0) {
    if (n&1) r = predFun(r, a);
    a = predFun(a, a);
    n >>= 1;
  }

  return r;
}

struct FactorRing(int m, bool pos = false)
{
  version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }
  alias FR = FactorRing!(m, pos);
  @property static init() { return FR(0); }
  @property int value() { return vi; }
  @property void value(int v) { vi = mod(v); }
  alias value this;

  this(int v) { vi = v; }
  this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
  this(long v) { vi = mod(v); }

  ref auto opAssign(int v) { vi = v; return this; }

  pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }
  pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }

  static if (!pos) pure ref auto opUnary(string op: "-")() { return FR(mod(-vi)); }

  static if (m < int.max / 2) {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vi"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vi"~op~"r")); return this; }
  } else {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vl"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vl"~op~"r")); return this; }
  }
  pure ref auto opBinary(string op: "*")(int r) { return FR(mod(vl*r)); }
  ref auto opOpAssign(string op: "*")(int r) { vi = mod(vl*r); return this; }

  pure ref auto opBinary(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opBinary!op(r.vi); }
  ref auto opOpAssign(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(r.vi); }
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

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

int main(){
  int x,y,z;
  cin >> x >> y >> z;
  int ans = max({x,y,z}) - min({x,y,z});
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
odd_common = Counter(a[::2]).most_common()
even_common = Counter(a[1::2]).most_common()
odd_common.append(('', 0))
even_common.append(('', 0))
if odd_common[0][0] != even_common[0][0]:
    print(n - odd_common[0][1] - even_common[0][1])
else:
    b = max(odd_common[0][1] + even_common[1][1], odd_common[1][1] + even_common[0][1])
    print(n - b)

Measured memory_bytes: 20572
n,m = map(int,input().split())
P = [list(map(int,input().split())) for _ in range(n)]
C = [list(map(int,input().split())) for _ in range(m)]

for i in range(n):
  d = 10**18
  t = 0
  for j in range(m):
    dist = abs(P[i][0]-C[j][0]) + abs(P[i][1]-C[j][1])
    if d > dist:
      t = j
      d = dist
  print(t+1)

Measured memory_bytes: 9120
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, K; cin >> N >> K;
	vector<int> a(26);
	while (N--) {
		string s; cin >> s;
		a[s[0] - 'A']++;
	}
	int ans = 0;
	for (;;) {
		sort(a.rbegin(), a.rend());
		if (a[K - 1]) {
			rep(i, K) a[i]--;
			ans++;
		}
		else break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

char a, b, c, d, e, f;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b >> c >> d >> e >> f;
	if (a == f && b == e && c == d) puts("YES");
	else puts("NO");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int r; cin >> r;
  if (r < 1200) {
    cout << "ABC" << endl;
    return 0;
  }
  if (r < 2800) {
    cout << "ARC" << endl;
    return 0;
  }
  cout << "AGC" << endl;
  return 0;

}


Measured memory_bytes: 256
s = input()
s = s[::-1]
l = len(s)
count = [0] * 2019
res = 0
count[res] = 1
d = 1
for i in s:
    res += int(i) * d
    res %= 2019
    count[res] += 1
    d *= 10
    d %= 2019
print(int(sum([m*(m-1)/2 for m in count])))

Measured memory_bytes: 9404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main()
{   
    int N;
    cin>>N;
    string S;
    cin >> S;
    string abc="ABC";
    int cnt=0;
    REP(i, N-3+1){
        bool flg=true;
        REP(j,3){
            if(S[i+j]!=abc[j]) flg=false;
        }
        if(flg) cnt++;
    }
    cout << cnt << endl;
    
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using pii = std::pair<int, int>;
using namespace std;

struct island {
  ll weight;
  ll limit;
  island() = default;
  island(ll weight, ll limit) : weight(weight), limit(limit) {}
  bool operator < (const island& rhs) const {
    return limit > rhs.limit;  // NOTE: REVERSE for min priority queue.
  }
};

int main() {
  for(;;) {
    ll n;
    cin >> n;
    if (n == 0) {
      break;
    }
    priority_queue<island> q;
    REP(i, n) {
      ll weight, limit;
      cin >> weight >> limit;
      q.emplace(weight, limit);
    }

    ll acc = 0;
    while (!q.empty()) {
      const auto island = q.top();
      if (acc + island.weight <= island.limit) {
        acc += island.weight;
        q.pop();
      }
      else {
        break;
      }
    }
    cout << (q.empty() ? "Yes" : "No") << endl;
  }
  return 0;
}



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

int main(){

	char a[2];

	cin >> a[0] >> a[1];

	if (a[0]=='9'){
		cout << "Yes";
	}
	else if(a[1]=='9'){
		cout << "Yes";
	}
	else{
		cout << "No";
	}



	return 0;
}

Measured memory_bytes: 256
# coding: UTF-8
from collections import deque
queue = deque()
ftime = deque()
n,quantum = map(int,input().split())
for i in range(n):
  name,time = input().split()
  time = int(time)
  queue.append((name,time))

t = 0
while queue:
 name,time = queue.popleft()
 if time <= quantum:
   t += time
   ftime.append(name + " " + str(t))
 else:
   t += quantum
   queue.append((name,time-quantum))

while ftime:
  print(ftime.popleft())
   
 


Measured memory_bytes: 12536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c && c == a) {
    cout << "No" << endl;
  } else {
    if (a != b && b != c && c != a) {
      cout << "No" << endl;
    } else
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))

d = {0: 1}
s = 0
for i in range(N):
  s += A[i]
  m = s % M
  if m in d:
    d[m] += 1
  else:
    d[m] = 1

ans = 0
for v in d.values():
  ans += v * (v - 1) // 2

print(ans)

Measured memory_bytes: 14224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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



int main(){
	ll n;
	int p[200000];
	cin >> n;
	for(int i=0;i<n;i++) cin >> p[i];

	int min = p[0];
	int ans = 1;
	for(int i=1;i<n;i++){
		if(min>p[i]){
			ans++;
			min = p[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024