akhauriyash/Code-Regression huggingface dataset:
// ------------------------------------
// Date:2018/ 4/ 7
// Problem:/ / / a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int cnt[26];

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

  SCIN(s);
  EACH(si, s) {
    cnt[si - 97]++;
  }

  REP(i, 26) {
    if (cnt[i] == 0) {
      printf("%c\n", i + 97);
      return 0;
    }
  }

  cout << "None" << endl;

  return 0;
}



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

int n;
int t[10005], dp[2][2][5005];

int main() {
    cin >> n;
    REP(i,n-1){
        cin >> t[i+1];
    }
    for(int i=0;i<2;i++){
        for(int j=0;j<=n/2;j++){
            dp[0][i][j] = IINF/3;
            dp[1][i][j] = IINF/3;
        }
    }
    dp[0][0][0] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=n/2;j++){
            dp[0][1][j] = min(dp[0][1][j],dp[0][0][j]);
            dp[0][1][j] = min(dp[0][1][j],dp[1][0][j]);
            dp[1][1][j+1] = min(dp[1][1][j+1],dp[0][0][j]+t[i]+t[i+1]);
            dp[1][1][j+1] = min(dp[1][1][j+1],dp[1][0][j]-t[i]+t[i+1]);
        }
        for(int j=0;j<=n/2;j++){
            dp[0][0][j] = dp[0][1][j];
            dp[1][0][j] = dp[1][1][j];
            dp[0][1][j] = IINF/3;
            dp[1][1][j] = IINF/3;
        }
    }
    cout << min(dp[0][0][n/2],dp[1][0][n/2]) << endl;
    return 0;
}


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

int main(){
    string a,b;
    cin>>a>>b;
    bool ok=false;
    long long n=a.size();
    if(a==b)cout<<"Yes";
    else{
        for(long long i=0;i<a.size();i++){
            a=a[n-1]+a;
            a.erase(n,1);
            if(a==b)ok=true;
        }
        if(ok)cout<<"Yes";
        else cout<<"No";
    }
}

Measured memory_bytes: 384
import operator
import sys
import heapq

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def link(x, y):
    if rank[x] > rank[y]:
        p[y] = x
    else:
        p[x] = y
        if rank[x] == rank[y]:
            rank[y] = rank[x] + 1


def _union(x, y):
    link(find_set(x), find_set(y))


def find_set(x):
    if x != p[x]:
        p[x] = find_set(p[x])
    return p[x]


def dist(j, k):
    return min(abs(pairs[j][0] - pairs[k][0]), abs(pairs[j][1] - pairs[k][1]))


n = read_int()
pairs = [read_int_list() for i in range(n)]

p = list(range(n))
rank = [0] * n

edges = []

for pos in range(2):
    indices = list(range(n))
    indices.sort(key=lambda u: pairs[u][pos])
    for i in range(1, n):
        j = indices[i - 1]
        k = indices[i]
        w = dist(j, k)
        heapq.heappush(edges, (w, j, k))

res = 0
while edges:
    edge = heapq.heappop(edges)
    w, j, k = edge
    if find_set(j) != find_set(k):
        res += w
        _union(j, k)

print(res)


Measured memory_bytes: 64632
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

def main(a_list, b_list, c_list):
    before_element = 999
    result = 0
    for element in a_list:
        result += b_list[element-1]
        if element == before_element + 1:
            result += c_list[before_element-1]
        before_element = element
    return result

print(main(a_list, b_list, c_list))

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

// using namespace std;
// using llong = long long;
// using ldbl = long double;
// using P = pair<llong, llong>;

// #define ALL(x) x.begin(), x.end()

// const llong inf = 1100100100100100ll;
// const llong mod = 1e9+7;

// llong N, K;
// vector<vector<llong> > dp;

// llong solve(llong now, llong bunkatsu) {
// 	if (now == 0) return bunkatsu == 0;
// 	if (bunkatsu == 0) return 0;
// 	if (dp[now][bunkatsu] != -1) return dp[now][bunkatsu];

// 	return dp[now][bunkatsu] = (solve(now-1, bunkatsu) + solve(now-1, bunkatsu-1)) % mod;
// }

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

// 	dp.resize(N+1, vector<llong>(K+2, -1));
// 	for (int i = 0; i <= K+1; ++i) {
// 		solve(N, i);
// 		solve(N-K, i);
// 	}

// 	for (int i = 1; i <= K; ++i) {
// 		cerr << dp[K][i] << " " << dp[N-K][i-1] << " " << dp[N-K][i] << " " << dp[N-K][i+1] << endl;
// 		cout << dp[K][i] * (max(0ll, dp[N-K][i-1]) + max(0ll, dp[N-K][i])*2ll + max(0ll, dp[N-K][i+1])) % mod << endl;
// 	}

