akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = 0
for i in range(k):
    dp = [[0] * (n // k + 3) for _ in range(3)]
    j = 0
    while j * k + i < n:
        dp[0][j + 1] = max(dp[1][j], dp[2][j])
        dp[1][j + 1] = max(dp[0][j], dp[2][j])
        dp[2][j + 1] = max(dp[0][j], dp[1][j])
        if t[j * k + i] == 'r':
            dp[2][j + 1] += p
        elif t[j * k + i] == 's':
            dp[0][j + 1] += r
        else:
            dp[1][j + 1] += s
        j += 1
    ans += max(dp[0][j], dp[1][j], dp[2][j])
print(ans)


Measured memory_bytes: 56816
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
  int c[10];
  int bi(int n){
    int tmp=0;
    while(n){
      c[tmp]=n%2;
      n/=2;
      tmp++;
    }
    return tmp;
  }
int main() {
  int n,m,ans=0;
  cin>>n>>m;
  int k[m],p[m];
  int s[m][n];
  for(int i=0;i<m;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j];
      //cout<<s[i][j];
    }
  }
  for(int i=0;i<m;i++) cin>>p[i];
  for(int i=0;i<pow(2,n);i++){
    int tmp,q=0;
    tmp=bi(i);//cout<<tmp;
    //for(int a=0;a<2;a++) cout<<c[a];
    for(int j=0;j<m;j++){
      int op=0;
      for(int l=0;l<k[j];l++){
        op+=c[s[j][l]-1];
      }
      //cout<<op;
      //cout<<p[j]<<endl;
      if(op%2!=p[j]){
          q=1;
        //cout<<q;
          break;
        } 
    }
    if(!q) ans++;
    //cout<<endl;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
from itertools import combinations

def getval():
    n,m = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(m)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            s[i][j] -= 1
    p = list(map(int,input().split()))
    return n,m,s,p 

def main(n,m,s,p):
    l = [[] for i in range(n)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            l[s[i][j]].append(i)
    ans = 0
    for i in range(n+1):
        for c in combinations(range(n),i):
            temp = [0 for i in range(m)]
            for j in c:
                for k in l[j]:
                    temp[k] += 1
                    temp[k] %= 2
            if temp==p:
                ans += 1
    print(ans)

if __name__=="__main__":
    n,m,s,p = getval()
    main(n,m,s,p)

Measured memory_bytes: 9288
import java.util.Scanner;
import java.util.ArrayList;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    if(x==2){
      System.out.println(2);
    }else{
    ArrayList <Integer> li = new ArrayList <Integer>();
    li.add(2);
    int i = 3;
    int l = 0;
    while(i<1000000){
      for(int j=0;j<li.size();j++){
        if(i%li.get(j)==0){
          l++;
          break;
        }
      }
      if(l==0&&i>=x){
        System.out.println(i);
        break;
      }else if(l==0){
        li.add(i);
      }
    i++;
    l = 0;
   }
    }
  }
}


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

long merge(int A[], int left, int right){
    if (left == right) return 0;
    int mid = (left + right) / 2;
    long cnt = 0;
    cnt += merge(A, left, mid);
    cnt += merge(A, mid + 1, right);

    queue<int> a;
    for (int i = left; i <= mid; i++) {
        a.push(A[i]);
    }
    a.push(-1);
    queue<int> b;
    for (int i = mid + 1; i <= right; i++) {
        b.push(A[i]);
    }
    b.push(-1);

    for (int i = left; i <= right; i++) {
        if (a.front() > b.front()) {
            A[i] = a.front();
            cnt += b.size() - 1;
            a.pop();
        } else {
            A[i] = b.front();
            b.pop();
        }
    }
    return cnt;

}

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

    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long cnt = merge(A, 0, N - 1);
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 4448
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) { cin >> a[i]; }
  int count = 1;
  int number = 1;
  while (count <= n) {
    if (a[number - 1] == 2) {
      break;
    }
    number = a[number - 1];
    count++;
  }
  if (count > n) {
    cout << -1 << endl;
    return 0;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,a,b=INTM()
    ans=0
    for i in range(1,n+1):
        ct=0
        si=str(i)
        for j in si:
            ct+=int(j)
        if a<=ct and ct<=b:
            ans+=i
            #print(i)
    print(ans)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    long long int a, b;
    int d, r;
    double f;
    
    cin  >> a >> b;
    
    d = a / b;
    r = a % b;
    f = static_cast<double>(a) / b;
    
    cout << d << " " << r << " " 
         << fixed << showpoint << setprecision(5)
         << f << endl;

    return 0;
}