// 	return 0;
// }

// /*

// Kをi分割して整列する場合の数
// N-Kをi-1, i, i+1分割して整列する場合の数

// dp i個まででj分割

// */


#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

llong N, K;
vector<vector<llong> > memo;

llong dp(llong now, llong sep) {
	if (now == 0) return memo[now][sep] = sep == 0;
	if (sep == 0) return memo[now][sep] = 0;
	if (memo[now][sep] != -1) return memo[now][sep];

	return memo[now][sep] = (dp(now-1, sep) + dp(now-1, sep-1)) % mod;
}

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

	memo.resize(N+1, vector<llong>(K+2, -1));
	for (int i = 0; i <= K+1; ++i)
		dp(N, i);

	for (int i = 1; i <= K; ++i) {
		llong b = memo[K][i];
		llong r = (memo[N-K][i-1] + memo[N-K][i]*2 + memo[N-K][i+1]) % mod;

		cout << b*r%mod << endl;
	}

	return 0;
}

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

const int MOD = (int)1e9+7;

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

  if(A%2==1 || B%2==1 || C%2==1){
    cout << 0 << endl;
    return 0;
  }
  if(A==B && B==C){
    cout << -1 << endl;
    return 0;
  }
  
  int ans=0;
  while(A%2==0 && B%2==0 && C%2==0){
    int a=A/2,b=B/2,c=C/2;
    A=b+c;
    B=a+c;
    C=a+b;
    ans++;
  }
  cout << ans << 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;
using ll = long long;

int n, m, k;
int id;
vector<int> cc_id;
vector<int> cc_num;

void dfs(const vector<vector<int>> &g, int v, int &cnt){
  cc_id[v] = id;
  cnt++;
  for(auto e : g.at(v)){
    if(cc_id.at(e) == -1){
      dfs(g, e, cnt);
    }
  }
}

int main(){
  cin >> n >> m >> k;
  vector<vector<int>> g(n);
  vector<int> a(m), b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g.at(a[i]).push_back(b[i]);
    g.at(b[i]).push_back(a[i]);
  }
  vector<int> c(k), d(k);
  rep(i,k){
    cin >> c[i] >> d[i];
    c[i]--, d[i]--;
  }
  
  id = 0;
  cc_id.assign(n, -1);
  rep(i,n){
    if(cc_id[i] == -1){
      int cnt = 0;
      dfs(g, i, cnt);
      id++;
      cc_num.push_back(cnt);
    }
  }
  
  vector<int> ans(n);
  rep(i,n){
    ans[i] = cc_num.at(cc_id[i]) - 1 - g[i].size();
  }
  rep(i,k){
    if(cc_id[c[i]] == cc_id[d[i]]){
      ans[c[i]]--;
      ans[d[i]]--;
    }
  }
  rep(i,n - 1){
    cout << ans[i] << ' ';
  }
  cout << ans[n - 1] << endl;
}



Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;

    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> R[i];

    int maxv = -2147483648;
    int minv = R[0];

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

    cout << maxv << endl;

    return 0;
}


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

int main(){
  int K;
  string S;
  cin >> K >> S;
  for(int i=0;i<S.size();i++){
    if(i<K){
      cout << S.at(i);
    }else{
      cout << "...";
      break;
    }
  }
  cout << endl;
      
}

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

using namespace std;


int main() {
    int n,m;
    cin>>m;
    n=m;
    int f=0;
    while(n>=1){
        f+=n%10;
        n/=10;
    }
    //cout<<3%2<<endl;
    if(m%f==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n, k = 2; scanf("%d", &n);
	vector<int> h(n), dp(n, 2000000000); dp[0] = 0;
	for (int i = 0; i < n; ++i) scanf("%d", &h[i]);
	for (int i = 1; i < n; ++i) for (int p = max(0, i - k); p < i; ++p) 
		dp[i] = min(dp[i], dp[p] + (int)abs(h[p] - h[i]));
	printf("%d\n", dp[n-1]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main() {

	int H1, M1, H2, M2, K;
	int result;

	std::cin >> H1 >> M1 >> H2 >> M2 >> K;

	result = (H2 * 60 + M2) - (H1 * 60 + M1) - K;

	std::cout << result;

}

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

int main(){
	int n,a,b,i,p,s=0,k=0;
	
	cin>>n>>a>>b;
	
	for(i=1;i<=n;i++){
		p=i;
		while(p!=0){
			k+=p%10;
			p=p/10;
		}
		if(k>=a&&k<=b){
			s+=i;
		}
		k=0;
	}
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

ll a[200000];  // 書かれている整数
ll num[200000] = { 0 };  // 整数が何個あるか

// 組み合わせnCrを求める関数
ll Combination(ll n, ll r) {
    ll molecule = 1;
    ll denominator = 1;
    for (ll i = 0; i < r; i++) {
        molecule *= n - i;
        denominator *= r - i;
    }
    return (molecule / denominator);
}

int main()
{
    ll n;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        num[a[i]-1] += 1;
    }
    ll all = 0;
    rep(i, n) {
        all += Combination(num[i], 2);
    }
    rep(i, n) {
        ll ans = all - num[a[i] - 1] + 1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  val n = readInt
  val dict = new SimpleDictionary(n)
  for (_ <- 1 to n) {
    val Array(cmd, str) = readLine.split(" ")
    cmd match {
      case "insert" => dict.insert(str)
      case "find" => { println(if (dict.find(str)) "yes" else "no") }
    }
  }

  class SimpleDictionary(inputSize: Int) {

    val size = Math.max(1, inputSize / 100)
    val arr:Array[SimpleLinkedList] = new Array[SimpleLinkedList](size)

    def insert(str: String): Unit = {
      val hashCode = (str.hashCode % size).abs
      var linkedList = arr(hashCode)
      if (linkedList == null) {
        linkedList = new SimpleLinkedList()
      }
      if (!linkedList.exists(str)) {
        linkedList.insert(str)
      }
      arr(hashCode) = linkedList
    }

    def find(str: String): Boolean = {
      val hashCode = (str.hashCode % size).abs
      val linkedList = arr(hashCode)
      if (linkedList == null) {
        return false
      }
      linkedList.exists(str)
    }
  }

  class SimpleLinkedList {

    class Node(v: String) {
      val value: String = v
      var next: Node = null
    }

    var head: Node = null

    def insert(value: String): Unit = {
      val newNode = new Node(value)
      newNode.next = head
      head = newNode
    }

    def exists(value: String): Boolean = {
      var current = head
      while (current != null) {
        if (current.value.equals(value)) {
          return true
        }
        current = current.next
      }
      false
    }

  }
}



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

int main()
{
    int a,b,c;
    int count5,count7;
    cin>>a>>b>>c;
    if(a==5)
    {
        count5++;
    }
    else if(a==7)
    {
        count7++;
    }
    if(b==5)
    {
        count5++;
    }
    else if(b==7)
    {
        count7++;
    }
    if(c==5)
    {
        count5++;
    }
    else if(c==7)
    {
        count7++;
    }

    if(count5==2&&count7==1)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[10005];
long long dp[10005];
struct poi
{
    long long zhi;
    int wz;
}p[100005];
bool cmp(poi a,poi b)
{
    return a.zhi>b.zhi;
}

int main(){
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        p[i].zhi=a[i];
        p[i].wz=i;
    }
    memset(dp,0,sizeof(dp));
    long long maxn=0;
    sort(p+1,p+1+n,cmp);
    for(i=1;i<=n;i++)
    {
        dp[i]=dp[i-1]+abs(p[i].wz-i)*p[i].zhi;
        for(j=i-1;j>=1;j--)
        {
            dp[j]=max(dp[j]+abs(n-(i-j-1)-p[i].wz)*p[i].zhi,dp[j-1]+abs(j-p[i].wz)*p[i].zhi);
        }
        dp[0]=dp[0]+abs(n-i+1-p[i].wz)*p[i].zhi;
    }
    for(i=0;i<=n;i++)maxn=max(maxn,dp[i]);
    cout<<maxn<<endl;
    return 0;
}


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

using namespace std;

int main()
{
	int N, x, a[100], ans = 0;

	cin >> N >> x;

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

	sort(a, a + N);

	for (int i = 0; i < N; i++) {
		if (x - a[i] >= 0) {
			ans++;
			x -= a[i];
			if (i + 1 == N - 1) {
				if (x - a[i+1] == 0)
					ans++;

				break;
			}
		}
		else {

			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
T, X, Y = 0, 0, 0

can_reach = True
for i in range(N):
  next_T, next_X, next_Y = map(int, input().split())
  
  z = next_T - T - abs(X - next_X) - abs(Y - next_Y)
  if z >= 0 and z % 2 == 0:
    T, X, Y = next_T, next_X, next_Y
  else:
    can_reach = False
    break
    
if can_reach:
  print('Yes')
else:
  print('No')
    
    
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
#define DB double
const int N=200010;
const int M=12000010;
const LL MOD=998244353;
using namespace std;

int n,len=0;
int a[N],b[N];
int mx[2],mxx[2],val[2];

void READ(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]);
}

void SOLVE(int x){
	sort(b+1,b+len+1);
	mx[x]=mxx[x]=0;val[x]=0;
	int num=1;
	b[len+1]=b[len]+1;
	rep(i,2,len+1){
		if(b[i]!=b[i-1]){
			if(num>mx[x])val[x]=b[i-1],mxx[x]=mx[x],mx[x]=num;
			else mxx[x]=max(mxx[x],num);
			num=1;
		}
		else num++;
	}
}

int main(){
	READ();
	len=0;for(int i=1;i<=n;i+=2)b[++len]=a[i];
	SOLVE(0);
	len=0;for(int i=2;i<=n;i+=2)b[++len]=a[i];
	SOLVE(1);
	if(val[0]==val[1])printf("%d\n",n-max(mx[0]+mxx[1],mx[1]+mxx[0]));
	else printf("%d\n",n-mx[0]-mx[1]);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    int n,k;cin>>n>>k;
    set<int> st;
    int tmp,j;
    rep(i,0,k){
        cin>>j;
        rep(i,0,j){
            cin>>tmp;
            st.insert(tmp);
        }
    }
    cout<<n-st.size();
 
return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int x,y; cin >> x >> y;

	if (y % x == 0) {
		cout << x + y  << endl;
	}else {
		cout << y - x << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];

    vector<int> t(d);
    rep(i, d) cin >> t[i], t[i]--;

    vector<int> last(26, -1);
    auto calc = [&](int day, int type, vector<int> last) {
        int ret = 0;
        ret += s[day][type];
        rep(i, 26) if (i != type) ret -= c[i] * (day - last[i]);
        return ret;
    };
    int ans = 0;
    rep(i, d) {
        ans += calc(i, t[i], last);
        last[t[i]] = i;
        cout << ans << '\n';
    }
}

Measured memory_bytes: 3628
N, M = map(int, input().split())
A = sorted(list(map(int,input().split())), reverse=True)

# jとの組み合わせがx以上になるiの個数
def combinations(x):
  s = 0
  i = 0
  for j in reversed(range(N)):
    while i<N and A[i]+A[j]>=x:
      i += 1
    s += i
  return s
 
#↑のような組み合わせの合計幸福度
def koufukudo(x):
  s = 0
  si = 0
  i = 0
  for j in reversed(range(N)):
    while i<N and A[i]+A[j]>=x:
      si += A[i]
      i += 1
    s += si + A[j]*i  
  return s
 
#
def bsearch(l, u):
  m = (l+u)//2
  c = combinations(m)
#   print(f"m{m}, c{c},c-M{c-M}")
  if c<M:
    return bsearch(l, m)
  else:
    if l==m:
      return (l, c-M)
    return bsearch(m, u)
 
x, dm = bsearch(0, A[0]*2+1)
print(koufukudo(x)-dm*x)

Measured memory_bytes: 14152
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

n, *a = map(int, read().split())

res = gcd(a[0],a[1])
for i in range(2,n):
    res = gcd(res, a[i])

print(res)

Measured memory_bytes: 18308
N,T=map(int, input().split())
A=list(map(int, input().split()))
L=[]
for i in range(N):
    if i==0:
        now=A[i]
        nowmax=now
    if now>A[i]:
        L.append(nowmax-now)
        now=A[i]
        nowmax=now
    else:
        nowmax=max(nowmax,A[i])
    if i==N-1:
        L.append(nowmax-now)
MAX=max(L)
ans=0
#print(L)
for l in L:
    if l==MAX:
        ans+=1
print(ans)

Measured memory_bytes: 15060
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s; cin >> s;
  reverse(begin(s), end(s));
  cout << s << '\n';
}


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

int main() {
  int n, t;
  cin >> n >> t;
  int ci[110];
  int ti[110];
  rep(i,n) cin >> ci[i] >> ti[i];
  int ans = 1e9;
  bool b = true;
  rep(i,n) {
    if (ti[i] <= t) {
      b = false;
      ans = min(ans, ci[i]);
    }
  }
  if(b) cout << "TLE" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
mod = 2019
s = input()
n = len(s)
w = 0
d = {}
p = 1
for i in reversed(range(n)):
	w += int(s[i]) * p
	p *= 10
	w %= mod
	p %= mod
	if w in d:
		d[w] += 1
	else:
		d[w] = 1
if 0 in d:
	d[0] += 1
else:
	d[0] = 1
o = 0
for x in d:
	o += d[x] * (d[x] - 1) // 2
print(o)


Measured memory_bytes: 9328
#include<stdio.h>

void roll( int *dice, char cmd )
{
	int t;
    if( 'E' == cmd ) {
        t = dice[0];
        dice[0] = dice[3];
        dice[3] = dice[5];
        dice[5] = dice[2];
        dice[2] = t;
    } else if( 'N' == cmd ) {
        t = dice[0];
        dice[0] = dice[1];
        dice[1] = dice[5];
        dice[5] = dice[4];
        dice[4] = t;
    } else if( 'S' == cmd ) {
        t = dice[0];
        dice[0] = dice[4];
        dice[4] = dice[5];
        dice[5] = dice[1];
        dice[1] = t;
    } else if( 'W' == cmd ) {
        t = dice[0];
        dice[0] = dice[2];
        dice[2] = dice[5];
        dice[5] = dice[3];
        dice[3] = t;
    } else if( 'M' == cmd ) {
        t = dice[4];
        dice[4] = dice[2];
        dice[2] = dice[1];
        dice[1] = dice[3];
        dice[3] = t;
    }
    return;
}

int isEqualDice( int *dice, int *dice2 )
{
	int i, j;
	char cmd[] = "MMMMNMMMMWMMMMWMMMMWMMMMNMMMM";

	for( i=0; '\0'!=cmd[i]; i++ ) {		
		if( dice[ 0 ]== dice2[ 0 ] ) {
			for( j=0; j<6; j++ ) {
				if( dice[j] != dice2[j] ) { break; }
			}
			if( 6 == j ) { return 1; }
		}
		roll( dice2, cmd[i] );
	}
	return 0;
}

int main( int argc, char *argv[] ) 
{ 
   int dice[101][7];
    int i,j;
    int n;
     
    scanf( "%d", &n );
    for( i=0;  i<n; i++ ) {
        for( j=0;  j<6; j++ ) {
            scanf( "%d", &dice[i][j] );
        }
    }
    int cnt = 0;
    for( i=0; i<n-1; i++ ) {
        for( j=i+1; j<n; j++ ) {
            cnt += isEqualDice( dice[i], dice[j] );
        }
    }
	 if( cnt ) {
        printf( "No\n" );
    } else {
        printf( "Yes\n" );
    }
   
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int cnt = 0;
	for (int i = 0;i < N - 2;i++) {
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n)	for(int i = 0; i < (n); ++i)
#define repA(i, a, n)	for(int i = a; i <= (n); ++i)
#define repD(i, a, n)	for(int i = a; i >= (n); --i)
#define trav(a, x)	for(auto& a : x)
#define fix(a)	cout << setprecision(a); cout << fixed;
#define fast	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
#define clr(a)	memset(a, 0, sizeof(a))
#define all(x)	(x).begin(), (x).end()
#define rall(x)	(x).rbegin(), (x).rend()
#define len(x)	((int)(x).size())
#define vi	vector<int>
#define vl	vector<ll>
#define vpii	vector<pair<int, int>>
#define vpll	vector<pair<ll, ll>>
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back

typedef long long ll;
typedef long double ld;

int main() {
	fast;
	int n, x, t;
	cin>>n>>x>>t;
	ll ans = n/x;
	if(n%x==0)
		cout << ans*t;
	else
		cout << (ans+1)*t;
}

Measured memory_bytes: 3592
def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


H, W = map(int, input().split())
wall = [list(map(int, input().split()))for _ in range(10)]
mat = warshall_floyd(10, wall)
ans = 0
for i in range(H):
    for n in map(int, input().split()):
        if n == -1:
            continue
        ans += mat[n][1]
print(ans)

Measured memory_bytes: 3064
import java.util.*;class Main{public static void main(String[]g){String s="";int h,l,a,f;for(Scanner S=new Scanner(System.in);(l=S.nextInt())+(h=S.nextInt())>0;s+=f<1?"NA\n\n":"\n"){for(f=0,a=l;a<=h;a++)if(a%4<1&&(a%100>0||a%400<1)){s+=a+"\n";f=1;}}System.out.println(s.trim());}}


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

typedef unsigned long long ull;
typedef long long ll;

constexpr size_t MAXV = 1e5;
constexpr size_t MAXW = 1e9;
constexpr size_t INF = MAXW + 1;

void solve() {
  int N, W;
  std::cin >> N >> W;
  std::vector<size_t> dp(MAXV + 1, INF);

  dp[0] = 0;

  size_t whole_sum = 0;

  for (int i = 0; i < N; ++i) {
    size_t weight, value;
    std::cin >> weight >> value;
    whole_sum += value;

    for (int already_in = whole_sum - value; already_in >= 0; --already_in) {
      dp[already_in + value] =
          std::min(dp[already_in + value], dp[already_in] + weight);
    }
  }

  size_t answer = 0;
  for (int i = 0; i < dp.size(); ++i) {
    if (dp[i] <= W) {
      answer = i;
    }
  }

  std::cout << answer << "\n";
}

void warp() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
}

int main() {
  warp();
  solve();
}


Measured memory_bytes: 3980
#include <cstdio>

int main(int argc, char const *argv[]) {
  int A, B, result = 0;
  
  scanf("%d %d", &A, &B);

  for (int i = 0; i < 2; ++i) {
    if (A >= B) {
      result += A;
      --A;
    } else {
      result += B;
      --B;
    }
  }

  printf("%d\n", result);
  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int sum[100000];

int main() {
   int H, W, D;
   cin >> H >> W >> D;
   vec<pair<int, int>> p(H*W+10);
   rep (i, H) {
      rep (j, W) {
         int A;
         cin >> A;
         p[A] = {i, j};
      }
   }

   for (int i = D+1; i <= H*W; i++) {
      sum[i] += sum[i-D] + abs(p[i].first - p[i-D].first) + abs(p[i].second - p[i-D].second);
      debug(sum[i])
   }

   int Q;
   cin >> Q;
   while (Q--) {
      int l, r;
      cin >> l >> r;
      cout << sum[r] - sum[l] << endl;
   }

   return 0;
}

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

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

using namespace std;

int A[2 * 100000];
int B[2 * 100000];

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

  vector<vector<int>> edges(N);
  REP(i, M) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    edges[A].push_back(B);
    edges[B].push_back(A);
  }

  map<int, int> prev;
  prev[0] = -1;

  queue<int> que;
  que.push(0);

  while (!que.empty()) {
    int here = que.front();
    que.pop();

    for (int there : edges[here]) {
      if (prev.count(there) > 0) {
        continue;
      }
      prev[there] = here;
      que.push(there);
    }
  }

  bool ok = true;
  for (int i = 2; i < N; ++i) {
    if (prev.count(i) == 0) {
      ok = false;
      break;
    }
  }
  if (!ok) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; ++i) {
    cout << prev[i] + 1 << endl;
  }
}


Measured memory_bytes: 14440
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, a int
	fmt.Scan(&n)
	s := []int{0}

	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		s = append(s, s[len(s)-1]+a)
	}
	sort.Ints(s)
	ans := 0
	cnt := 0
	for i := 1; i < len(s); i++ {
		if s[i-1] == s[i] {
			cnt++
		} else {
			cnt = 0
		}
		ans += cnt
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        String[] input = Console.ReadLine().Split();
        long A = long.Parse(input[0]);
        long B = (long)(decimal.Parse(input[1])*100);       
        Console.WriteLine(A*B/100);
    }
}

Measured memory_bytes: 27372
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> grid(H, vector<int> (W, -1));
  queue<pair<int, int>> black;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      char c; cin >> c;
      if(c == '#') {
        grid.at(i).at(j) = 0;
        black.push(make_pair(i, j));
      }
    }
  }
  vector<int> dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
  while(!black.empty()) {
    auto st = black.front();
    black.pop();
    for(int i = 0; i < 4; i++) {
      int px = st.first + dx.at(i);
      int py = st.second + dy.at(i);
      if(px >= 0 && px < H && py >= 0 && py < W) {
        if(grid.at(px).at(py) == -1) {
          grid.at(px).at(py) = grid.at(st.first).at(st.second) + 1;
          black.push(make_pair(px, py));
        }
      }
    }
  }
  int count = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      count = max(count, grid.at(i).at(j));
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 12432
n,k=map(int,input().split())
S=[]