Measured memory_bytes: 3296
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left, bisect_right
from functools import lru_cache
MOD = int(1e9)+7
INF = float('inf')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    
    s = sum(a)
    x = s - 2 * sum(e for i, e in enumerate(a) if i % 2)

    ans = [0] * n
    ans[0] = x
    for i in range(1, n):
        ans[i] = 2 * a[i-1] - ans[i-1]
    print(*ans)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
1
4
-1 1 1 -1

"""


Measured memory_bytes: 21340
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int D;
    cin >> D;
    vector<int>c(26);
    for(int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    vector<vector<int>>s(D,vector<int>(26));
    for(int i = 0; i < D; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int>t(D);
    for(int i = 0; i < D; i++) {
        t[i] = rand()%26+1;
    }
    int ans = 0;
    vector<int>Last(26);
    for(int i = 0; i < D; i++) {
        ans+=s[i][t[i]-1];
        Last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            ans-=c[j]*(i+1-Last[j]);
        }
    }
    int M = 2000000;
    vector<P>horyuu;
    int cnt = 0;
    for(int i = 0; i < M; i++) {
        int d = rand()%D+1;
        int q = rand()%26+1;
        int ord = ans;
        int X = 0;
        int Y = 0;
        int A = 0;
        int B = 0;
        ans+=s[d-1][q-1]-s[d-1][t[d-1]-1];
        for(int j = 0; j < D; j++) {
            if(t[j] == t[d-1]) {
                if(j == d-1) {
                    Y = j+1;
                }
                else {
                    X = j+1;
                }
                A = j+1;
            }
            if(t[j] == q) {
                Y = j+1;
                B = j+1;
            }
            ans-=c[t[d-1]-1]*(j+1-X)-c[t[d-1]-1]*(j+1-A);
            ans+=c[q-1]*(j+1-B)-c[q-1]*(j+1-Y);
        }
        if(ans >= ord) {
            ord = ans;
            horyuu.push_back({d,q});
            cnt++;
        }
        else {
            ans = ord;
        }
        if(cnt == 3) {
            cnt = 0;
            t[horyuu[1].first-1] = horyuu[1].second;
            horyuu = {};
        }
    }
    for(int i = 0; i < D; i++) {
        cout << t[i] << "\n";
    }
}

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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  vector<int> d(n+1);
  d[0]=0;
  rep(i,n) d[i+1]=d[i]+l[i];
  int ans=0;
  for(int i=0;i<n+1;i++){
    if(d[i]<=x) ans++;
    else break;
  }
  cout << ans << endl;
}


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

int main()
{
  int n;
  long long ans=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    if((i%3!=0)&&(i%5!=0))
    {
      ans+=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
fun time (x: Int): Int {
  return ((x + 9) / 10) * 10
}

fun remain (x: Int): Int {
  if (x % 10 == 0) {
    return 0
  } else {
    return (10 - x % 10)
  }
}

fun main (args: Array<String>) {
  val a = readLine()!!.toInt()
  val b = readLine()!!.toInt()
  val c = readLine()!!.toInt()
  val d = readLine()!!.toInt()
  val e = readLine()!!.toInt()
  var sum = time(a) + time(b) + time(c) + time(d) + time(e)
  val lis = intArrayOf(remain(a), remain(b), remain(c), remain(d), remain(e))
  println(sum - lis.max()!!.toInt())
}


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

#define mod 998244353

long long dp[300001];

int a[300001];

int N;

long long f(int i) {
    stack<int> st;
    
    for(int i = 0; i < N; i++) {
        if(st.size() > 0) {
            if(st.top() % 2 == a[i] % 2) {
                st.pop();
            }else st.push(a[i]);
        }else st.push(a[i]);
    }
    long long cnt = 0;
    while(!st.empty()) {
        if(st.top() % 2) cnt++;
        st.pop();
    }
    return cnt;

}


int main() {
    // oh hi mark
    int a,b; cin >> a >> b;
    cout << 6 - a -b  << endl;
    return 0;
}


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}
int main()
{

    ll H, N;

    cin >> H >> N;

    ll tmp = 0;
    ll a;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        tmp += a;
    }

    if (H <= tmp)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
text=input()
N=len(text)
ls=[]
for i in range(N):
  ls.append(int(text[i]))
ans=1000
for i in range(N-2):
  a=100*ls[i]+10*ls[i+1]+ls[i+2]
  if abs(a-753)<ans:
    ans=abs(a-753)
print(ans)


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

int main() {
    int n; cin >> n;
    vector<long long> l(0);
    l.push_back(2);
    l.push_back(1);
    for (size_t i = 2; i <= n; i++)
    {
        l.push_back(l.at(i-1) + l.at(i-2));
    }
    cout << l.back() << endl;
}

Measured memory_bytes: 256
S = input()

lst = list()
rev = False
r = 0
l = 0
start = 0
for i in range(len(S)):
    c = S[i]
    if rev and c == 'R':
        lst.append((start, r, l))
        r = 1
        l = 0
        start = i + 1
        rev = False
        continue
    if c == 'R':
        r += 1
    elif c == 'L':
        rev = True
        l += 1
lst.append((start, r, l))

ans = list()
for start, r, l in lst:
    for _ in range(r - 1):
        ans.append(0)

    a = 0
    b = 0
    if r % 2 != 0:
        a += 1
    a += r // 2
    b += r // 2
    if l % 2 != 0:
        b += 1
    a += l // 2
    b += l // 2
    ans.append(a)
    ans.append(b)

    for _ in range(l - 1):
        ans.append(0)

print(' '.join([str(x) for x in ans]))


Measured memory_bytes: 16096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    char str = s[0];
    for (int i = 1; i < s.length(); i++)
    {
        if (str != s[i])
        {
            ans++;
            str = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
require 'bigdecimal'
input = STDIN.read.split("\n")
a = Array.new(input.shift.to_i) do
  x1, y1, x2, y2, x3, y3, x4, y4 = input.shift.chomp.split.map { |e| BigDecimal.new(e) }
  if (y1 == y2 && y3 == y4) || (y2 - y1) / (x2 - x1) == (y4 - y3) / (x4 - x3)
    'YES'
  else
    'NO'
  end
end
puts a

Measured memory_bytes: 8804
K,A,B=map(int,input().split())
b_count=1

if B-A<=2:
    b_count+=K
else:
    b_chenge_count=max(0,int((K-(A-1))/2))
    b_count+=b_chenge_count*(B-A)+(A-1)+(K-(A-1)-b_chenge_count*2)

print(b_count)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int a,b;
  	char op;
	cin >> a >> op >> b;
  	if(op=='+'){
		cout << a+b << endl;
    }else{
		cout << a-b << endl;
    }	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int a;
cin>>a;
  if(a>699&&a<800){cout<<"Yes";return 0;}
  else if(a%10==7){cout<<"Yes";return 0;}
    else if(a%100-a%10==70){cout<<"Yes";return 0;}
  cout<<"No";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/













int N, M, A[101010], B[101010];
vector<int> Q[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> A[i] >> B[i];
	rep(i, 0, N) Q[A[i]].push_back(B[i]);

	priority_queue<int> que;
	int ans = 0;
	rep(m, 1, M + 1) {
		fore(b, Q[m]) que.push(b);
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}

	cout << ans << endl;
}









Measured memory_bytes: 6528
from decimal import Decimal
from math import floor
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    A,B = readline().split()
    A = int(A)
    B = Decimal(B)

    print(floor(A * B))


if __name__ == "__main__":
    main()


Measured memory_bytes: 10096
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True


ans=0

n,k=LI()
a=LI()

a.sort()
g,h=0,0
cm=Comb(n+5)

for i in range(n):
    Mc=cm.comb(i+1,k)-cm.comb(i,k)
    mc=cm.comb(n-i,k)-cm.comb(n-i-1,k)
    gi=a[i]*Mc
    hi=a[i]*mc
    g+=gi
    h+=hi
    g%=mo
    h%=mo

'''
for i in range(n):
    M=bisect.bisect(a,a[i])
    m=bisect.bisect(a,a[i]-1)
    Mc=cm.comb(M,k)-cm.comb(M-m,k)
    mc=cm.comb(n-m,k)-cm.comb(n-M,k)
    gi=a[i]*Mc*(1 if m<k-1 else 1)
    hi=a[i]*mc*(1 if n-m<k-1 else 1)
    g+=gi
    h+=hi
    show(i,a[i],(m,M),Mc,mc,gi,hi)
    show('max',(M,k),(M-m,k))
    show('min',(n-m,k),(n-M,k))
'''

ans=g-h
print(ans%mo)


Measured memory_bytes: 65132
#include<cstdio>
#include<cstring>
using namespace std;
int k;
int h[1000001],p;
struct edge{
    int to,w,nx;
}e[5000001];
int q[1000001],d[1000001],he,ta;
void ae(int fr,int to,int w){
	e[++p]=(edge){to,w,h[fr]};h[fr]=p;
}
int main(){
    scanf("%d",&k);
    for(int i=0;i<k;i++) ae(i,(i+1)%k,1),ae(i,(i*10)%k,0);
    q[++ta]=1;
    memset(d,127/3,sizeof(d));
    d[1]=0;
    while(he<ta){
        int u=q[++he];
        for(int i=h[u];i;i=e[i].nx){
            if(d[e[i].to]>d[u]+e[i].w){
                d[e[i].to]=d[u]+e[i].w;
                q[++ta]=e[i].to;
            }
        }
    }
    printf("%d\n",d[0]+1);
    return 0;
}

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

int main() {
  string s; cin >> s;
  ll k; cin >> k;
  rep(i, s.size()) {
    if (s.at(i) == '1' && i+1 >= k) {
      cout << '1' << endl;
      return 0;
    }
    if (s.at(i) != '1') {
      cout << s.at(i) << endl;
      return 0;
    }
  }
  cout << '1' << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
long long gcd(long long a, long long b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}
int main()
{
    long long A, B, C, D, g, lcm, c, d, l;
    cin >> A >> B >> C >> D;
    g = gcd(C, D);
    lcm = (C / g) * (D / g) * g;
    if (A % C == 0)
    {
        c = B / C - A / C + 1;
    }
    else
    {
        c = B / C - A / C;
    }
    if (A % D == 0)
    {
        d = B / D - A / D + 1;
    }
    else
    {
        d = B / D - A / D;
    }
    if (A % lcm == 0)
    {
        l = B / lcm - A / lcm + 1;
    }
    else
    {
        l = B / lcm - A / lcm;
    }
    cout << (B - A + 1) - (c + d - l) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
 //freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
  ios_base:: sync_with_stdio(0);
    cin.tie(0);
    int a=0,b,c,n,i,j,k=0,l=0;
   cin>>a;
   int art[a];
   for(i=0;i<a;i++){
    cin>>art[i];
   }
   for(i=0;i<a-1;i++){
    for(j=i+1;j<a;j++){
      l+=art[i]*art[j];
    }
   }
   cout<<l;

  
}


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

signed main(){
  int n;
  cin >> n;
  map<long, long> rValues;
  map<long, long> lValues;

  for(int i = 0; i < n; i++){
    long height;
    cin >> height;
    long rValue = height + i;
    long lValue = i - height;
    rValues[rValue]++;
    lValues[lValue]++;
  }

  long long count = 0;
  for(auto itr = rValues.begin(); itr != rValues.end(); itr++){
    count += itr->second * lValues[itr->first];
  }
  cout << count << endl;
}

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


bool inside(int i, int j, int h, int w) {
	return (i >= 0 && i < h && j >= 0 && j < w);
	}

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	string s;
	cin>>s;
	if(s == "ABC")
		cout<<"ARC";
	else cout<<"ABC";

	return 0;		
}


Measured memory_bytes: 3564
n =int(input())
xs = [int(i) for i in input().split()]
a = 0
ret = 0
for i in range(n):
    ind = i + 1
    if ind == xs[i]:
        a += 1
    elif a > 0:
        ret += a // 2
        ret += a % 2
        a = 0
if a > 0:
    ret += a // 2
    ret += a %2
print(ret)

Measured memory_bytes: 13880
# -*- coding: utf-8 -*-
import sys
n = int(input());
words = []

for i in range(n):
    words.append(input())

if (len(words) > len(set(words))):
    print('No')
    sys.exit(0)

before_word = words.pop(0)
while( len(words) > 0 ):
    after_word = words.pop(0)
    if (before_word[-1] != after_word[0]):
        print('No')
        sys.exit(0)
    before_word = after_word
print('Yes')

Measured memory_bytes: 3064
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n%1000==0) System.out.println(0);
        else{
            n=n%1000;
            int balance=1000-n;
            System.out.println(balance);
        }
    }
}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < 0) {
        if (b < 0) {
            if ((a-b)%2) {
                cout << "Positive" << endl;
            } else {
                cout << "Negative" << endl;
            }
        } else {
            cout << "Zero" << endl;
        }
    } else {
        if (b < 0) {
            cout << "Zero" << endl;
        } else {
            cout << "Positive" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
char chin(){char c;cin>>c;return c;}
ll lin(){ll x;scanf("%lld",&x);return x;}

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

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

using namespace std;

typedef long long ll;


int main() {

    ll N, K;
    vector<ll> tree;

    cin >> N >> K;
    tree.resize(N, 0);

    for (ll i = 0; i < N; ++i)
        cin >> tree[i];

    sort(tree.begin(), tree.end());

    ll res = 10000000000;
    for(ll i=0; i+K-1<N; i+=1)
    {
        res=min(res,abs(tree[i]-tree[i+K-1]));
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <utility>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define MP make_pair
#define PB push_back
const int N=1e3+10;
int a[N*4],flag[N*4];
void add(int n,int x,int l,int r,int L,int R){
    if(L<=l&&r<=R){
        a[n]+=x;
        flag[n]+=x;
    }
    else if(!(L>r||l>R)){
        int mid=(l+r)>>1;
        if(flag[n]!=0){
            flag[n*2+2]+=flag[n];
            flag[n*2+1]+=flag[n];
            a[n*2+2]+=flag[n];
            a[n*2+1]+=flag[n];
            flag[n]=0;
        }
        add(n*2+1,x,l,mid,L,R);
        add(n*2+2,x,mid+1,r,L,R);
        a[n]=max(a[n*2+1],a[n*2+2]);
    }
    return ;
}
int main(){
    int n,x1,x2,y1,y2,ans=0;
    vector<pi> l[N],r[N];
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(flag,0,sizeof(flag));
    for(int i=0;i<n;i++){
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        l[y1].PB({x1+1,x2});
        r[y2].PB({x1+1,x2});
    }
    for(int i=0;i<N;i++){
        for(auto u:l[i])add(0,1,0,N-1,u.F,u.S);
        for(auto u:r[i])add(0,-1,0,N-1,u.F,u.S);
        ans=max(ans,a[0]);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

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

    vector<int> a(n+10,0);
    ll ans = 0,sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i-1]+a[i] <= x) continue;
        else{
            ans += a[i-1]+a[i]-x;
            a[i] = x-a[i-1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forr(a,b,v) for(int v=a; v<=b; v++)
#define ford(a,b,v) for(int v=a; v>=b; v--)
const int N = 100005;
int main () {
    int n;
    int A[N];
    // store the sum of the result in a long long pair
    ll s = 0;
    cin >> n;
    forr(1,n,i) {
        cin >> A[i];
    }

    if ( n == 2 ) {
        int s = max(A[n-1] + A[n], -A[n-1]-A[n]);
        cout << s << endl;
        return 0;
    }
    forr(1,n-2,i) {
        if (A[i] < 0) {
            A[i] *= -1;
            A[i+1] *= -1;
        }
        s += A[i];
    }
    // add the last two pairs
    if ( (A[n] > 0 and A[n-1] > 0) or (A[n] < 0 and A[n-1] < 0) ) {
        s += max(A[n-1] + A[n], -A[n-1]-A[n]);
    }
    else {
        int* mni = min_element( A+1, A+n-2);
        int mnv = *mni;

        if ( mnv > min(abs(A[n-1]), abs(A[n])) ) {
            s += max(A[n-1] + A[n], -A[n-1]-A[n]);
        }
        else {
            s -= mnv * 2;
            s += abs(A[n-1]);
            s += abs(A[n]);
        }
    }

    cout << s << endl;
    return 0;
}


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

int SumOfDigit(ll n)
{
    int sum=0;
    while(n)
        sum+=n%10,n/=10;
    return sum;
}

int main()
{
    ll n;
    cin>>n;
    int s=SumOfDigit(n);
    if(n%s)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


Measured memory_bytes: 3604
from collections import deque

S = input()
Q = int(input())
Queries = [input().split() for i in range(Q)]

def start(S):
    state = {
        "S": S,
        "is_reversed": False,
        "left": deque(),
        "right": deque(),
    }

    return state


def T1(state, Query):
    state['is_reversed'] = not state['is_reversed']


def T2(state, Query):
    F = Query[1]
    C = Query[2]

    if not state['is_reversed']:
        if F == '1':
            state['left'].appendleft(C)
        else:
            state['right'].append(C)
    else:
        if F == '1':
            state['right'].append(C)
        else:
            state['left'].appendleft(C)


def output(state):
    output = ''.join(state['left']) + state['S'] + ''.join(state['right'])
    if state['is_reversed']:
        output = ''.join(list(reversed(output)))

    return output

def fetch(Query):
    operations = {
        '1': T1,
        '2': T2,
    }

    index = Query[0]
    operation = operations[index]

    return operation

def operate(state, Query):
    T = fetch(Query)
    T(state, Query)


def execute(state, Queries):
    state = start(S)

    for Query in Queries:
        operate(state, Query)

    result = output(state)

    return result


answer = execute(S, Queries)

print(answer)


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

using namespace std;
using ll = long long;
using ld = long double;

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

  for (auto i = max(X-K+1,-1000000); i <= min(X+K-1,1000000); ++i) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
let N = Int(readLine()!)!
let a = readLine()!.characters.split(" ").map{Int(String($0))!}
var A = [Int : Int]()
var ans = 0
for i in a {
  if A[i] == nil {
    A[i] = 0
  }
  A[i]! += 1
}
for (i, j) in A {
  if i > j {
    ans += j
  } else {
    ans += j - i
  }
}
print(ans)

Measured memory_bytes: 7748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

int main(){
	int H,W,N;
	
	scanf("%d %d %d",&N,&H,&W);

	printf("%d\n",(N-W+1)*(N-H+1));
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> PII;

int main(){
  int A,B;
  cin>>A>>B;
  if(abs(A-B)%2) cout<<"IMPOSSIBLE"<<endl;
  else cout<<(A+B)/2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define cn cout<<"\n"
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repr(i,a,b) for(int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>
#define flush fflush(stdout)

const int INF = 1e8;
const ll MOD = 1e9 + 7;

using namespace std;

int acu[100005];

int main(){
	_

	int t = 1;

	string s;
	int n, q, a, b;
	cin>>n>>q;
	cin>>s;

	rep(i, 0, n - 1)
		if(s[i] == 'A' and s[i + 1] == 'C')
			acu[i + 1] += 1;

	rep(i, 0, n){
		acu[i] = acu[i] + ((i - 1) >= 0 ? acu[i - 1] : 0 );
		// cout<<acu[i]<<" ";
	}

	// cout<<"-----\n";

	rep(i, 0, q){
		cin>>a>>b;
		a--; b--;

		if(s[a] == 'C') a++;
		int ans;
		if(a <= b)
			ans = acu[b] - ((a - 1) >= 0 ? acu[a - 1] : 0 );
		else ans = 0;
		cout<<ans; cn;
	}

	return 0;
}

Measured memory_bytes: 1488
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]

pT, pX, pY = 0, 0, 0

for i in range(n):
    cT, cX, cY = d[i]
    mvT, mvX, mvY = abs(cT-pT), abs(cX-pX), abs(cY-pY)
    
    dam = mvT - (mvX+mvY)

    if dam%2 == 1 or dam<0:
        print('No')
        exit()

    pT, pX, pY = d[i]

print('Yes')

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}



struct Union_Find {
private:
	vector<int> parent;
	vector<int> num;
	int treenum;

public:
	Union_Find(int n) : parent(n),num(n,1) {
		treenum=n;
		for(int i=0; i<n; i++) {
			parent[i]=i;
		}
	}

	int root(int x) {
		assert(x < parent.size());
		if(parent[x]==x) return x;
		return parent[x]=root(parent[x]);
	}

	int size(int x) {
		return num[root(x)];
	}

	void merge(int x, int y) {
		int xrt=root(x);
		int yrt=root(y);
		if(xrt==yrt) return;
		parent[yrt]=xrt;
		num[xrt]+=num[yrt];
		treenum--;
	}

	bool same(int x, int y) {
		return root(x)==root(y);
	}

	int tnum() {
		return treenum;
	}
};

int N,M;

void input() {
	cin>>N>>M;
}

void solve() {
	Union_Find uf(N);
	for(int i=0; i<M; i++){
		int A,B; cin>>A>>B; A--,B--;
		uf.merge(A,B);
	}
	
	int ans=1;
	for(int i=0; i<N; i++) chmax(ans,uf.size(i));
	cout<<ans<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 5016
//
//  main.cpp

#include <iostream>
using namespace std;
using ll = long long;

int main(){	
	int N,Q;
	ll T;
	cin >> N >> T >> Q;
	
	ll people[1001];
	ll A[100001];
	int D[100001];
	for(int i=0;i<N;i++){
		cin >> A[i] >> D[i];
	}
	for(int i=0;i<Q;i++){
		cin >> people[i];
		people[i]--;
	}
	
	ll east = 0;
	ll west = 0;
	ll t = 0;
	for(int i=0;i<Q;i++){
		if(D[people[i]] == 1){
			east = A[people[i]];
			for(ll j=people[i]+1;j<N;j++){
				if(D[j] == 1){
					east = A[j];
				}else{
					t = (east + A[j])/2;
					break;
				}
			}
			if(T < abs(t - A[people[i]])){
				cout << A[people[i]] + T << endl;
			}else{
				cout << t << endl;
			}
		}else{
			west = A[people[i]];
			for(ll j=people[i]-1;j>=0;j--){
				if(D[j] == 1){
					t = (west + A[j])/2;
					break;
				}else{
					west = A[j];
				}
			}
			if(T < abs(A[people[i]] - t)){
				cout << A[people[i]] - T << endl;
			}else{
				cout << t << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 4248
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <map>
using namespace std;


int main()
{
   int a;
   cin >> a;

   cout << a + a * a + a * a * a;

   return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
#define SpaceNewLine(a) Rep(i,a.size())cout<<a[i]<<(i==a.size()-1?'\n':' ')
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {
    // setup {{{ 1
    cin.tie(0);
    ios::sync_with_stdio(false);
    // }}}

    int N;
    Scd(N);

    printf ("%d\n", 3*N*N );

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[10009],n,i;
scanf("%d\n",&n);
long long sum=0;
for(i=1;i<=n;i++){
	scanf("%d",&a[i]);
	sum+=a[i]-1;
}
printf("%lld\n",sum);
	return 0;
}

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

int main() {
  int x,a,b,c,d;
  cin >> x;
  d = x % 10;
  c = (x % 100 -d)/10;
  b = (x % 1000 -x%100)/100;
  a = (x - x % 1000)/1000;
  
  if (a == b && b == c) {
    cout << "Yes" << endl;
  }
  else if (b == c && c == d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}


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

using namespace std;

int main(){

  int count = 0;
  int H,D;
  
  cin >> D;
  cin >> H;
  
  for(count=0; D>0; count++){
    D = D - H;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,k;
    fi>>n>>k;
    static int str[256];
    while (n --)
    {
        string s;
        fi>>s;
        ++str[s[0] - 'A'];
    }
    int ans = 0;
    while (1)
    {
        sort(str,str + 26,greater < int > ());
        if (!str[k - 1]) break;
        for (int i = 0;i < k;++i)
            --str[i];
        ++ans;
    }
    fo << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

int main(){
  ll N,ans=0;
  cin>>N;
  vector<ll> L(N);
  REP(i,N) cin>>L[i];
  SORT(L);
  
  for(int i=0; i<N-2; ++i){
    for(int j=i+1; j<N-1; ++j){
      for(int k=j+1; k<N; ++k){
        if(L[i]!=L[j] && L[j]!=L[k] && L[k]!=L[i] && L[i]+L[j]>L[k]) ans++;
      }
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 3628
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	map<string, ll> d;
	ll ans = 0;
	rep(i, n) {
		cin >> s[i];
		sort(all(s[i]));
		if (d.find(s[i]) != d.end()) {
			d[s[i]] += 1;
			ans += d[s[i]];
		}
		else d[s[i]] = 0;
	}
	cout << ans << endl;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n), b(n);
    for (auto &e : a) std::cin >> e;
    for (auto &e : b) std::cin >> e;
    std::set<std::pair<int, int>> s;
    for (int i = 0; i < n; i++) s.emplace(-b[i], i);

    i64 ret = 0;
    while (!s.empty()) {
        auto c = s.begin();
        int i = c->second;
        int p = b[(i + 1) % n] + b[(i + n - 1) % n];
        if ((b[i] - a[i]) % p == 0) {
            ret += (b[i] - a[i]) / p;
            b[i] = a[i];
            s.erase(c);
        } else {
            int k = (b[i] - 1) / p;
            ret += k;
            b[i] -= k * p;
            if (k == 0 || b[i] < a[i]) {
                std::cout << -1 << std::endl;
                return 0;
            }
            s.erase(c);
            s.emplace(-b[i], i);
        }
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 13184
package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	n := len(s)

	l,r := 0,n-1
	ans := 0
	for r > l {
		if s[l] == s[r] {
			l++
			r--
		} else {
			if s[r] == 'x' {
				r--
				ans++
			} else if s[l] == 'x' {
				l++
				ans++
			} else {
				fmt.Fprintln(wr, -1)
				return
			}
		}
	}

	fmt.Fprintln(wr, ans)

}


Measured memory_bytes: 1024
# coding: utf-8
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# 町Aiを訪れた時刻のリスト (time[Ai] = t_Ai)
time = [-1 for _ in range(N+10)]
# new: 次に訪れる町, t: 現在の時刻
# 初期値 Ai = 1, t = 0
new = 1
t = 0

# 町newが到達済みになるまで時刻を計算
while time[new] == -1:
    time[new] = t
    new = A[new - 1]
    t += 1

# line: ループ前までの時刻, loop: ループ1回の時間
line = time[new]
loop = t - time[new]

# 場合分け
# Kがループ中の時刻なら、line分を引く
if K > line:
    K = (K - line) % loop
    for i in range(N+1):
        time[i] -= line
# Kがループ前までの時刻なら、そのまま (if K <= line:)
for i in range(N+1):
    if time[i] == K:
        print(i)
        break

Measured memory_bytes: 33224
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
# e1,e2,e3 = map(int,input().split())
#f = list(map(int,input().split()))
# g = [input() for _ in range(a)]

if a==0:
    print(1)
elif a==1:
    print(0)

Measured memory_bytes: 9088