for i in range(n):
    a,b=map(int,input().split())
    S.append((a,b))
    
S.sort()

for tup in S:
    k-=tup[1]
    if k<=0:
        print(tup[0])
        break

Measured memory_bytes: 16944
import sys
from collections import Counter
ct = {i:0 for i in range(1,5)}
for i in range(3):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    ct[a] += 1
    ct[b] += 1
ct2 = Counter(ct.values())
if ct2[1] == 2 and ct2[2] == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38256
import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 n=sum(e.count(s)for s in e)-5
 print([['null','straight'][e[4]-e[0]==4 or e[0]*10==e[1]],'one pair','two pair','three card','full house',0,'four card'][n//2])


Measured memory_bytes: 5604
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;
typedef long long ll;

ll X, Y;

int main(void) {
  cin >> X >> Y;
  cout << (abs(X - Y) > 1 ? "Alice" : "Brown") << endl;

  return 0;
}


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

int main() {
    string S;
    cin >> S;

    map<string, string> w;
    w["Sunny"] = "Cloudy";
    w["Cloudy"] = "Rainy";
    w["Rainy"] = "Sunny";

    cout << w[S] << endl;

}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = INF;
    int num;
    
    for (int i = -100; i <= 101; i++) {
        int flag = 0;
        for (int j = 0; j < n; j++) {
            if (p[j] == i) {
                flag = 1;
                break;
            }
        }
        if (flag == 1) continue;
        if (ans > abs(x - i)) {
            ans = abs(x - i);
            num = i;
        }
    }

    cout << num << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  int n;
  cin >> n;
  map<ll,ll> mp;
  vector<ll> a(n);
  rep(i,n) { cin >> a[i]; ++mp[a[i]]; }
  ll sum = 0;
  for(auto v : mp) {
    ll cnt = v.snd;
    sum += ( (cnt * (cnt-1LL)/2LL) );
  }
  rep(i,n) {
    ll ans = sum;
    ll cnt = mp[a[i]];
    if( cnt >= 2 ) {
      ans -= ( ( cnt * (cnt-1LL) ) / 2LL );
      --cnt;
      ans += ( ( cnt * (cnt-1LL) ) / 2LL );
    }
    cout  << ans << endl;
  }
  return 0;
}


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

int main(){
	int n,i[1000],p[1000],q[1000],r[1000],P,Q,R,C;
	while(scanf("%d",&n),n){
		for(int j=0;j<n;j++) scanf("%d%d%d%d",&i[j],&p[j],&q[j],&r[j]);
		scanf("%d%d%d%d",&P,&Q,&R,&C);
		int res=0;
		for(int j=0;j<n;j++) if(!(p[j]>P||q[j]>Q||r[j]>R||((p[j]+r[j])*4+q[j]*9>C))){
				printf("%d\n",i[j]);
				res=1;
		}
		if(res==0) printf("NA\n");
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, m;
    cin>>n>>m;
    vector<ll> a(n);
    f(i, n) cin>>a[i];
    s(a);
    vector<pair<ll, ll> > v;
    f(i, m){
        ll b, c;
        cin>>b>>c;
        v.pb({c, b});
    }
    rs(v);
    int l = 0;
    f(i, m){
        ll to = v[i].first;
        ll can = v[i].second;
        while(a[l] >= to && l < n) l++;
        if(l == n) break;
        while(can > 0 && l < n && a[l] < to){
            a[l] = to;
            can--;
            l++;
        }
    }
    ll ans = 0ll;
    f(i, n) ans += a[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<stdlib.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<math.h>
using namespace std;

int main()
{
   
   int solution=1, counting, x, maximium=0;
   cin>>x;
   for(int i=x;i>0;i--)
   {
       counting=0;
       int temp=i;
       while(temp%2==0)
       {
           temp/=2;
           counting++;
       }
       if(counting>maximium)
       {
           maximium=counting;
           solution=i;
       }
   }
    cout<<solution<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a[3][3],m[3][3], i, j, k, n, found=0;

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

    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) {
            m[i][j] = 0;
            for(k=0; k<n; k++) {
                if(a[i][j] == b[k]) {
                    m[i][j]=1;
                    break;
                }
            }
        }
    }
    for(i=0; i<3; i++){
        if(m[i][0] +m[i][1] +m[i][2] ==3) found = 1;
        if(m[0][i] +m[1][i] +m[2][i] ==3) found = 1;
    }
    if(m[0][0] +m[1][1] +m[2][2] ==3) found = 1;
    if(m[2][0] +m[1][1] +m[0][2] ==3) found = 1;
    if(found) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int counter[200005];
int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)
    {
        cin >> a[i];
        counter[a[i]]++;
    }
    vector<int> temp;
    int kind = 0;
    for (auto s : counter)
    {
        if(s!=0)
        {
            temp.push_back(s);
            kind++;
        }
    }
    sort(temp.begin(),temp.end());
    ll ans = 0;
    rep(i, kind-k)
    {
        ans += (ll)temp[i];
    }
    cout << ans << endl;
    
}

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

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  char a[100][100] = {{'#'}};
  vector<int> rows(h, 1);
  vector<int> cols(w, 1);

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        rows[i] = 0;
        cols[j] = 0;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    if (rows[i]) continue;
    for (int j = 0; j < w; j++) {
      if (cols[j]) continue;

      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# input1 = list(map(int, (input().split())))
# input2 = list(map(int, (input().split())))
N = int(input())
input2 = []
for i in range(N):
    input2.append(input())

jisyo = {}

for a in input2:
    if a not in jisyo:
        jisyo[a] = 1
    else:
        jisyo[a] += 1

result = sorted(jisyo.items(), key=lambda x: x[1], reverse=True)

m = result[0][1]
liststr = []
for r in result:
    if m != r[1]:
        break
    liststr.append(r[0])

liststr.sort()

for a in liststr:
    print(a)


Measured memory_bytes: 47248
n,k = map(int,input().split())
MOD = 10**9 + 7

def pk(x,n,mod):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x % mod
        x = x ** 2 % mod
        n //= 2

    return K * x % mod


yaku = [0]*(k+1)
for i in range(1,k+1):
    yaku[i] = k // i
am = [0]*(k+1)
for i in range(1,k+1):
    am[i] = pk(yaku[i],n,MOD)
    
newam = [0]*(k+1)
for i in range(k,0,-1):
    newam[i] = am[i]
    for j in range(i*2,k+1,i):
        newam[i] = ((newam[i] + MOD) - newam[j]) % MOD
        
ans = 0
for i in range(1,k+1):
    ans = (ans + (newam[i]*i)) % MOD
    
print(ans)

Measured memory_bytes: 76408
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int w, n;
	cin >> w >> n;
	vector<P> Vec(n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d,%d", &Vec[i].first, &Vec[i].second);
	}
	vector<int> start(w);
	for(int i = 0; i < w; ++i)
	{
		start[i] = i + 1;
	}
	vector<int> end(w);
	for(int i = 0; i < w; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			if(start[i] == Vec[j].first)
			{
				start[i] = Vec[j].second;
			}
			else if(start[i] == Vec[j].second)
			{
				start[i] = Vec[j].first;
			}
		}
		end[start[i] - 1] = i + 1;
	}
	for(int i = 0; i < w; ++i)
	{
		cout << end[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
 using namespace std;
 int main()
 {
 int k;
  cin>>k;
  string s;
  cin>>s;
  int n=s.length();
  if(k>=n)
  cout<<s;
  else{
  string d=s.substr(0,k);
  d+="...";
  cout<<d;
  }
     
     
 }

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

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

int main(void) {
    int h;
    int w;
    cin >> h >> w;
    Vec<Vec<char> > table(h + 2, Vec<char>(w + 2));
    Vec<Vec<int> > res(h + 2, Vec<int>(w + 2, 0));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> table[i][j]; 
            if (table[i][j] == '#') {
                for (int k = 0; k < 8; k++) {
                    res[i + dy[k]][j + dx[k]]++;
                }
            }
        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (table[i][j] == '#') {
                cout << '#';
            } else {
                cout << res[i][j];
            }
        }
        cout << 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;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<pii,int>;


int main(){
    ll x;
    cin >> x;
    ll n = 100,cnt = 0;
    while(x > n){
        n *= 1.01;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3636
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
ans=[0 for i in range(n)]
s2=sum(a[1::2])
x0=s-s2*2
ans[0]=x0
for i in range(1,n):
    ans[i]=2*a[i-1]-ans[i-1]
print(*ans)



Measured memory_bytes: 14028
import sys


Q = int(input())
pair = []

MAX = 0
for i in range(Q):
    l, r = map(int, input().split())
    MAX = max(MAX, l, r)
    pair.append((l, r))

N = 101010
N = 25
N = MAX + 1
is_prime = [1 for i in range(N)]

is_prime[0] = is_prime[1] = 0

# sieve
for i in range(2, N):
    if not is_prime[i]:
        # 0, 1, 4, 6, 9, ...
        continue
    for j in range(i*2, N, i):
        #print(j)
        is_prime[j] = 0
#print('sieve')
#print(is_prime)

# 2017-like
a = [0 for i in range(N)]
for i in range(N):
    if i % 2 == 0:
        continue
    if is_prime[i] and is_prime[(i+1) // 2]:
        a[i] = 1
#print('2017')
#print(a)

# accum
s = [0]
for i, n in enumerate(a):
    s.append(s[i] + n)
s.pop(0)
#print('accum')
#print(s)

# Query
#print(pair)
#print('ANS')
for l, r in pair:
    print(s[r] - s[l-1])



Measured memory_bytes: 27048
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    VI v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    sort(ALL(v), greater<int>());
    ll ans = 0;
    n--;
    ans += v[0];
    n--;
    int cur = 1;
    while (n > 0)
    {
        ans += v[cur];
        n--;
        if (n == 0)
            break;
        ans += v[cur];
        n--;
        cur++;
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;


int main(){
  ll n;
  cin >> n;
  st s;
  cin >> s;

  vector<vvll> dp(n + 1, vvll(4, vll(1000, 0)));
  dp.at(0).at(0).at(0) = 1;
  rep(i, 0, n)rep(j, 0, 4)rep(k, 0, 1000){
    chmax(dp.at(i + 1).at(j).at(k), dp.at(i).at(j).at(k));
    if(j < 3 && k * 10 + (s.at(i) - '0') < 1000) chmax(dp.at(i + 1).at(j + 1).at(k * 10 + (s.at(i) - '0')), dp.at(i).at(j).at(k));
  }
  ll ans = 0;
  vrep(i, dp.at(n).at(3)) if(i == 1) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 943744